use alloc::boxed::Box;
use super::super::{
ConnectionConversationCapacityExceeded, ConversationId, ConversationOrderExhausted,
ConversationSequenceExhausted, InvalidObserverEpoch, InvalidObserverEpochList,
MarkerClosureCapacityExceeded, NoBinding, ObserverBackpressure, ObserverRecoveryAccepted,
ParticipantUnknown, RecordAdmissionEnvelope, RecordCommitted, RecordTooLarge, ResponseEnvelope,
Retired, ServerDiscriminant, ServerValue, StaleAuthority,
};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RecordAdmissionResponse {
value: ServerValue,
}
impl RecordAdmissionResponse {
#[must_use]
pub const fn connection_conversation_capacity_exceeded(
request: RecordAdmissionEnvelope,
limit: u64,
) -> Self {
Self {
value: ServerValue::ConnectionConversationCapacityExceeded(
ConnectionConversationCapacityExceeded::SemanticRequest {
request: ResponseEnvelope::RecordAdmission(request),
limit,
},
),
}
}
pub(crate) const fn from_conversation_order_exhausted(
value: Box<ConversationOrderExhausted>,
) -> Self {
Self {
value: ServerValue::ConversationOrderExhausted(value),
}
}
pub(crate) const fn from_participant_unknown(value: ParticipantUnknown) -> Self {
Self {
value: ServerValue::ParticipantUnknown(value),
}
}
pub(crate) const fn from_no_binding(value: NoBinding) -> Self {
Self {
value: ServerValue::NoBinding(value),
}
}
pub(crate) const fn from_stale_authority(value: StaleAuthority) -> Self {
Self {
value: ServerValue::StaleAuthority(value),
}
}
pub(crate) const fn from_retired(value: Retired) -> Self {
Self {
value: ServerValue::Retired(value),
}
}
pub(crate) const fn from_marker_closure_capacity_exceeded(
value: Box<MarkerClosureCapacityExceeded>,
) -> Self {
Self {
value: ServerValue::MarkerClosureCapacityExceeded(value),
}
}
#[must_use]
pub const fn record_committed(value: RecordCommitted) -> Self {
Self {
value: ServerValue::RecordCommitted(value),
}
}
#[must_use]
pub const fn record_too_large(value: RecordTooLarge) -> Self {
Self {
value: ServerValue::RecordTooLarge(value),
}
}
pub(crate) const fn from_conversation_sequence_exhausted(
value: Box<ConversationSequenceExhausted>,
) -> Self {
Self {
value: ServerValue::ConversationSequenceExhausted(value),
}
}
pub(crate) const fn from_observer_backpressure(value: ObserverBackpressure) -> Self {
Self {
value: ServerValue::ObserverBackpressure(value),
}
}
#[must_use]
pub const fn server_value(&self) -> &ServerValue {
&self.value
}
#[must_use]
pub const fn discriminant(&self) -> ServerDiscriminant {
self.value.discriminant()
}
#[must_use]
pub fn into_server_value(self) -> ServerValue {
self.value
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ObserverRecoveryResponse {
value: ServerValue,
}
impl ObserverRecoveryResponse {
#[must_use]
pub const fn connection_capacity_exceeded(conversation_id: ConversationId, limit: u64) -> Self {
Self {
value: ServerValue::ConnectionConversationCapacityExceeded(
ConnectionConversationCapacityExceeded::ObserverRecovery {
conversation_id,
limit,
},
),
}
}
#[must_use]
pub const fn accepted(value: ObserverRecoveryAccepted) -> Self {
Self {
value: ServerValue::ObserverRecoveryAccepted(value),
}
}
#[must_use]
pub const fn invalid_observer_epoch(value: InvalidObserverEpoch) -> Self {
Self {
value: ServerValue::InvalidObserverEpoch(value),
}
}
#[must_use]
pub const fn invalid_observer_epoch_list(value: InvalidObserverEpochList) -> Self {
Self {
value: ServerValue::InvalidObserverEpochList(value),
}
}
#[must_use]
pub const fn server_value(&self) -> &ServerValue {
&self.value
}
#[must_use]
pub const fn discriminant(&self) -> ServerDiscriminant {
self.value.discriminant()
}
#[must_use]
pub fn into_server_value(self) -> ServerValue {
self.value
}
}