def unpack(self, buff, offset=0): """Unpack a binary message into this object's attributes. Unpack the binary value *buff* and update this object attributes based on the results. Args: buff (bytes): Binary data package to be unpacked. offset (int): Where to begin unpacking. Raises: Exception: If there is a struct unpacking error. """ def _int2hex(number): return "{0:0{1}x}".format(number, 2) try: unpacked_data = struct.unpack('!6B', buff[offset:offset + 6]) except struct.error as exception: raise exceptions.UnpackException('%s; %s: %s' % (exception, offset, buff)) transformed_data = ':'.join([_int2hex(x) for x in unpacked_data]) self._value = transformed_data
def unpack(self, buff, offset=0): """Unpack a binary message into this object's attributes. Unpack the binary value *buff* and update this object attributes based on the results. Args: buff (bytes): Binary data package to be unpacked. offset (int): Where to begin unpacking. Raises: Exception: If there is a struct unpacking error. """ try: unpacked_data = struct.unpack('!4B', buff[offset:offset + 4]) self._value = '.'.join([str(x) for x in unpacked_data]) except struct.error as exception: raise exceptions.UnpackException('%s; %s: %s' % (exception, offset, buff))