At 19:04 11-08-05 +0000, you wrote: >Hello everybody: > >I am seeking advice about the best practices to design message >structures for MSP430-based systems. I am having some of the problems >described in: >https://mail.millennium.berkeley.edu/pipermail/tinyos-devel/2004-April/0003 38.html > >For instance, on the platform we are working with, initially our >TOS_Msg header had an odd number of bytes. After porting >MultiHopRouter (from tos/lib/Route, by providing a qsort() >implementation) I suppose some things may not work correctly as its >first field in the header is a uint16_t -- so I pad the TOS_Msg header >to an even number of bytes. MultiHopRouter, in turn, also has a 7-byte >header, if the application on top of it starts with a 16-bit field >(...) repeat the same process? > >My conclusion from what I have seen so far is that all protocol layers >should strive to declare even-sized headers, so that their payload >fields are word-aligned... Insights from whoever "been there done >that" are very much appreciated.
I would go for a text based message format. Saves the hassle of writing test tools. Besides that, text based formats can easely be extended. A binary format is fixed and extending it usually means saying bye bye to backward compatibility. If you really need to transfer binary information, you could transmit this using bytes and rebuild the message from it instead of mapping a struct over the input/output buffer. This would make the implementation platform independant: uint16_t r; r=inbuf[0] | inbuf[1]<<8; >PS: While on this topic, I'd like to know if anyone has horror stories >with C bit-fields to share, especially in data that goes directly >through networks or storage. I need to convice a colleague that they >are evil >:-} Look at the Unix snf format. This was used to describe X11 fonts. In the snf format the fonts are stored in bitfields so you couldn't take a font from a little endian to a big endian system. I had to write my own converter to use fonts from a 68k based Unix system on my PC. Luckily the snf format is no longer in use nowadays. Talking about portability and fonts; als take a look at the bdf format which is used for X11 fonts. Its text based.
