Skip to main content

live_data/
manifest.rs

1//! Top-level manifest a consumer fetches to browse a publisher.
2
3use serde::{Deserialize, Serialize};
4
5use crate::PROTOCOL_VERSION;
6use crate::descriptor::FeedDescriptor;
7
8/// Snapshot of everything a publisher currently exposes.
9///
10/// Returned by a `live-stream` server in response to a `live.feeds` control
11/// message. Consumers in `live-feed` typically render this into a browseable
12/// catalogue.
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct FeedManifest {
15    /// Protocol version the server speaks. Consumers should refuse to proceed
16    /// if this is newer than they understand.
17    pub protocol_version: u32,
18    /// Free-form server build identifier, useful for diagnostics.
19    pub server_version: String,
20    /// All feeds the publisher is currently offering.
21    pub feeds: Vec<FeedDescriptor>,
22}
23
24impl FeedManifest {
25    pub fn new(server_version: impl Into<String>, feeds: Vec<FeedDescriptor>) -> Self {
26        Self { protocol_version: PROTOCOL_VERSION, server_version: server_version.into(), feeds }
27    }
28
29    pub fn empty(server_version: impl Into<String>) -> Self {
30        Self::new(server_version, Vec::new())
31    }
32
33    pub fn find(&self, name: &str) -> Option<&FeedDescriptor> {
34        self.feeds.iter().find(|f| f.name == name)
35    }
36}