tpt_protocol_tup/
source_protocol.rs1use core::fmt;
2use core::str::FromStr;
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5#[non_exhaustive]
6pub enum SourceProtocol {
7 Modbus,
8 J1939,
9 Isobus,
10 Uds,
11 Canopen,
12 DoipSomeip,
13 Nmea,
14 Mavlink,
15 Bacnet,
16 Opcua,
17 Dnp3,
18 Ethercat,
19 Sparkplugb,
20 Ocpp,
21 Ieee11073Sdc,
22 Hl7v2,
23 Knx,
24 MatterThread,
25 Coap,
26}
27
28impl SourceProtocol {
29 pub fn as_str(&self) -> &'static str {
30 match self {
31 Self::Modbus => "modbus",
32 Self::J1939 => "j1939",
33 Self::Isobus => "isobus",
34 Self::Uds => "uds",
35 Self::Canopen => "canopen",
36 Self::DoipSomeip => "doip-someip",
37 Self::Nmea => "nmea",
38 Self::Mavlink => "mavlink",
39 Self::Bacnet => "bacnet",
40 Self::Opcua => "opcua",
41 Self::Dnp3 => "dnp3",
42 Self::Ethercat => "ethercat",
43 Self::Sparkplugb => "sparkplugb",
44 Self::Ocpp => "ocpp",
45 Self::Ieee11073Sdc => "ieee11073-sdc",
46 Self::Hl7v2 => "hl7v2",
47 Self::Knx => "knx",
48 Self::MatterThread => "matter-thread",
49 Self::Coap => "coap",
50 }
51 }
52
53 pub fn from_str_opt(s: &str) -> Option<Self> {
54 Self::from_str_inner(s)
55 }
56
57 fn from_str_inner(s: &str) -> Option<Self> {
58 match s {
59 "modbus" => Some(Self::Modbus),
60 "j1939" => Some(Self::J1939),
61 "isobus" => Some(Self::Isobus),
62 "uds" => Some(Self::Uds),
63 "canopen" => Some(Self::Canopen),
64 "doip-someip" => Some(Self::DoipSomeip),
65 "nmea" => Some(Self::Nmea),
66 "mavlink" => Some(Self::Mavlink),
67 "bacnet" => Some(Self::Bacnet),
68 "opcua" => Some(Self::Opcua),
69 "dnp3" => Some(Self::Dnp3),
70 "ethercat" => Some(Self::Ethercat),
71 "sparkplugb" => Some(Self::Sparkplugb),
72 "ocpp" => Some(Self::Ocpp),
73 "ieee11073-sdc" => Some(Self::Ieee11073Sdc),
74 "hl7v2" => Some(Self::Hl7v2),
75 "knx" => Some(Self::Knx),
76 "matter-thread" => Some(Self::MatterThread),
77 "coap" => Some(Self::Coap),
78 _ => None,
79 }
80 }
81}
82
83impl FromStr for SourceProtocol {
84 type Err = ();
85
86 fn from_str(s: &str) -> Result<Self, Self::Err> {
87 Self::from_str_inner(s).ok_or(())
88 }
89}
90
91impl fmt::Display for SourceProtocol {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 f.write_str(self.as_str())
94 }
95}