title: How to Deal with Special Characters in Communication Frames?
body: <p>I am implementing a very simple communication system based in serial transmission and message frames, small, roughly and loosely adapted from <a href="https://en.wikipedia.org/wiki/Modbus" rel="nofollow noreferrer">Modbus</a>, with <code>0x3A</code> as starting byte, <code>0x0D 0x0A</code> sequence as ending bytes.</p>
  
  <p>Most of the action happens when the serial bus detects the <code>0x3A</code> byte, and stops until the <code>0x0D 0x0A</code> sequence is found.</p>
  
  <p>I would wish a little advice about:</p>
  
  <ul>
  <li>How should escape "special ending symbols", such as <code>0x0A</code> and <code>0x0D</code> inside a frame? for example, if one of the data in a frame happens to be equal to <code>0x0A</code> (an address?). </li>
  <li>How should I deal with frames with random raw data, i.e. data included in a frame "as is", without any additional conversion, when the special ending byte happens as data?</li>
  </ul>
  
  <p>I noted ASCII represents digits symbols with the <code>0x30</code> offset, should I do something like that in order to represent raw data, at the obvious expense of losing bytes? Do this have a possible <em>real</em> advantage in here?</p>
  
  <p>Summarizing: Should I stop interpreting the ending bytes as ending bytes and treat all frames as given (predefined or header defined) length?</p>