Correctly pack 0.6.5 ctrl connect
This commit is contained in:
parent
93ad98ec96
commit
01331e8141
|
@ -1,4 +1,4 @@
|
|||
from twnet_parser.packet import parse6
|
||||
from twnet_parser.packet import parse6, TwPacket, PacketHeader6
|
||||
from twnet_parser.messages6.control.connect import CtrlConnect
|
||||
|
||||
def test_ctrl_connect():
|
||||
|
@ -50,11 +50,13 @@ def test_ctrl_connect():
|
|||
packet = parse6(data)
|
||||
|
||||
assert packet.version == '0.6'
|
||||
|
||||
assert packet.header.ack == 0
|
||||
assert packet.header.num_chunks == 0
|
||||
assert packet.header.flags.token is False
|
||||
assert packet.header.flags.control is True
|
||||
assert packet.header.flags.compression is False
|
||||
assert packet.header.flags.resend is False
|
||||
assert packet.header.flags.connless is False
|
||||
assert packet.header.flags.resend is False
|
||||
assert packet.header.flags.compression is False
|
||||
|
||||
assert len(packet.messages) == 1
|
||||
|
||||
|
@ -64,5 +66,29 @@ def test_ctrl_connect():
|
|||
assert msg.response_token == b'\x37\xb5\xbb\x06'
|
||||
|
||||
repack = packet.pack()
|
||||
assert repack == data
|
||||
|
||||
def test_pack_ctrl_connect():
|
||||
packet: TwPacket = TwPacket()
|
||||
packet.header = PacketHeader6()
|
||||
msg: CtrlConnect = CtrlConnect()
|
||||
msg.response_token = b'\x37\xb5\xbb\x06'
|
||||
packet.messages.append(msg)
|
||||
data: bytes = packet.pack()
|
||||
|
||||
packet2: TwPacket = parse6(data)
|
||||
assert packet2.version == '0.6'
|
||||
assert packet2.header.ack == 0
|
||||
assert packet2.header.num_chunks == 0
|
||||
assert packet2.header.flags.token is False
|
||||
assert packet2.header.flags.control is True
|
||||
assert packet2.header.flags.connless is False
|
||||
assert packet2.header.flags.resend is False
|
||||
assert packet2.header.flags.compression is False
|
||||
assert len(packet.messages) == 1
|
||||
msg2: CtrlConnect = packet2.messages[0]
|
||||
assert msg2.message_name == 'connect'
|
||||
assert msg2.response_token == b'\x37\xb5\xbb\x06'
|
||||
|
||||
assert packet2.pack() == data
|
||||
|
||||
# assert repack == data
|
||||
|
|
|
@ -113,11 +113,14 @@ class PacketHeader6(PrettyPrint):
|
|||
return bytes([ \
|
||||
((PACKETFLAG6_CONNLESS<<2)&0xfc) | (self.connless_version&0x03)
|
||||
]) + self.token + self.response_token
|
||||
return bytes([ \
|
||||
packed = bytes([ \
|
||||
((flags << 2)&0xfc) | ((self.ack>>8)&0x03), \
|
||||
self.ack&0xff, \
|
||||
self.num_chunks \
|
||||
]) + self.token
|
||||
])
|
||||
if self.flags.token:
|
||||
packed += self.token
|
||||
return packed
|
||||
|
||||
class PacketHeader(PrettyPrint):
|
||||
def __init__(
|
||||
|
|
Loading…
Reference in a new issue