pub struct CausalContext {
pub parent_id: Option<MessageId>,
pub vector_clock_entry: Option<u64>,
}Expand description
Causal metadata carried inside a protocol message envelope.
Fields§
§parent_id: Option<MessageId>Optional reference to the causally preceding message.
vector_clock_entry: Option<u64>Optional logical timestamp for this message’s causal-chain position.
Implementations§
Source§impl CausalContext
impl CausalContext
Sourcepub const fn independent() -> Self
pub const fn independent() -> Self
Create a causally independent context with no parent or vector-clock entry.
Sourcepub const fn with_parent(parent_id: MessageId) -> Self
pub const fn with_parent(parent_id: MessageId) -> Self
Create a context that follows parent_id in a causal chain.
Sourcepub fn encoded_len(&self) -> Result<usize, ProtocolError>
pub fn encoded_len(&self) -> Result<usize, ProtocolError>
Return the number of bytes needed for deterministic causal-context encoding.
§Errors
Returns ProtocolError::CodecError when the message id length cannot fit
in the protocol’s u32 length field or the total length overflows usize.
Sourcepub fn serialize(&self) -> Result<Vec<u8>, ProtocolError>
pub fn serialize(&self) -> Result<Vec<u8>, ProtocolError>
Serialize this causal context with deterministic big-endian field encoding.
§Errors
Returns ProtocolError::CodecError when a length field cannot represent
the encoded context.
Sourcepub fn to_wire_bytes(&self) -> Result<Vec<u8>, ProtocolError>
pub fn to_wire_bytes(&self) -> Result<Vec<u8>, ProtocolError>
Serialize this causal context for wire transport.
§Errors
Returns ProtocolError::CodecError when a length field cannot represent
the encoded context.
Sourcepub fn deserialize(bytes: &[u8]) -> Result<Self, ProtocolError>
pub fn deserialize(bytes: &[u8]) -> Result<Self, ProtocolError>
Deserialize a causal context from deterministic wire bytes.
§Errors
Returns ProtocolError::CodecError when the bytes are truncated, contain
invalid presence tags, contain invalid UTF-8 message ids, or contain
trailing bytes.
Sourcepub fn from_wire_bytes(bytes: &[u8]) -> Result<Self, ProtocolError>
pub fn from_wire_bytes(bytes: &[u8]) -> Result<Self, ProtocolError>
Deserialize a causal context from deterministic wire bytes.
§Errors
Returns ProtocolError::CodecError when the bytes are truncated, contain
invalid presence tags, contain invalid UTF-8 message ids, or contain
trailing bytes.