helius_laserstream/
config.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "lowercase")]
6pub enum CompressionEncoding {
7 Gzip,
9 Zstd,
11}
12
13#[derive(Debug, Clone)]
14pub struct LaserstreamConfig {
15 pub api_key: String,
17 pub endpoint: String,
19 pub max_reconnect_attempts: Option<u32>,
22 pub channel_options: ChannelOptions,
24 pub replay: bool,
28}
29
30#[derive(Debug, Clone, Default)]
31pub struct ChannelOptions {
32 pub connect_timeout_secs: Option<u64>,
34 pub timeout_secs: Option<u64>,
36 pub max_decoding_message_size: Option<usize>,
38 pub max_encoding_message_size: Option<usize>,
40 pub http2_keep_alive_interval_secs: Option<u64>,
42 pub keep_alive_timeout_secs: Option<u64>,
44 pub keep_alive_while_idle: Option<bool>,
46 pub initial_stream_window_size: Option<u32>,
48 pub initial_connection_window_size: Option<u32>,
50 pub http2_adaptive_window: Option<bool>,
52 pub tcp_nodelay: Option<bool>,
54 pub tcp_keepalive_secs: Option<u64>,
56 pub buffer_size: Option<usize>,
58 pub accept_compression: Option<Vec<CompressionEncoding>>,
60 pub send_compression: Option<CompressionEncoding>,
62}
63
64
65impl ChannelOptions {
66 pub fn with_zstd_compression(mut self) -> Self {
68 self.send_compression = Some(CompressionEncoding::Zstd);
69 self.accept_compression = Some(vec![CompressionEncoding::Zstd, CompressionEncoding::Gzip]);
70 self
71 }
72
73 pub fn with_gzip_compression(mut self) -> Self {
75 self.send_compression = Some(CompressionEncoding::Gzip);
76 self.accept_compression = Some(vec![CompressionEncoding::Gzip, CompressionEncoding::Zstd]);
77 self
78 }
79}
80
81impl Default for LaserstreamConfig {
82 fn default() -> Self {
83 Self {
84 api_key: String::new(),
85 endpoint: String::new(),
86 max_reconnect_attempts: None, channel_options: ChannelOptions::default(),
88 replay: true, }
90 }
91}
92
93impl LaserstreamConfig {
94 pub fn new(endpoint: String, api_key: String) -> Self {
95 Self {
96 endpoint,
97 api_key,
98 max_reconnect_attempts: None, channel_options: ChannelOptions::default(),
100 replay: true, }
102 }
103
104 pub fn with_max_reconnect_attempts(mut self, attempts: u32) -> Self {
106 self.max_reconnect_attempts = Some(attempts);
107 self
108 }
109
110 pub fn with_channel_options(mut self, options: ChannelOptions) -> Self {
112 self.channel_options = options;
113 self
114 }
115
116 pub fn with_replay(mut self, replay: bool) -> Self {
120 self.replay = replay;
121 self
122 }
123}