From be601713fc9895ddeab1796e660a31bf230ade8e Mon Sep 17 00:00:00 2001 From: "Peter Gulko (zTrap)" Date: Tue, 24 Oct 2023 12:31:57 +0300 Subject: [PATCH] Delegate OptionalSnowflake serialization to Snowflake serializer --- .../kotlin/entity/optional/OptionalSnowflake.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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) } } }