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

commonMain.dev.inmo.tgbotapi.utils.TimeSpanAsSecondsSerializer.kt Maven / Gradle / Ivy

Go to download

Core part of tgbotapi with all (and only) required functionality for working with Telegram Bot API

There is a newer version: 23.1.0
Show newest version
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