use crate::{Catalog, Result};
#[derive(Clone)]
pub struct CatalogConsumer {
pub track: moq_lite::TrackConsumer,
group: Option<moq_lite::GroupConsumer>,
}
impl CatalogConsumer {
pub fn new(track: moq_lite::TrackConsumer) -> Self {
Self { track, group: None }
}
pub async fn next(&mut self) -> Result<Option<Catalog>> {
loop {
tokio::select! {
res = self.track.next_group() => {
match res? {
Some(group) => {
self.group = Some(group);
}
None => return Ok(None),
}
},
Some(frame) = async { self.group.as_mut()?.read_frame().await.transpose() } => {
self.group.take(); let catalog = Catalog::from_slice(&frame?)?;
return Ok(Some(catalog));
}
}
}
}
pub async fn closed(&self) -> Result<()> {
Ok(self.track.closed().await?)
}
}
impl From<moq_lite::TrackConsumer> for CatalogConsumer {
fn from(inner: moq_lite::TrackConsumer) -> Self {
Self::new(inner)
}
}