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

io.github.binaryfoo.decoders.annotator.BackgroundReading.kt Maven / Gradle / Ivy

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

import io.github.binaryfoo.decoders.apdu.APDUCommand
import io.github.binaryfoo.res.ClasspathIO
import org.yaml.snakeyaml.Yaml
import kotlin.collections.mapOf

/**
 * Some english description for each field. From a set of .yaml files.
 */
class BackgroundReading {

    companion object {

        @JvmStatic fun readingFor(apdu: APDUCommand): Map? {
            return apduDescriptions["$apdu"]
        }


        @JvmStatic fun readingFor(field: String): Map? {
            return descriptions["$field"]
        }

        private val apduDescriptions: Map> by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            @Suppress("UNCHECKED_CAST")
            (Yaml().load(ClasspathIO.open("apdus.yaml")) as Map>)
        }

        private val descriptions: Map> by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            @Suppress("UNCHECKED_CAST")
            (Yaml().load(ClasspathIO.open("descriptions.yaml")) as Map>)
        }

    }
}
fun backgroundOf(short: String, long: String? = null): Map = mapOf("short" to short, "long" to long)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy