Ejemplo n.º 1
0
 async def decode_remaining_length():
     """
     Decode message length according to MQTT specifications
     :return:
     """
     multiplier = 1
     value = 0
     buffer = bytearray()
     while True:
         encoded_byte = await reader.read(1)
         int_byte = unpack('!B', encoded_byte)
         buffer.append(int_byte[0])
         value += (int_byte[0] & 0x7f) * multiplier
         if (int_byte[0] & 0x80) == 0:
             break
         else:
             multiplier *= 128
             if multiplier > 128 * 128 * 128:
                 raise MQTTException(
                     "Invalid remaining length bytes:%s, packet_type=%d"
                     % (bytes_to_hex_str(buffer), msg_type))
     return value
Ejemplo n.º 2
0
 def decode_remaining_length():
     """
     Decode message length according to MQTT specifications
     :return:
     """
     multiplier = 1
     value = 0
     buffer = bytearray()
     while True:
         encoded_byte = yield from reader.read(1)
         int_byte = unpack('!B', encoded_byte)
         buffer.append(int_byte[0])
         value += (int_byte[0] & 0x7f) * multiplier
         if (int_byte[0] & 0x80) == 0:
             break
         else:
             multiplier *= 128
             if multiplier > 128 * 128 * 128:
                 raise MQTTException("Invalid remaining length bytes:%s, packet_type=%d" % (bytes_to_hex_str(buffer), msg_type))
     return value
Ejemplo n.º 3
0
 def test_bytes_to_hex_str(self):
     ret = bytes_to_hex_str(b'\x7f')
     self.assertEqual(ret, '0x7f')
Ejemplo n.º 4
0
 def test_bytes_to_hex_str(self):
     ret = bytes_to_hex_str(b"\x7f")
     self.assertEqual(ret, "0x7f")