moq_transport/message/
subscribe_done.rsuse crate::coding::{Decode, DecodeError, Encode, EncodeError};
#[derive(Clone, Debug)]
pub struct SubscribeDone {
pub id: u64,
pub code: u64,
pub reason: String,
pub last: Option<(u64, u64)>,
}
impl Decode for SubscribeDone {
fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
let id = u64::decode(r)?;
let code = u64::decode(r)?;
let reason = String::decode(r)?;
Self::decode_remaining(r, 1)?;
let last = match r.get_u8() {
0 => None,
1 => Some((u64::decode(r)?, u64::decode(r)?)),
_ => return Err(DecodeError::InvalidValue),
};
Ok(Self { id, code, reason, last })
}
}
impl Encode for SubscribeDone {
fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> {
self.id.encode(w)?;
self.code.encode(w)?;
self.reason.encode(w)?;
Self::encode_remaining(w, 1)?;
if let Some((group, object)) = self.last {
w.put_u8(1);
group.encode(w)?;
object.encode(w)?;
} else {
w.put_u8(0);
}
Ok(())
}
}