moq_transport/data/
group.rsuse crate::coding::{Decode, DecodeError, Encode, EncodeError};
use crate::data::ObjectStatus;
#[derive(Clone, Debug)]
pub struct GroupHeader {
pub subscribe_id: u64,
pub track_alias: u64,
pub group_id: u64,
pub publisher_priority: u8,
}
impl Decode for GroupHeader {
fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
Ok(Self {
subscribe_id: u64::decode(r)?,
track_alias: u64::decode(r)?,
group_id: u64::decode(r)?,
publisher_priority: u8::decode(r)?,
})
}
}
impl Encode for GroupHeader {
fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> {
self.subscribe_id.encode(w)?;
self.track_alias.encode(w)?;
self.group_id.encode(w)?;
self.publisher_priority.encode(w)?;
Ok(())
}
}
#[derive(Clone, Debug)]
pub struct GroupObject {
pub object_id: u64,
pub size: usize,
pub status: ObjectStatus,
}
impl Decode for GroupObject {
fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
let object_id = u64::decode(r)?;
let size = usize::decode(r)?;
let status = if size == 0 {
ObjectStatus::decode(r)?
} else {
ObjectStatus::Object
};
Ok(Self {
object_id,
size,
status,
})
}
}
impl Encode for GroupObject {
fn encode<W: bytes::BufMut>(&self, w: &mut W) -> Result<(), EncodeError> {
self.object_id.encode(w)?;
self.size.encode(w)?;
if self.size == 0 {
self.status.encode(w)?;
}
Ok(())
}
}