commonMain.at.asitplus.wallet.mdl.IsoSexEnumSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mobiledrivinglicence Show documentation
Show all versions of mobiledrivinglicence Show documentation
Use data representing Mobile Driving Licences as a ISO 18013-5 Credential
package at.asitplus.wallet.mdl
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
object IsoSexEnumSerializer : KSerializer {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("IsoSexEnum?", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: IsoSexEnum?) {
value?.let { encoder.encodeInt(it.code) }
}
override fun deserialize(decoder: Decoder): IsoSexEnum? {
return IsoSexEnum.parseCode(decoder.decodeInt())
}
}