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

kernl.data.source.serialize.BooleanSerializer.kt Maven / Gradle / Ivy

Go to download

Kernl: A Kotlin Symbol Processing (KSP) library for automatic repository generation.

There is a newer version: 0.0.1-beta6
Show newest version
package io.github.mattshoe.shoebox.kernl.data.source.serialize

import java.nio.ByteBuffer

class BooleanSerializer: Serializer {
    private val t = 1.toByte()
    private val f = 0.toByte()

    override fun serialize(data: Boolean): ByteArray {
        return ByteBuffer.allocate(1)
            .put(
                if (data) t else f
            )
            .array()
    }

    override fun deserialize(data: ByteArray): Boolean {
        return ByteBuffer.wrap(data)[0] == t
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy