fix length problem

This commit is contained in:
Jakob Ketterl 2019-09-25 00:36:40 +02:00
parent ecb754ab29
commit 68fbc436f2

View File

@ -94,17 +94,14 @@ class Uploader(object):
packets = [] packets = []
# 50 seems to be a safe bet # 50 seems to be a safe bet
for chunk in chunks(encoded, 50): for chunk in chunks(encoded, 50):
sInfo = self.padBytes(b"".join(chunk), 4) sInfo = self.getSenderInformation(chunk)
sInfoLength = len(sInfo) length = 16 + len(rHeader) + len(sHeader) + len(rInfo) + len(sInfo)
length = sInfoLength + 16 + len(rHeader) + len(sHeader) + len(rInfo) + 4
header = self.getHeader(length) header = self.getHeader(length)
packets.append( packets.append(
header header
+ rHeader + rHeader
+ sHeader + sHeader
+ rInfo + rInfo
+ bytes(Uploader.senderDelimiter)
+ sInfoLength.to_bytes(2, "big")
+ sInfo + sInfo
) )
@ -186,6 +183,11 @@ class Uploader(object):
+ [0x00, 0x96, 0x00, 0x04] + [0x00, 0x96, 0x00, 0x04]
) )
def getSenderInformation(self, chunk):
sInfo = self.padBytes(b"".join(chunk), 4)
sInfoLength = len(sInfo) + 4
return bytes(Uploader.senderDelimiter) + sInfoLength.to_bytes(2, "big") + sInfo
def pad(self, b, l): def pad(self, b, l):
return b + [0x00 for _ in range(0, -1 * len(b) % l)] return b + [0x00 for _ in range(0, -1 * len(b) % l)]