live-data 0.1.0

Shared descriptor, manifest, and subscription types for the live-feed publisher SDK and the live-stream consumer SDK.
Documentation
//! Network or local endpoint used to reach a publisher.
//!
//! An [`Endpoint`] carries the transport tag plus enough information for the
//! appropriate `lightstream` reader to dial in. The shape stays small and
//! string-typed so the same struct works across TCP, WebSocket, QUIC, UDS,
//! WebTransport, and stdio without forcing per-transport variants.

use serde::{Deserialize, Serialize};

use crate::transport::TransportTag;

/// Identifies where a consumer should connect to read a feed.
///
/// `address` is interpreted in a transport-specific way:
///
/// - `Tcp`, `Quic`              - `"host:port"`
/// - `WebSocket`, `WebTransport`- full URL, e.g. `"wss://host:port/path"`
/// - `Uds`                      - filesystem path
/// - `Stdio`                    - empty
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Endpoint {
    pub transport: TransportTag,
    pub address: String,
}

impl Endpoint {
    pub fn new(transport: TransportTag, address: impl Into<String>) -> Self {
        Self { transport, address: address.into() }
    }

    pub fn tcp(address: impl Into<String>) -> Self {
        Self::new(TransportTag::Tcp, address)
    }

    pub fn websocket(url: impl Into<String>) -> Self {
        Self::new(TransportTag::WebSocket, url)
    }

    pub fn quic(address: impl Into<String>) -> Self {
        Self::new(TransportTag::Quic, address)
    }

    pub fn uds(path: impl Into<String>) -> Self {
        Self::new(TransportTag::Uds, path)
    }

    pub fn webtransport(url: impl Into<String>) -> Self {
        Self::new(TransportTag::WebTransport, url)
    }

    pub fn stdio() -> Self {
        Self::new(TransportTag::Stdio, String::new())
    }
}