fix!: rename PacketHeader -> PacketHeader7
This commit is contained in:
parent
813d8f5f96
commit
c19f0dfdab
|
@ -1,5 +1,5 @@
|
|||
from twnet_parser.packet import \
|
||||
PacketHeaderParser6, PacketHeader, PacketFlags6
|
||||
PacketHeaderParser6, PacketHeader7, PacketFlags6
|
||||
|
||||
def test_parse_flags() -> None:
|
||||
parser = PacketHeaderParser6()
|
||||
|
@ -19,7 +19,7 @@ def test_parse_flags() -> None:
|
|||
|
||||
def test_packet_header_no_token_unpack() -> None:
|
||||
parser = PacketHeaderParser6()
|
||||
header: PacketHeader = parser.parse_header(b'\x10\x00\x00')
|
||||
header: PacketHeader7 = parser.parse_header(b'\x10\x00\x00')
|
||||
|
||||
assert header.ack == 0
|
||||
assert header.num_chunks == 0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from twnet_parser.packet import \
|
||||
parse7, PacketHeaderParser7, PacketHeader, TwPacket
|
||||
parse7, PacketHeaderParser7, PacketHeader7, TwPacket
|
||||
|
||||
def test_packet_header_unpack() -> None:
|
||||
# TODO: change api to
|
||||
|
@ -7,7 +7,7 @@ def test_packet_header_unpack() -> None:
|
|||
# PacketHeader.unpack(bytes)
|
||||
|
||||
parser = PacketHeaderParser7()
|
||||
header: PacketHeader = parser.parse_header(b'\x04\x0a\x00\xcf\x2e\xde\x1d')
|
||||
header: PacketHeader7 = parser.parse_header(b'\x04\x0a\x00\xcf\x2e\xde\x1d')
|
||||
|
||||
assert header.ack == 10
|
||||
assert header.token == b'\xcf.\xde\x1d'
|
||||
|
@ -19,7 +19,7 @@ def test_packet_header_unpack() -> None:
|
|||
assert header.flags.connless is False
|
||||
|
||||
def test_packet_header_pack_flags() -> None:
|
||||
header: PacketHeader = PacketHeader()
|
||||
header: PacketHeader7 = PacketHeader7()
|
||||
header.ack = 0
|
||||
|
||||
header.flags.control = True
|
||||
|
@ -35,7 +35,7 @@ def test_packet_header_pack_flags() -> None:
|
|||
assert header.pack()[0:1] == b'\x10'
|
||||
|
||||
def test_packet_header_pack_ack() -> None:
|
||||
header: PacketHeader = PacketHeader()
|
||||
header: PacketHeader7 = PacketHeader7()
|
||||
header.flags.control = False
|
||||
header.flags.resend = False
|
||||
header.flags.compression = False
|
||||
|
@ -51,7 +51,7 @@ def test_packet_header_pack_ack() -> None:
|
|||
assert header.pack()[1:2] == b'\x0b'
|
||||
|
||||
def test_packet_header_repack_overflowing_ack() -> None:
|
||||
header: PacketHeader = PacketHeader()
|
||||
header: PacketHeader7 = PacketHeader7()
|
||||
header.flags.control = False
|
||||
header.flags.resend = False
|
||||
header.flags.compression = False
|
||||
|
@ -73,7 +73,7 @@ def test_packet_header_repack_overflowing_ack() -> None:
|
|||
assert header.ack == 976
|
||||
|
||||
def test_packet_header_repack_ack_overlapping_into_flags_byte() -> None:
|
||||
header: PacketHeader = PacketHeader()
|
||||
header: PacketHeader7 = PacketHeader7()
|
||||
header.flags.control = False
|
||||
header.flags.resend = False
|
||||
header.flags.compression = False
|
||||
|
@ -133,7 +133,7 @@ def test_packet_header_repack_ack_overlapping_into_flags_byte() -> None:
|
|||
assert header.ack == 511
|
||||
|
||||
def test_packet_header_pack_num_chunks() -> None:
|
||||
header = PacketHeader()
|
||||
header = PacketHeader7()
|
||||
|
||||
header.num_chunks = 0
|
||||
assert header.pack()[2:3] == b'\x00'
|
||||
|
@ -145,7 +145,7 @@ def test_packet_header_pack_num_chunks() -> None:
|
|||
assert header.pack()[2:3] == b'\x06'
|
||||
|
||||
def test_packet_header_pack_token() -> None:
|
||||
header = PacketHeader()
|
||||
header = PacketHeader7()
|
||||
header.token = b'\x11\x22\x33\xff'
|
||||
assert header.pack()[3:] == b'\x11\x22\x33\xff'
|
||||
|
||||
|
@ -162,7 +162,7 @@ def test_packet_header_pack_token() -> None:
|
|||
assert header.pack()[3:] == b'tekn'
|
||||
|
||||
def test_packet_header_pack_full() -> None:
|
||||
header: PacketHeader = PacketHeader()
|
||||
header: PacketHeader7 = PacketHeader7()
|
||||
|
||||
header.ack = 10
|
||||
header.token = b'\xcf.\xde\x1d'
|
||||
|
@ -176,7 +176,7 @@ def test_packet_header_pack_full() -> None:
|
|||
assert header.pack() == b'\x04\x0a\x00\xcf\x2e\xde\x1d'
|
||||
|
||||
def test_packet_header_repack_all_set() -> None:
|
||||
header: PacketHeader = PacketHeader()
|
||||
header: PacketHeader7 = PacketHeader7()
|
||||
|
||||
header.ack = 1023
|
||||
header.token = b'\xff\xff\xff\xff'
|
||||
|
@ -235,7 +235,7 @@ def test_packet_header_repack_all_set() -> None:
|
|||
assert header.flags.connless is False
|
||||
|
||||
def test_packet_header_repack_none_set() -> None:
|
||||
header: PacketHeader = PacketHeader()
|
||||
header: PacketHeader7 = PacketHeader7()
|
||||
|
||||
header.ack = 0
|
||||
header.token = b'\x00\x00\x00\x00'
|
||||
|
|
|
@ -158,7 +158,7 @@ class PacketHeader6(PrettyPrint):
|
|||
packed += self.token
|
||||
return packed
|
||||
|
||||
class PacketHeader(PrettyPrint):
|
||||
class PacketHeader7(PrettyPrint):
|
||||
def __init__(
|
||||
self,
|
||||
flags: Optional[PacketFlags7] = None,
|
||||
|
@ -228,11 +228,11 @@ class TwPacket(PrettyPrint):
|
|||
self._version: Literal['0.6', '0.7'] = version
|
||||
self.payload_raw: bytes = b''
|
||||
self.payload_decompressed: bytes = b''
|
||||
self.header: Union[PacketHeader, PacketHeader6]
|
||||
self.header: Union[PacketHeader7, PacketHeader6]
|
||||
if self.version == '0.6':
|
||||
self.header = PacketHeader6()
|
||||
elif self.version == '0.7':
|
||||
self.header = PacketHeader()
|
||||
self.header = PacketHeader7()
|
||||
else:
|
||||
raise ValueError(f"Error: invalid packet version '{self.version}'")
|
||||
self.messages: list[Union[CtrlMessage, NetMessage, ConnlessMessage]] = []
|
||||
|
@ -356,8 +356,8 @@ class PacketHeaderParser7():
|
|||
def parse_token(self, header_bytes: bytes) -> bytes:
|
||||
return header_bytes[3:7]
|
||||
|
||||
def parse_header(self, data: bytes) -> PacketHeader:
|
||||
header = PacketHeader()
|
||||
def parse_header(self, data: bytes) -> PacketHeader7:
|
||||
header = PacketHeader7()
|
||||
# bits 2..5
|
||||
header.flags = self.parse_flags7(data)
|
||||
if header.flags.connless:
|
||||
|
|
Loading…
Reference in a new issue