当前位置: 首页>>代码示例>>Python>>正文


Python Packet.decode方法代码示例

本文整理汇总了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
开发者ID:umbc-hackafe,项目名称:x10-controller,代码行数:10,代码来源:daemon.py

示例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))
开发者ID:norbert-jiang,项目名称:tinyos-2.x-contrib,代码行数:60,代码来源:server.py


注:本文中的packet.Packet.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。