def deserialize(self, str): """ unpack serialized message in str into this message instance :param str: byte array of serialized message, ``str`` """ try: if self.dim is None: self.dim = None end = 0 start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) self.dim = [] for i in range(0, length): val1 = std_msgs.MultiArrayDimension() start = end end += 4 (length,) = _struct_I.unpack(str[start:end]) start = end end += length if python3: val1.label = str[start:end].decode('utf-8') else: val1.label = str[start:end] _x = val1 start = end end += 8 (_x.size, _x.stride,) = _get_struct_2I().unpack(str[start:end]) self.dim.append(val1) start = end end += 4 (self.data_offset,) = _get_struct_I().unpack(str[start:end]) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill
def deserialize_numpy(self, str, numpy): """ unpack serialized message in str into this message instance using numpy for array types :param str: byte array of serialized message, ``str`` :param numpy: numpy python module """ try: if self.layout is None: self.layout = std_msgs.MultiArrayLayout() end = 0 start = end end += 4 (length, ) = _struct_I.unpack(str[start:end]) self.layout.dim = [] for i in range(0, length): val1 = std_msgs.MultiArrayDimension() start = end end += 4 (length, ) = _struct_I.unpack(str[start:end]) start = end end += length if python3: val1.label = str[start:end].decode('utf-8') else: val1.label = str[start:end] _x = val1 start = end end += 8 ( _x.size, _x.stride, ) = _get_struct_2I().unpack(str[start:end]) self.layout.dim.append(val1) start = end end += 4 (self.layout.data_offset, ) = _get_struct_I().unpack( str[start:end]) start = end end += 4 (length, ) = _struct_I.unpack(str[start:end]) pattern = '<%si' % length start = end end += struct.calcsize(pattern) self.data = numpy.frombuffer(str[start:end], dtype=numpy.int32, count=length) return self except struct.error as e: raise genpy.DeserializationError(e) #most likely buffer underfill