Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update QNameDictionaryTextRecord encoding to Protocol Version V8.0 - 2019/03/13 #16

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions wcf/records/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,11 @@ def __init__(self, prefix, index):
def to_bytes(self):
"""
>>> QNameDictionaryTextRecord('b', 2).to_bytes()
b'\\xbc\\x01\\x00\\x00\\x02'
b'\\xbc\\x01\\x02'
"""
bt = struct.pack(b'<B', self.type)
bt += struct.pack(b'<B', ord(self.prefix) - ord('a'))
bt += struct.pack(b'<BBB',
(self.index >> 16) & 0xFF,
(self.index >> 8) & 0xFF,
(self.index >> 0) & 0xFF)
bt += MultiByteInt31(self.index).to_bytes()
return bytes(bt)

def __str__(self):
Expand All @@ -391,13 +388,12 @@ def __str__(self):
def parse(cls, fp):
"""
>>> from io import BytesIO
>>> fp = BytesIO(b'\\x01\\x00\\x00\\x02')
>>> fp = BytesIO(b'\\x01\\x02')
>>> str(QNameDictionaryTextRecord.parse(fp))
'b:Envelope'
"""
prefix = chr(struct.unpack(b'<B', fp.read(1))[0] + ord('a'))
idx = struct.unpack(b'<BBB', fp.read(3))
index = idx[0] << 16 | idx[1] << 8 | idx[2]
index = MultiByteInt31.parse(fp).value
return cls(prefix, index)


Expand Down