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

io.github.binaryfoo.decoders.ByteLabeller.kt Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
package io.github.binaryfoo.decoders

import io.github.binaryfoo.DecodedData
import io.github.binaryfoo.Decoder
import io.github.binaryfoo.bit.*
import io.github.binaryfoo.bit.EmvBit

import java.util.ArrayList

/**
 * Decode and label bits in a string according to the EMV spec convention.
 */
public class ByteLabeller : Decoder {
    override fun decode(input: String, startIndexInBytes: Int, session: DecodeSession): List {
        val decoded = ArrayList()
        for (bit in fromHex(input)) {
            val byteIndex = startIndexInBytes + bit.byteNumber - 1
            decoded.add(DecodedData.primitive(bit.toString(), "", byteIndex, byteIndex + 1))
        }
        return decoded
    }

    override fun validate(input: String?): String? {
        if (input != null && (input.length() % 2) != 0) {
            return "Must be an even number of characters"
        }
        return null
    }

    override fun getMaxLength(): Int = Integer.MAX_VALUE
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy