hello, Is there a way to convert object to bytearr...
# multiplatform
n
hello, Is there a way to convert object to bytearray using kotlinx.serialization? I am only able to find encodeToString and decodeToString functions.
p
You can transform the string into a bytearray
Iirc protobuf directly has a bytearray output
n
thanks
e
some formats are StringFormat (JSON, Properties), some formats are BinaryFormat (CBOR, Protobuf), and some are neither (HOCON)
c
why is hocon not a string format?
p
It’s explained in the docs, ephemient linked
It does not impose any restrictions on a serialized form or underlying storage, neither it exposes them.
Concrete data types and API for user-interaction are responsibility of a concrete subclass or subinterface
e
Hocon serializes to/deserializes from Config, not String or ByteArray, so it is not StringFormat or BinaryFormat
c
ah interesting.
is that just an example of whats theoretically possible? i mean a config class is not really a serialization format imo.
is mapping from one class to another or mapping from a sql result also a usecase for kotlinx-serialization?
e
I did write a non-String non-Binary SerialFormat recently, https://gist.github.com/ephemient/65a3ee700f020661858c89b5648a2772/209384b9d9168828cbf326b358dfd95c1f29af91, as Parcel is a core part of serialization on Android. but for sql result I think it's more questionable… is that really a read-write format?
c
a sql result is not a read write format, but is a hocon config a read write format?
e
yes, it's effectively equivalent to JSON with some syntax alternatives - which I think kotlinx.serialization is understandably staying out of by just saying "go use the hocon library for the rest"
c
ah makes sense. i thought its just for type safe mapping of hocon config files.