title: how to manage a prefixed byte sequence which identifies your protocol
body: <p>This is related to my question regarding the unification setup (<a href="https://stackoverflow.com/questions/18445861/port-unification-with-persistent-channel">port unification with persistent channel</a>)</p>
  
  <p>I am attempting to send a two byte sequence prefixed to all traffic for my protocol; I am doing this so there is something to sniff in the unification handler when i update to support more than one protocol.</p>
  
  <p>On the client, i have a simple outbound handler at the end of the pipeline that prefixes the ByteBuf with the two protocol identifying bytes, and a simple inbound handler in the front of the server pipeline which will extract them.  I've managed to get this working for small messages.</p>
  
  <p>The subsequent handler in the server queue is a <code>LengthFieldBasedFrameDecoder</code> which I'm using to frame in the incoming traffic (protobuf objects).  What appears to be happening is the client sends a large request, say 5M.  I get a series of 64k buffers that come through the server pipeline, the last one of which passes over the threshold the <code>LengthFieldBasedFrameDecoder</code> is waiting for, it extracts the frame and passes it on for handling -- this happens correctly.</p>
  
  <p>At this point, everything breaks.  From what I can tell, the last 64k buffer from the client contained the rest of the data for the frame, the 2 byte sequence signaling the start of the next request, and then some more content.  I think this data is sitting in the frame decoder, which now will use the two protocol magic bytes as the length of the next frame, which is incorrect, and things break down from there.</p>
  
  <p>The <code>DelimiterBasedFrameDecoder</code> looks like it would work in this case since that two byte sequence will break apart each logical frame/request, but that seems like overkill in this scenario.</p>
  
  <p>Is there some other decoder that would work in this case, or should I stick with the <code>DelimiterBasedFrameDecoder</code>?</p>