Ian
08/18/2020, 4:31 PMByteArraySegment
- this is what I've tried (I suspect the issue may be the descriptor
I'm using, but I'm not sure how I should be doing it):
@Serializer(forClass = ByteArraySegment::class)
companion object : KSerializer<ByteArraySegment> {
override val descriptor: SerialDescriptor
get() = ByteArraySerializer().descriptor
override fun serialize(encoder: Encoder, value: ByteArraySegment) {
encoder.encode(ByteArraySerializer(), value.asArray)
}
override fun deserialize(decoder: Decoder): ByteArraySegment {
return ByteArraySegment(decoder.decode(ByteArraySerializer()))
}
}
I've explained the problem in more detail on Reddit but nobody has been able to suggest a solution yet, would greatly appreciate any suggestions.travis
08/19/2020, 2:45 AMByteArray
may be serialized as a "CBOR byte string": https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/formats.md#byte-arrays-and-cbor-data-types
It is written all at once rather than byte-by-byte. It is driven by an annotation. Perhaps a similar approach could be followed for what you're trying to accomplish?
https://github.com/Kotlin/kotlinx.serialization/pull/898
It was integrated directly into the CBOR serialization, not sure how well it will translate to your custom serializer approach; but might provide some hints to help unblock you?