Is there any stable way of serializing into a ByteArray without any significant size overhead? Basically looking for an alternative to Android Parcelable.
j
jw
08/27/2023, 11:10 PM
Depends on the data, really. Is it key-heavy and value-light? Proto. Is it key-light and value-heavy? Maybe cbor. Custom format also is a possibility if you know the structure a bit.
a
Arkadii Ivanov
08/27/2023, 11:12 PM
Is it possible to avoid keys completely? Just encode values in order, and then decode in the same order.
Also, could you please point me on custom formats?
And I would need this in a library, so looking for stable solutions.
l
Landry Norris
08/28/2023, 12:53 AM
How do you plan on handling new/removed fields without keys? If you can ignore those cases, you may be able to create a custom serializer that appends to a ByteArray for each field.
h
hfhbd
08/28/2023, 8:16 AM
How you you plan to deserialize the data? Do you need a delimiter? Otherwise, you could use a fixed length format. This requires to serialize the values in order and you need to handle empty values/new attributes with care.
Thanks Adam, that Efficient binary format looks like what I need. As I'm looking for an alternative for Android Parcelable for state preservation, I don't care about backward or forward compatibility.
Though, AbstractEncoder is not stable for inheritance, so most likely I won't be able to use it in a library. Would be nice to have that in kotlinx-serialization as a stable solution. But thaks anyway.