Skip to main content

live_data/
endpoint.rs

1//! Network or local endpoint used to reach a publisher.
2//!
3//! An [`Endpoint`] carries the transport tag plus enough information for the
4//! appropriate `lightstream` reader to dial in. The shape stays small and
5//! string-typed so the same struct works across TCP, WebSocket, QUIC, UDS,
6//! WebTransport, and stdio without forcing per-transport variants.
7
8use serde::{Deserialize, Serialize};
9
10use crate::transport::TransportTag;
11
12/// Identifies where a consumer should connect to read a feed.
13///
14/// `address` is interpreted in a transport-specific way:
15///
16/// - `Tcp`, `Quic`              - `"host:port"`
17/// - `WebSocket`, `WebTransport`- full URL, e.g. `"wss://host:port/path"`
18/// - `Uds`                      - filesystem path
19/// - `Stdio`                    - empty
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub struct Endpoint {
22    pub transport: TransportTag,
23    pub address: String,
24}
25
26impl Endpoint {
27    pub fn new(transport: TransportTag, address: impl Into<String>) -> Self {
28        Self { transport, address: address.into() }
29    }
30
31    pub fn tcp(address: impl Into<String>) -> Self {
32        Self::new(TransportTag::Tcp, address)
33    }
34
35    pub fn websocket(url: impl Into<String>) -> Self {
36        Self::new(TransportTag::WebSocket, url)
37    }
38
39    pub fn quic(address: impl Into<String>) -> Self {
40        Self::new(TransportTag::Quic, address)
41    }
42
43    pub fn uds(path: impl Into<String>) -> Self {
44        Self::new(TransportTag::Uds, path)
45    }
46
47    pub fn webtransport(url: impl Into<String>) -> Self {
48        Self::new(TransportTag::WebTransport, url)
49    }
50
51    pub fn stdio() -> Self {
52        Self::new(TransportTag::Stdio, String::new())
53    }
54}