liminal_protocol/wire/
push.rs1use alloc::vec::Vec;
2
3use super::{
4 BindingEpoch, CloseCause, ConversationId, DeliverySeq, ObserverEpoch, ParticipantId,
5 PushDiscriminant, RecordKind,
6};
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum DetachedCause {
11 CleanDeregister,
13 Superseded,
15 ServerShutdown,
17}
18
19impl DetachedCause {
20 #[must_use]
22 pub const fn close_cause(self) -> CloseCause {
23 match self {
24 Self::CleanDeregister => CloseCause::CleanDeregister,
25 Self::Superseded => CloseCause::Superseded,
26 Self::ServerShutdown => CloseCause::ServerShutdown,
27 }
28 }
29}
30
31#[derive(Clone, Copy, Debug, PartialEq, Eq)]
33pub enum DiedCause {
34 ConnectionLost,
36 ProcessKilled,
38 ProtocolError,
40 UncleanServerRestart {
42 prior_server_incarnation: u64,
44 },
45}
46
47impl DiedCause {
48 #[must_use]
50 pub const fn close_cause(self) -> CloseCause {
51 match self {
52 Self::ConnectionLost => CloseCause::ConnectionLost,
53 Self::ProcessKilled => CloseCause::ProcessKilled,
54 Self::ProtocolError => CloseCause::ProtocolError,
55 Self::UncleanServerRestart {
56 prior_server_incarnation,
57 } => CloseCause::UncleanServerRestart {
58 prior_server_incarnation,
59 },
60 }
61 }
62}
63
64#[derive(Clone, Debug, PartialEq, Eq)]
66pub enum ParticipantRecord {
67 OrdinaryRecord {
69 sender_participant_id: ParticipantId,
71 payload: Vec<u8>,
73 },
74 Attached {
76 affected_participant_id: ParticipantId,
78 binding_epoch: BindingEpoch,
80 },
81 Detached {
83 affected_participant_id: ParticipantId,
85 binding_epoch: BindingEpoch,
87 cause: DetachedCause,
89 },
90 Died {
92 affected_participant_id: ParticipantId,
94 binding_epoch: BindingEpoch,
96 cause: DiedCause,
98 },
99 Left {
101 affected_participant_id: ParticipantId,
103 ended_binding_epoch: Option<BindingEpoch>,
105 },
106 HistoryCompacted {
108 affected_participant_id: ParticipantId,
110 abandoned_after: DeliverySeq,
112 abandoned_through: DeliverySeq,
114 physical_floor_at_decision: DeliverySeq,
116 },
117}
118
119impl ParticipantRecord {
120 #[must_use]
122 pub const fn record_kind(&self) -> RecordKind {
123 match self {
124 Self::OrdinaryRecord { .. } => RecordKind::OrdinaryRecord,
125 Self::Attached { .. } => RecordKind::Attached,
126 Self::Detached { .. } => RecordKind::Detached,
127 Self::Died { .. } => RecordKind::Died,
128 Self::Left { .. } => RecordKind::Left,
129 Self::HistoryCompacted { .. } => RecordKind::HistoryCompacted,
130 }
131 }
132}
133
134#[derive(Clone, Debug, PartialEq, Eq)]
136pub struct ParticipantDelivery {
137 pub conversation_id: ConversationId,
139 pub delivery_seq: DeliverySeq,
141 pub record: ParticipantRecord,
143}
144
145#[derive(Clone, Debug, PartialEq, Eq)]
147pub enum ServerPush {
148 ObserverProgressed {
150 conversation_id: ConversationId,
152 refused_epoch: ObserverEpoch,
154 observer_progress: DeliverySeq,
156 },
157 ParticipantDelivery(ParticipantDelivery),
159}
160
161impl ServerPush {
162 #[must_use]
164 pub const fn discriminant(&self) -> PushDiscriminant {
165 match self {
166 Self::ObserverProgressed { .. } => PushDiscriminant::ObserverProgressed,
167 Self::ParticipantDelivery(_) => PushDiscriminant::ParticipantDelivery,
168 }
169 }
170}