Structs in C have both host/compiler-specific padding and host endianness. When communicating over a network, the struct must be framed (prefix length or frame character), packed (this means getting rid of the padding) and ordered according to a common endianness. On the reverse, the bytestream must then be read, message framed, re-ordered, and unpacked into a struct.
It is important that the structs that are used as interfaces have fixed sizes, that is uint32_t
and not int
.
Prefix length message frames with big-endian ordered bytes is probably the most popular style.
We should have some C or Rust code demonstrating this procedure.
In most cases, just use protocol buffers or GRPC. Or go all the way to HTTP with just RESTful methods! https://sbdevel.wordpress.com/2009/12/17/the-case-rpc-vs-messaging/