feat: implement dict on ChunkHeader

This commit is contained in:
ChillerDragon 2024-06-16 10:32:15 +08:00
parent 22f7b437bd
commit 813d8f5f96

View file

@ -6,9 +6,18 @@ class ChunkFlags(PrettyPrint):
def __init__(self):
self.resend = False
self.vital = False
def __repr__(self):
return "<class: '" + str(self.__class__.__name__) + "'>: " + str(self.__dict__)
def __iter__(self):
flags = []
if self.resend:
flags.append('resend')
if self.vital:
flags.append('vital')
return iter(flags)
# same fields for 0.6 and 0.7
# different bit layout tho
class ChunkHeader(PrettyPrint):
@ -32,6 +41,12 @@ class ChunkHeader(PrettyPrint):
# if unset
self.seq: int = -1
def __iter__(self):
yield 'version', self.version
yield 'flags', list(self.flags)
yield 'size', self.size
yield 'seq', self.seq
def pack(self) -> bytes:
flags: int = 0
if self.flags.resend:
@ -60,3 +75,7 @@ class ChunkHeader(PrettyPrint):
data[1] |= (self.seq >> 2) & 0xc0
data += bytes([self.seq & 0xff])
return bytes(data)
def __repr__(self):
return "<class: '" + str(self.__class__.__name__) + "'>: " + str(dict(self))