def encode_payload(self) -> None: payload = '' self.packets.sort() count = len(self.packets) records = 0 if count > 0: pointer = 1 start = self.packets[0] last = self.packets[0] while pointer < count: current = self.packets[pointer+1] diff = current - last if(diff == 1): last = current elif diff > 1: if start is last: payload += chr(self.RECORD_TYPE_SINGLE) payload += Binary.write_l_triad(start) start = last = current else: payload += chr(self.RECORD_TYPE_RANGE) payload += Binary.write_l_triad(start) payload += Binary.write_l_triad(last) start = last = current records+=1 if start is last: payload += chr(self.RECORD_TYPE_SINGLE) payload += Binary.write_l_triad(start) else: payload += chr(self.RECORD_TYPE_RANGE) payload += Binary.write_l_triad(start) payload += Binary.write_l_triad(last) records+=1 self.put_short(records) self.buffer += payload
def put_l_int(self, i: int): self.put(Binary.write_l_int(i))
def put_l_long(self, l: int): self.put(Binary.write_l_long(l))
def get_l_int(self) -> int: return Binary.read_l_int(self.get(4))
def put_l_triad(self, triad: int): self.put(Binary.write_l_triad(triad))
def get_l_long(self) -> int: return Binary.read_l_long(self.get(8))
def get_l_triad(self) -> int: return Binary.read_l_triad(self.get(3))
def put_l_float(self, f: int): self.put(Binary.write_l_float(f))
def get_float(self) -> int: return Binary.read_float(self.get(4))
def put_l_short(self, s: int): self.put(Binary.write_l_short(s))
def get_l_short(self) -> int: return Binary.read_l_short(self.get(2))