Skip to main content

moq_transport/message/
requests_blocked.rs

1use crate::coding::{Decode, DecodeError, Encode, EncodeError};
2
3/// Sent by the publisher to update the max allowed subscription ID for the session.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct RequestsBlocked {
6    /// The max allowed request ID
7    pub max_request_id: u64,
8}
9
10impl Decode for RequestsBlocked {
11    fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
12        let max_request_id = u64::decode(r)?;
13
14        Ok(Self { max_request_id })
15    }
16}
17
18impl Encode for RequestsBlocked {
19    fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> {
20        self.max_request_id.encode(w)?;
21
22        Ok(())
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use bytes::BytesMut;
30
31    #[test]
32    fn encode_decode() {
33        let mut buf = BytesMut::new();
34
35        let msg = RequestsBlocked {
36            max_request_id: 12345,
37        };
38        msg.encode(&mut buf).unwrap();
39        let decoded = RequestsBlocked::decode(&mut buf).unwrap();
40        assert_eq!(decoded, msg);
41    }
42}