All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.binaryfoo.decoders.bit.EnumeratedBitStringField.kt Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
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