#!/usr/bin/python
+import re as _re
import subprocess as _subprocess
import struct as _struct
63: 'private',
}
+ _clean_type_regex = _re.compile('\W+')
+
+ def _clean_type(self):
+ return self._clean_type_regex.sub('_', self['type'])
+
def from_bytes(self, data):
offset = self._parse_header(data=data)
packet = data[offset:offset + self['length']]
raise ValueError('packet too short ({} < {})'.format(
len(packet), self['length']))
offset += self['length']
+ method_name = '_parse_{}'.format(self._clean_type())
+ method = getattr(self, method_name, None)
+ if not method:
+ raise NotImplementedError(
+ 'cannot parse packet type {!r}'.format(self['type']))
+ method(data=packet)
return offset
def _parse_header(self, data):