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

commonMain.com.inkapplications.glassconsole.structures.MillisecondsInstantSerializer.kt Maven / Gradle / Ivy

package com.inkapplications.glassconsole.structures

import kotlinx.datetime.Instant
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

internal class MillisecondsInstantSerializer: KSerializer {
    private val delegate = Long.serializer()
    override val descriptor: SerialDescriptor = delegate.descriptor

    override fun deserialize(decoder: Decoder): Instant {
        return Instant.fromEpochMilliseconds(decoder.decodeSerializableValue(delegate))
    }

    override fun serialize(encoder: Encoder, value: Instant) {
        encoder.encodeSerializableValue(delegate, value.toEpochMilliseconds())
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy