Skip to content
Snippets Groups Projects
Commit ef60bf23 authored by Corné Lukken's avatar Corné Lukken
Browse files

Merge branch 'L2SS-502-print-packets' into 'master'

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

Closes L2SS-502

See merge request !189
parents 45f70341 4f0b6df4
No related branches found
No related tags found
1 merge request!189L2SS-502: Print all packets received on stdin, and support SST/XST/BST.
...@@ -75,13 +75,13 @@ class StatisticsPacket(object): ...@@ -75,13 +75,13 @@ class StatisticsPacket(object):
"Invalid SDP statistics packet: packet marker (first byte) is {}, not one of 'SBX'.".format( "Invalid SDP statistics packet: packet marker (first byte) is {}, not one of 'SBX'.".format(
self.marker)) 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): def unpack(self):
""" Unpack the packet into properties of this object. """ """ 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 # unpack fields
try: try:
(self.marker_raw, (self.marker_raw,
...@@ -335,11 +335,35 @@ def main(args=None, **kwargs): ...@@ -335,11 +335,35 @@ def main(args=None, **kwargs):
import sys import sys
import pprint import pprint
# read all of stdin, even though we only parse the first packet. we're too lazy to intelligently decide when # packet counter
# the packet is complete and can stop reading. nr = 0
data = sys.stdin.buffer.read()
packet = SSTPacket(data) # byte offset in the stream
offset = 0
# print header & payload
pprint.pprint(packet.header()) while True:
pprint.pprint(packet.payload) # 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