liminal_protocol/wire/
primitives.rs1pub type ConversationId = u64;
3
4pub type ParticipantId = u64;
6
7pub type ParticipantIndex = u64;
9
10#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub struct Generation(core::num::NonZeroU64);
13
14impl Generation {
15 pub const ONE: Self = Self(core::num::NonZeroU64::MIN);
17
18 #[must_use]
20 pub const fn new(value: u64) -> Option<Self> {
21 match core::num::NonZeroU64::new(value) {
22 Some(value) => Some(Self(value)),
23 None => None,
24 }
25 }
26
27 #[must_use]
29 pub const fn get(self) -> u64 {
30 self.0.get()
31 }
32}
33
34pub type DeliverySeq = u64;
36
37pub type TransactionOrder = u64;
39
40pub type ObserverEpoch = u64;
42
43pub type SettlementEpoch = u64;
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq)]
53pub struct ProtocolVersion {
54 pub major: u16,
56 pub minor: u16,
58}
59
60impl ProtocolVersion {
61 pub const V1: Self = Self { major: 1, minor: 0 };
63
64 #[must_use]
66 pub const fn new(major: u16, minor: u16) -> Self {
67 Self { major, minor }
68 }
69}
70
71#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
73pub struct ConnectionIncarnation {
74 pub server_incarnation: u64,
76 pub connection_ordinal: u64,
78}
79
80impl ConnectionIncarnation {
81 #[must_use]
83 pub const fn new(server_incarnation: u64, connection_ordinal: u64) -> Self {
84 Self {
85 server_incarnation,
86 connection_ordinal,
87 }
88 }
89}
90
91#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
93pub struct BindingEpoch {
94 pub connection_incarnation: ConnectionIncarnation,
96 pub capability_generation: Generation,
98}
99
100impl BindingEpoch {
101 #[must_use]
103 pub const fn new(
104 connection_incarnation: ConnectionIncarnation,
105 capability_generation: Generation,
106 ) -> Self {
107 Self {
108 connection_incarnation,
109 capability_generation,
110 }
111 }
112}
113
114macro_rules! fixed_credential {
115 ($(#[$meta:meta])* $name:ident, $length:expr) => {
116 $(#[$meta])*
117 #[derive(Clone, Copy, PartialEq, Eq, Hash)]
118 pub struct $name([u8; $length]);
119
120 impl core::fmt::Debug for $name {
123 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
124 write!(formatter, "{}({} bytes)", stringify!($name), $length)
125 }
126 }
127
128 impl $name {
129 #[must_use]
131 pub const fn new(bytes: [u8; $length]) -> Self {
132 Self(bytes)
133 }
134
135 #[must_use]
137 pub const fn into_bytes(self) -> [u8; $length] {
138 self.0
139 }
140
141 #[must_use]
143 pub const fn as_bytes(&self) -> &[u8; $length] {
144 &self.0
145 }
146 }
147 };
148}
149
150fixed_credential!(
151 EnrollmentToken,
153 16
154);
155fixed_credential!(
156 AttachAttemptToken,
158 16
159);
160fixed_credential!(
161 DetachAttemptToken,
163 16
164);
165fixed_credential!(
166 LeaveAttemptToken,
168 16
169);
170fixed_credential!(
171 RecordAdmissionAttemptToken,
173 16
174);
175fixed_credential!(
176 AttachSecret,
178 32
179);