}
def from_bytes(self, data):
+ offset = self._parse_header(data=data)
+ packet = data[offset:offset + self['length']]
+ if len(packet) < self['length']:
+ raise ValueError('packet too short ({} < {})'.format(
+ len(packet), self['length']))
+ offset += self['length']
+ return offset
+
+ def _parse_header(self, data):
packet_tag = data[0]
offset = 1
always_one = packet_tag & 1 << 7
length_data = data[offset: offset + length_bytes]
offset += length_bytes
self['length'] = _struct.unpack(length_format, length_data)[0]
- packet = data[offset:offset + self['length']]
- if len(packet) < self['length']:
- raise ValueError('packet too short ({} < {})'.format(
- len(packet), self['length']))
- offset += self['length']
return offset
def to_bytes(self):