bash
mosquitto_pub -m "test" -t "test" -i test_id \
-u iz \
-P 1234 \
--will-topic "will" \
--will-payload "lastwill" \
--will-qos 2 \
--will-retain \
-D will response-topic "will_respond" \
-D will content-type "text" \
-D will correlation-data "1234" \
-D will message-expiry-interval 120 \
-D will payload-format-indicator 2 \
-D will user-property "sfilename" "test.txt" \
-D will will-delay-interval 5 -V 5
```rust use gmqtt::{ controlpacket::{ connect::{ConnectProperties, Login}, Connect, Packet, }, readpacket, write_packet, };
const MAXMQTTPACKET_SIZE: u32 = 1024;
pub fn main() { let keepalive: u16 = 60; // 60 seconds let login = Login { username: "username", password: "password".asbytes(), }; let properties = ConnectProperties { topicaliasmax: Some(0), maxpacketsize: Some(MAXMQTTPACKETSIZE), ..ConnectProperties::default() }; let connectpacket = Packet::Connect(Connect { protocol: gmqtt::Protocol::V5, cleanstart: false, keepalive, clientid: "our client id", lastwill: None, login: Some(login), properties: Some(properties), });
let mut buffer = [0x00u8; MAX_MQTT_PACKET_SIZE as usize];
let len = write_packet(&connect_packet, &mut buffer).unwrap();
let read_packet = read_packet(&buffer[..len]).unwrap();
assert_eq!(connect_packet, read_packet);
}
```