diff --git a/README.md b/README.md index cb505ef..abf2e58 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ fn main() -> Result<(), Box> { .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) .payload(b"Hello, MQTT!") - .packet_id(connection.acquire_packet_id()?) + .packet_id(Some(connection.acquire_packet_id()?)) .build()?; let events = connection.checked_send(publish_packet); diff --git a/examples/publish.rs b/examples/publish.rs index 891a75d..81ccb49 100644 --- a/examples/publish.rs +++ b/examples/publish.rs @@ -65,20 +65,21 @@ fn main() -> Result<(), Box> { handle_events(&mut stream, &mut connection, events)?; } - let mut publish_builder = mqtt::packet::v5_0::Publish::builder() + let packet_id = match qos_level { + mqtt::packet::Qos::AtMostOnce => None, + _ => Some( + connection + .acquire_packet_id() + .map_err(|e| format!("Failed to acquire packet ID: {e:?}"))?, + ), + }; + + let publish_packet = mqtt::packet::v5_0::Publish::builder() .topic_name(topic) .unwrap() .qos(qos_level) - .payload(payload.as_bytes()); - - if qos_level != mqtt::packet::Qos::AtMostOnce { - let packet_id = connection - .acquire_packet_id() - .map_err(|e| format!("Failed to acquire packet ID: {e:?}"))?; - publish_builder = publish_builder.packet_id(packet_id); - } - - let publish_packet = publish_builder + .packet_id(packet_id) + .payload(payload.as_bytes()) .build() .map_err(|e| format!("Failed to build PUBLISH packet: {e:?}"))?; diff --git a/src/mqtt/packet/v3_1_1/publish.rs b/src/mqtt/packet/v3_1_1/publish.rs index cab716b..06a7a93 100644 --- a/src/mqtt/packet/v3_1_1/publish.rs +++ b/src/mqtt/packet/v3_1_1/publish.rs @@ -861,10 +861,10 @@ where /// .topic_name("test/topic") /// .unwrap() /// .qos(Qos::AtLeastOnce) - /// .packet_id(123); + /// .packet_id(Some(123)); /// ``` - pub fn packet_id(mut self, id: PacketIdType) -> Self { - self.packet_id_buf = Some(Some(id.to_buffer())); + pub fn packet_id(mut self, id: Option) -> Self { + self.packet_id_buf = id.map(|id| Some(id.to_buffer())); self } diff --git a/src/mqtt/packet/v5_0/publish.rs b/src/mqtt/packet/v5_0/publish.rs index fcf7417..2156b09 100644 --- a/src/mqtt/packet/v5_0/publish.rs +++ b/src/mqtt/packet/v5_0/publish.rs @@ -1155,10 +1155,10 @@ where /// use mqtt_protocol_core::mqtt; /// /// let builder = mqtt::packet::v5_0::Publish::builder() - /// .packet_id(42); + /// .packet_id(Some(42)); /// ``` - pub fn packet_id(mut self, id: PacketIdType) -> Self { - self.packet_id_buf = Some(Some(id.to_buffer())); + pub fn packet_id(mut self, id: Option) -> Self { + self.packet_id_buf = id.map(|id| Some(id.to_buffer())); self } diff --git a/tests/connection-core-auto-res.rs b/tests/connection-core-auto-res.rs index 8adee54..78855fa 100644 --- a/tests/connection-core-auto-res.rs +++ b/tests/connection-core-auto-res.rs @@ -55,7 +55,7 @@ fn auto_pub_response_v3_1_1() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -89,7 +89,7 @@ fn auto_pub_response_v3_1_1() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -188,7 +188,7 @@ fn auto_pub_response_v5_0() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -222,7 +222,7 @@ fn auto_pub_response_v5_0() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -323,7 +323,7 @@ fn qos2_pubrel_send_request_v3_1_1() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id) + .packet_id(Some(packet_id)) .payload(b"test payload".to_vec()) .build() .unwrap(); @@ -393,7 +393,7 @@ fn qos2_pubrel_send_request_v5_0() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id) + .packet_id(Some(packet_id)) .payload(b"test payload".to_vec()) .build() .unwrap(); diff --git a/tests/connection-core-maximum-packet-size.rs b/tests/connection-core-maximum-packet-size.rs index 88999e9..771c5f6 100644 --- a/tests/connection-core-maximum-packet-size.rs +++ b/tests/connection-core-maximum-packet-size.rs @@ -324,7 +324,7 @@ fn client_over_maximum_packet_size_recv() { .topic_name("topic/c") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"012345678901234567890123456789".to_vec()) .build() .unwrap(); @@ -408,7 +408,7 @@ fn server_over_maximum_packet_size_recv() { .topic_name("topic/c") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"012345678901234567890123456789".to_vec()) .build() .unwrap(); diff --git a/tests/connection-core-misc.rs b/tests/connection-core-misc.rs index b980fa7..8f8ada0 100644 --- a/tests/connection-core-misc.rs +++ b/tests/connection-core-misc.rs @@ -85,7 +85,7 @@ fn offline_publish_v3_1_1() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -98,7 +98,7 @@ fn offline_publish_v3_1_1() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -170,7 +170,7 @@ fn offline_publish_v5_0() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -183,7 +183,7 @@ fn offline_publish_v5_0() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -253,7 +253,7 @@ fn puback_match_v3_1_1() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -930,7 +930,7 @@ fn qos2_publish_handled_v3_1_1() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); diff --git a/tests/connection-core-notify-closed.rs b/tests/connection-core-notify-closed.rs index 3a48ad9..97457db 100644 --- a/tests/connection-core-notify-closed.rs +++ b/tests/connection-core-notify-closed.rs @@ -272,7 +272,7 @@ fn notify_closed_with_acquired_packet_ids() { .topic_name("test/qos1") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(publish_qos1_pid) + .packet_id(Some(publish_qos1_pid)) .payload(b"qos1 payload") .build() .expect("Failed to build Publish QoS1 packet") @@ -287,7 +287,7 @@ fn notify_closed_with_acquired_packet_ids() { .topic_name("test/qos2") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(publish_qos2_pid) + .packet_id(Some(publish_qos2_pid)) .payload(b"qos2 payload") .build() .expect("Failed to build Publish QoS2 packet") @@ -391,7 +391,7 @@ fn notify_closed_with_acquired_packet_ids_session_storage() { .topic_name("test/qos1") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(publish_qos1_pid) + .packet_id(Some(publish_qos1_pid)) .payload(b"qos1 payload") .build() .expect("Failed to build Publish QoS1 packet") @@ -406,7 +406,7 @@ fn notify_closed_with_acquired_packet_ids_session_storage() { .topic_name("test/qos2") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(publish_qos2_pid) + .packet_id(Some(publish_qos2_pid)) .payload(b"qos2 payload") .build() .expect("Failed to build Publish QoS2 packet") @@ -506,7 +506,7 @@ fn notify_closed_v5_0_with_acquired_packet_ids() { .topic_name("test/qos1") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(publish_qos1_pid) + .packet_id(Some(publish_qos1_pid)) .payload(b"qos1 payload") .build() .expect("Failed to build Publish QoS1 packet") @@ -521,7 +521,7 @@ fn notify_closed_v5_0_with_acquired_packet_ids() { .topic_name("test/qos2") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(publish_qos2_pid) + .packet_id(Some(publish_qos2_pid)) .payload(b"qos2 payload") .build() .expect("Failed to build Publish QoS2 packet") diff --git a/tests/connection-core-receive-maximum.rs b/tests/connection-core-receive-maximum.rs index 0a534bc..becdb41 100644 --- a/tests/connection-core-receive-maximum.rs +++ b/tests/connection-core-receive-maximum.rs @@ -50,7 +50,7 @@ fn get_receive_maximum_vacancy_for_send_client() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -64,7 +64,7 @@ fn get_receive_maximum_vacancy_for_send_client() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -78,7 +78,7 @@ fn get_receive_maximum_vacancy_for_send_client() { .topic_name("topic/c") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_c) + .packet_id(Some(packet_id_c)) .payload(b"payload C".to_vec()) .build() .unwrap(); @@ -173,7 +173,7 @@ fn get_receive_maximum_vacancy_for_send_server() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -187,7 +187,7 @@ fn get_receive_maximum_vacancy_for_send_server() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -201,7 +201,7 @@ fn get_receive_maximum_vacancy_for_send_server() { .topic_name("topic/c") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_c) + .packet_id(Some(packet_id_c)) .payload(b"payload C".to_vec()) .build() .unwrap(); @@ -286,7 +286,7 @@ fn receive_maximum_exceeded_send() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -298,7 +298,7 @@ fn receive_maximum_exceeded_send() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -361,7 +361,7 @@ fn receive_maximum_exceeded_recv() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -374,7 +374,7 @@ fn receive_maximum_exceeded_recv() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -451,7 +451,7 @@ fn receive_maximum_exceeded_recv_server() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -464,7 +464,7 @@ fn receive_maximum_exceeded_recv_server() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); diff --git a/tests/connection-core-recv-success.rs b/tests/connection-core-recv-success.rs index 7595bea..8fa1f26 100644 --- a/tests/connection-core-recv-success.rs +++ b/tests/connection-core-recv-success.rs @@ -129,7 +129,7 @@ fn client_recv_pubrel_success_v5_0() { v5_0_client_establish_connection(&mut connection); let packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) diff --git a/tests/connection-core-send-error-status.rs b/tests/connection-core-send-error-status.rs index 715860d..9ad3b3b 100644 --- a/tests/connection-core-send-error-status.rs +++ b/tests/connection-core-send-error-status.rs @@ -99,7 +99,7 @@ fn v3_1_1_client_not_allowed_to_send_invalid_pid_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); v3_1_1_client_establish_connection(&mut con, true, false); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -129,7 +129,7 @@ fn v3_1_1_client_not_allowed_to_send_invalid_pid_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); v3_1_1_client_establish_connection(&mut con, true, false); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -268,7 +268,7 @@ fn v3_1_1_client_not_allowed_to_send_on_status_connecting_publish_qos1() { v3_1_1_client_connecting(&mut con, true); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -304,7 +304,7 @@ fn v3_1_1_client_not_allowed_to_send_on_status_connecting_publish_qos2() { v3_1_1_client_connecting(&mut con, true); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -476,7 +476,7 @@ fn v3_1_1_client_not_allowed_to_send_on_status_disconnected_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -511,7 +511,7 @@ fn v3_1_1_client_not_allowed_to_send_on_status_disconnected_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -748,7 +748,7 @@ fn v3_1_1_server_not_allowed_to_send_invalid_pid_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); v3_1_1_server_establish_connection(&mut con, true, false); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -778,7 +778,7 @@ fn v3_1_1_server_not_allowed_to_send_invalid_pid_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); v3_1_1_server_establish_connection(&mut con, true, false); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -890,7 +890,7 @@ fn v3_1_1_server_not_allowed_to_send_on_status_connecting_publish_qos1() { v3_1_1_server_connecting(&mut con, true); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -926,7 +926,7 @@ fn v3_1_1_server_not_allowed_to_send_on_status_connecting_publish_qos2() { v3_1_1_server_connecting(&mut con, true); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -1079,7 +1079,7 @@ fn v3_1_1_server_not_allowed_to_send_on_status_disconnected_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -1114,7 +1114,7 @@ fn v3_1_1_server_not_allowed_to_send_on_status_disconnected_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V3_1_1); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -1282,7 +1282,7 @@ fn v5_0_client_not_allowed_to_send_invalid_pid_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); v5_0_client_establish_connection(&mut con); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -1312,7 +1312,7 @@ fn v5_0_client_not_allowed_to_send_invalid_pid_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); v5_0_client_establish_connection(&mut con); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -1458,7 +1458,7 @@ fn v5_0_client_not_allowed_to_send_on_status_connecting_publish_qos1() { v5_0_client_connecting(&mut con); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -1494,7 +1494,7 @@ fn v5_0_client_not_allowed_to_send_on_status_connecting_publish_qos2() { v5_0_client_connecting(&mut con); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -1670,7 +1670,7 @@ fn v5_0_client_not_allowed_to_send_on_status_disconnected_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -1705,7 +1705,7 @@ fn v5_0_client_not_allowed_to_send_on_status_disconnected_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -1968,7 +1968,7 @@ fn v5_0_server_not_allowed_to_send_invalid_pid_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); v5_0_server_establish_connection(&mut con); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -1998,7 +1998,7 @@ fn v5_0_server_not_allowed_to_send_invalid_pid_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); v5_0_server_establish_connection(&mut con); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -2110,7 +2110,7 @@ fn v5_0_server_not_allowed_to_send_on_status_connecting_publish_qos1() { v5_0_server_connecting(&mut con); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -2146,7 +2146,7 @@ fn v5_0_server_not_allowed_to_send_on_status_connecting_publish_qos2() { v5_0_server_connecting(&mut con); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -2321,7 +2321,7 @@ fn v5_0_server_not_allowed_to_send_on_status_disconnected_publish_qos1() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -2356,7 +2356,7 @@ fn v5_0_server_not_allowed_to_send_on_status_disconnected_publish_qos2() { let mut con = mqtt::Connection::::new(mqtt::Version::V5_0); let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) diff --git a/tests/connection-core-send-success.rs b/tests/connection-core-send-success.rs index 3590ff4..addee77 100644 --- a/tests/connection-core-send-success.rs +++ b/tests/connection-core-send-success.rs @@ -68,7 +68,7 @@ fn v3_1_1_client_send_publish_pubrel() { let packet_id = con.acquire_packet_id().unwrap(); let packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -131,7 +131,7 @@ fn v3_1_1_client_send_puback() { let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -173,7 +173,7 @@ fn v5_0_client_send_puback() { let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) @@ -215,7 +215,7 @@ fn v3_1_1_client_send_pubrec_pubcomp() { let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v3_1_1::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -287,7 +287,7 @@ fn v5_0_client_send_pubrec_pubcomp() { let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) @@ -362,7 +362,7 @@ fn v5_0_client_send_pubrec() { let packet_id = con.acquire_packet_id().unwrap(); let packet: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(packet_id) + .packet_id(Some(packet_id)) .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) diff --git a/tests/connection-core-store.rs b/tests/connection-core-store.rs index 04aa50c..8910ccd 100644 --- a/tests/connection-core-store.rs +++ b/tests/connection-core-store.rs @@ -49,7 +49,7 @@ fn v5_0_send_stored_success() { let pid_q1_a = con.acquire_packet_id().unwrap(); let pub_q1_a = mqtt::packet::v5_0::Publish::builder() - .packet_id(pid_q1_a) + .packet_id(Some(pid_q1_a)) .qos(mqtt::packet::Qos::AtLeastOnce) .topic_name("t") .unwrap() @@ -60,7 +60,7 @@ fn v5_0_send_stored_success() { let pid_q2_b = con.acquire_packet_id().unwrap(); let pub_q2_b = mqtt::packet::v5_0::Publish::builder() - .packet_id(pid_q2_b) + .packet_id(Some(pid_q2_b)) .qos(mqtt::packet::Qos::ExactlyOnce) .topic_name("t") .unwrap() @@ -71,7 +71,7 @@ fn v5_0_send_stored_success() { let pid_q2_c = con.acquire_packet_id().unwrap(); let pub_q2_c = mqtt::packet::v5_0::Publish::builder() - .packet_id(pid_q2_c) + .packet_id(Some(pid_q2_c)) .qos(mqtt::packet::Qos::ExactlyOnce) .topic_name("t") .unwrap() @@ -197,7 +197,7 @@ fn v5_0_send_stored_oversize() { let pid = con.acquire_packet_id().unwrap(); { let packet = mqtt::packet::v5_0::Publish::builder() - .packet_id(pid) + .packet_id(Some(pid)) .qos(mqtt::packet::Qos::AtLeastOnce) .topic_name("t") .unwrap() @@ -305,7 +305,7 @@ fn restore_packets_v3_1_1() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -314,7 +314,7 @@ fn restore_packets_v3_1_1() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(2) + .packet_id(Some(2)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -460,7 +460,7 @@ fn restore_packets_v5_0_server() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -469,7 +469,7 @@ fn restore_packets_v5_0_server() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(2) + .packet_id(Some(2)) .payload(b"payload B".to_vec()) .build() .unwrap(); @@ -640,7 +640,7 @@ fn qos2_publish_handled_restore_v5_0() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -692,7 +692,7 @@ fn v5_0_send_stored_success_server() { .topic_name("topic/a") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_a) + .packet_id(Some(packet_id_a)) .payload(b"payload A".to_vec()) .build() .unwrap(); @@ -703,7 +703,7 @@ fn v5_0_send_stored_success_server() { .topic_name("topic/b") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(packet_id_b) + .packet_id(Some(packet_id_b)) .payload(b"payload B".to_vec()) .build() .unwrap(); diff --git a/tests/connection-core-topic-alias.rs b/tests/connection-core-topic-alias.rs index 1331ff6..b96b855 100644 --- a/tests/connection-core-topic-alias.rs +++ b/tests/connection-core-topic-alias.rs @@ -362,7 +362,7 @@ fn manual_topic_alias() { // Send QoS0 PUBLISH B let publish_b = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(connection.acquire_packet_id().unwrap()) + .packet_id(Some(connection.acquire_packet_id().unwrap())) .payload(b"payload B".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -430,7 +430,7 @@ fn manual_topic_alias() { { let publish_extracted: mqtt::packet::Packet = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic/a") .unwrap() .payload(b"payload B".to_vec()) @@ -500,7 +500,7 @@ fn manual_topic_alias_store_not_registered() { let pid = connection.acquire_packet_id().unwrap(); let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(pid) + .packet_id(Some(pid)) .payload(b"payload A".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -569,7 +569,7 @@ fn manual_topic_alias_not_registered() { let pid = connection.acquire_packet_id().unwrap(); let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(pid) + .packet_id(Some(pid)) .payload(b"payload A".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -638,7 +638,7 @@ fn manual_topic_alias_oor() { let pid = connection.acquire_packet_id().unwrap(); let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(pid) + .packet_id(Some(pid)) .topic_name("topic/a") .unwrap() .payload(b"payload B".to_vec()) @@ -708,7 +708,7 @@ fn manual_topic_alias_register_oor_recv() { // Recv QoS0 PUBLISH A with unregistered topic alias let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic/a") .unwrap() .payload(b"payload A".to_vec()) @@ -800,7 +800,7 @@ fn manual_topic_alias_register_oor_recv_server() { // Recv QoS0 PUBLISH A with unregistered topic alias let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic/a") .unwrap() .payload(b"payload A".to_vec()) @@ -892,7 +892,7 @@ fn manual_topic_alias_extract_recv() { // Recv QoS0 PUBLISH A with topic alias register let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .topic_name("topic/a") .unwrap() .payload(b"payload A".to_vec()) @@ -907,7 +907,7 @@ fn manual_topic_alias_extract_recv() { // Recv QoS0 PUBLISH B with using topic alias let publish_b = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .payload(b"payload B".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -963,7 +963,7 @@ fn manual_topic_alias_use_oor_recv() { // Recv QoS0 PUBLISH A with unregistered topic alias let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .payload(b"payload A".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(4).unwrap().into()]) .build() @@ -1053,7 +1053,7 @@ fn manual_topic_alias_use_unreg_recv() { // Recv QoS0 PUBLISH A with unregistered topic alias let publish_a = mqtt::packet::v5_0::Publish::builder() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1) + .packet_id(Some(1)) .payload(b"payload A".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -1234,7 +1234,7 @@ fn regulate_for_store_topic_alias() { .topic_name("original/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_1) + .packet_id(Some(packet_id_1)) .payload(b"original payload".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -1247,7 +1247,7 @@ fn regulate_for_store_topic_alias() { .topic_name("") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_2) + .packet_id(Some(packet_id_2)) .payload(b"test payload 1".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -1267,7 +1267,7 @@ fn regulate_for_store_topic_alias() { .topic_name("new/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_3) + .packet_id(Some(packet_id_3)) .payload(b"test payload 2".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(1).unwrap().into()]) .build() @@ -1287,7 +1287,7 @@ fn regulate_for_store_topic_alias() { .topic_name("") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(packet_id_6) + .packet_id(Some(packet_id_6)) .payload(b"test payload 5".to_vec()) .props(vec![mqtt::packet::TopicAlias::new(2).unwrap().into()]) .build() diff --git a/tests/connection-store.rs b/tests/connection-store.rs index e58be5f..d6e70c7 100644 --- a/tests/connection-store.rs +++ b/tests/connection-store.rs @@ -35,7 +35,7 @@ fn make_packet_u32(id: u32, qos: Qos) -> GenericStorePacket { .unwrap() .payload("test payload") .qos(qos) - .packet_id(id) + .packet_id(Some(id)) .build() .unwrap(); @@ -50,7 +50,7 @@ fn make_packet_u16(id: u16, qos: Qos) -> GenericStorePacket { .unwrap() .payload("test payload") .qos(qos) - .packet_id(id) + .packet_id(Some(id)) .build() .unwrap(); diff --git a/tests/packet-enum_store_packet.rs b/tests/packet-enum_store_packet.rs index ae2620a..047eb11 100644 --- a/tests/packet-enum_store_packet.rs +++ b/tests/packet-enum_store_packet.rs @@ -77,7 +77,7 @@ fn v3_1_1_publish_qos1_store_packet() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(123u16) + .packet_id(Some(123u16)) .payload(b"test payload") .build() .unwrap(); @@ -100,7 +100,7 @@ fn v3_1_1_publish_qos2_store_packet() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(456u16) + .packet_id(Some(456u16)) .payload(b"test payload") .build() .unwrap(); @@ -142,7 +142,7 @@ fn v5_0_publish_qos1_store_packet() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(789u16) + .packet_id(Some(789u16)) .payload(b"test payload") .build() .unwrap(); @@ -165,7 +165,7 @@ fn v5_0_publish_qos2_store_packet() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(999u16) + .packet_id(Some(999u16)) .payload(b"test payload") .build() .unwrap(); @@ -245,7 +245,7 @@ fn packet_type_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap(); @@ -275,7 +275,7 @@ fn packet_type_v5_0_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap(); @@ -306,7 +306,7 @@ fn packet_id_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(333u16) + .packet_id(Some(333u16)) .build() .unwrap(); @@ -333,7 +333,7 @@ fn packet_id_v5_0_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(555u16) + .packet_id(Some(555u16)) .build() .unwrap(); @@ -361,7 +361,7 @@ fn response_packet_v3_1_1_publish_qos1() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap(); @@ -379,7 +379,7 @@ fn response_packet_v3_1_1_publish_qos2() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap(); @@ -412,7 +412,7 @@ fn response_packet_v5_0_publish_qos1() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap(); @@ -430,7 +430,7 @@ fn response_packet_v5_0_publish_qos2() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap(); @@ -464,7 +464,7 @@ fn size_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -508,7 +508,7 @@ fn size_v5_0_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -554,7 +554,7 @@ fn to_buffers_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -600,7 +600,7 @@ fn to_buffers_v5_0_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -646,7 +646,7 @@ fn debug_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -664,7 +664,7 @@ fn display_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -696,7 +696,7 @@ fn debug_v5_0_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -742,7 +742,7 @@ fn display_v5_0_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -775,7 +775,7 @@ fn clone_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -806,7 +806,7 @@ fn convert_to_generic_packet_v3_1_1_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .payload(b"test payload") .build() .unwrap(); @@ -848,7 +848,7 @@ fn convert_to_generic_packet_v5_0_publish() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(789u16) + .packet_id(Some(789u16)) .payload(b"test payload") .build() .unwrap(); diff --git a/tests/packet-v3_1_1-publish.rs b/tests/packet-v3_1_1-publish.rs index d09305b..d8aa03d 100644 --- a/tests/packet-v3_1_1-publish.rs +++ b/tests/packet-v3_1_1-publish.rs @@ -84,7 +84,7 @@ fn build_fail_qos0_with_packet_id() { let err = mqtt::packet::v3_1_1::Publish::builder() .topic_name("test") .unwrap() - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap_err(); assert_eq!(err, mqtt::result_code::MqttError::MalformedPacket); @@ -98,7 +98,7 @@ fn build_fail_qos0_with_packet_id_validation() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtMostOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap_err(); assert_eq!(err, mqtt::result_code::MqttError::MalformedPacket); @@ -112,7 +112,7 @@ fn build_fail_qos1_packet_id_zero() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(0u16) + .packet_id(Some(0u16)) .build() .unwrap_err(); assert_eq!(err, mqtt::result_code::MqttError::MalformedPacket); @@ -141,7 +141,7 @@ fn build_success_qos2() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -190,7 +190,7 @@ fn display_qos1_with_packet_id() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -282,6 +282,7 @@ fn getter_qos0() { let packet = mqtt::packet::v3_1_1::Publish::builder() .topic_name("test/topic") .unwrap() + .packet_id(None) .payload("hello") .build() .unwrap(); @@ -301,7 +302,7 @@ fn getter_qos1_with_packet_id() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -367,7 +368,7 @@ fn to_buffers_qos1() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -577,7 +578,7 @@ fn size_qos1() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -620,7 +621,7 @@ fn test_set_dup_false() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(123u16) + .packet_id(Some(123u16)) .dup(true) .retain(true) .payload("test payload") @@ -648,7 +649,7 @@ fn test_set_dup_chaining() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(456u16) + .packet_id(Some(456u16)) .payload("test payload") .build() .unwrap(); diff --git a/tests/packet-v5_0-publish.rs b/tests/packet-v5_0-publish.rs index a76575c..d71d168 100644 --- a/tests/packet-v5_0-publish.rs +++ b/tests/packet-v5_0-publish.rs @@ -82,7 +82,7 @@ fn build_fail_qos0_with_packet_id() { let err = mqtt::packet::v5_0::Publish::builder() .topic_name("test") .unwrap() - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap_err(); assert_eq!(err, mqtt::result_code::MqttError::MalformedPacket); @@ -120,7 +120,7 @@ fn build_fail_qos0_with_packet_id_validation() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtMostOnce) - .packet_id(1u16) + .packet_id(Some(1u16)) .build() .unwrap_err(); assert_eq!(err, mqtt::result_code::MqttError::MalformedPacket); @@ -134,7 +134,7 @@ fn build_fail_qos1_packet_id_zero() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(0u16) + .packet_id(Some(0u16)) .build() .unwrap_err(); assert_eq!(err, mqtt::result_code::MqttError::MalformedPacket); @@ -179,7 +179,7 @@ fn build_success_qos2() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -228,7 +228,7 @@ fn display_qos1_with_packet_id() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -361,6 +361,7 @@ fn getter_qos0() { let packet = mqtt::packet::v5_0::Publish::builder() .topic_name("test/topic") .unwrap() + .packet_id(None) .payload("hello") .build() .unwrap(); @@ -381,7 +382,7 @@ fn getter_qos1_with_packet_id() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -474,7 +475,7 @@ fn to_buffers_qos1() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -813,7 +814,7 @@ fn size_qos1() { .topic_name("test") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(1234u16) + .packet_id(Some(1234u16)) .payload("hello") .build() .unwrap(); @@ -1091,7 +1092,7 @@ fn test_length_recalculation_with_qos1() { .topic_name("") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(123u16) + .packet_id(Some(123u16)) .props(props) .payload("test payload") .build() @@ -1230,7 +1231,7 @@ fn test_roundtrip_serialization_after_modification() { .topic_name("") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(456u16) + .packet_id(Some(456u16)) .props(props) .payload("modified packet payload") .build() @@ -1321,7 +1322,7 @@ fn test_set_dup_false() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::AtLeastOnce) - .packet_id(123u16) + .packet_id(Some(123u16)) .dup(true) .retain(true) .props(props) @@ -1357,7 +1358,7 @@ fn test_set_dup_chaining() { .topic_name("test/topic") .unwrap() .qos(mqtt::packet::Qos::ExactlyOnce) - .packet_id(456u16) + .packet_id(Some(456u16)) .payload("test payload") .build() .unwrap();