pub struct Message {
pub v: u8,
pub t: MessageType,
pub id: u32,
pub flags: u8,
pub p: Vec<u8>,
}Expand description
The message envelope sent over the wire.
Each message contains a version, type, correlation ID, flags, and a CBOR payload.
Wire format: [len: u32 BE][id: u32 BE][flags: u8][CBOR(v, t, p)]
The id and flags fields live in the binary frame header (outside CBOR)
so that relay intermediaries can route frames without CBOR parsing.
Fields§
§v: u8Protocol version.
t: MessageTypeMessage type.
id: u32Correlation ID used to associate requests with responses and to identify exec sessions.
Serialized in the binary frame header, not in CBOR.
flags: u8Frame flags computed from the message type.
Serialized in the binary frame header, not in CBOR.
p: Vec<u8>The CBOR-encoded payload bytes.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(t: MessageType, id: u32, p: Vec<u8>) -> Self
pub fn new(t: MessageType, id: u32, p: Vec<u8>) -> Self
Creates a new message with the current protocol version and raw payload bytes.
Sourcepub fn with_payload<T: Serialize>(
t: MessageType,
id: u32,
payload: &T,
) -> ProtocolResult<Self>
pub fn with_payload<T: Serialize>( t: MessageType, id: u32, payload: &T, ) -> ProtocolResult<Self>
Creates a new message by serializing the given payload to CBOR.
Sourcepub fn payload<T: DeserializeOwned>(&self) -> ProtocolResult<T>
pub fn payload<T: DeserializeOwned>(&self) -> ProtocolResult<T>
Deserializes the payload bytes into the given type.