1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use crate::engine::{AdapterLauncher};
#[cfg(feature = "tcp")]
use crate::adapters::tcp::{self, TcpAdapter};
#[cfg(feature = "tcp")]
use crate::adapters::framed_tcp::{self, FramedTcpAdapter};
#[cfg(feature = "udp")]
use crate::adapters::udp::{self, UdpAdapter};
#[cfg(feature = "websocket")]
use crate::adapters::web_socket::{self, WsAdapter};
use strum::{EnumIter};
use serde::{Serialize, Deserialize};
#[derive(EnumIter, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Transport {
#[cfg(feature = "tcp")]
Tcp,
#[cfg(feature = "tcp")]
FramedTcp,
#[cfg(feature = "udp")]
Udp,
#[cfg(feature = "websocket")]
Ws,
}
impl Transport {
pub fn mount_adapter(self, launcher: &mut AdapterLauncher) {
match self {
#[cfg(feature = "tcp")]
Self::Tcp => launcher.mount(self.id(), TcpAdapter),
#[cfg(feature = "tcp")]
Self::FramedTcp => launcher.mount(self.id(), FramedTcpAdapter),
#[cfg(feature = "udp")]
Self::Udp => launcher.mount(self.id(), UdpAdapter),
#[cfg(feature = "websocket")]
Self::Ws => launcher.mount(self.id(), WsAdapter),
};
}
pub const fn max_message_size(self) -> usize {
match self {
#[cfg(feature = "tcp")]
Self::Tcp => tcp::INPUT_BUFFER_SIZE,
#[cfg(feature = "tcp")]
Self::FramedTcp => framed_tcp::MAX_TCP_PAYLOAD_LEN,
#[cfg(feature = "udp")]
Self::Udp => udp::MAX_UDP_PAYLOAD_LEN,
#[cfg(feature = "websocket")]
Self::Ws => web_socket::MAX_WS_PAYLOAD_LEN,
}
}
pub const fn is_connection_oriented(self) -> bool {
match self {
#[cfg(feature = "tcp")]
Transport::Tcp => true,
#[cfg(feature = "tcp")]
Transport::FramedTcp => true,
#[cfg(feature = "udp")]
Transport::Udp => false,
#[cfg(feature = "websocket")]
Transport::Ws => true,
}
}
pub const fn is_packet_based(self) -> bool {
match self {
#[cfg(feature = "tcp")]
Transport::Tcp => false,
#[cfg(feature = "tcp")]
Transport::FramedTcp => true,
#[cfg(feature = "udp")]
Transport::Udp => true,
#[cfg(feature = "websocket")]
Transport::Ws => true,
}
}
pub fn id(self) -> u8 {
self as u8
}
}
impl std::fmt::Display for Transport {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}