On Tue, Jul 1, 2014 at 8:01 AM, Markus Teich <markus.te...@stusta.mhn.de> wrote: > Rob wrote: >> You've got alignment issues here - msg will be aligned to support any >> type (as malloc's interface specifies) so msg+1 will most likely be on >> an odd address, one byte off a highly aligned address. This means if >> your struct contains anything other than chars, you'll have UB. This is >> fine on x86, which allows unaligned access with a performance penalty >> but on something like an ARM machine you'll have issues. > > Heyho, > > so if every field in the message is a multiple of 4 bytes long, this should > fix > the problem? In this case I would just make op an uint32_t and htonl it before > sending, ntohl after receiving.
It may be worth taking a look at capnproto as I mentioned above if you haven't yet. It's taken a very similar approach to the problem, and come up with a rather low-suck solution. Messages are all aligned to 64-bit words and sent that way over the wire, with an optional lightweight packing format to reduce message sizes. There are C bindings in a mostly-working state. You don't need to touch C++ except to compile their protocol format, which you shouldn't have to do most of the time. The only thing from your strawman that capnproto doesn't do directly in a similarly simple manner is message signing, and it's not hard to imagine adding it. That said, I think your strawman is great, and I'm not trying to shoot it down -- just pointing in the direction of similar work that might be inspiring or might save you some effort. > > --Markus >