live-data 0.1.0

Shared descriptor, manifest, and subscription types for the live-feed publisher SDK and the live-stream consumer SDK.
Documentation
//! Top-level manifest a consumer fetches to browse a publisher.

use serde::{Deserialize, Serialize};

use crate::PROTOCOL_VERSION;
use crate::descriptor::FeedDescriptor;

/// Snapshot of everything a publisher currently exposes.
///
/// Returned by a `live-stream` server in response to a `live.feeds` control
/// message. Consumers in `live-feed` typically render this into a browseable
/// catalogue.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FeedManifest {
    /// Protocol version the server speaks. Consumers should refuse to proceed
    /// if this is newer than they understand.
    pub protocol_version: u32,
    /// Free-form server build identifier, useful for diagnostics.
    pub server_version: String,
    /// All feeds the publisher is currently offering.
    pub feeds: Vec<FeedDescriptor>,
}

impl FeedManifest {
    pub fn new(server_version: impl Into<String>, feeds: Vec<FeedDescriptor>) -> Self {
        Self { protocol_version: PROTOCOL_VERSION, server_version: server_version.into(), feeds }
    }

    pub fn empty(server_version: impl Into<String>) -> Self {
        Self::new(server_version, Vec::new())
    }

    pub fn find(&self, name: &str) -> Option<&FeedDescriptor> {
        self.feeds.iter().find(|f| f.name == name)
    }
}