Skip to content

Commit

Permalink
fix: fixed Int128 serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed Oct 11, 2023
1 parent 9419dd8 commit 9c9f7a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]

kotlin = "1.9.0"
koTLVersion = "0.0.13"
koTLVersion = "0.0.14"
kotlinxSerialization = "1.5.0"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package kotl.serialization.int

import kotl.serialization.annotation.TLSize
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.JvmInline

@Serializable
@Serializable(with = Int128.Serializer::class)
public data class Int128(
@TLSize(bits = 128)
public val data: IntArray
Expand All @@ -22,4 +27,35 @@ public data class Int128(
override fun hashCode(): Int {
return data.contentHashCode()
}

public object Serializer : KSerializer<Int128> {

@OptIn(ExperimentalSerializationApi::class)
override val descriptor: SerialDescriptor = SerialDescriptor(
serialName = "kotl.serialization.int.Int128",
original = Int128Serializable.serializer().descriptor
)

override fun deserialize(decoder: Decoder): Int128 {
val serializable = decoder.decodeSerializableValue(
deserializer = Int128Serializable.serializer()
)
return Int128(serializable.data)
}

override fun serialize(encoder: Encoder, value: Int128) {
val serializable = Int128Serializable(value.data)
encoder.encodeSerializableValue(
serializer = Int128Serializable.serializer(),
value = serializable
)
}
}
}

@Serializable
@JvmInline
private value class Int128Serializable(
@TLSize(bits = 128)
val data: IntArray
)

0 comments on commit 9c9f7a6

Please sign in to comment.