本文整理汇总了Python中packet.Packet.read_length方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.read_length方法的具体用法?Python Packet.read_length怎么用?Python Packet.read_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.read_length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_buffer
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import read_length [as 别名]
def process_buffer(self):
"""
Attempt to parse the packet from the buffer.
If a complete packet exists in the buffer it is removed and
the server packet_read callback is invoked.
Returns True iff a packet was processed.
"""
if not self.packet_size:
self.packet_size = Packet.read_length(self.buffer_in)
if self.packet_size:
print "Reading packet with length %s" % self.packet_size
if self.packet_size and len(self.buffer_in) >= self.packet_size:
# remove from buffer
raw_packet = self.buffer_in[0:self.packet_size]
self.buffer_in = self.buffer_in[self.packet_size:]
self.packet_size = None
# callback
self.server.packet_read(self, raw_packet)
return True