示例#1
0
 def __init__(self, fixed: MQTTFixedHeader=None, variable_header: PacketIdVariableHeader=None):
     if fixed is None:
         header = MQTTFixedHeader(PUBACK, 0x00)
     else:
         if fixed.packet_type is not PUBACK:
             raise DistMQTTException("Invalid fixed packet type %s for PubackPacket init" % fixed.packet_type)
         header = fixed
     super().__init__(header)
     self.variable_header = variable_header
     self.payload = None
示例#2
0
 def __init__(self, fixed: MQTTFixedHeader=None):
     if fixed is None:
         header = MQTTFixedHeader(DISCONNECT, 0x00)
     else:
         if fixed.packet_type is not DISCONNECT:
             raise DistMQTTException("Invalid fixed packet type %s for DisconnectPacket init" % fixed.packet_type)
         header = fixed
     super().__init__(header)
     self.variable_header = None
     self.payload = None
示例#3
0
 def test_encode(self):
     header = MQTTFixedHeader(CONNECT, 0x00, 0)
     variable_header = ConnectVariableHeader(0xCE, 0, "MQTT", 4)
     payload = ConnectPayload("0123456789", "WillTopic", b"WillMessage",
                              "user", "password")
     message = ConnectPacket(header, variable_header, payload)
     encoded = message.to_bytes()
     self.assertEqual(
         encoded,
         b"\x10\x3e\x00\x04MQTT\x04\xce\x00\x00\x00\x0a0123456789\x00\x09WillTopic\x00\x0bWillMessage\x00\x04user\x00\x08password",
     )
示例#4
0
 def test_encode(self):
     header = MQTTFixedHeader(CONNECT, 0x00, 0)
     variable_header = ConnectVariableHeader(0xce, 0, 'MQTT', 4)
     payload = ConnectPayload('0123456789', 'WillTopic', b'WillMessage',
                              'user', 'password')
     message = ConnectPacket(header, variable_header, payload)
     encoded = message.to_bytes()
     self.assertEqual(
         encoded,
         b'\x10\x3e\x00\x04MQTT\x04\xce\x00\x00\x00\x0a0123456789\x00\x09WillTopic\x00\x0bWillMessage\x00\x04user\x00\x08password'
     )
示例#5
0
 def __init__(self, fixed: MQTTFixedHeader = None):
     if fixed is None:
         header = MQTTFixedHeader(PINGRESP, 0x00)
     else:
         if fixed.packet_type is not PINGRESP:
             raise DistMQTTException(
                 "Invalid fixed packet type %s for PingRespPacket init" %
                 fixed.packet_type)
         header = fixed
     super().__init__(header)
     self.variable_header = None
     self.payload = None
示例#6
0
 def __init__(
     self, fixed: MQTTFixedHeader = None, variable_header: PacketIdVariableHeader = None,
 ):
     if fixed is None:
         header = MQTTFixedHeader(PUBREL, 0x02)  # [MQTT-3.6.1-1]
     else:
         if fixed.packet_type != PUBREL:
             raise DistMQTTException(
                 "Invalid fixed packet type %s for PubrelPacket init" % fixed.packet_type
             )
         header = fixed
     super().__init__(header)
     self.variable_header = variable_header
     self.payload = None
示例#7
0
    def __init__(self,
                 fixed: MQTTFixedHeader = None,
                 variable_header: PacketIdVariableHeader = None,
                 payload=None):
        if fixed is None:
            header = MQTTFixedHeader(UNSUBSCRIBE, 0x02)  # [MQTT-3.10.1-1]
        else:
            if fixed.packet_type is not UNSUBSCRIBE:
                raise DistMQTTException(
                    "Invalid fixed packet type %s for UnsubscribePacket init" %
                    fixed.packet_type)
            header = fixed

        super().__init__(header)
        self.variable_header = variable_header
        self.payload = payload
示例#8
0
 def __init__(
     self,
     fixed: MQTTFixedHeader = None,
     variable_header: ConnackVariableHeader = None,
     payload=None,
 ):
     if fixed is None:
         header = MQTTFixedHeader(CONNACK, 0x00)
     else:
         if fixed.packet_type != CONNACK:
             raise DistMQTTException(
                 "Invalid fixed packet type %s for ConnackPacket init" %
                 fixed.packet_type)
         header = fixed
     super().__init__(header)
     self.variable_header = variable_header
     self.payload = None
示例#9
0
    def __init__(
        self,
        fixed: MQTTFixedHeader = None,
        variable_header: PublishVariableHeader = None,
        payload=None,
    ):
        if fixed is None:
            header = MQTTFixedHeader(PUBLISH, 0x00)
        else:
            if fixed.packet_type != PUBLISH:
                raise DistMQTTException(
                    "Invalid fixed packet type %s for PublishPacket init" %
                    fixed.packet_type)
            header = fixed

        super().__init__(header)
        self.variable_header = variable_header
        self.payload = payload
示例#10
0
 def test_to_bytes_2(self):
     header = MQTTFixedHeader(CONNECT, 0x00, 268435455)
     data = header.to_bytes()
     self.assertEqual(data, b"\x10\xff\xff\xff\x7f")
示例#11
0
 def test_to_bytes(self):
     header = MQTTFixedHeader(CONNECT, 0x00, 0)
     data = header.to_bytes()
     self.assertEqual(data, b"\x10\x00")