I think you will not find an easy to use serializer that matches the custom protocol you are looking at. But it looks like a set of primitives that you have (int, bool + size) are simple enough to be able to write your own decoder / encoder. It simply generates C / C ++ code based on the received message. It should be a fairly simple task to generate compilation code with such a description. This should be an automatic generation performed at compile time, similar to what protobuf / Corba does.
Example: from specification:
class Message{ int msg_num : 7 int dest_addr : 4 bool SRR : 1 bool IDE : 1 int source_addr : 6
the converter could write a function with a body similar (abstract notation and assuming MSB):
Decoder:
m = new Message() { long long val = 0 for(int i=0; i<7; i++) { val <<= 8 val += nextByte() } m.msg_num = val } { long long val = 0 for(int i=0; i<4; i++) { val <<= 8 val += nextByte() } m.dest_addr = val } { int val = nextByte() m.SRR = val } { int val = nextByte() m.IDE = val } { long long val = 0 for(int i=0; i<6; i++) { val <<= 8 val += nextByte() } m.source_addr = val }
encoder:
{ long long val = m.msg_num for(int i=0;i<7;i++) { writeByte(val & 0xFF) val >>= 8 } } { long long val = m.dest_addr for(int i=0;i<4;i++) { writeByte(val & 0xFF) val >>= 8 } } ....
This is pretty easy to create and the easiest way to make sure the encoding is normal.
source share