1use serde::{Deserialize, Serialize};
8use std::collections::HashMap;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(rename_all = "lowercase")]
13pub enum OperationType {
14 Control = 0,
16 Data = 1,
18 Ack = 2,
20 Error = 3,
22 Request = 4,
24 Response = 5,
26}
27
28impl Default for OperationType {
29 fn default() -> Self {
30 OperationType::Control
31 }
32}
33
34impl std::fmt::Display for OperationType {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 let op_str = match self {
37 OperationType::Control => "control",
38 OperationType::Data => "data",
39 OperationType::Ack => "ack",
40 OperationType::Error => "error",
41 OperationType::Request => "request",
42 OperationType::Response => "response",
43 };
44 write!(f, "{}", op_str)
45 }
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
50#[serde(rename_all = "lowercase")]
51pub enum PayloadType {
52 Vector = 0,
54 Text = 1,
56 Metadata = 2,
58 Binary = 3,
60}
61
62impl Default for PayloadType {
63 fn default() -> Self {
64 PayloadType::Text
65 }
66}
67
68impl std::fmt::Display for PayloadType {
69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70 let type_str = match self {
71 PayloadType::Vector => "vector",
72 PayloadType::Text => "text",
73 PayloadType::Metadata => "metadata",
74 PayloadType::Binary => "binary",
75 };
76 write!(f, "{}", type_str)
77 }
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
82#[serde(rename_all = "lowercase")]
83pub enum EncodingType {
84 Float32 = 0,
86 Float64 = 1,
88 Int32 = 2,
90 Int64 = 3,
92 Uint8 = 4,
94 Uint16 = 5,
96 Uint32 = 6,
98 Uint64 = 7,
100}
101
102impl Default for EncodingType {
103 fn default() -> Self {
104 EncodingType::Float32
105 }
106}
107
108impl std::fmt::Display for EncodingType {
109 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110 let enc_str = match self {
111 EncodingType::Float32 => "float32",
112 EncodingType::Float64 => "float64",
113 EncodingType::Int32 => "int32",
114 EncodingType::Int64 => "int64",
115 EncodingType::Uint8 => "uint8",
116 EncodingType::Uint16 => "uint16",
117 EncodingType::Uint32 => "uint32",
118 EncodingType::Uint64 => "uint64",
119 };
120 write!(f, "{}", enc_str)
121 }
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct PayloadHint {
127 pub payload_type: PayloadType,
129 pub size: Option<u64>,
131 pub encoding: Option<EncodingType>,
133 pub count: Option<u64>,
135}
136
137impl Default for PayloadHint {
138 fn default() -> Self {
139 PayloadHint {
140 payload_type: PayloadType::Text,
141 size: None,
142 encoding: None,
143 count: None,
144 }
145 }
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize, Default)]
150pub struct TransportStats {
151 pub messages_sent: u64,
153 pub messages_received: u64,
155 pub bytes_sent: u64,
157 pub bytes_received: u64,
159 pub active_connections: u32,
161 pub total_connections: u64,
163 pub uptime_seconds: u64,
165 pub avg_latency_ms: Option<f64>,
167}
168
169#[derive(Debug, Clone, Serialize, Deserialize)]
171pub struct ConnectionInfo {
172 pub id: String,
174 pub remote_addr: String,
176 pub local_addr: String,
178 pub connected_at: chrono::DateTime<chrono::Utc>,
180 pub last_activity: chrono::DateTime<chrono::Utc>,
182}
183
184#[derive(Debug, Clone)]
186pub struct MatrixResult {
187 pub success: bool,
189 pub error: Option<String>,
191 pub result: Option<f64>,
193 pub similarity: Option<f64>,
195 pub data: Option<Vec<f32>>,
197}
198
199#[derive(Debug, Clone, Serialize, Deserialize)]
201pub struct FrameOptions {
202 pub frame_type: Option<u32>,
204 pub stream_id: Option<u32>,
206 pub sequence: Option<u64>,
208 pub flags: Option<u32>,
210 pub compressed: bool,
212 pub encrypted: bool,
214}
215
216impl Default for FrameOptions {
217 fn default() -> Self {
218 FrameOptions {
219 frame_type: None,
220 stream_id: None,
221 sequence: None,
222 flags: None,
223 compressed: false,
224 encrypted: false,
225 }
226 }
227}
228
229#[derive(Debug, Clone)]
231pub struct TransportConfig {
232 pub max_payload_size: usize,
234 pub heartbeat_interval: u64,
236 pub max_reconnect_attempts: u32,
238 pub connection_timeout: u64,
240 pub compression_enabled: bool,
242 pub tls_enabled: bool,
244 pub tls_cert_path: Option<String>,
246 pub tls_key_path: Option<String>,
248}
249
250impl Default for TransportConfig {
251 fn default() -> Self {
252 TransportConfig {
253 max_payload_size: 1024 * 1024, heartbeat_interval: 30,
255 max_reconnect_attempts: 3,
256 connection_timeout: 10,
257 compression_enabled: true,
258 tls_enabled: false,
259 tls_cert_path: None,
260 tls_key_path: None,
261 }
262 }
263}
264
265pub type Capabilities = HashMap<String, serde_json::Value>;
270
271pub type AcceptTypes = Vec<String>;
273
274pub type PayloadRefs = Vec<HashMap<String, String>>;