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
This commit is contained in:
parent
6f2a9eda51
commit
9c3cbbc105
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue