Ejemplo n.º 1
0
    def _event_publish(self, packet, qos, dup, retain):
        """ Receive a "Published" message

        Here we get a published message from the broker.
        Extract the parts of the packet.
        @param packet: is a bytearray containing the variable header and payload combined.
        """
        #  Extract the topic portion of the packet.
        l_topic = EncodeDecode._decodeString(packet)
        packet = packet[len(l_topic) + 2:]
        #  Extract the message ID if appropriate
        messageId = None
        if qos > 0:
            messageId = EncodeDecode._decodeValue(packet[:2])
            packet = packet[2:]
            LOG.debug('Publish MsgID:{}'.format(messageId))
        #  Extract whatever remains as the message
        l_json = EncodeDecode._get_string(packet)
        # l_json = packet.decode('utf-8')
        l_message = json_tools.decode_json_unicode(l_json)
        # l_topic is a string
        # l_message is a string
        self.publishReceived(l_topic, l_message, qos, dup, retain, messageId)