live-data 0.1.0

Shared descriptor, manifest, and subscription types for the live-feed publisher SDK and the live-stream consumer SDK.
Documentation
//! Transport and format enumerations shared by publishers and consumers.
//!
//! Both sets mirror what `lightstream` already supports. They are
//! `#[non_exhaustive]` so adding a future variant is not a breaking change for
//! downstream pattern matchers.

use serde::{Deserialize, Serialize};

/// One of the transports a feed can be exposed over.
///
/// Mirrors the transports `lightstream` supports today.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum TransportTag {
    Tcp,
    WebSocket,
    Quic,
    Uds,
    WebTransport,
    Stdio,
}

/// Ordered transport preference list, most-preferred first.
///
/// The publisher picks the first entry that intersects with what it offers for
/// the requested feed. An empty list means "any".
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TransportPreference(pub Vec<TransportTag>);

impl TransportPreference {
    pub fn any() -> Self {
        Self(Vec::new())
    }

    pub fn one(tag: TransportTag) -> Self {
        Self(vec![tag])
    }

    pub fn iter(&self) -> std::slice::Iter<'_, TransportTag> {
        self.0.iter()
    }

    pub fn is_any(&self) -> bool {
        self.0.is_empty()
    }
}

impl From<Vec<TransportTag>> for TransportPreference {
    fn from(v: Vec<TransportTag>) -> Self {
        Self(v)
    }
}

/// Format the publisher will emit batches in once a subscription is accepted.
///
/// Mirrors `lightstream`'s format options.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum FormatPreference {
    /// Arrow IPC stream protocol, the default high-throughput choice.
    Arrow,
    /// Lightstream TLV framing for opaque payloads.
    Tlv,
    /// Streaming CSV, intended for ad-hoc inspection rather than throughput.
    Csv,
}

impl Default for FormatPreference {
    fn default() -> Self {
        Self::Arrow
    }
}