pub fn new(topic: &str, data: &[u8], properties: &[Property]) -> Result<Self, ProtocolError> {
        // Check that the input properties are valid for a will.
        for property in properties {
            match property.id() {
                PropertyIdentifier::WillDelayInterval
                | PropertyIdentifier::PayloadFormatIndicator
                | PropertyIdentifier::MessageExpiryInterval
                | PropertyIdentifier::ContentType
                | PropertyIdentifier::ResponseTopic
                | PropertyIdentifier::CorrelationData
                | PropertyIdentifier::UserProperty => {}
                _ => return Err(ProtocolError::InvalidProperty),
            }
        }

        let mut buffer: [u8; MSG_SIZE] = [0; MSG_SIZE];
        let mut packet = ReversedPacketWriter::new(&mut buffer);

        // Serialize the will payload
        packet.write_binary_data(data)?;
        packet.write_utf8_string(topic)?;
        packet.write_properties(properties)?;

        Ok(Self {
            qos: QoS::AtMostOnce,
            retain: Retain::NotRetained,
            // Note(unwrap): The vectro is declared as identical size to the vector, so it will
            // always fit.
            payload: Vec::from_slice(packet.finish()).unwrap(),
        })
    }
/// Construct a new will message.
///
/// # Args
/// * `topic` - The topic to send the message on
/// * `data` - The message to transmit
/// * `properties` - Any properties to send with the will message.
Construct a new will message.
Construct a new will message .
pub fn new(topic: &str, data: &[u8], properties: &[Property]) -> Result<Self, ProtocolError> {
        // Check that the input properties are valid for a will.
        for property in properties {
            match property.id() {
                PropertyIdentifier::WillDelayInterval
                | PropertyIdentifier::PayloadFormatIndicator
                | PropertyIdentifier::MessageExpiryInterval
                | PropertyIdentifier::ContentType
                | PropertyIdentifier::ResponseTopic
                | PropertyIdentifier::CorrelationData
                | PropertyIdentifier::UserProperty => {}
                _ => return Err(ProtocolError::InvalidProperty),
            }
        }
        let mut buffer: [u8; MSG_SIZE] = [0; MSG_SIZE];
        let mut packet = ReversedPacketWriter::new(&mut buffer);
        // Serialize the will payload
        packet.write_binary_data(data)?;
        packet.write_utf8_string(topic)?;
        packet.write_properties(properties)?;
        Ok(Self {
            qos: QoS::AtMostOnce,
            retain: Retain::NotRetained,
            // Note(unwrap): The vectro is declared as identical size to the vector, so it will
            // always fit.
            payload: Vec::from_slice(packet.finish()).unwrap(),
        })
    }
pub fn new ( topic : & str , data : & [ u8 ] , properties : & [ Property ] ) -> Result < Self , ProtocolError > { // Check that the input properties are valid for a will. for property in properties { match property . id ( ) { PropertyIdentifier :: WillDelayInterval | PropertyIdentifier :: PayloadFormatIndicator | PropertyIdentifier :: MessageExpiryInterval | PropertyIdentifier :: ContentType | PropertyIdentifier :: ResponseTopic | PropertyIdentifier :: CorrelationData | PropertyIdentifier :: UserProperty => { } _ => return Err ( ProtocolError :: InvalidProperty ) , } } let mut buffer : [ u8 ; MSG_SIZE ] = [ 0 ; MSG_SIZE ] ; let mut packet = ReversedPacketWriter :: new ( & mut buffer ) ; // Serialize the will payload packet . write_binary_data ( data ) ? ; packet . write_utf8_string ( topic ) ? ; packet . write_properties ( properties ) ? ; Ok ( Self { qos : QoS :: AtMostOnce , retain : Retain :: NotRetained , // Note(unwrap): The vectro is declared as identical size to the vector, so it will // always fit. payload : Vec :: from_slice ( packet . finish ( ) ) . unwrap ( ) , } ) }
Construct a new will message.
Construct a new will message .
topic
&str
data
&[u8]
properties
&[Property]
topic
&str
data
&[u8]
properties
&[Property]
args
`topic` - The topic to send the message on
`data` - The message to transmit
`properties` - Any properties to send with the will message.
` topic ` - The topic to send the message on ` data ` - The message to transmit ` properties ` - Any properties to send with the will message .