moq_transfork/message/
announce.rsuse crate::coding::*;
use crate::Path;
#[derive(Clone, Debug)]
pub struct Announce {
pub status: AnnounceStatus,
pub suffix: Path,
}
impl Decode for Announce {
fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
let status = AnnounceStatus::decode(r)?;
let suffix = Path::decode(r)?;
Ok(Self { status, suffix })
}
}
impl Encode for Announce {
fn encode<W: bytes::BufMut>(&self, w: &mut W) {
self.status.encode(w);
self.suffix.encode(w)
}
}
#[derive(Clone, Debug)]
pub struct AnnounceInterest {
pub prefix: Path,
}
impl Decode for AnnounceInterest {
fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
let prefix = Path::decode(r)?;
Ok(Self { prefix })
}
}
impl Encode for AnnounceInterest {
fn encode<W: bytes::BufMut>(&self, w: &mut W) {
self.prefix.encode(w)
}
}
#[derive(Clone, Copy, Debug)]
pub enum AnnounceStatus {
Active = 1,
Ended = 0,
}
impl Decode for AnnounceStatus {
fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
let status = u8::decode(r)?;
match status {
0 => Ok(Self::Ended),
1 => Ok(Self::Active),
_ => Err(DecodeError::InvalidValue),
}
}
}
impl Encode for AnnounceStatus {
fn encode<W: bytes::BufMut>(&self, w: &mut W) {
(*self as u8).encode(w)
}
}