From 9c3cbbc10525eb763bab87f78d09b7f3dd92434b Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 18 Mar 2023 09:10:56 +0100 Subject: [PATCH] Do not abstract away versions This library should not try to detect versions because the user of the library might not want to do that and it has performance implications A user of this library should either know which protocol version they expect to send and receive or they should just try the 0.6 parser and then the 0.7 parser of this library and decide them selfs which version to detect --- twnet_parser/packet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/twnet_parser/packet.py b/twnet_parser/packet.py index f2a9819..3849fd1 100644 --- a/twnet_parser/packet.py +++ b/twnet_parser/packet.py @@ -57,7 +57,7 @@ class TwPacket(PrettyPrint): self.header: PacketHeader = PacketHeader() self.messages: list[Union[CtrlMessage, GameMessage, SysMessage]] = [] -class PacketHeaderParser(): +class PacketHeaderParser7(): def parse_flags7(self, data: bytes) -> PacketFlags7: # FFFF FFaa flag_bits = (data[0] & 0xfc) >> 2 @@ -96,10 +96,10 @@ class PacketParser(): pck = TwPacket() pck.version = '0.7' # TODO: what is the most performant way in python to do this? - # heap allocating a PacketHeaderParser just to bundle a bunch of + # heap allocating a PacketHeaderParser7 just to bundle a bunch of # methods that do not share state seems like a waste of performance # would this be nicer with class methods? - pck.header = PacketHeaderParser().parse_header(data) + pck.header = PacketHeaderParser7().parse_header(data) if pck.header.flags.control: if data[7] == 0x04: # close msg_dc = CtrlMessage('close')