Skip to main content

moq_transport/message/
fetch_cancel.rs

1use crate::coding::{Decode, DecodeError, Encode, EncodeError};
2
3/// A subscriber issues a FETCH_CANCEL message to a publisher indicating it is
4/// no longer interested in receiving Objects for the fetch.
5#[derive(Clone, Debug, Eq, PartialEq)]
6pub struct FetchCancel {
7    /// The request ID of the Fetch this message is cancelling.
8    pub id: u64,
9}
10
11impl Decode for FetchCancel {
12    fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
13        let id = u64::decode(r)?;
14        Ok(Self { id })
15    }
16}
17
18impl Encode for FetchCancel {
19    fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> {
20        self.id.encode(w)?;
21        Ok(())
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use bytes::BytesMut;
29
30    #[test]
31    fn encode_decode() {
32        let mut buf = BytesMut::new();
33
34        let msg = FetchCancel { id: 12345 };
35        msg.encode(&mut buf).unwrap();
36        let decoded = FetchCancel::decode(&mut buf).unwrap();
37        assert_eq!(decoded, msg);
38    }
39}