Hi, someone told me to ask here about serializatio...
# serialization
m
Hi, someone told me to ask here about serialization; I have several dozen formats of packets to send over USB, and I'm unsure how to define the classes to easily (de-)serialize them to/from a ByteArray/UByteArray send them over libusb from Kotlin/Native. How would I approach this?
e
are you talking about the USB packets themselves, or your own custom data to be sent within them?
m
custom data following specific formats required by the device connected, i.e. the protocol just above the USB protocol.
e
ah. unfortunately none of the existing formats supported by kotlinx.serialization are suitable for that
it should be doable, I created a super-basic binary format here: https://gist.githubusercontent.com/ephemient/65a3ee700f020661858c89b5648a2772/raw/29865d80af61fd965d54cf521f1bd54f0d65e3db/SimpleBinaryFormat.kt I imagine you'll need to add more control over packing and port it to native (possible with okio)
m
So what's the recommended way to deal with situations like this? I don't know how to define struct-like classes from kotlin, and I'd like to avoid defining several dozen structs in a cinterop def file
e
hah, just noticed auto-correct turned suitable into adorable above
personally I'd pass on kotlinx.serialization for this and just build some custom code generation based on an external protocol definition
m
Hmm, that sounds fairly tricky to implement inheritance with. Are there any projects you recommend I look into?