mqtt/pdu.py
def decode(self, packet):
        '''
        Decode a CONNECT control packet. 
        '''
        self.encoded = packet
        # Strip the fixed header plus variable length field
        lenLen = 1
        while packet[lenLen] & 0x80:
            lenLen += 1
        packet_remaining = packet[lenLen+1:]
        # Variable Header
        version_str, packet_remaining = decodeString(packet_remaining)
        version_id = int(packet_remaining[0])
        if version_id == v31['level']:
            self.version = v31
        else:
            self.version = v311
        flags = packet_remaining[1]
        self.cleanStart = (flags & 0x02) != 0
        willFlag   = (flags & 0x04) != 0
        willQoS    = (flags >> 3) & 0x03
        willRetain = (flags & 0x20) != 0
        userFlag   = (flags & 0x80)  != 0
        passFlag   = (flags & 0x40)  != 0
        packet_remaining = packet_remaining[2:]
        self.keepalive = decode16Int(packet_remaining)
        # Payload
        packet_remaining = packet_remaining[2:]
        self.clientId, packet_remaining = decodeString(packet_remaining)
        if willFlag:
            self.willRetain = willRetain
            self.willQoS    = willQoS
            self.willTopic,  packet_remaining  = decodeString(packet_remaining)
            self.willMessage, packet_remaining = decodeString(packet_remaining)
        if userFlag:
            self.username, packet_remaining = decodeString(packet_remaining)
        if passFlag:
            l = decode16Int(packet_remaining)
            self.password = packet_remaining[2:2+l]
def decode(self, packet):
        '''
        Decode a CONNECT control packet. 
        '''
        self.encoded = packet
        # Strip the fixed header plus variable length field
        lenLen = 1
        while packet[lenLen] & 0x80:
            lenLen += 1
        packet_remaining = packet[lenLen+1:]
        # Variable Header
        version_str, packet_remaining = decodeString(packet_remaining)
        version_id = int(packet_remaining[0])
        if version_id == v31['level']:
            self.version = v31
        else:
            self.version = v311
        flags = packet_remaining[1]
        self.cleanStart = (flags & 0x02) != 0
        willFlag   = (flags & 0x04) != 0
        willQoS    = (flags >> 3) & 0x03
        willRetain = (flags & 0x20) != 0
        userFlag   = (flags & 0x80)  != 0
        passFlag   = (flags & 0x40)  != 0
        packet_remaining = packet_remaining[2:]
        self.keepalive = decode16Int(packet_remaining)
        # Payload
        packet_remaining = packet_remaining[2:]
        self.clientId, packet_remaining = decodeString(packet_remaining)
        if willFlag:
            self.willRetain = willRetain
            self.willQoS    = willQoS
            self.willTopic,  packet_remaining  = decodeString(packet_remaining)
            self.willMessage, packet_remaining = decodeString(packet_remaining)
        if userFlag:
            self.username, packet_remaining = decodeString(packet_remaining)
        if passFlag:
            l = decode16Int(packet_remaining)
            self.password = packet_remaining[2:2+l]
Decode a CONNECT control packet.