'Parse a fragment of data and call back for any completed packets.'

def parse(self, data):

    self._readahead.write(data)
    buf = self._readahead.getvalue()
    if (len(buf) < 4):
        return
    while (len(buf) >= 4):
        size = int(buf[:4], 16)
        if (size == 0):
            self.handle_pkt(None)
            buf = buf[4:]
        elif (size <= len(buf)):
            self.handle_pkt(buf[4:size])
            buf = buf[size:]
        else:
            break
    self._readahead = BytesIO()
    self._readahead.write(buf)
