def encodePayload(self): payload = b"" records = 0 self.packets.sort() if len(self.packets) > 0: pointer = 1 start = self.packets[0] last = self.packets[0] while pointer < len(self.packets): current = self.packets[pointer] pointer += 1 diff = current - last if diff == 1: last = current elif diff > 1: if start == last: payload += Binary.writeByte(1) payload += Binary.writeLTriad(start) start = last = current else: payload += Binary.writeByte(0) payload += Binary.writeLTriad(start) payload += Binary.writeLTriad(last) start = last = current records += 1 if start == last: payload += Binary.writeByte(1) payload += Binary.writeLTriad(start) else: payload += Binary.writeByte(0) payload += Binary.writeLTriad(start) payload += Binary.writeLTriad(last) records += 1 self.putShort(records) self.put(payload)
def toBinary(self): buffer = b"" header = self.reliability << 5 if self.split: header |= BitFlags.Split buffer += Binary.writeByte(header) buffer += Binary.writeShort(len(self.buffer) << 3) if Reliability().isReliable(self.reliability): buffer += Binary.writeLTriad(self.messageIndex) if Reliability().isSequenced(self.reliability): buffer += Binary.writeLTriad(self.sequenceIndex) if Reliability().isSequencedOrOrdered(self.reliability): buffer += Binary.writeLTriad(self.orderIndex) buffer += Binary.writeByte(self.orderChannel) if self.split: buffer += Binary.writeInt(self.splitCount) buffer += Binary.writeShort(self.splitId) buffer += Binary.writeInt(self.splitIndex) return buffer + self.buffer