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

xyz.cssxsh.arknights.TimestampSerializer.kt Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
package xyz.cssxsh.arknights

import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import java.time.*

internal object TimestampSerializer : KSerializer {

    fun timestamp(second: Long): OffsetDateTime {
        return OffsetDateTime.ofInstant(Instant.ofEpochSecond(second), ZoneId.systemDefault())
    }

    override val descriptor: SerialDescriptor =
        PrimitiveSerialDescriptor(OffsetDateTime::class.qualifiedName!!, PrimitiveKind.LONG)

    override fun deserialize(decoder: Decoder): OffsetDateTime {
        return timestamp(decoder.decodeLong())
    }

    override fun serialize(encoder: Encoder, value: OffsetDateTime) {
        encoder.encodeLong(value.toEpochSecond())
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy