本文整理汇总了Python中packet.Packet.from_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.from_bytes方法的具体用法?Python Packet.from_bytes怎么用?Python Packet.from_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.from_bytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: row_squash
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import from_bytes [as 别名]
def row_squash(packet_iter, n_rows):
for l_list in split_seq(packet_iter, n_rows):
a = numpy.array([numpy.fromstring(l.to_bytes(), dtype=numpy.uint8) for l in l_list])
best, counts = mode(a)
best = best[0].astype(numpy.uint8)
p = Packet.from_bytes(best)
p._offset = l_list[0]._offset
yield p
示例2: reader
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import from_bytes [as 别名]
def reader(infile, start=0, stop=-1):
"""Helper to read t42 lines from a file-like object."""
if start > 0:
infile.seek(start * 42)
lines = iter(partial(infile.read, 42), b'')
for n,l in enumerate(lines):
offset = n + start
if len(l) < 42:
return
elif offset == stop:
return
else:
p = Packet.from_bytes(l)
p._offset = offset
yield p
示例3: subpage_squash
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import from_bytes [as 别名]
def subpage_squash(packet_iter, minimum_dups=3, pages=All, yield_func=packets):
subpages = defaultdict(list)
for pl in paginate(packet_iter, pages=pages, yield_func=packet_lists, drop_empty=True):
subpagekey = (pl[0].mrag.magazine, pl[0].header.page, pl[0].header.subpage)
arr = numpy.zeros((42, 32), dtype=numpy.uint8)
for p in pl:
arr[:,p.mrag.row] = p._original_bytes
subpages[subpagekey].append(arr)
for arrlist in subpages.itervalues():
if len(arrlist) >= minimum_dups:
arr = mode(numpy.array(arrlist), axis=0)[0][0].astype(numpy.uint8)
packets = []
for i in range(32):
if arr[:,i].any():
packets.append(Packet.from_bytes(arr[:,i]))
for item in yield_func(packets):
yield item