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, Debug, PartialEq, Eq, Hash)]
118 pub struct $name([u8; $length]);
119
120 impl $name {
121 #[must_use]
123 pub const fn new(bytes: [u8; $length]) -> Self {
124 Self(bytes)
125 }
126
127 #[must_use]
129 pub const fn into_bytes(self) -> [u8; $length] {
130 self.0
131 }
132
133 #[must_use]
135 pub const fn as_bytes(&self) -> &[u8; $length] {
136 &self.0
137 }
138 }
139 };
140}
141
142fixed_credential!(
143 EnrollmentToken,
145 16
146);
147fixed_credential!(
148 AttachAttemptToken,
150 16
151);
152fixed_credential!(
153 DetachAttemptToken,
155 16
156);
157fixed_credential!(
158 LeaveAttemptToken,
160 16
161);
162fixed_credential!(
163 RecordAdmissionAttemptToken,
165 16
166);
167fixed_credential!(
168 AttachSecret,
170 32
171);