pub struct MessageEnvelope {
pub schema_id: SchemaId,
pub causal_context: CausalContext,
pub payload: Vec<u8>,
}Expand description
Protocol message envelope carried by publish and conversation-message frames.
Fields§
§schema_id: SchemaIdContent type hash identifying the payload schema.
causal_context: CausalContextStructured causal metadata used by the bus for ordering decisions.
payload: Vec<u8>Opaque application payload bytes.
Implementations§
Source§impl MessageEnvelope
impl MessageEnvelope
Sourcepub const fn new(
schema_id: SchemaId,
causal_context: CausalContext,
payload: Vec<u8>,
) -> Self
pub const fn new( schema_id: SchemaId, causal_context: CausalContext, payload: Vec<u8>, ) -> Self
Create a protocol message envelope from all of its fields.
Sourcepub fn encoded_len(&self) -> Result<usize, ProtocolError>
pub fn encoded_len(&self) -> Result<usize, ProtocolError>
Return the deterministic encoded length of this envelope.
§Errors
Returns ProtocolError::CodecError when the causal-context or payload
length cannot fit in the protocol’s u32 length fields, or when the total
length overflows usize.
Sourcepub fn serialize(&self) -> Result<Vec<u8>, ProtocolError>
pub fn serialize(&self) -> Result<Vec<u8>, ProtocolError>
Serialize this envelope with deterministic big-endian field encoding.
§Errors
Returns ProtocolError::CodecError when a length field cannot represent
the encoded envelope.
Sourcepub fn to_wire_bytes(&self) -> Result<Vec<u8>, ProtocolError>
pub fn to_wire_bytes(&self) -> Result<Vec<u8>, ProtocolError>
Serialize this envelope for wire transport.
§Errors
Returns ProtocolError::CodecError when a length field cannot represent
the encoded envelope.
Sourcepub fn deserialize(bytes: &[u8]) -> Result<Self, ProtocolError>
pub fn deserialize(bytes: &[u8]) -> Result<Self, ProtocolError>
Deserialize an envelope from deterministic wire bytes.
§Errors
Returns ProtocolError::CodecError when the bytes are truncated,
contain malformed causal context bytes, 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 an envelope from deterministic wire bytes.
§Errors
Returns ProtocolError::CodecError when the bytes are truncated,
contain malformed causal context bytes, or contain trailing bytes.