_PDF.py
Go to the documentation of this file.
00001 """autogenerated by genpy from problib/PDF.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 PDF(genpy.Message):
00009   _md5sum = "75a0d678d0983733e909d6d13b746309"
00010   _type = "problib/PDF"
00011   _has_header = False #flag to mark the presence of a Header object
00012   _full_text = """uint8 EXACT=0     # Is here for easier msg creation, but is actually a specialized case:
00013                   # - continuous: is a Gaussian with zero covariance
00014                   # - discrete: is a Discrete pdf with one entry with P=1                
00015 uint8 GAUSSIAN=1
00016 uint8 UNIFORM=2
00017 uint8 PARTICLES=3
00018 uint8 MIXTURE=4
00019 uint8 DISCRETE=5
00020 uint8 HYBRID=6
00021 
00022 uint8 type
00023 uint32 dimensions
00024 
00025 # For continuous pdf's
00026 float64[] data
00027 
00028 # For discrete pdf's (pmf)
00029 int32 domain_size
00030 string[] values
00031 float64[] probabilities
00032 
00033 # For exact values, either a string or a vector
00034 string exact_value_str
00035 float64[] exact_value_vec
00036 
00037 """
00038   # Pseudo-constants
00039   EXACT = 0
00040   GAUSSIAN = 1
00041   UNIFORM = 2
00042   PARTICLES = 3
00043   MIXTURE = 4
00044   DISCRETE = 5
00045   HYBRID = 6
00046 
00047   __slots__ = ['type','dimensions','data','domain_size','values','probabilities','exact_value_str','exact_value_vec']
00048   _slot_types = ['uint8','uint32','float64[]','int32','string[]','float64[]','string','float64[]']
00049 
00050   def __init__(self, *args, **kwds):
00051     """
00052     Constructor. Any message fields that are implicitly/explicitly
00053     set to None will be assigned a default value. The recommend
00054     use is keyword arguments as this is more robust to future message
00055     changes.  You cannot mix in-order arguments and keyword arguments.
00056 
00057     The available fields are:
00058        type,dimensions,data,domain_size,values,probabilities,exact_value_str,exact_value_vec
00059 
00060     :param args: complete set of field values, in .msg order
00061     :param kwds: use keyword arguments corresponding to message field names
00062     to set specific fields.
00063     """
00064     if args or kwds:
00065       super(PDF, self).__init__(*args, **kwds)
00066       #message fields cannot be None, assign default values for those that are
00067       if self.type is None:
00068         self.type = 0
00069       if self.dimensions is None:
00070         self.dimensions = 0
00071       if self.data is None:
00072         self.data = []
00073       if self.domain_size is None:
00074         self.domain_size = 0
00075       if self.values is None:
00076         self.values = []
00077       if self.probabilities is None:
00078         self.probabilities = []
00079       if self.exact_value_str is None:
00080         self.exact_value_str = ''
00081       if self.exact_value_vec is None:
00082         self.exact_value_vec = []
00083     else:
00084       self.type = 0
00085       self.dimensions = 0
00086       self.data = []
00087       self.domain_size = 0
00088       self.values = []
00089       self.probabilities = []
00090       self.exact_value_str = ''
00091       self.exact_value_vec = []
00092 
00093   def _get_types(self):
00094     """
00095     internal API method
00096     """
00097     return self._slot_types
00098 
00099   def serialize(self, buff):
00100     """
00101     serialize message into buffer
00102     :param buff: buffer, ``StringIO``
00103     """
00104     try:
00105       _x = self
00106       buff.write(_struct_BI.pack(_x.type, _x.dimensions))
00107       length = len(self.data)
00108       buff.write(_struct_I.pack(length))
00109       pattern = '<%sd'%length
00110       buff.write(struct.pack(pattern, *self.data))
00111       buff.write(_struct_i.pack(self.domain_size))
00112       length = len(self.values)
00113       buff.write(_struct_I.pack(length))
00114       for val1 in self.values:
00115         length = len(val1)
00116         if python3 or type(val1) == unicode:
00117           val1 = val1.encode('utf-8')
00118           length = len(val1)
00119         buff.write(struct.pack('<I%ss'%length, length, val1))
00120       length = len(self.probabilities)
00121       buff.write(_struct_I.pack(length))
00122       pattern = '<%sd'%length
00123       buff.write(struct.pack(pattern, *self.probabilities))
00124       _x = self.exact_value_str
00125       length = len(_x)
00126       if python3 or type(_x) == unicode:
00127         _x = _x.encode('utf-8')
00128         length = len(_x)
00129       buff.write(struct.pack('<I%ss'%length, length, _x))
00130       length = len(self.exact_value_vec)
00131       buff.write(_struct_I.pack(length))
00132       pattern = '<%sd'%length
00133       buff.write(struct.pack(pattern, *self.exact_value_vec))
00134     except struct.error as se: self._check_types(se)
00135     except TypeError as te: self._check_types(te)
00136 
00137   def deserialize(self, str):
00138     """
00139     unpack serialized message in str into this message instance
00140     :param str: byte array of serialized message, ``str``
00141     """
00142     try:
00143       end = 0
00144       _x = self
00145       start = end
00146       end += 5
00147       (_x.type, _x.dimensions,) = _struct_BI.unpack(str[start:end])
00148       start = end
00149       end += 4
00150       (length,) = _struct_I.unpack(str[start:end])
00151       pattern = '<%sd'%length
00152       start = end
00153       end += struct.calcsize(pattern)
00154       self.data = struct.unpack(pattern, str[start:end])
00155       start = end
00156       end += 4
00157       (self.domain_size,) = _struct_i.unpack(str[start:end])
00158       start = end
00159       end += 4
00160       (length,) = _struct_I.unpack(str[start:end])
00161       self.values = []
00162       for i in range(0, length):
00163         start = end
00164         end += 4
00165         (length,) = _struct_I.unpack(str[start:end])
00166         start = end
00167         end += length
00168         if python3:
00169           val1 = str[start:end].decode('utf-8')
00170         else:
00171           val1 = str[start:end]
00172         self.values.append(val1)
00173       start = end
00174       end += 4
00175       (length,) = _struct_I.unpack(str[start:end])
00176       pattern = '<%sd'%length
00177       start = end
00178       end += struct.calcsize(pattern)
00179       self.probabilities = struct.unpack(pattern, str[start:end])
00180       start = end
00181       end += 4
00182       (length,) = _struct_I.unpack(str[start:end])
00183       start = end
00184       end += length
00185       if python3:
00186         self.exact_value_str = str[start:end].decode('utf-8')
00187       else:
00188         self.exact_value_str = str[start:end]
00189       start = end
00190       end += 4
00191       (length,) = _struct_I.unpack(str[start:end])
00192       pattern = '<%sd'%length
00193       start = end
00194       end += struct.calcsize(pattern)
00195       self.exact_value_vec = struct.unpack(pattern, str[start:end])
00196       return self
00197     except struct.error as e:
00198       raise genpy.DeserializationError(e) #most likely buffer underfill
00199 
00200 
00201   def serialize_numpy(self, buff, numpy):
00202     """
00203     serialize message with numpy array types into buffer
00204     :param buff: buffer, ``StringIO``
00205     :param numpy: numpy python module
00206     """
00207     try:
00208       _x = self
00209       buff.write(_struct_BI.pack(_x.type, _x.dimensions))
00210       length = len(self.data)
00211       buff.write(_struct_I.pack(length))
00212       pattern = '<%sd'%length
00213       buff.write(self.data.tostring())
00214       buff.write(_struct_i.pack(self.domain_size))
00215       length = len(self.values)
00216       buff.write(_struct_I.pack(length))
00217       for val1 in self.values:
00218         length = len(val1)
00219         if python3 or type(val1) == unicode:
00220           val1 = val1.encode('utf-8')
00221           length = len(val1)
00222         buff.write(struct.pack('<I%ss'%length, length, val1))
00223       length = len(self.probabilities)
00224       buff.write(_struct_I.pack(length))
00225       pattern = '<%sd'%length
00226       buff.write(self.probabilities.tostring())
00227       _x = self.exact_value_str
00228       length = len(_x)
00229       if python3 or type(_x) == unicode:
00230         _x = _x.encode('utf-8')
00231         length = len(_x)
00232       buff.write(struct.pack('<I%ss'%length, length, _x))
00233       length = len(self.exact_value_vec)
00234       buff.write(_struct_I.pack(length))
00235       pattern = '<%sd'%length
00236       buff.write(self.exact_value_vec.tostring())
00237     except struct.error as se: self._check_types(se)
00238     except TypeError as te: self._check_types(te)
00239 
00240   def deserialize_numpy(self, str, numpy):
00241     """
00242     unpack serialized message in str into this message instance using numpy for array types
00243     :param str: byte array of serialized message, ``str``
00244     :param numpy: numpy python module
00245     """
00246     try:
00247       end = 0
00248       _x = self
00249       start = end
00250       end += 5
00251       (_x.type, _x.dimensions,) = _struct_BI.unpack(str[start:end])
00252       start = end
00253       end += 4
00254       (length,) = _struct_I.unpack(str[start:end])
00255       pattern = '<%sd'%length
00256       start = end
00257       end += struct.calcsize(pattern)
00258       self.data = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length)
00259       start = end
00260       end += 4
00261       (self.domain_size,) = _struct_i.unpack(str[start:end])
00262       start = end
00263       end += 4
00264       (length,) = _struct_I.unpack(str[start:end])
00265       self.values = []
00266       for i in range(0, length):
00267         start = end
00268         end += 4
00269         (length,) = _struct_I.unpack(str[start:end])
00270         start = end
00271         end += length
00272         if python3:
00273           val1 = str[start:end].decode('utf-8')
00274         else:
00275           val1 = str[start:end]
00276         self.values.append(val1)
00277       start = end
00278       end += 4
00279       (length,) = _struct_I.unpack(str[start:end])
00280       pattern = '<%sd'%length
00281       start = end
00282       end += struct.calcsize(pattern)
00283       self.probabilities = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length)
00284       start = end
00285       end += 4
00286       (length,) = _struct_I.unpack(str[start:end])
00287       start = end
00288       end += length
00289       if python3:
00290         self.exact_value_str = str[start:end].decode('utf-8')
00291       else:
00292         self.exact_value_str = str[start:end]
00293       start = end
00294       end += 4
00295       (length,) = _struct_I.unpack(str[start:end])
00296       pattern = '<%sd'%length
00297       start = end
00298       end += struct.calcsize(pattern)
00299       self.exact_value_vec = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length)
00300       return self
00301     except struct.error as e:
00302       raise genpy.DeserializationError(e) #most likely buffer underfill
00303 
00304 _struct_I = genpy.struct_I
00305 _struct_i = struct.Struct("<i")
00306 _struct_BI = struct.Struct("<BI")


problib
Author(s): Sjoerd van den Dries
autogenerated on Tue Jan 7 2014 11:42:42