mqtt_5/
unsubscribe.rs

1use super::data_representation::{
2    properties::Properties, 
3    reserved_flags::ReservedFlags,
4    RemainingLength,
5    TwoByteInteger,
6    UTF8EncodedString
7};
8
9use packattack::*;
10use crate::error::MQTTParserError;
11
12#[derive(Clone, Debug, PartialEq, FromBitReader)]
13pub struct Unsubscribe
14(
15    ReservedFlags,
16    #[expose = "r_length"]
17    RemainingLength,
18    PacketIdentifier,
19    Properties,
20    //find the remaining length by subtracting the bytes we've already read from the total size
21    //we subtract 1 byte for reserved flags and the length of the Remaining Length
22    //since these are not included in the the remaining length measure
23    #[length = "usize::from(&r_length) - (reader.byte_count()-1 - r_length.size())"]
24    Vec<TopicFilter>,
25);
26
27pub type PacketIdentifier = TwoByteInteger;
28
29pub type TopicFilter = UTF8EncodedString;
30
31#[async_trait]
32impl<R> FromBitReaderWithLength<MQTTParserError, R> for Vec<TopicFilter> where R : Read + std::marker::Unpin + std::marker::Send
33{
34    async fn from_bitreader_with_length(reader : &mut bitreader_async::BitReader<R>, len : usize) -> Result<Vec<TopicFilter>, MQTTParserError>
35    {
36        let mut topics : Vec<TopicFilter> = Vec::new();
37
38        let end = reader.byte_count() + len;
39
40        while reader.byte_count() < end
41        {
42            topics.push(TopicFilter::from_bitreader(reader).await?);
43        }
44
45        Ok(topics)
46    }
47}