diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2024-04-04 12:38:00 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2024-04-04 12:44:14 +0200 |
commit | 5f42459ab99a5864bbb70a5b4be8edba1474f24a (patch) | |
tree | a3e66cc67474d4192fc68703254c83afbb0accc4 | |
parent | 04b96d6c1c43f90c3cb78cf6cc91c1c3771a4041 (diff) |
Make PacketIdentifier always hold NonZeroU16
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | mqtt-format/src/v5/packets/puback.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/pubcomp.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/publish.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/pubrec.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/pubrel.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/suback.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/subscribe.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/unsuback.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/packets/unsubscribe.rs | 4 | ||||
-rw-r--r-- | mqtt-format/src/v5/variable_header.rs | 6 |
10 files changed, 21 insertions, 21 deletions
diff --git a/mqtt-format/src/v5/packets/puback.rs b/mqtt-format/src/v5/packets/puback.rs index d2f86b2..d5b45df 100644 --- a/mqtt-format/src/v5/packets/puback.rs +++ b/mqtt-format/src/v5/packets/puback.rs @@ -101,7 +101,7 @@ mod test { #[test] fn test_roundtrip_puback_no_props() { crate::v5::test::make_roundtrip_test!(MPuback { - packet_identifier: PacketIdentifier(123), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(123).unwrap()), reason: PubackReasonCode::Success, properties: PubackProperties { reason_string: None, @@ -113,7 +113,7 @@ mod test { #[test] fn test_roundtrip_puback_with_props() { crate::v5::test::make_roundtrip_test!(MPuback { - packet_identifier: PacketIdentifier(123), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(123).unwrap()), reason: PubackReasonCode::Success, properties: PubackProperties { reason_string: Some(ReasonString("fooooo")), diff --git a/mqtt-format/src/v5/packets/pubcomp.rs b/mqtt-format/src/v5/packets/pubcomp.rs index c8fe2b0..e338b52 100644 --- a/mqtt-format/src/v5/packets/pubcomp.rs +++ b/mqtt-format/src/v5/packets/pubcomp.rs @@ -93,7 +93,7 @@ mod test { #[test] fn test_roundtrip_pubcomp_no_props() { crate::v5::test::make_roundtrip_test!(MPubcomp { - packet_identifier: PacketIdentifier(123), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(123).unwrap()), reason: PubcompReasonCode::Success, properties: PubcompProperties { reason_string: None, @@ -105,7 +105,7 @@ mod test { #[test] fn test_roundtrip_puback_with_props() { crate::v5::test::make_roundtrip_test!(MPubcomp { - packet_identifier: PacketIdentifier(123), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(123).unwrap()), reason: PubcompReasonCode::Success, properties: PubcompProperties { reason_string: Some(ReasonString("fooooo")), diff --git a/mqtt-format/src/v5/packets/publish.rs b/mqtt-format/src/v5/packets/publish.rs index d8c90b3..e7556e0 100644 --- a/mqtt-format/src/v5/packets/publish.rs +++ b/mqtt-format/src/v5/packets/publish.rs @@ -158,7 +158,7 @@ mod test { quality_of_service, retain, topic_name: "top/ic", - packet_identifier: Some(PacketIdentifier(1)), + packet_identifier: Some(PacketIdentifier(core::num::NonZeroU16::new(1).unwrap())), properties: PublishProperties { payload_format_indicator: None, message_expiry_interval: None, @@ -194,7 +194,7 @@ mod test { quality_of_service, retain, topic_name: "top/ic", - packet_identifier: Some(PacketIdentifier(1)), + packet_identifier: Some(PacketIdentifier(core::num::NonZeroU16::new(1).unwrap())), properties: PublishProperties { payload_format_indicator: None, message_expiry_interval: None, diff --git a/mqtt-format/src/v5/packets/pubrec.rs b/mqtt-format/src/v5/packets/pubrec.rs index 655219d..0f18753 100644 --- a/mqtt-format/src/v5/packets/pubrec.rs +++ b/mqtt-format/src/v5/packets/pubrec.rs @@ -101,7 +101,7 @@ mod test { #[test] fn test_roundtrip_mauth_no_props() { crate::v5::test::make_roundtrip_test!(MPubrec { - packet_identifier: PacketIdentifier(123), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(123).unwrap()), reason: PubrecReasonCode::Success, properties: PubrecProperties { reason_string: None, @@ -113,7 +113,7 @@ mod test { #[test] fn test_roundtrip_mauth_props() { crate::v5::test::make_roundtrip_test!(MPubrec { - packet_identifier: PacketIdentifier(123), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(123).unwrap()), reason: PubrecReasonCode::Success, properties: PubrecProperties { reason_string: Some(ReasonString("fooobasrbbarbabwer")), diff --git a/mqtt-format/src/v5/packets/pubrel.rs b/mqtt-format/src/v5/packets/pubrel.rs index d646c71..1cb6ef8 100644 --- a/mqtt-format/src/v5/packets/pubrel.rs +++ b/mqtt-format/src/v5/packets/pubrel.rs @@ -94,7 +94,7 @@ mod test { #[test] fn test_roundtrip_mauth_no_props() { crate::v5::test::make_roundtrip_test!(MPubrel { - packet_identifier: PacketIdentifier(13), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(13).unwrap()), reason: PubrelReasonCode::Success, properties: PubrelProperties { reason_string: None, @@ -106,7 +106,7 @@ mod test { #[test] fn test_roundtrip_mauth_props() { crate::v5::test::make_roundtrip_test!(MPubrel { - packet_identifier: PacketIdentifier(13), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(13).unwrap()), reason: PubrelReasonCode::Success, properties: PubrelProperties { reason_string: Some(ReasonString("fooobasrbbarbabwer")), diff --git a/mqtt-format/src/v5/packets/suback.rs b/mqtt-format/src/v5/packets/suback.rs index e09d150..a8791c4 100644 --- a/mqtt-format/src/v5/packets/suback.rs +++ b/mqtt-format/src/v5/packets/suback.rs @@ -110,7 +110,7 @@ mod test { #[test] fn test_roundtrip_suback_no_props() { crate::v5::test::make_roundtrip_test!(MSuback { - packet_identifier: PacketIdentifier(17), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(17).unwrap()), reasons: &[SubackReasonCode::GrantedQoS0], properties: SubackProperties { reason_string: None, @@ -122,7 +122,7 @@ mod test { #[test] fn test_roundtrip_suback_props() { crate::v5::test::make_roundtrip_test!(MSuback { - packet_identifier: PacketIdentifier(17), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(17).unwrap()), reasons: &[SubackReasonCode::GrantedQoS0], properties: SubackProperties { reason_string: Some(ReasonString("sgjdhsbgjsghb")), diff --git a/mqtt-format/src/v5/packets/subscribe.rs b/mqtt-format/src/v5/packets/subscribe.rs index 7b65137..ba57111 100644 --- a/mqtt-format/src/v5/packets/subscribe.rs +++ b/mqtt-format/src/v5/packets/subscribe.rs @@ -272,7 +272,7 @@ mod test { subscription.write(&mut sub_writer).unwrap(); crate::v5::test::make_roundtrip_test!(MSubscribe { - packet_identifier: PacketIdentifier(88), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(88).unwrap()), subscriptions: Subscriptions { start: &sub_writer.buffer }, @@ -300,7 +300,7 @@ mod test { subscription.write(&mut sub_writer).unwrap(); crate::v5::test::make_roundtrip_test!(MSubscribe { - packet_identifier: PacketIdentifier(88), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(88).unwrap()), subscriptions: Subscriptions { start: &sub_writer.buffer }, diff --git a/mqtt-format/src/v5/packets/unsuback.rs b/mqtt-format/src/v5/packets/unsuback.rs index 120ba49..2dcbc6e 100644 --- a/mqtt-format/src/v5/packets/unsuback.rs +++ b/mqtt-format/src/v5/packets/unsuback.rs @@ -106,7 +106,7 @@ mod test { #[test] fn test_roundtrip_unsuback_no_props() { crate::v5::test::make_roundtrip_test!(MUnsuback { - packet_identifier: PacketIdentifier(89), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(89).unwrap()), properties: UnsubackProperties { reason_string: None, user_properties: None @@ -118,7 +118,7 @@ mod test { #[test] fn test_roundtrip_unsuback_props() { crate::v5::test::make_roundtrip_test!(MUnsuback { - packet_identifier: PacketIdentifier(89), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(89).unwrap()), properties: UnsubackProperties { reason_string: Some(ReasonString("2345678")), user_properties: Some(UserProperties(&[0x0, 0x1, b'f', 0x0, 0x2, b'h', b'j'])), diff --git a/mqtt-format/src/v5/packets/unsubscribe.rs b/mqtt-format/src/v5/packets/unsubscribe.rs index 8b6ba23..1ee8b9e 100644 --- a/mqtt-format/src/v5/packets/unsubscribe.rs +++ b/mqtt-format/src/v5/packets/unsubscribe.rs @@ -192,7 +192,7 @@ mod test { subscription.write(&mut sub_writer).unwrap(); crate::v5::test::make_roundtrip_test!(MUnsubscribe { - packet_identifier: PacketIdentifier(88), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(88).unwrap()), unsubscriptions: Unsubscriptions { start: &sub_writer.buffer }, @@ -214,7 +214,7 @@ mod test { subscription.write(&mut sub_writer).unwrap(); crate::v5::test::make_roundtrip_test!(MUnsubscribe { - packet_identifier: PacketIdentifier(88), + packet_identifier: PacketIdentifier(core::num::NonZeroU16::new(88).unwrap()), unsubscriptions: Unsubscriptions { start: &sub_writer.buffer }, diff --git a/mqtt-format/src/v5/variable_header.rs b/mqtt-format/src/v5/variable_header.rs index fa8e118..33196c2 100644 --- a/mqtt-format/src/v5/variable_header.rs +++ b/mqtt-format/src/v5/variable_header.rs @@ -18,12 +18,12 @@ use super::MResult; use crate::v5::integers::parse_variable_u32; #[derive(Debug, Clone, Copy, PartialEq)] -pub struct PacketIdentifier(pub u16); +pub struct PacketIdentifier(pub core::num::NonZeroU16); impl PacketIdentifier { pub fn parse(input: &mut &Bytes) -> MResult<Self> { winnow::combinator::trace("PacketIdentifier", |input: &mut &Bytes| { - parse_u16(input).map(PacketIdentifier) + parse_u16_nonzero(input).map(PacketIdentifier) }) .parse_next(input) } @@ -33,7 +33,7 @@ impl PacketIdentifier { } pub fn write<W: WriteMqttPacket>(&self, buffer: &mut W) -> WResult<W> { - buffer.write_u16(self.0) + buffer.write_u16(self.0.get()) } } |