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 host: String,
46 pub port: u16,
48 pub auto_reconnect: bool,
50 pub reconnect_delay_ms: u64,
52 pub max_reconnect_attempts: u32,
54 pub ping_interval_ms: u64,
56}
57
58impl Default for MIPClientOptions {
59 fn default() -> Self {
60 Self {
61 host: "127.0.0.1".to_string(),
62 port: 9000,
63 auto_reconnect: true,
64 reconnect_delay_ms: 3000,
65 max_reconnect_attempts: 10,
66 ping_interval_ms: 0,
67 }
68 }
69}
70
71impl MIPClientOptions {
72 pub fn host(mut self, host: impl Into<String>) -> Self {
74 self.host = host.into();
75 self
76 }
77
78 pub fn port(mut self, port: u16) -> Self {
80 self.port = port;
81 self
82 }
83
84 pub fn auto_reconnect(mut self, enabled: bool) -> Self {
86 self.auto_reconnect = enabled;
87 self
88 }
89
90 pub fn reconnect_delay_ms(mut self, delay: u64) -> Self {
92 self.reconnect_delay_ms = delay;
93 self
94 }
95
96 pub fn max_reconnect_attempts(mut self, attempts: u32) -> Self {
98 self.max_reconnect_attempts = attempts;
99 self
100 }
101
102 pub fn ping_interval_ms(mut self, interval: u64) -> Self {
104 self.ping_interval_ms = interval;
105 self
106 }
107}
108
109#[derive(Debug, Clone)]
115pub struct MIPMessage {
116 pub header: Header,
118 pub topic: String,
120 pub message: String,
122}