Deserialize byte/char array into struct

I am building a patch editor for a 90s synth (Kawai K5000) using Juce. Usual midi CC stuff is working great for supported parameters. Now, I am getting into the nasty world of sysex. First step is to be able to parse a sysex dump and populate a data structure that represents a patch. I couldn’t find options in Juce that could help me with this, basically with deserializing the sysex dump (maybe I am looking at the wrong places). Since the data will have some variable arrays, I am definitely not looking for a magic bullet. I understand that I need to orchestrate the deserialization. If I could get some pointers on deserializing parts of the sysex dump into structures (either directly in Juce or in C++) that will be super helpful. I am a C++ rookie but am very comfortable in C#.

Simply

struct foo{int32_t a, b, c;};
foo* bar = reinterpret_cast<foo*>(sysexmemptr);
DBG(bar->b);

You also can declare plain c arrays with as members for variable sized arrays:

struct baz{int32_t numFoos; foo foos[];};

You probably want to do bounds checks before accessing the data:

if(bar + sizeof(foo) <= xyz) ...

The dude who wrote the sysex serializer at the other end 25 years ago probably did it the same way in the mcu.

Hope that’s what you actually meant!

Edit: you could also use a MemoryInputStream to read into instances of these structs to simplify the bounds checks.

1 Like

This is perfect. Makes a lot of sense :). I have obviously been overthinking it. Gonna try this out today. Thanks!

MemoryInputStream worked delightfully well. Thanks :slight_smile: