Пример #1
0
    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
Пример #2
0
 def put_l_int(self, i: int):
     self.put(Binary.write_l_int(i))
Пример #3
0
 def put_l_long(self, l: int):
     self.put(Binary.write_l_long(l))
Пример #4
0
 def get_l_int(self) -> int:
     return Binary.read_l_int(self.get(4))
Пример #5
0
 def put_l_triad(self, triad: int):
     self.put(Binary.write_l_triad(triad))
Пример #6
0
 def get_l_long(self) -> int:
     return Binary.read_l_long(self.get(8))
Пример #7
0
 def get_l_triad(self) -> int:
     return Binary.read_l_triad(self.get(3))
Пример #8
0
 def put_l_float(self, f: int):
     self.put(Binary.write_l_float(f))
Пример #9
0
 def get_float(self) -> int:
     return Binary.read_float(self.get(4))
Пример #10
0
 def put_l_short(self, s: int):
     self.put(Binary.write_l_short(s))
Пример #11
0
 def get_l_short(self) -> int:
     return Binary.read_l_short(self.get(2))