_TestPrimitiveArray.py
Go to the documentation of this file.
00001 """autogenerated by genpy from genpy/TestPrimitiveArray.msg. Do not edit."""
00002 import sys
00003 python3 = True if sys.hexversion > 0x03000000 else False
00004 import genpy
00005 import struct
00006 
00007 
00008 class TestPrimitiveArray(genpy.Message):
00009   _md5sum = "967cfe360901d64005cbd5a83593b144"
00010   _type = "genpy/TestPrimitiveArray"
00011   _has_header = False #flag to mark the presence of a Header object
00012   _full_text = """int32[] ints
00013 int32[4] fixed_ints
00014 string[] strings
00015 string[4] fixed_strings
00016 
00017 """
00018   __slots__ = ['ints','fixed_ints','strings','fixed_strings']
00019   _slot_types = ['int32[]','int32[4]','string[]','string[4]']
00020 
00021   def __init__(self, *args, **kwds):
00022     """
00023     Constructor. Any message fields that are implicitly/explicitly
00024     set to None will be assigned a default value. The recommend
00025     use is keyword arguments as this is more robust to future message
00026     changes.  You cannot mix in-order arguments and keyword arguments.
00027 
00028     The available fields are:
00029        ints,fixed_ints,strings,fixed_strings
00030 
00031     :param args: complete set of field values, in .msg order
00032     :param kwds: use keyword arguments corresponding to message field names
00033     to set specific fields.
00034     """
00035     if args or kwds:
00036       super(TestPrimitiveArray, self).__init__(*args, **kwds)
00037       #message fields cannot be None, assign default values for those that are
00038       if self.ints is None:
00039         self.ints = []
00040       if self.fixed_ints is None:
00041         self.fixed_ints = [0,0,0,0]
00042       if self.strings is None:
00043         self.strings = []
00044       if self.fixed_strings is None:
00045         self.fixed_strings = ['','','','']
00046     else:
00047       self.ints = []
00048       self.fixed_ints = [0,0,0,0]
00049       self.strings = []
00050       self.fixed_strings = ['','','','']
00051 
00052   def _get_types(self):
00053     """
00054     internal API method
00055     """
00056     return self._slot_types
00057 
00058   def serialize(self, buff):
00059     """
00060     serialize message into buffer
00061     :param buff: buffer, ``StringIO``
00062     """
00063     try:
00064       length = len(self.ints)
00065       buff.write(_struct_I.pack(length))
00066       pattern = '<%si'%length
00067       buff.write(struct.pack(pattern, *self.ints))
00068       buff.write(_struct_4i.pack(*self.fixed_ints))
00069       length = len(self.strings)
00070       buff.write(_struct_I.pack(length))
00071       for val1 in self.strings:
00072         length = len(val1)
00073         if python3 or type(val1) == unicode:
00074           val1 = val1.encode('utf-8')
00075           length = len(val1)
00076         buff.write(struct.pack('<I%ss'%length, length, val1))
00077       for val1 in self.fixed_strings:
00078         length = len(val1)
00079         if python3 or type(val1) == unicode:
00080           val1 = val1.encode('utf-8')
00081           length = len(val1)
00082         buff.write(struct.pack('<I%ss'%length, length, val1))
00083     except struct.error as se: self._check_types(se)
00084     except TypeError as te: self._check_types(te)
00085 
00086   def deserialize(self, str):
00087     """
00088     unpack serialized message in str into this message instance
00089     :param str: byte array of serialized message, ``str``
00090     """
00091     try:
00092       end = 0
00093       start = end
00094       end += 4
00095       (length,) = _struct_I.unpack(str[start:end])
00096       pattern = '<%si'%length
00097       start = end
00098       end += struct.calcsize(pattern)
00099       self.ints = struct.unpack(pattern, str[start:end])
00100       start = end
00101       end += 16
00102       self.fixed_ints = _struct_4i.unpack(str[start:end])
00103       start = end
00104       end += 4
00105       (length,) = _struct_I.unpack(str[start:end])
00106       self.strings = []
00107       for i in range(0, length):
00108         start = end
00109         end += 4
00110         (length,) = _struct_I.unpack(str[start:end])
00111         start = end
00112         end += length
00113         if python3:
00114           val1 = str[start:end].decode('utf-8')
00115         else:
00116           val1 = str[start:end]
00117         self.strings.append(val1)
00118       self.fixed_strings = []
00119       for i in range(0, 4):
00120         start = end
00121         end += 4
00122         (length,) = _struct_I.unpack(str[start:end])
00123         start = end
00124         end += length
00125         if python3:
00126           val1 = str[start:end].decode('utf-8')
00127         else:
00128           val1 = str[start:end]
00129         self.fixed_strings.append(val1)
00130       return self
00131     except struct.error as e:
00132       raise genpy.DeserializationError(e) #most likely buffer underfill
00133 
00134 
00135   def serialize_numpy(self, buff, numpy):
00136     """
00137     serialize message with numpy array types into buffer
00138     :param buff: buffer, ``StringIO``
00139     :param numpy: numpy python module
00140     """
00141     try:
00142       length = len(self.ints)
00143       buff.write(_struct_I.pack(length))
00144       pattern = '<%si'%length
00145       buff.write(self.ints.tostring())
00146       buff.write(self.fixed_ints.tostring())
00147       length = len(self.strings)
00148       buff.write(_struct_I.pack(length))
00149       for val1 in self.strings:
00150         length = len(val1)
00151         if python3 or type(val1) == unicode:
00152           val1 = val1.encode('utf-8')
00153           length = len(val1)
00154         buff.write(struct.pack('<I%ss'%length, length, val1))
00155       for val1 in self.fixed_strings:
00156         length = len(val1)
00157         if python3 or type(val1) == unicode:
00158           val1 = val1.encode('utf-8')
00159           length = len(val1)
00160         buff.write(struct.pack('<I%ss'%length, length, val1))
00161     except struct.error as se: self._check_types(se)
00162     except TypeError as te: self._check_types(te)
00163 
00164   def deserialize_numpy(self, str, numpy):
00165     """
00166     unpack serialized message in str into this message instance using numpy for array types
00167     :param str: byte array of serialized message, ``str``
00168     :param numpy: numpy python module
00169     """
00170     try:
00171       end = 0
00172       start = end
00173       end += 4
00174       (length,) = _struct_I.unpack(str[start:end])
00175       pattern = '<%si'%length
00176       start = end
00177       end += struct.calcsize(pattern)
00178       self.ints = numpy.frombuffer(str[start:end], dtype=numpy.int32, count=length)
00179       start = end
00180       end += 16
00181       self.fixed_ints = numpy.frombuffer(str[start:end], dtype=numpy.int32, count=4)
00182       start = end
00183       end += 4
00184       (length,) = _struct_I.unpack(str[start:end])
00185       self.strings = []
00186       for i in range(0, length):
00187         start = end
00188         end += 4
00189         (length,) = _struct_I.unpack(str[start:end])
00190         start = end
00191         end += length
00192         if python3:
00193           val1 = str[start:end].decode('utf-8')
00194         else:
00195           val1 = str[start:end]
00196         self.strings.append(val1)
00197       self.fixed_strings = []
00198       for i in range(0, 4):
00199         start = end
00200         end += 4
00201         (length,) = _struct_I.unpack(str[start:end])
00202         start = end
00203         end += length
00204         if python3:
00205           val1 = str[start:end].decode('utf-8')
00206         else:
00207           val1 = str[start:end]
00208         self.fixed_strings.append(val1)
00209       return self
00210     except struct.error as e:
00211       raise genpy.DeserializationError(e) #most likely buffer underfill
00212 
00213 _struct_I = genpy.struct_I
00214 _struct_4i = struct.Struct("<4i")


firos
Author(s): IƱigo Gonzalez, igonzalez@ikergune.com
autogenerated on Thu Jun 6 2019 17:51:04