diff --git a/common/src/commonMain/kotlin/entity/Snowflake.kt b/common/src/commonMain/kotlin/entity/Snowflake.kt index a7b38d4270f..205e98c820d 100644 --- a/common/src/commonMain/kotlin/entity/Snowflake.kt +++ b/common/src/commonMain/kotlin/entity/Snowflake.kt @@ -214,14 +214,10 @@ public value class Snowflake(public val value: ULong) : Comparable { } internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor = ULong.serializer().descriptor - - override fun deserialize(decoder: Decoder): Snowflake = - Snowflake(decoder.decodeInline(descriptor).decodeLong().toULong()) - - override fun serialize(encoder: Encoder, value: Snowflake) { - encoder.encodeInline(descriptor).encodeLong(value.value.toLong()) - } + private val delegate = ULong.serializer() + override val descriptor: SerialDescriptor = delegate.descriptor + override fun deserialize(decoder: Decoder): Snowflake = Snowflake(delegate.deserialize(decoder)) + override fun serialize(encoder: Encoder, value: Snowflake) = delegate.serialize(encoder, value.value) } } diff --git a/common/src/commonMain/kotlin/entity/optional/OptionalSnowflake.kt b/common/src/commonMain/kotlin/entity/optional/OptionalSnowflake.kt index ab2125a1e48..197b15e8638 100644 --- a/common/src/commonMain/kotlin/entity/optional/OptionalSnowflake.kt +++ b/common/src/commonMain/kotlin/entity/optional/OptionalSnowflake.kt @@ -3,7 +3,6 @@ package dev.kord.common.entity.optional import dev.kord.common.entity.Snowflake import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -91,14 +90,15 @@ public sealed class OptionalSnowflake { } internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor = ULong.serializer().descriptor + private val delegate = Snowflake.serializer() - override fun deserialize(decoder: Decoder): OptionalSnowflake = - Value(Snowflake(decoder.decodeInline(descriptor).decodeLong().toULong())) + override val descriptor: SerialDescriptor = delegate.descriptor + + override fun deserialize(decoder: Decoder): OptionalSnowflake = Value(delegate.deserialize(decoder)) override fun serialize(encoder: Encoder, value: OptionalSnowflake) = when (value) { Missing -> Unit // ignore value - is Value -> encoder.encodeInline(descriptor).encodeLong(value.value.value.toLong()) + is Value -> delegate.serialize(encoder, value.value) } } }