36 from itertools
import izip
37 from cStringIO
import StringIO
50 return getattr(msg, self.name)
56 class SubMessageHandler(Handler):
59 self.
msg_cls = roslib.message.get_message_class(field.type)
75 return genpy.base.SIMPLE_TYPES_DICT[field.type]
77 if field.base_type
in [
'uint8',
'char']
and field.array_len
is not None:
78 return "%is" % field.array_len
82 struct_strs.extend([pattern(f)
for f
in fields])
83 self.
struct = struct.Struct(
''.join(struct_strs))
84 self.
names = [f.name
for f
in fields]
85 self.
size = self.struct.size
88 buff.write(self.struct.pack(*[getattr(msg, name)
for name
in self.
names]))
91 st = buff.read(self.struct.size)
94 values = self.struct.unpack(st)
95 for name, value
in izip(self.
names, values):
96 setattr(msg, name, value)
100 struct_uint16 = struct.Struct(
'<H')
101 struct_uint8 = struct.Struct(
'<B')
106 self.
msg_cls = roslib.message.get_message_class(field.base_type)
113 data = StringIO(buff.read(length))
119 array = self.
field(msg)
126 array.append(submessage)
131 for submessage
in self.
field(msg):
140 struct_bytes = struct.Struct(
'<H')
146 length = self.struct_bytes.unpack(buff.read(self.struct_bytes.size))[0]
147 setattr(msg, self.
name, str(buff.read(length)))
155 cls_name, spec = roslib.msgs.load_by_type(msg_cls._type)
158 for field
in spec.parsed_fields():
159 if field.type ==
'novatel_msgs/CommonHeader':
163 if genpy.base.is_simple(field.base_type)
and (field.array_len
is not None or not field.is_array):
165 fixed_fields.append(field)
169 if len(fixed_fields) > 0:
174 if field.type ==
'string' or (field.base_type ==
'uint8' and field.is_array):
181 if len(fixed_fields) > 0:
196 for handler
in self.translator.handlers:
197 handler.deserialize(buff, self.
msg)
198 except struct.error
as e:
203 for handler
in self.translator.handlers:
204 handler.serialize(buff, self.
msg)
205 except struct.error
as e:
209 for handler
in self.translator.handlers:
210 handler.preserialize(self.
msg)
214 if not hasattr(self.__class__,
"_translator"):
215 self.__class__._translator =
Translator(self.__class__)
218 roslib.message.Message.translator = translator
def serialize(self, buff)
def __init__(self, msg_cls)
def __init__(self, field)
def serialize(self, buff, msg)
def serialize(self, buff, msg)
def __init__(self, fields)
def __init__(self, field)
def deserialize(self, buff)
def deserialize(self, buff, msg)
def deserialize(self, buff, msg)
def preserialize(self, msg)
def __init__(self, translator, msg)
def deserialize(self, buff, msg)
def serialize(self, buff, msg)
def deserialize(self, buff, msg)
def preserialize(self, msg)
def __init__(self, field)