示例#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))