io.github.binaryfoo.decoders.bit.EnumeratedBitStringField.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of emv-bertlv Show documentation
Show all versions of emv-bertlv Show documentation
Some decoders for the data used in EMV credit card transactions.
package io.github.binaryfoo.decoders.bit
import io.github.binaryfoo.bit.*
import java.util.*
/**
* The english description attached to one or more bit positions being set (to 0 or 1) in a single byte.
*/
class EnumeratedBitStringField(field: Set, private val value: String) : BitStringField {
private val field: Set
init {
this.field = TreeSet(field)
}
override fun getPositionIn(bits: Set?): String {
if (bits == null) {
return field.toString(includeValue = true)
}
return field.toHexString(bits.getByteCount()) + " (" + field.toString(field.size > 1) + ")"
}
override fun getValueIn(bits: Set): String? {
return if (field.matches(bits)) value else null
}
override fun getStartBytesOffset(): Int = field.first().byteNumber - 1
override fun getLengthInBytes(): Int = 1
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy