Skip to main content

dlep_core/
ids.rs

1//! Type-id newtypes for signals, messages, data items and extensions.
2//!
3//! All on-the-wire identifiers are 16-bit, network byte order. Using newtypes
4//! (instead of bare `u16`) prevents accidental mixing between e.g. a
5//! `MessageType` and a `DataItemType`.
6
7macro_rules! id_newtype {
8    ($(#[$m:meta])* $vis:vis $name:ident) => {
9        $(#[$m])*
10        #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
11        $vis struct $name(pub u16);
12
13        impl From<u16> for $name {
14            fn from(v: u16) -> Self { Self(v) }
15        }
16        impl From<$name> for u16 {
17            fn from(v: $name) -> u16 { v.0 }
18        }
19    };
20}
21
22id_newtype!(
23    /// Signal type on the UDP discovery channel (RFC 8175 §11.1 / §15.2).
24    pub SignalType
25);
26id_newtype!(
27    /// Message type on the TCP session channel (RFC 8175 §11.2 / §15.3).
28    pub MessageType
29);
30id_newtype!(
31    /// Data item type inside a message or signal (RFC 8175 §11.3 / §15.4).
32    pub DataItemType
33);
34id_newtype!(
35    /// Extension identifier advertised in `Extensions Supported` (RFC 8175 §13.6).
36    pub ExtensionId
37);
38
39impl SignalType {
40    pub const PEER_DISCOVERY: Self = Self(1);
41    pub const PEER_OFFER: Self = Self(2);
42}
43
44impl MessageType {
45    pub const SESSION_INITIALIZATION: Self = Self(1);
46    pub const SESSION_INITIALIZATION_RESPONSE: Self = Self(2);
47    pub const SESSION_UPDATE: Self = Self(3);
48    pub const SESSION_UPDATE_RESPONSE: Self = Self(4);
49    pub const SESSION_TERMINATION: Self = Self(5);
50    pub const SESSION_TERMINATION_RESPONSE: Self = Self(6);
51    pub const DESTINATION_UP: Self = Self(7);
52    pub const DESTINATION_UP_RESPONSE: Self = Self(8);
53    pub const DESTINATION_ANNOUNCE: Self = Self(9);
54    pub const DESTINATION_ANNOUNCE_RESPONSE: Self = Self(10);
55    pub const DESTINATION_DOWN: Self = Self(11);
56    pub const DESTINATION_DOWN_RESPONSE: Self = Self(12);
57    pub const DESTINATION_UPDATE: Self = Self(13);
58    pub const LINK_CHARACTERISTICS_REQUEST: Self = Self(14);
59    pub const LINK_CHARACTERISTICS_RESPONSE: Self = Self(15);
60    pub const HEARTBEAT: Self = Self(16);
61}
62
63impl DataItemType {
64    pub const STATUS: Self = Self(1);
65    pub const IPV4_CONNECTION_POINT: Self = Self(2);
66    pub const IPV6_CONNECTION_POINT: Self = Self(3);
67    pub const PEER_TYPE: Self = Self(4);
68    pub const HEARTBEAT_INTERVAL: Self = Self(5);
69    pub const EXTENSIONS_SUPPORTED: Self = Self(6);
70    pub const MAC_ADDRESS: Self = Self(7);
71    pub const IPV4_ADDRESS: Self = Self(8);
72    pub const IPV6_ADDRESS: Self = Self(9);
73    pub const IPV4_ATTACHED_SUBNET: Self = Self(10);
74    pub const IPV6_ATTACHED_SUBNET: Self = Self(11);
75    pub const MAXIMUM_DATA_RATE_RECEIVE: Self = Self(12);
76    pub const MAXIMUM_DATA_RATE_TRANSMIT: Self = Self(13);
77    pub const CURRENT_DATA_RATE_RECEIVE: Self = Self(14);
78    pub const CURRENT_DATA_RATE_TRANSMIT: Self = Self(15);
79    pub const LATENCY: Self = Self(16);
80    pub const RESOURCES: Self = Self(17);
81    pub const RELATIVE_LINK_QUALITY_RECEIVE: Self = Self(18);
82    pub const RELATIVE_LINK_QUALITY_TRANSMIT: Self = Self(19);
83    pub const MTU: Self = Self(20);
84}