kernl.data.source.serialize.BooleanSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Kernl.Runtime Show documentation
Show all versions of Kernl.Runtime Show documentation
Kernl: A Kotlin Symbol Processing (KSP) library for automatic repository generation.
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
}
}