pub fn publish(
        &mut self,
        topic: &str,
        data: &[u8],
        qos: QoS,
        properties: &[Property],
    ) -> Result<(), Error<TcpStack::Error>> {
        // TODO: QoS 2 support.
        assert!(qos != QoS::ExactlyOnce);

        // If we are not yet connected to the broker, we can't transmit a message.
        if self.is_connected() == false {
            return Ok(());
        }

        debug!(
            "Publishing to `{}`: {:?} Props: {:?}",
            topic, data, properties
        );

        // If QoS 0 the ID will be ignored
        let id = self.session_state.get_packet_identifier();

        let mut buffer: [u8; MSG_SIZE] = [0; MSG_SIZE];
        let packet = serialize::publish_message(&mut buffer, topic, data, qos, id, properties)?;

        self.network.write(packet)?;
        self.session_state.increment_packet_identifier();

        if qos == QoS::AtLeastOnce {
            self.session_state.handle_publish(qos, id, packet);
        }

        Ok(())
    }
/// Publish a message over MQTT.
///
/// # Note
/// If the client is not yet connected to the broker, the message will be silently ignored.
///
/// # Note
/// Currently, QoS level 2 (exactly once) delivery is not supported.
///
/// # Args
/// * `topic` - The topic to publish the message to.
/// * `data` - The data to transmit as the message contents.
/// * `qos` - The desired quality-of-service level of the message. Must be QoS::AtMostOnce
/// * `properties` - A list of properties to associate with the message being published. May be
///   empty.
Publish a message over MQTT.
Publish a message over MQTT .
pub fn publish(
        &mut self,
        topic: &str,
        data: &[u8],
        qos: QoS,
        properties: &[Property],
    ) -> Result<(), Error<TcpStack::Error>> {
        // TODO: QoS 2 support.
        assert!(qos != QoS::ExactlyOnce);
        // If we are not yet connected to the broker, we can't transmit a message.
        if self.is_connected() == false {
            return Ok(());
        }
        debug!(
            "Publishing to `{}`: {:?} Props: {:?}",
            topic, data, properties
        );
        // If QoS 0 the ID will be ignored
        let id = self.session_state.get_packet_identifier();
        let mut buffer: [u8; MSG_SIZE] = [0; MSG_SIZE];
        let packet = serialize::publish_message(&mut buffer, topic, data, qos, id, properties)?;
        self.network.write(packet)?;
        self.session_state.increment_packet_identifier();
        if qos == QoS::AtLeastOnce {
            self.session_state.handle_publish(qos, id, packet);
        }
        Ok(())
    }
pub fn publish ( & mut self , topic : & str , data : & [ u8 ] , qos : QoS , properties : & [ Property ] , ) -> Result < ( ) , Error < TcpStack :: Error > > { // TODO: QoS 2 support. assert ! ( qos QoS ExactlyOnce ) ; // If we are not yet connected to the broker, we can't transmit a message. if self . is_connected ( ) == false { return Ok ( ( ) ) ; } debug ! ( " " topic data properties ) ; // If QoS 0 the ID will be ignored let id = self . session_state . get_packet_identifier ( ) ; let mut buffer : [ u8 ; MSG_SIZE ] = [ 0 ; MSG_SIZE ] ; let packet = serialize :: publish_message ( & mut buffer , topic , data , qos , id , properties ) ? ; self . network . write ( packet ) ? ; self . session_state . increment_packet_identifier ( ) ; if qos == QoS :: AtLeastOnce { self . session_state . handle_publish ( qos , id , packet ) ; } Ok ( ( ) ) }
Publish a message over MQTT.
Publish a message over MQTT .
&mut self
topic
&str
data
&[u8]
qos
QoS
properties
&[Property]
note
If the client is not yet connected to the broker, the message will be silently ignored.
If the client is not yet connected to the broker the message will be silently ignored .
note
Currently, QoS level 2 (exactly once) delivery is not supported.
Currently QoS level 2 ( exactly once ) delivery is not supported .
args
`topic` - The topic to publish the message to.
`data` - The data to transmit as the message contents.
`qos` - The desired quality-of-service level of the message. Must be QoS::AtMostOnce
`properties` - A list of properties to associate with the message being published. May be
empty.
` topic ` - The topic to publish the message to . ` data ` - The data to transmit as the message contents . ` qos ` - The desired quality - of - service level of the message . Must be QoS :: AtMostOnce ` properties ` - A list of properties to associate with the message being published . May be empty .