use alloc::vec::Vec;
use super::{
BindingEpoch, CloseCause, ConversationId, DeliverySeq, ObserverEpoch, ParticipantId,
PushDiscriminant, RecordKind, SettlementEpoch,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DetachedCause {
CleanDeregister,
Superseded,
ServerShutdown,
}
impl DetachedCause {
#[must_use]
pub const fn close_cause(self) -> CloseCause {
match self {
Self::CleanDeregister => CloseCause::CleanDeregister,
Self::Superseded => CloseCause::Superseded,
Self::ServerShutdown => CloseCause::ServerShutdown,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DiedCause {
ConnectionLost,
ProcessKilled,
ProtocolError,
UncleanServerRestart {
prior_server_incarnation: u64,
},
}
impl DiedCause {
#[must_use]
pub const fn close_cause(self) -> CloseCause {
match self {
Self::ConnectionLost => CloseCause::ConnectionLost,
Self::ProcessKilled => CloseCause::ProcessKilled,
Self::ProtocolError => CloseCause::ProtocolError,
Self::UncleanServerRestart {
prior_server_incarnation,
} => CloseCause::UncleanServerRestart {
prior_server_incarnation,
},
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ParticipantRecord {
OrdinaryRecord {
sender_participant_id: ParticipantId,
payload: Vec<u8>,
},
Attached {
affected_participant_id: ParticipantId,
binding_epoch: BindingEpoch,
},
Detached {
affected_participant_id: ParticipantId,
binding_epoch: BindingEpoch,
cause: DetachedCause,
},
Died {
affected_participant_id: ParticipantId,
binding_epoch: BindingEpoch,
cause: DiedCause,
},
Left {
affected_participant_id: ParticipantId,
ended_binding_epoch: Option<BindingEpoch>,
},
HistoryCompacted {
affected_participant_id: ParticipantId,
abandoned_after: DeliverySeq,
abandoned_through: DeliverySeq,
physical_floor_at_decision: DeliverySeq,
},
}
impl ParticipantRecord {
#[must_use]
pub const fn record_kind(&self) -> RecordKind {
match self {
Self::OrdinaryRecord { .. } => RecordKind::OrdinaryRecord,
Self::Attached { .. } => RecordKind::Attached,
Self::Detached { .. } => RecordKind::Detached,
Self::Died { .. } => RecordKind::Died,
Self::Left { .. } => RecordKind::Left,
Self::HistoryCompacted { .. } => RecordKind::HistoryCompacted,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParticipantDelivery {
pub conversation_id: ConversationId,
pub delivery_seq: DeliverySeq,
pub record: ParticipantRecord,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ServerPush {
ObserverProgressed {
conversation_id: ConversationId,
refused_epoch: ObserverEpoch,
observer_progress: DeliverySeq,
},
ParticipantDelivery(ParticipantDelivery),
MarkerSettled {
conversation_id: ConversationId,
refused_epoch: SettlementEpoch,
},
}
impl ServerPush {
#[must_use]
pub const fn discriminant(&self) -> PushDiscriminant {
match self {
Self::ObserverProgressed { .. } => PushDiscriminant::ObserverProgressed,
Self::ParticipantDelivery(_) => PushDiscriminant::ParticipantDelivery,
Self::MarkerSettled { .. } => PushDiscriminant::MarkerSettled,
}
}
}