title: Serialize/deserialize structure to binary packet
body: <p>I do some embedded coding and quite frequently have to parse binary packets of data.
  They are usually pretty simple, so I wrote parsers by hand. Unfortunately I have to do it over and over for slightly different protocols which is dull and error-prone.</p>
  
  <p>Packets look something like this:</p>
  
  <pre><code>| startByte | size | datadatadata | checksum |
  </code></pre>
  
  <p>Data can have it's own structure (which I would also like to serialize).</p>
  
  <p>So I thought, maybe there is some simple way of doing it? 
  Ideally I want to be able to write packet format in the class, make an object of that class and serialize it into buffer. And deserialize it, of course.</p>
  
  <p>What are the difficulties:</p>
  
  <ul>
  <li>Packets may have different length (but length is either a field in the packet or a constant).</li>
  <li>Packets contain some fields which must be calculated (like CRC or checksum).</li>
  <li>Packets are received one byte at time and can be corrupted, so deserialization should be able to find valid packet.</li>
  <li>It's an embedded code for microcontroller, so I'm restricted to C++ without fancy stuff (like Boost or heavy classes from standart library).</li>
  </ul>
  
  <p>So, my question is:</p>
  
  <ul>
  <li>Is there anything ready-to-use for my case?</li>
  <li>If there is not, should I try and build it myself? If so, in what direction should I think (like, lexers, parser generators or something else)?</li>
  </ul>