jvmMain.kr.jadekim.jext.kotlinx.serialization.serializer.ByteArraySerializer.kt Maven / Gradle / Ivy
package kr.jadekim.jext.kotlinx.serialization.serializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kr.jadekim.common.encoder.BASE64
import kr.jadekim.common.encoder.HEX
object HexByteArraySerializer : KSerializer {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("HexByteArray", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): ByteArray = HEX.decode(decoder.decodeString())
override fun serialize(encoder: Encoder, value: ByteArray) {
encoder.encodeString(HEX.encodeToString(value))
}
}
object Base64ByteArraySerializer : KSerializer {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Base64ByteArray", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): ByteArray = BASE64.decode(decoder.decodeString())
override fun serialize(encoder: Encoder, value: ByteArray) {
encoder.encodeString(BASE64.encodeToString(value))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy