diff options
author | Marcel Müller <neikos@neikos.email> | 2024-03-20 16:30:15 +0100 |
---|---|---|
committer | Marcel Müller <neikos@neikos.email> | 2024-03-20 16:30:15 +0100 |
commit | b1d5d75c9a8e51f39a8d0611c0a8f9be0eb51e39 (patch) | |
tree | 54b9f79041644f6153b5f904770649165eebeab4 | |
parent | 1a650b92b522bdc4bf4b64631f55131a93809522 (diff) |
Add trace to all parsers
This will allow for easier debugging through the debug feature
Signed-off-by: Marcel Müller <neikos@neikos.email>
22 files changed, 430 insertions, 337 deletions
diff --git a/mqtt-format/src/v5/bytes.rs b/mqtt-format/src/v5/bytes.rs index 2f276c4..f9a2a01 100644 --- a/mqtt-format/src/v5/bytes.rs +++ b/mqtt-format/src/v5/bytes.rs @@ -11,7 +11,10 @@ use winnow::Parser; use super::MResult; pub fn parse_binary_data<'i>(input: &mut &'i Bytes) -> MResult<&'i [u8]> { - length_take(super::integers::parse_u16).parse_next(input) + winnow::combinator::trace("mqtt_binary_data", |input: &mut &'i Bytes| { + length_take(super::integers::parse_u16).parse_next(input) + }) + .parse_next(input) } #[cfg(test)] diff --git a/mqtt-format/src/v5/integers.rs b/mqtt-format/src/v5/integers.rs index e2c4d13..96fa8aa 100644 --- a/mqtt-format/src/v5/integers.rs +++ b/mqtt-format/src/v5/integers.rs @@ -13,7 +13,7 @@ use super::MResult; pub fn parse_u16(input: &mut &Bytes) -> MResult<u16> { trace( - "parse_u16", + "mqtt_u16", winnow::binary::u16(winnow::binary::Endianness::Big), ) .parse_next(input) @@ -21,14 +21,14 @@ pub fn parse_u16(input: &mut &Bytes) -> MResult<u16> { pub fn parse_u32(input: &mut &Bytes) -> MResult<u32> { trace( - "parse_u32", + "mqtt_u32", winnow::binary::u32(winnow::binary::Endianness::Big), ) .parse_next(input) } pub fn parse_variable_u32(input: &mut &Bytes) -> MResult<u32> { - trace("parse_variable_u32", |input: &mut &Bytes| { + trace("mqtt_variable_u32", |input: &mut &Bytes| { let var_bytes = ( take_while(0..=3, |b| b & 0b1000_0000 != 0), winnow::binary::u8.verify(|b: &u8| b & 0b1000_0000 == 0), diff --git a/mqtt-format/src/v5/packets/auth.rs b/mqtt-format/src/v5/packets/auth.rs index b3db81a..c0d8880 100644 --- a/mqtt-format/src/v5/packets/auth.rs +++ b/mqtt-format/src/v5/packets/auth.rs @@ -5,6 +5,7 @@ // use winnow::Bytes; +use winnow::Parser; use crate::v5::variable_header::AuthenticationData; use crate::v5::variable_header::AuthenticationMethod; @@ -47,9 +48,12 @@ pub struct MAuth<'i> { impl<'i> MAuth<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - let reason = AuthReasonCode::parse(input)?; - let properties = AuthProperties::parse(input)?; + winnow::combinator::trace("MAuth", |input: &mut &'i Bytes| { + let reason = AuthReasonCode::parse(input)?; + let properties = AuthProperties::parse(input)?; - Ok(Self { reason, properties }) + Ok(Self { reason, properties }) + }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/connack.rs b/mqtt-format/src/v5/packets/connack.rs index 5af6163..a3af49f 100644 --- a/mqtt-format/src/v5/packets/connack.rs +++ b/mqtt-format/src/v5/packets/connack.rs @@ -123,23 +123,26 @@ pub struct MConnack<'i> { impl<'i> MConnack<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<MConnack<'i>> { - let (session_present, _) = - winnow::binary::bits::bits::<_, _, InputError<(_, usize)>, _, _>(( - winnow::binary::bits::take(1usize).map(|b: u8| b == 1), - winnow::binary::bits::pattern(0b000_0000, 7usize), - )) - .parse_next(input) - .map_err(|_: ErrMode<InputError<_>>| { - ErrMode::from_error_kind(input, winnow::error::ErrorKind::Slice) - })?; - - let reason_code = ConnectReasonCode::parse(input)?; - let properties = ConnackProperties::parse(input)?; - - Ok(MConnack { - session_present, - reason_code, - properties, + winnow::combinator::trace("MConnack", |input: &mut &'i Bytes| { + let (session_present, _) = + winnow::binary::bits::bits::<_, _, InputError<(_, usize)>, _, _>(( + winnow::binary::bits::take(1usize).map(|b: u8| b == 1), + winnow::binary::bits::pattern(0b000_0000, 7usize), + )) + .parse_next(input) + .map_err(|_: ErrMode<InputError<_>>| { + ErrMode::from_error_kind(input, winnow::error::ErrorKind::Slice) + })?; + + let reason_code = ConnectReasonCode::parse(input)?; + let properties = ConnackProperties::parse(input)?; + + Ok(MConnack { + session_present, + reason_code, + properties, + }) }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/connect.rs b/mqtt-format/src/v5/packets/connect.rs index b5d2d8f..fa90f77 100644 --- a/mqtt-format/src/v5/packets/connect.rs +++ b/mqtt-format/src/v5/packets/connect.rs @@ -79,84 +79,88 @@ crate::v5::properties::define_properties! { #[doc = crate::v5::util::md_speclink!("_Toc3901033")] impl<'i> MConnect<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - // parse header - - // verify the protocol name - let _ = crate::v5::strings::parse_string - .verify(|s: &str| s == "MQTT") - .parse_next(input)?; - - // just for verification - let _ = ProtocolLevel::parse - .verify(|lvl: &ProtocolLevel| *lvl == ProtocolLevel::V5) - .parse_next(input)?; - - let ( - _reserved, - clean_start, - will_flag, - will_qos, - will_retain, - password_flag, - user_name_flag, - ) = winnow::binary::bits::bits::<_, _, InputError<(_, usize)>, _, _>(( - winnow::binary::bits::pattern(0x0, 1usize), - winnow::binary::bits::bool, - winnow::binary::bits::bool, - winnow::binary::bits::take(2usize).try_map(<QualityOfService as TryFrom<u8>>::try_from), - winnow::binary::bits::bool, - winnow::binary::bits::bool, - winnow::binary::bits::bool, - )) - .parse_next(input) - .map_err(|_: ErrMode<InputError<_>>| { - ErrMode::from_error_kind(input, winnow::error::ErrorKind::Slice) - })?; - - let keep_alive = parse_u16(input)?; - - let properties = ConnectProperties::parse(input)?; - - // finished parsing header, now parse payload - - let client_identifier = { - let client_identifier = parse_string(input)?; - if client_identifier.is_empty() { - // Generate client ID? - } - client_identifier - }; - - let will = will_flag - .then(|| { - let properties = ConnectWillProperties::parse(input)?; - let topic = parse_string(input)?; - let payload = crate::v5::bytes::parse_binary_data(input)?; - - Ok(Will { - properties, - topic, - payload, - will_qos, - will_retain, + winnow::combinator::trace("MConnect", |input: &mut &'i Bytes| { + // parse header + + // verify the protocol name + let _ = crate::v5::strings::parse_string + .verify(|s: &str| s == "MQTT") + .parse_next(input)?; + + // just for verification + let _ = ProtocolLevel::parse + .verify(|lvl: &ProtocolLevel| *lvl == ProtocolLevel::V5) + .parse_next(input)?; + + let ( + _reserved, + clean_start, + will_flag, + will_qos, + will_retain, + password_flag, + user_name_flag, + ) = winnow::binary::bits::bits::<_, _, InputError<(_, usize)>, _, _>(( + winnow::binary::bits::pattern(0x0, 1usize), + winnow::binary::bits::bool, + winnow::binary::bits::bool, + winnow::binary::bits::take(2usize) + .try_map(<QualityOfService as TryFrom<u8>>::try_from), + winnow::binary::bits::bool, + winnow::binary::bits::bool, + winnow::binary::bits::bool, + )) + .parse_next(input) + .map_err(|_: ErrMode<InputError<_>>| { + ErrMode::from_error_kind(input, winnow::error::ErrorKind::Slice) + })?; + + let keep_alive = parse_u16(input)?; + + let properties = ConnectProperties::parse(input)?; + + // finished parsing header, now parse payload + + let client_identifier = { + let client_identifier = parse_string(input)?; + if client_identifier.is_empty() { + // Generate client ID? + } + client_identifier + }; + + let will = will_flag + .then(|| { + let properties = ConnectWillProperties::parse(input)?; + let topic = parse_string(input)?; + let payload = crate::v5::bytes::parse_binary_data(input)?; + + Ok(Will { + properties, + topic, + payload, + will_qos, + will_retain, + }) }) + .transpose()?; + + let username = user_name_flag.then(|| parse_string(input)).transpose()?; + let password = password_flag + .then(|| parse_binary_data(input)) + .transpose()?; + + Ok(Self { + client_identifier, + username, + password, + will, + clean_start, + properties, + keep_alive, }) - .transpose()?; - - let username = user_name_flag.then(|| parse_string(input)).transpose()?; - let password = password_flag - .then(|| parse_binary_data(input)) - .transpose()?; - - Ok(Self { - client_identifier, - username, - password, - will, - clean_start, - properties, - keep_alive, }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/disconnect.rs b/mqtt-format/src/v5/packets/disconnect.rs index 85eced6..7dd6cc5 100644 --- a/mqtt-format/src/v5/packets/disconnect.rs +++ b/mqtt-format/src/v5/packets/disconnect.rs @@ -76,12 +76,15 @@ pub struct MDisconnect<'i> { impl<'i> MDisconnect<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<MDisconnect<'i>> { - let (reason_code, properties) = - (DisconnectReasonCode::parse, DisconnectProperties::parse).parse_next(input)?; + winnow::combinator::trace("MDisconnect", |input: &mut &'i Bytes| { + let (reason_code, properties) = + (DisconnectReasonCode::parse, DisconnectProperties::parse).parse_next(input)?; - Ok(MDisconnect { - reason_code, - properties, + Ok(MDisconnect { + reason_code, + properties, + }) }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/mod.rs b/mqtt-format/src/v5/packets/mod.rs index 575eadc..0de3b41 100644 --- a/mqtt-format/src/v5/packets/mod.rs +++ b/mqtt-format/src/v5/packets/mod.rs @@ -63,33 +63,38 @@ pub enum MqttPacket<'i> { impl<'i> MqttPacket<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - let fixed_header = MFixedHeader::parse(input)?; + winnow::combinator::trace("MqttPacket", |input: &mut &'i Bytes| { + let fixed_header = MFixedHeader::parse(input)?; - let parse_packet = |input: &mut &'i Bytes| match fixed_header.packet_type { - PacketType::Connect => MConnect::parse(input).map(MqttPacket::from), - PacketType::Connack => MConnack::parse(input).map(MqttPacket::from), - PacketType::Publish { dup, qos, retain } => { - MPublish::parse(dup, qos, retain, input).map(MqttPacket::from) - } - PacketType::Puback => MPuback::parse(input).map(MqttPacket::from), - PacketType::Pubrec => MPubrec::parse(input).map(MqttPacket::from), - PacketType::Pubrel => MPubrel::parse(input).map(MqttPacket::from), - PacketType::Pubcomp => MPubcomp::parse(input).map(MqttPacket::from), - PacketType::Subscribe => MSubscribe::parse(input).map(MqttPacket::from), - PacketType::Suback => MSuback::parse(input).map(MqttPacket::from), - PacketType::Unsubscribe => MUnsubscribe::parse(input).map(MqttPacket::from), - PacketType::Unsuback => MUnsuback::parse(input).map(MqttPacket::from), - PacketType::Pingreq => MPingreq::parse(input).map(MqttPacket::from), - PacketType::Pingresp => MPingresp::parse(input).map(MqttPacket::from), - PacketType::Disconnect => MDisconnect::parse(input).map(MqttPacket::from), - PacketType::Auth => MAuth::parse(input).map(MqttPacket::from), - }; + let parse_packet = |input: &mut &'i Bytes| match fixed_header.packet_type { + PacketType::Connect => MConnect::parse(input).map(MqttPacket::from), + PacketType::Connack => MConnack::parse(input).map(MqttPacket::from), + PacketType::Publish { dup, qos, retain } => { + MPublish::parse(dup, qos, retain, input).map(MqttPacket::from) + } + PacketType::Puback => MPuback::parse(input).map(MqttPacket::from), + PacketType::Pubrec => MPubrec::parse(input).map(MqttPacket::from), + PacketType::Pubrel => MPubrel::parse(input).map(MqttPacket::from), + PacketType::Pubcomp => MPubcomp::parse(input).map(MqttPacket::from), + PacketType::Subscribe => MSubscribe::parse(input).map(MqttPacket::from), + PacketType::Suback => MSuback::parse(input).map(MqttPacket::from), + PacketType::Unsubscribe => MUnsubscribe::parse(input).map(MqttPacket::from), + PacketType::Unsuback => MUnsuback::parse(input).map(MqttPacket::from), + PacketType::Pingreq => MPingreq::parse(input).map(MqttPacket::from), + PacketType::Pingresp => MPingresp::parse(input).map(MqttPacket::from), + PacketType::Disconnect => MDisconnect::parse(input).map(MqttPacket::from), + PacketType::Auth => MAuth::parse(input).map(MqttPacket::from), + }; - let packet = - winnow::binary::length_and_then(crate::v5::integers::parse_variable_u32, parse_packet) - .parse_next(input)?; + let packet = winnow::binary::length_and_then( + crate::v5::integers::parse_variable_u32, + parse_packet, + ) + .parse_next(input)?; - Ok(packet) + Ok(packet) + }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/pingreq.rs b/mqtt-format/src/v5/packets/pingreq.rs index 01f32b9..6f17797 100644 --- a/mqtt-format/src/v5/packets/pingreq.rs +++ b/mqtt-format/src/v5/packets/pingreq.rs @@ -15,6 +15,7 @@ pub struct MPingreq; impl MPingreq { pub fn parse(input: &mut &Bytes) -> MResult<MPingreq> { - winnow::combinator::eof.map(|_| MPingreq).parse_next(input) + winnow::combinator::trace("MPingreq", winnow::combinator::eof.map(|_| Self)) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/pingresp.rs b/mqtt-format/src/v5/packets/pingresp.rs index 712bf2e..c66e309 100644 --- a/mqtt-format/src/v5/packets/pingresp.rs +++ b/mqtt-format/src/v5/packets/pingresp.rs @@ -5,6 +5,7 @@ // use winnow::Bytes; +use winnow::Parser; use crate::v5::MResult; @@ -14,6 +15,7 @@ pub struct MPingresp; impl MPingresp { pub fn parse(input: &mut &Bytes) -> MResult<Self> { - winnow::combinator::eof(input).map(|_| Self) + winnow::combinator::trace("MPingresp", winnow::combinator::eof.map(|_| Self)) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/puback.rs b/mqtt-format/src/v5/packets/puback.rs index d1be7a2..0aeaa32 100644 --- a/mqtt-format/src/v5/packets/puback.rs +++ b/mqtt-format/src/v5/packets/puback.rs @@ -5,6 +5,7 @@ // use winnow::Bytes; +use winnow::Parser; use crate::v5::properties::define_properties; use crate::v5::variable_header::PacketIdentifier; @@ -48,22 +49,25 @@ pub struct MPuback<'i> { impl<'i> MPuback<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - let packet_identifier = PacketIdentifier::parse(input)?; + winnow::combinator::trace("MPuback", |input: &mut &'i Bytes| { + let packet_identifier = PacketIdentifier::parse(input)?; - if input.is_empty() { - Ok(Self { - packet_identifier, - reason: PubackReasonCode::Success, - properties: PubackProperties::new(), - }) - } else { - let reason = PubackReasonCode::parse(input)?; - let properties = PubackProperties::parse(input)?; - Ok(Self { - packet_identifier, - reason, - properties, - }) - } + if input.is_empty() { + Ok(Self { + packet_identifier, + reason: PubackReasonCode::Success, + properties: PubackProperties::new(), + }) + } else { + let reason = PubackReasonCode::parse(input)?; + let properties = PubackProperties::parse(input)?; + Ok(Self { + packet_identifier, + reason, + properties, + }) + } + }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/pubcomp.rs b/mqtt-format/src/v5/packets/pubcomp.rs index 4303710..c5eb201 100644 --- a/mqtt-format/src/v5/packets/pubcomp.rs +++ b/mqtt-format/src/v5/packets/pubcomp.rs @@ -5,6 +5,7 @@ // use winnow::Bytes; +use winnow::Parser; use crate::v5::variable_header::PacketIdentifier; use crate::v5::variable_header::ReasonString; @@ -40,13 +41,16 @@ pub struct MPubcomp<'i> { impl<'i> MPubcomp<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - let packet_identifier = PacketIdentifier::parse(input)?; - let reason = PubcompReasonCode::parse(input)?; - let properties = PubcompProperties::parse(input)?; - Ok(Self { - packet_identifier, - reason, - properties, + winnow::combinator::trace("MPubcomp", |input: &mut &'i Bytes| { + let packet_identifier = PacketIdentifier::parse(input)?; + let reason = PubcompReasonCode::parse(input)?; + let properties = PubcompProperties::parse(input)?; + Ok(Self { + packet_identifier, + reason, + properties, + }) }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/publish.rs b/mqtt-format/src/v5/packets/publish.rs index 25b59e3..bae5498 100644 --- a/mqtt-format/src/v5/packets/publish.rs +++ b/mqtt-format/src/v5/packets/publish.rs @@ -8,6 +8,7 @@ use winnow::error::ErrMode; use winnow::error::ParserError; use winnow::stream::Stream; use winnow::Bytes; +use winnow::Parser; use crate::v5::fixed_header::QualityOfService; use crate::v5::variable_header::ContentType; @@ -69,28 +70,31 @@ impl<'i> MPublish<'i> { retain: bool, input: &mut &'i Bytes, ) -> MResult<Self> { - let topic_name = crate::v5::strings::parse_string(input)?; - if !sanity_check_topic_name(topic_name) { - return Err(ErrMode::from_error_kind( - input, - winnow::error::ErrorKind::Verify, - )); - } - - let packet_identifier = crate::v5::variable_header::PacketIdentifier::parse(input)?; - let properties = PublishProperties::parse(input)?; - - let payload = input.finish(); - - Ok(Self { - duplicate, - quality_of_service, - retain, - topic_name, - packet_identifier, - properties, - payload, + winnow::combinator::trace("MPublish", |input: &mut &'i Bytes| { + let topic_name = crate::v5::strings::parse_string(input)?; + if !sanity_check_topic_name(topic_name) { + return Err(ErrMode::from_error_kind( + input, + winnow::error::ErrorKind::Verify, + )); + } + + let packet_identifier = crate::v5::variable_header::PacketIdentifier::parse(input)?; + let properties = PublishProperties::parse(input)?; + + let payload = input.finish(); + + Ok(Self { + duplicate, + quality_of_service, + retain, + topic_name, + packet_identifier, + properties, + payload, + }) }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/pubrec.rs b/mqtt-format/src/v5/packets/pubrec.rs index e2ba9ae..2d7c984 100644 --- a/mqtt-format/src/v5/packets/pubrec.rs +++ b/mqtt-format/src/v5/packets/pubrec.rs @@ -5,6 +5,7 @@ // use winnow::Bytes; +use winnow::Parser; use crate::v5::variable_header::PacketIdentifier; use crate::v5::variable_header::ReasonString; @@ -48,13 +49,16 @@ pub struct MPubrec<'i> { impl<'i> MPubrec<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - let packet_identifier = PacketIdentifier::parse(input)?; - let reason = PubrecReasonCode::parse(input)?; - let properties = PubrecProperties::parse(input)?; - Ok(Self { - packet_identifier, - reason, - properties, + winnow::combinator::trace("MPubrec", |input: &mut &'i Bytes| { + let packet_identifier = PacketIdentifier::parse(input)?; + let reason = PubrecReasonCode::parse(input)?; + let properties = PubrecProperties::parse(input)?; + Ok(Self { + packet_identifier, + reason, + properties, + }) }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/pubrel.rs b/mqtt-format/src/v5/packets/pubrel.rs index fceb133..aa8a799 100644 --- a/mqtt-format/src/v5/packets/pubrel.rs +++ b/mqtt-format/src/v5/packets/pubrel.rs @@ -5,6 +5,7 @@ // use winnow::Bytes; +use winnow::Parser; use crate::v5::properties::define_properties; use crate::v5::variable_header::PacketIdentifier; @@ -41,22 +42,25 @@ pub struct MPubrel<'i> { impl<'i> MPubrel<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - let packet_identifier = PacketIdentifier::parse(input)?; - - if input.is_empty() { - Ok(Self { - packet_identifier, - reason: PubrelReasonCode::Success, - properties: PubrelProperties::new(), - }) - } else { - let reason = PubrelReasonCode::parse(input)?; - let properties = PubrelProperties::parse(input)?; - Ok(Self { - packet_identifier, - reason, - properties, - }) - } + winnow::combinator::trace("MPubrel", |input: &mut &'i Bytes| { + let packet_identifier = PacketIdentifier::parse(input)?; + + if input.is_empty() { + Ok(Self { + packet_identifier, + reason: PubrelReasonCode::Success, + properties: PubrelProperties::new(), + }) + } else { + let reason = PubrelReasonCode::parse(input)?; + let properties = PubrelProperties::parse(input)?; + Ok(Self { + packet_identifier, + reason, + properties, + }) + } + }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/suback.rs b/mqtt-format/src/v5/packets/suback.rs index 638a25a..7138e1e 100644 --- a/mqtt-format/src/v5/packets/suback.rs +++ b/mqtt-format/src/v5/packets/suback.rs @@ -51,26 +51,29 @@ pub struct MSuback<'i> { impl<'i> MSuback<'i> { pub fn parse(input: &mut &'i Bytes) -> MResult<Self> { - let packet_identifier = PacketIdentifier::parse(input)?; - let properties = SubackProperties::parse(input)?; + winnow::combinator::trace("MSuback", |input: &mut &'i Bytes| { + let packet_identifier = PacketIdentifier::parse(input)?; + let properties = SubackProperties::parse(input)?; - // Verify that the payload only contains valid reason codes - let payload: &[u8] = winnow::combinator::repeat_till::<_, _, (), _, _, _, _>( - 0.., - SubackReasonCode::parse, - winnow::combinator::eof, - ) - .recognize() - .parse_next(input)?; + // Verify that the payload only contains valid reason codes + let payload: &[u8] = winnow::combinator::repeat_till::<_, _, (), _, _, _, _>( + 0.., + SubackReasonCode::parse, + winnow::combinator::eof, + ) + .recognize() + .parse_next(input)?; - // SAFETY: We verified above that the payload slice only contains valid SubackReasonCode - // bytes - let reasons: &[SubackReasonCode] = unsafe { std::mem::transmute(payload) }; + // SAFETY: We verified above that the payload slice only contains valid SubackReasonCode + // bytes + let reasons: &[SubackReasonCode] = unsafe { std::mem::transmute(payload) }; - Ok(Self { - packet_identifier, - properties, - reasons, + Ok(Self { + packet_identifier, + properties, + reasons, + }) }) + .parse_next(input) } } diff --git a/mqtt-format/src/v5/packets/subscribe.rs b/mqtt-format/src/v5/packets/subscribe.rs index 320aa1d..04ea2f9 100644 --- a/mqtt-format/src/v5/packets/subscribe.rs +++ b/mqtt-format/src/v5/packets/subscribe.rs @@ -45,26 +45,29 @@ pub struct SubscriptionOptions { impl SubscriptionOptions { fn parse(input: &mut &Bytes) -> MResult<SubscriptionOptions> { - let (quality_of_service, no_local, retain_as_published, retain_handling) = - bits::<_, _, InputError<(_, usize)>, _, _>(( - winnow::binary::bits::take(2usize) - .try_map(<QualityOfService as TryFrom<u8>>::try_from), - winnow::binary::bits::bool, - winnow::binary::bits::bool, - winnow::binary::bits::take(2usize) - |