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
43#[derive(Clone, Copy, Debug, PartialEq, Eq)]
45pub struct ProtocolVersion {
46 pub major: u16,
48 pub minor: u16,
50}
51
52impl ProtocolVersion {
53 pub const V1: Self = Self { major: 1, minor: 0 };
55
56 #[must_use]
58 pub const fn new(major: u16, minor: u16) -> Self {
59 Self { major, minor }
60 }
61}
62
63#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
65pub struct ConnectionIncarnation {
66 pub server_incarnation: u64,
68 pub connection_ordinal: u64,
70}
71
72impl ConnectionIncarnation {
73 #[must_use]
75 pub const fn new(server_incarnation: u64, connection_ordinal: u64) -> Self {
76 Self {
77 server_incarnation,
78 connection_ordinal,
79 }
80 }
81}
82
83#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
85pub struct BindingEpoch {
86 pub connection_incarnation: ConnectionIncarnation,
88 pub capability_generation: Generation,
90}
91
92impl BindingEpoch {
93 #[must_use]
95 pub const fn new(
96 connection_incarnation: ConnectionIncarnation,
97 capability_generation: Generation,
98 ) -> Self {
99 Self {
100 connection_incarnation,
101 capability_generation,
102 }
103 }
104}
105
106macro_rules! fixed_credential {
107 ($(#[$meta:meta])* $name:ident, $length:expr) => {
108 $(#[$meta])*
109 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
110 pub struct $name([u8; $length]);
111
112 impl $name {
113 #[must_use]
115 pub const fn new(bytes: [u8; $length]) -> Self {
116 Self(bytes)
117 }
118
119 #[must_use]
121 pub const fn into_bytes(self) -> [u8; $length] {
122 self.0
123 }
124
125 #[must_use]
127 pub const fn as_bytes(&self) -> &[u8; $length] {
128 &self.0
129 }
130 }
131 };
132}
133
134fixed_credential!(
135 EnrollmentToken,
137 16
138);
139fixed_credential!(
140 AttachAttemptToken,
142 16
143);
144fixed_credential!(
145 DetachAttemptToken,
147 16
148);
149fixed_credential!(
150 LeaveAttemptToken,
152 16
153);
154fixed_credential!(
155 RecordAdmissionAttemptToken,
157 16
158);
159fixed_credential!(
160 AttachSecret,
162 32
163);