commonMain.dev.inmo.tgbotapi.utils.TimeSpanAsSecondsSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tgbotapi.core-jvm Show documentation
Show all versions of tgbotapi.core-jvm Show documentation
Core part of tgbotapi with all (and only) required functionality for working with Telegram Bot API
package dev.inmo.tgbotapi.utils
import korlibs.time.TimeSpan
import korlibs.time.seconds
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
object TimeSpanAsSecondsSerializer : KSerializer {
override val descriptor: SerialDescriptor
get() = Long.serializer().descriptor
override fun deserialize(decoder: Decoder): TimeSpan {
return decoder.decodeLong().seconds
}
override fun serialize(encoder: Encoder, value: TimeSpan) {
encoder.encodeLong(value.inWholeSeconds)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy