Skip to main content

live_data/
transport.rs

1//! Transport and format enumerations shared by publishers and consumers.
2//!
3//! Both sets mirror what `lightstream` already supports. They are
4//! `#[non_exhaustive]` so adding a future variant is not a breaking change for
5//! downstream pattern matchers.
6
7use serde::{Deserialize, Serialize};
8
9/// One of the transports a feed can be exposed over.
10///
11/// Mirrors the transports `lightstream` supports today.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
13#[serde(rename_all = "snake_case")]
14#[non_exhaustive]
15pub enum TransportTag {
16    Tcp,
17    WebSocket,
18    Quic,
19    Uds,
20    WebTransport,
21    Stdio,
22}
23
24/// Ordered transport preference list, most-preferred first.
25///
26/// The publisher picks the first entry that intersects with what it offers for
27/// the requested feed. An empty list means "any".
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29pub struct TransportPreference(pub Vec<TransportTag>);
30
31impl TransportPreference {
32    pub fn any() -> Self {
33        Self(Vec::new())
34    }
35
36    pub fn one(tag: TransportTag) -> Self {
37        Self(vec![tag])
38    }
39
40    pub fn iter(&self) -> std::slice::Iter<'_, TransportTag> {
41        self.0.iter()
42    }
43
44    pub fn is_any(&self) -> bool {
45        self.0.is_empty()
46    }
47}
48
49impl From<Vec<TransportTag>> for TransportPreference {
50    fn from(v: Vec<TransportTag>) -> Self {
51        Self(v)
52    }
53}
54
55/// Format the publisher will emit batches in once a subscription is accepted.
56///
57/// Mirrors `lightstream`'s format options.
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
59#[serde(rename_all = "snake_case")]
60#[non_exhaustive]
61pub enum FormatPreference {
62    /// Arrow IPC stream protocol, the default high-throughput choice.
63    Arrow,
64    /// Lightstream TLV framing for opaque payloads.
65    Tlv,
66    /// Streaming CSV, intended for ad-hoc inspection rather than throughput.
67    Csv,
68}
69
70impl Default for FormatPreference {
71    fn default() -> Self {
72        Self::Arrow
73    }
74}