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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//! Addressing
//!
//! Addresses in Ergot have three main components:
//!
//! * A 16-bit **Network ID**
//! * An 8-bit **Node ID**
//! * An 8-bit **Socket ID**
//!
//! This addressing is similar in form to AppleTalk's addressing. This
//! addressing is quite different to how TCP/IP IPv4 addressing works.
//!
//! ### Network IDs
//!
//! Network IDs represent a single "network segment", where all nodes of a
//! network segment can hear all messages sent on that segment.
//!
//! For example, in a point-to-point link (e.g. UART, TCP, USB), that link will
//! be a single Network ID, containing two nodes. In a bus-style link
//! (e.g. RS-485, I2C), the bus will be a single Network ID, with one or more
//! nodes residing on that link.
//!
//! The Network ID of "0" is reserved, and is generally used when sending
//! messages within the local device, or used to mean "the current network
//! segment" before an interface has discovered the Network ID of the Network
//! Segment it resides on.
//!
//! The Network ID of "65535" is reserved.
//!
//! Network IDs are intended to be discovered/negotiated at runtime, and are
//! not typically hardcoded. The general process of negotiating Network IDs,
//! particularly across multiple network segment hops, is not yet defined.
//!
//! Networks that require more than 65534 network segments are not supported
//! by Ergot. At that point, you should probably just use IPv4/v6.
//!
//! ### Node IDs
//!
//! Node IDs represent a single entity on a network segment.
//!
//! The Node ID of "0" is reserved, and is generally used when sending messages
//! within the local device.
//!
//! The Node ID of "255" is reserved.
//!
//! Network segments that require more than 254 nodes are not supported by
//! Ergot.
//!
//! Network IDs are intended to be discovered/negotiated at runtime, and are
//! not typically hardcoded. One exception to this is for known point-to-point
//! network segments that have a defined "controller" and "target" role, such
//! as USB (where the "host" is the "controller", and the "device" is the
//! "target"). In these cases, the "controller" typically hardcodes the Node ID
//! of "1", and the "target" hardcodes the Node ID of "2". This is done to
//! reduce complexity on these interface implementations.
//!
//! ### Socket IDs
//!
//! Socket IDs represent a single receiving socket within a [`NetStack`].
//!
//! The Socket ID of "0" is reserved, and is generally used as a "wildcard"
//! when sending messages to a device.
//!
//! The Socket ID of "255" is reserved.
//!
//! Systems that require more than 254 active sockets are not supported by
//! Ergot.
//!
//! Socket IDs are assigned dynamically by the [`NetStack`], and are never
//! intended to be hardcoded. Socket IDs may be recycled over time.
//!
//! If a device has multiple interfaces, and therefore has multiple (Network ID,
//! Node ID) tuples that refer to it, the same Socket ID is used on all
//! interfaces.
//!
//! ### Form on the wire
//!
//! When serialized into a packet, addresses are encoded with Network ID as the
//! most significant bytes, and the socket ID as the least significant bytes,
//! and then varint encoded. This means that in many cases, where "0" is used
//! for the Network or Node ID, or low numbers are used, Addresses can be
//! encoded in fewer than 4 bytes on the wire.
//!
//! For this reason, when negotiating any ID, lower numbers should be preferred
//! when possible. Addresses are only encoded as larger than 4 bytes when
//! addressing a network ID >= 4096.
//!
//! [`NetStack`]: crate::NetStack
use ;
/// The Ergot Address type
// ---- impl Address ----