pub(crate) fn parse_message<'reader: 'a, const T: usize>(
        packet_reader: &'reader PacketReader<T>,
    ) -> Result<ReceivedPacket<'a>, Error> {
        let (message_type, flags, remaining_length) = packet_reader.read_fixed_header()?;

        // Validate packet length.
        if remaining_length != packet_reader.len()? {
            return Err(Error::MalformedPacket);
        }

        match message_type {
            MessageType::ConnAck => {
                if flags != 0 {
                    return Err(Error::MalformedPacket);
                }

                Ok(ReceivedPacket::ConnAck(parse_connack(packet_reader)?))
            }

            MessageType::Publish => Ok(ReceivedPacket::Publish(parse_publish(packet_reader)?)),

            MessageType::PubAck => Ok(ReceivedPacket::PubAck(parse_puback(packet_reader)?)),

            MessageType::SubAck => {
                if flags != 0 {
                    return Err(Error::MalformedPacket);
                }

                Ok(ReceivedPacket::SubAck(parse_suback(packet_reader)?))
            }

            MessageType::PingResp => {
                if flags != 0 || remaining_length != 0 {
                    return Err(Error::MalformedPacket);
                }

                Ok(ReceivedPacket::PingResp)
            }

            _ => Err(Error::UnsupportedPacket),
        }
    }
/// Parse a message out of a `PacketReader` into a validated MQTT control message.
///
/// # Args
/// * `packet_reader` - The reader to parse the message out of.
///
/// # Returns
/// A packet describing the received content.
Parse a message out of a `PacketReader` into a validated MQTT control message.
Parse a message out of a ` PacketReader ` into a validated MQTT control message .
pub(crate) fn parse_message<'reader: 'a, const T: usize>(
        packet_reader: &'reader PacketReader<T>,
    ) -> Result<ReceivedPacket<'a>, Error> {
        let (message_type, flags, remaining_length) = packet_reader.read_fixed_header()?;
        // Validate packet length.
        if remaining_length != packet_reader.len()? {
            return Err(Error::MalformedPacket);
        }
        match message_type {
            MessageType::ConnAck => {
                if flags != 0 {
                    return Err(Error::MalformedPacket);
                }
                Ok(ReceivedPacket::ConnAck(parse_connack(packet_reader)?))
            }
            MessageType::Publish => Ok(ReceivedPacket::Publish(parse_publish(packet_reader)?)),
            MessageType::PubAck => Ok(ReceivedPacket::PubAck(parse_puback(packet_reader)?)),
            MessageType::SubAck => {
                if flags != 0 {
                    return Err(Error::MalformedPacket);
                }
                Ok(ReceivedPacket::SubAck(parse_suback(packet_reader)?))
            }
            MessageType::PingResp => {
                if flags != 0 || remaining_length != 0 {
                    return Err(Error::MalformedPacket);
                }
                Ok(ReceivedPacket::PingResp)
            }
            _ => Err(Error::UnsupportedPacket),
        }
    }
pub ( crate ) fn parse_message < ' reader : ' a , const T : usize > ( packet_reader : & ' reader PacketReader < T > , ) -> Result < ReceivedPacket < ' a > , Error > { let ( message_type , flags , remaining_length ) = packet_reader . read_fixed_header ( ) ? ; // Validate packet length. if remaining_length != packet_reader . len ( ) ? { return Err ( Error :: MalformedPacket ) ; } match message_type { MessageType :: ConnAck => { if flags != 0 { return Err ( Error :: MalformedPacket ) ; } Ok ( ReceivedPacket :: ConnAck ( parse_connack ( packet_reader ) ? ) ) } MessageType :: Publish => Ok ( ReceivedPacket :: Publish ( parse_publish ( packet_reader ) ? ) ) , MessageType :: PubAck => Ok ( ReceivedPacket :: PubAck ( parse_puback ( packet_reader ) ? ) ) , MessageType :: SubAck => { if flags != 0 { return Err ( Error :: MalformedPacket ) ; } Ok ( ReceivedPacket :: SubAck ( parse_suback ( packet_reader ) ? ) ) } MessageType :: PingResp => { if flags != 0 || remaining_length != 0 { return Err ( Error :: MalformedPacket ) ; } Ok ( ReceivedPacket :: PingResp ) } _ => Err ( Error :: UnsupportedPacket ) , } }
Parse a message out of a `PacketReader` into a validated MQTT control message.
Parse a message out of a ` PacketReader ` into a validated MQTT control message .
packet_reader
&'reader PacketReader<T>
A packet describing the received content.
A packet describing the received content .
packet_reader
&'reader PacketReader<T>
args
`packet_reader` - The reader to parse the message out of.
` packet_reader ` - The reader to parse the message out of .