<kotlinx-serialization 1.4.0-RC> makes unsigned ty...
# serialization
i
kotlinx-serialization 1.4.0-RC makes unsigned types a stable feature, so explicit opt-in is no longer required: https://github.com/Kotlin/kotlinx.serialization/pull/1962 But why the core interfaces such as Encoder/Decoder still don’t have specific
encodeU...
/
decodeU...
methods for unsigned types, so generic
encodeSerializable…
/
decodeSerializable…
methods that require explicit serializer for the value have to be used when dealing with unsigned values?
i
does it mean that unsigned types are still considered as higher-level abstraction (such as value/inline classes) to be considered as “primitives” and handled equally with other primitive types such as Byte, Boolean, Int, Short, Long, String, etc? I’m asking, because I developed encoder/decoder for the custom binary format that supports unsigned types and that map nicely to Kotlin’s own unsigned types, but I have to treat unsigned values specially (unlike primitive types), e.g. here:
Copy code
override fun <T> decodeSerializableElement(
    descriptor: SerialDescriptor,
    index: Int,
    deserializer: DeserializationStrategy<T>,
    previousValue: T?,
): T = when (descriptor.getElementDescriptor(index).serialName) {
    "kotlin.UShort" -> parser.parseUINT16().toUShort() as T
    "kotlin.UInt" -> parser.parseUINT32().toUInt() as T
    "kotlin.ULong" -> parser.parseUINT64().toULong() as T
    else -> super.decodeSerializableElement(descriptor, index, deserializer, previousValue)
}