Skip to content
Snippets Groups Projects
Commit 4f0b6df4 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-502: Print all packets received on stdin, and support SST/XST/BST.

parent ec6354fb
Branches
Tags
1 merge request!189L2SS-502: Print all packets received on stdin, and support SST/XST/BST.
......@@ -75,13 +75,13 @@ class StatisticsPacket(object):
"Invalid SDP statistics packet: packet marker (first byte) is {}, not one of 'SBX'.".format(
self.marker))
# format string for the header, see unpack below
header_format = ">cBL HHB BHL BBH HQ"
header_size = struct.calcsize(header_format)
def unpack(self):
""" Unpack the packet into properties of this object. """
# format string for the header, see unpack below
self.header_format = ">cBL HHB BHL BBH HQ"
self.header_size = struct.calcsize(self.header_format)
# unpack fields
try:
(self.marker_raw,
......@@ -335,11 +335,35 @@ def main(args=None, **kwargs):
import sys
import pprint
# read all of stdin, even though we only parse the first packet. we're too lazy to intelligently decide when
# the packet is complete and can stop reading.
data = sys.stdin.buffer.read()
packet = SSTPacket(data)
# print header & payload
pprint.pprint(packet.header())
pprint.pprint(packet.payload)
# packet counter
nr = 0
# byte offset in the stream
offset = 0
while True:
# read just the header
header = sys.stdin.buffer.read(StatisticsPacket.header_size)
if not header:
break
# read the payload
packet = StatisticsPacket(header)
payload_size = packet.expected_size() - len(header)
payload = sys.stdin.buffer.read(payload_size)
# construct the packet based on type
if packet.marker == 'S':
packet = SSTPacket(header + payload)
elif packet.marker == 'X':
packet = XSTPacket(header + payload)
elif packet.marker == 'B':
packet = BSTPacket(header + payload)
# print header
print(f"# Packet {nr} starting at offset {offset}")
pprint.pprint(packet.header())
# increment counters
nr += 1
offset += len(header) + len(payload)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment