Binary message formatter
Passing messages across computers and/or microcontrollers with different architectures can be a real pain (endianness...). So do not fall into NIH / reinventing the wheel traps but keep standing on the shoulders of giants! Several message serialization protocols exist.


BSON
MessagePack
Protocol Buffers
CBOR (Concise Binary Object Representation)
...


Several implementations of such protocols exist (even for Arduino).

I suggest to have a look in a search engine for such protocols and add Arduino.

I've found:


BSON


ardubson

MessagePack


msgpack-mcu
arduino_msgpack
MsgPacketizer
msgpack-arduino
ArduinoJSON serializeMsgPack / deserializeMsgPack

Protocol Buffers


nanopb

CBOR


Arduino-Cbor

...


PS: You might read https://scottlocklin.wordpress.com/2017/04/02/please-stop-writing-new-serialization-protocols/
and have a look at https://xkcd.com/927/
Just choose a giant compatible with your requirements ;-)

https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats may help