mip_client/client/
types.rs1use thiserror::Error;
2
3use crate::protocol::header::Header;
4
5#[derive(Debug, Error)]
11pub enum MIPError {
12 #[error("Connection error: {0}")]
13 Connection(String),
14
15 #[error("IO error: {0}")]
16 Io(#[from] std::io::Error),
17
18 #[error("Client not connected")]
19 NotConnected,
20
21 #[error("Invalid magic number: {0}")]
22 InvalidMagic(u32),
23
24 #[error("Protocol error: {0}")]
25 Protocol(String),
26
27 #[error("Max reconnection attempts ({0}) reached")]
28 MaxReconnectAttempts(u32),
29
30 #[error("Server error: {0}")]
31 ServerError(String),
32}
33
34pub type MIPResult<T> = Result<T, MIPError>;
36
37#[derive(Debug, Clone)]
43pub struct MIPClientOptions {
44 pub client_id: String,
46 pub host: String,
48 pub port: u16,
50 pub auto_reconnect: bool,
52 pub reconnect_delay_ms: u64,
54 pub max_reconnect_attempts: u32,
56 pub ping_interval_ms: u64,
58}
59
60impl Default for MIPClientOptions {
61 fn default() -> Self {
62 Self {
63 host: "127.0.0.1".to_string(),
64 port: 9000,
65 client_id: "".to_string(),
66 auto_reconnect: true,
67 reconnect_delay_ms: 3000,
68 max_reconnect_attempts: 10,
69 ping_interval_ms: 0,
70 }
71 }
72}
73
74impl MIPClientOptions {
75 pub fn client_id(mut self, client_id: impl Into<String>) -> Self {
77 self.client_id = client_id.into();
78 self
79 }
80
81 pub fn host(mut self, host: impl Into<String>) -> Self {
83 self.host = host.into();
84 self
85 }
86
87 pub fn port(mut self, port: u16) -> Self {
89 self.port = port;
90 self
91 }
92
93 pub fn auto_reconnect(mut self, enabled: bool) -> Self {
95 self.auto_reconnect = enabled;
96 self
97 }
98
99 pub fn reconnect_delay_ms(mut self, delay: u64) -> Self {
101 self.reconnect_delay_ms = delay;
102 self
103 }
104
105 pub fn max_reconnect_attempts(mut self, attempts: u32) -> Self {
107 self.max_reconnect_attempts = attempts;
108 self
109 }
110
111 pub fn ping_interval_ms(mut self, interval: u64) -> Self {
113 self.ping_interval_ms = interval;
114 self
115 }
116}
117
118#[derive(Debug, Clone)]
124pub struct MIPMessage {
125 pub header: Header,
127 pub topic: String,
129 pub message: String,
131}