pub struct Message {
pub v: u8,
pub t: MessageType,
pub id: u32,
pub p: Vec<u8>,
}Expand description
The message envelope sent over the wire.
Each message contains a version, type, correlation ID, and a CBOR payload.
Fields§
§v: u8Protocol version.
t: MessageTypeMessage type.
id: u32Correlation ID used to associate requests with responses and to identify exec sessions.
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more