コード例 #1
0
    def extract_variable_header(packet_info: cp.processing):

        iterations = 2
        for index in range(0, iterations):

            if packet_info.reduced_bytes.__len__() < iterations:
                raise Exception(
                    "Error in packet size, can not get variable packet header "
                )

            byte = packet_info.reduced_bytes[0]
            packet_info.pop_a_msb()

            # print("byte:", byte)

            if index == 0:
                if byte != 0:
                    raise Exception("Invalid packet identifier 1")
                packet_info.packet_identifier = ((byte & 255) << 8)
                packet_info.packet_identifier_msb = byte

            # FIXME : Paho request of subscribe doesnt' match documentation of MQTTv311 section 3.8.2.1, figure 3.21
            # Documentation says the packet identifier lsb should be 10
            # But the paho is sending the packet identifier lsb equal to 1

            elif index == 1:
                # if byte != 10:
                #     print(byte)
                #     raise Exception("Invalid packet identifier 2")
                packet_info.packet_identifier = packet_info.packet_identifier | (
                    byte & 255)
                # packet_info.packet_identifier_lsb = 10
                packet_info.packet_identifier_lsb = byte
コード例 #2
0
    def extract_variable_header(packet_info: cp.processing):

        iterations = 2
        for index in range(0, iterations):

            if packet_info.reduced_bytes.__len__() < iterations:
                raise Exception(
                    "Error in packet size, can not get variable packet header "
                )

            byte = packet_info.reduced_bytes[0]
            packet_info.pop_a_msb()

            if index == 0:
                if byte != 0:
                    raise Exception("Invalid packet identifier 1")
                packet_info.packet_identifier = ((byte & 255) << 8)
                packet_info.packet_identifier_msb = byte

            elif index == 1:
                packet_info.packet_identifier = packet_info.packet_identifier | (
                    byte & 255)
                packet_info.packet_identifier_lsb = byte