本文整理汇总了Python中packet.Packet.decode方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.decode方法的具体用法?Python Packet.decode怎么用?Python Packet.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.decode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next_event
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import decode [as 别名]
def next_event(self):
raw_bytes = self.serial.read(Packet.PACKET_LENGTH)
if DEBUG:
print(hex(int.from_bytes(raw_bytes,byteorder='big')))
packet = Packet.decode(raw_bytes)
if packet is not None:
return X10Event(packet)
return None
示例2: packet_read
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import decode [as 别名]
def packet_read(self, conn, raw_packet):
"""
Read in a packet and dispatch -- asyncore callback.
"""
packet = Packet.decode(raw_packet)
print "packet in with protocol"
if Packet.is_named(packet.protocol):
# protocol is named, resolve id first
name = packet.protocol
id = self.server_map.resolve_id(name)
if id:
named = MappedName()
named.name = name
named.id = id
msg = Message(0, named)
self.q_out.fifo_put((conn, msg))
else:
print "unmapped name: " + str(name)
rejected = MessageRejected()
rejected.id = 0
rejected.reason = rejected.UNMAPPED_NAME
rejected.message = "Unmapped name: '%s'" % name
msg = Message(0, rejected)
self.q_out.fifo_put((conn, msg))
# stop processing
return
else:
# just take id
id = packet.protocol
# this seems slightly silly in the case where the message was
# a named message (it shouldn't hurt though)
name = self.server_map.resolve_name(id)
if not name:
# if the reverse name lookup fails
print "unmapped id: " + str(id)
rejected = MessageRejected()
rejected.id = 0
rejected.reason = rejected.UNMAPPED_ID
rejected.message = "Unmapped ID: %d" % id
msg = Message(0, rejected)
self.q_out.fifo_put((conn, msg))
# stop processing
return
protobuf_class = self.server_map.resolve_protobuffer(name)
assert protobuf_class
protobuf = protobuf_class()
protobuf.ParseFromString(packet.payload)
message = Message(packet.track_id, protobuf, name=name)
print "have protobuf: {" + str(protobuf) + "}"
self.q_in.fifo_put((conn, message))