Can anyone clarify whether `ByteArray`s are curren...
# serialization
i
Can anyone clarify whether `ByteArray`s are currently serialized efficiently to CBOR format?
d
i
I'm not sure. I guess I'm asking whether a
ByteArray
will be serialized to raw bytes of the same length, or close to it?
p
Just try it out, its really easy to setup an intellij sample project and play with it
t
My understanding is that
ByteArray
is serialized as type 4 CBOR byte-by-byte (so seemingly sub-optimal, but I haven't benchmarked to confirm). Not sure why that design choice, possibly because in the future they want to support serializing from an unknown length stream of data? PR #898 adds CBOR type 2 serialization of
ByteArray
and serializes the entire
ByteArray
in a single pass (similar to how
String
is serialized).
I guess I'm asking whether a 
ByteArray
 will be serialized to raw bytes of the same length, or close to it?
Could've just been the data used, but in PR 898, it seems type 4 can sometimes take up more bytes than type 2. e.g.
0xCAFE
serialized to
0x383521
for type 4 (default type for kotlinx.serialization) and
0xCAFE
serialized to
0xCAFE
for type 2. https://github.com/Kotlin/kotlinx.serialization/pull/898#discussion_r452625386