本文整理汇总了Python中struct.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: serialize
def serialize(self, buff):
"""
serialize message into buffer
:param buff: buffer, ``StringIO``
"""
try:
_x = self.agent_one
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode("utf-8")
length = len(_x)
buff.write(struct.pack("<I%ss" % length, length, _x))
_x = self.agent_two
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode("utf-8")
length = len(_x)
buff.write(struct.pack("<I%ss" % length, length, _x))
_x = self
buff.write(
_struct_6d.pack(_x.rotationx, _x.rotationy, _x.angle, _x.referencex, _x.referencey, _x.evaluation)
)
except struct.error as se:
self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te:
self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:sloumotion,项目名称:cs_merge,代码行数:26,代码来源:_transform.py
示例2: _struct_check_length
def _struct_check_length(self, fmt, offset):
if offset < 0:
raise struct.error('can not (un)pack at a negative offset')
fmt_size = struct.calcsize(fmt)
if fmt_size > len(self) - offset:
raise struct.error('(un)pack requires a buffer of at least %d bytes' % fmt_size)
开发者ID:devinbarry,项目名称:python-mp3,代码行数:7,代码来源:_buffer.py
示例3: _count
def _count(format):
"""
Count the number of variables needed to pack a given format.
"""
if format[:1] in b"@=<>!":
format = format[1:]
count = 0
q = b""
for index in range(len(format)):
char = format[index:index+1]
if char.isdigit():
q += char
continue
elif char in b" \t\r\n":
if q:
raise error("bad char in struct format")
continue
elif char in b"ps":
count += 1
q = b""
elif char in b"xcbB?hHiIlLqQfdP":
count += int(q or 1)
q = b""
else:
raise error("bad char in struct format")
return count
开发者ID:stendec,项目名称:netstruct,代码行数:29,代码来源:netstruct.py
示例4: fromstr
def fromstr(self, data):
try:
vals = self.unpack(data)
ind = self._pack.index('id')
if vals[ind] != self.id:
raise struct.error("Packet id %s does not match my id %s" % (vals[ind], self.id))
if len(vals) == len(self._pack):
for var in self._pack:
setattr(self, var, vals[self._pack.index(var)])
return vals
else:
raise struct.error("Data indexes do not match pack indexes.")
except (struct.error) as e: raise
开发者ID:gitter-badger,项目名称:malibu,代码行数:14,代码来源:packets.py
示例5: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_2I.pack(_x.status.goal_id.stamp.secs, _x.status.goal_id.stamp.nsecs))
_x = self.status.goal_id.id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
buff.write(_struct_B.pack(self.status.status))
_x = self.status.text
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
buff.write(_struct_f.pack(self.feedback.percent_complete))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:daphnak,项目名称:WildCats,代码行数:33,代码来源:_GotoActionFeedback.py
示例6: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
length = len(self.edges)
buff.write(_struct_I.pack(length))
for val1 in self.edges:
_x = val1
buff.write(_struct_2q.pack(_x.idA, _x.idB))
_v7 = val1.poseATB
_v8 = _v7.position
_x = _v8
buff.write(_struct_3d.pack(_x.x, _x.y, _x.z))
_v9 = _v7.orientation
_x = _v9
buff.write(_struct_4d.pack(_x.x, _x.y, _x.z, _x.w))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:johnjsb,项目名称:idSLAM,代码行数:32,代码来源:_Edges.py
示例7: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.ns
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_3i10d4f2iB.pack(_x.id, _x.type, _x.action, _x.pose.position.x, _x.pose.position.y, _x.pose.position.z, _x.pose.orientation.x, _x.pose.orientation.y, _x.pose.orientation.z, _x.pose.orientation.w, _x.scale.x, _x.scale.y, _x.scale.z, _x.color.r, _x.color.g, _x.color.b, _x.color.a, _x.lifetime.secs, _x.lifetime.nsecs, _x.frame_locked))
length = len(self.points)
buff.write(_struct_I.pack(length))
for val1 in self.points:
_x = val1
buff.write(_struct_3d.pack(_x.x, _x.y, _x.z))
length = len(self.colors)
buff.write(_struct_I.pack(length))
for val1 in self.colors:
_x = val1
buff.write(_struct_4f.pack(_x.r, _x.g, _x.b, _x.a))
_x = self.text
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.mesh_resource
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
buff.write(_struct_B.pack(self.mesh_use_embedded_materials))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:SDSMT-CSC464-F15,项目名称:landingpad,代码行数:60,代码来源:_Marker.py
示例8: serialize
def serialize(self, buff):
"""
serialize message into buffer
:param buff: buffer, ``StringIO``
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
buff.write(_struct_f.pack(self.processing_time))
length = len(self.keyframes)
buff.write(_struct_I.pack(length))
pattern = '<%si'%length
buff.write(struct.pack(pattern, *self.keyframes))
_x = self
buff.write(_struct_3i.pack(_x.num_matches, _x.tracking_quality, _x.stage))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:jepierre,项目名称:catkin_ws,代码行数:26,代码来源:_Info.py
示例9: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self
buff.write(_struct_H3I.pack(_x.vehicle_id, _x.state.header.seq, _x.state.header.stamp.secs, _x.state.header.stamp.nsecs))
_x = self.state.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.state.child_frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_4d2B4d.pack(_x.state.pose.pose.position.lat, _x.state.pose.pose.position.lon, _x.state.pose.pose.position.alt, _x.state.pose.pose.position.rel_alt, _x.state.pose.pose.position.using_alt, _x.state.pose.pose.position.using_rel_alt, _x.state.pose.pose.orientation.x, _x.state.pose.pose.orientation.y, _x.state.pose.pose.orientation.z, _x.state.pose.pose.orientation.w))
buff.write(self.state.pose.covariance.tostring())
_x = self
buff.write(_struct_6d.pack(_x.state.twist.twist.linear.x, _x.state.twist.twist.linear.y, _x.state.twist.twist.linear.z, _x.state.twist.twist.angular.x, _x.state.twist.twist.angular.y, _x.state.twist.twist.angular.z))
buff.write(self.state.twist.covariance.tostring())
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(locals().get('_x', self)))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self)))))
开发者ID:niravshirishdesai,项目名称:ACS,代码行数:35,代码来源:_RedVehicleState.py
示例10: serialize
def serialize(self, buff):
"""
serialize message into buffer
:param buff: buffer, ``StringIO``
"""
try:
_x = self.resource_name
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.format
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.data
length = len(_x)
# - if encoded as a list instead, serialize as bytes instead of string
if type(_x) in [list, tuple]:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:suryaprakaz,项目名称:rospy_android,代码行数:33,代码来源:_Icon.py
示例11: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
length = len(self.x)
buff.write(_struct_I.pack(length))
pattern = '<%sf'%length
buff.write(self.x.tostring())
length = len(self.y)
buff.write(_struct_I.pack(length))
pattern = '<%sf'%length
buff.write(self.y.tostring())
length = len(self.z)
buff.write(_struct_I.pack(length))
pattern = '<%sf'%length
buff.write(self.z.tostring())
length = len(self.labels)
buff.write(_struct_I.pack(length))
pattern = '<%si'%length
buff.write(self.labels.tostring())
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:Pontusun,项目名称:CIS700_Team2,代码行数:25,代码来源:_Loc.py
示例12: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_2I.pack(_x.goal_id.stamp.secs, _x.goal_id.stamp.nsecs))
_x = self.goal_id.id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_B6fib.pack(_x.goal.mode.mode, _x.goal.mode.color.r, _x.goal.mode.color.g, _x.goal.mode.color.b, _x.goal.mode.color.a, _x.goal.mode.frequency, _x.goal.mode.timeout, _x.goal.mode.pulses, _x.goal.mode.priority))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:kerekare,项目名称:ros_hydra_libphidgetsupdated,代码行数:33,代码来源:_SetLightModeActionGoal.py
示例13: serialize
def serialize(self, buff):
"""
serialize message into buffer
:param buff: buffer, ``StringIO``
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.ssid
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_h2B.pack(_x.rssi, _x.band, _x.channel))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:nicolasgallardo,项目名称:Bebop_Vision,代码行数:30,代码来源:_Ardrone3NetworkStateWifiScanListChanged.py
示例14: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
length = len(self.readings)
buff.write(_struct_I.pack(length))
for val1 in self.readings:
_x = val1
buff.write(_struct_2f.pack(_x.angle, _x.distance))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(locals().get('_x', self)))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self)))))
开发者ID:vainmouse,项目名称:Nao,代码行数:25,代码来源:_PolarReadingScan.py
示例15: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
length = len(self.results)
buff.write(_struct_I.pack(length))
for val1 in self.results:
_x = val1.key
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
length = len(val1.values)
buff.write(_struct_I.pack(length))
for val2 in val1.values:
length = len(val2)
if python3 or type(val2) == unicode:
val2 = val2.encode('utf-8')
length = len(val2)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *val2))
else:
buff.write(struct.pack('<I%ss'%length, length, val2))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(locals().get('_x', self)))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self)))))
开发者ID:CognitiveComputingResearchGroup,项目名称:Cryptoquip,代码行数:32,代码来源:_csmAddContent.py
示例16: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
length = len(self.data)
buff.write(_struct_I.pack(length))
pattern = '<%sI'%length
buff.write(self.data.tostring())
_x = self
buff.write(_struct_3f3d3I.pack(_x.origin.x, _x.origin.y, _x.origin.z, _x.resolutions.x, _x.resolutions.y, _x.resolutions.z, _x.size_x, _x.size_y, _x.size_z))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(locals().get('_x', self)))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self)))))
开发者ID:hitrobotgroup,项目名称:release,代码行数:26,代码来源:_VoxelGrid.py
示例17: serialize
def serialize(self, buff):
"""
serialize message into buffer
:param buff: buffer, ``StringIO``
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_2I.pack(_x.status.goal_id.stamp.secs, _x.status.goal_id.stamp.nsecs))
_x = self.status.goal_id.id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
buff.write(_struct_B.pack(self.status.status))
_x = self.status.text
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_2i.pack(_x.feedback.errorx, _x.feedback.errory))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:shyamgt,项目名称:kraken_3.0,代码行数:33,代码来源:_buoyActionFeedback.py
示例18: serialize
def serialize(self, buff):
"""
serialize message into buffer
:param buff: buffer, ``StringIO``
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
length = len(self.acceleration)
buff.write(_struct_I.pack(length))
pattern = '<%sd'%length
buff.write(struct.pack(pattern, *self.acceleration))
length = len(self.orientation)
buff.write(_struct_I.pack(length))
pattern = '<%sd'%length
buff.write(struct.pack(pattern, *self.orientation))
length = len(self.stamp)
buff.write(_struct_I.pack(length))
for val1 in self.stamp:
_x = val1
buff.write(_struct_2I.pack(_x.secs, _x.nsecs))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:bioinroboticsuottawa,项目名称:dextrus_ws,代码行数:32,代码来源:_accelerometer_params.py
示例19: serialize_numpy
def serialize_numpy(self, buff, numpy):
"""
serialize message with numpy array types into buffer
:param buff: buffer, ``StringIO``
:param numpy: numpy python module
"""
try:
_x = self.source
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.type
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self.data
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
buff.write(struct.pack('<I%ss'%length, length, _x))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:PR2,项目名称:web_interface,代码行数:27,代码来源:_WebEvent.py
示例20: serialize
def serialize(self, buff):
"""
serialize message into buffer
:param buff: buffer, ``StringIO``
"""
try:
_x = self
buff.write(_struct_3I.pack(_x.header.seq, _x.header.stamp.secs, _x.header.stamp.nsecs))
_x = self.header.frame_id
length = len(_x)
if python3 or type(_x) == unicode:
_x = _x.encode('utf-8')
length = len(_x)
if python3:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
_x = self
buff.write(_struct_6B.pack(_x.len, _x.seq, _x.sysid, _x.compid, _x.msgid, _x.fromlcm))
length = len(self.payload64)
buff.write(_struct_I.pack(length))
pattern = '<%sQ'%length
buff.write(struct.pack(pattern, *self.payload64))
except struct.error as se: self._check_types(struct.error("%s: '%s' when writing '%s'" % (type(se), str(se), str(_x))))
except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(_x))))
开发者ID:aldopl,项目名称:trui-bot-prj,代码行数:25,代码来源:_Mavlink.py
注:本文中的struct.error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论