commonMain.model.DurationSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sponsorblock-jvm Show documentation
Show all versions of sponsorblock-jvm Show documentation
Coroutine based client for Lavalink (Kotlin and Java)
The newest version!
package dev.schlaubi.lavakord.plugins.sponsorblock.model
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
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration
internal object DurationSerializer : KSerializer {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(
"com.github.topi314.sponsorblock.plugin.protocol.serialization.DurationonAsMilliseconds", PrimitiveKind.LONG
)
override fun deserialize(decoder: Decoder): Duration = decoder.decodeLong().toDuration(DurationUnit.MILLISECONDS)
override fun serialize(encoder: Encoder, value: Duration): Unit = encoder.encodeLong(value.inWholeMilliseconds)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy