Ahmed Mourad
04/02/2020, 4:17 PMrusshwolf
04/02/2020, 4:42 PMAhmed Mourad
04/02/2020, 7:36 PMAbstractEncoder/Decoder
that would convert to and from a List<Any?>
where would i instantiate and retrieve the list instance from? and what does beginning and ending a structure mean?
class ListEncoder : AbstractEncoder() {
override fun beginStructure(
descriptor: SerialDescriptor,
vararg typeSerializers: KSerializer<*>
): CompositeEncoder {
// What to do here?
}
override fun encodeString(value: String) {
[list???].add(value) // Where to instantiate list
}
...
}
class ListDecoder : AbstractDecoder() {
override fun beginStructure(
descriptor: SerialDescriptor,
vararg typeSerializers: KSerializer<*>
)CompositeDecoder {
// What to do here?
}
override fun decodeString(): String {
[list???].get(0) // Where to retrieve list from
}
...
}
russhwolf
04/02/2020, 7:59 PMrusshwolf
04/02/2020, 8:01 PMbeginStructure()
that you can then add to in encode()
. For decode()
, you could supply the existing list to the decider and then read from it.Ahmed Mourad
04/02/2020, 8:38 PMrusshwolf
04/02/2020, 8:40 PMBundle
would be the way to go. Would be reasonably straightforward with the Named
classes. The hard part with Abstract
is managing the key names and I haven't fully wrapped my head around thatAhmed Mourad
04/02/2020, 8:50 PMrusshwolf
04/02/2020, 9:07 PMencodeElement()
but then you have to cache that somewhere so you can reference it in encodeValue()
. Even more awkward on decode()
because you have to do your own counting. It's frustrating because the `CompositeEncoder`/`Decoder` APIs include the descriptor which would make this much easier but they aren't overrideableAhmed Mourad
04/02/2020, 10:15 PMencodeElement()
method but didn't find a similar one for the decoder so i dismissed it, looks like we have to do some weird stuff to get this to work lol .
Not sure why those are final or why NamedEncoders/Decoders were made internal though, the lack of docs make this even more frustrating.Ahmed Mourad
04/03/2020, 9:09 PMSerialDescriptor#elementCount
always returns 1 for lists, which makes sense as it doesn't know how many element this list has, but it makes it unreliable if you want to check when to stop incrementing the index and just return -1.russhwolf
04/03/2020, 9:10 PMrusshwolf
04/03/2020, 9:12 PMAhmed Mourad
04/03/2020, 9:28 PM$size
as key to avoid collisions for StructureKind LIST/MAP, works fine for now.