pub struct Message {
pub id: MessageId,
pub metadata: MessageMetadata,
pub payload: MessagePayload,
}
Expand description
Optimized message container with zero-copy support
Fields§
§id: MessageId
Message identifier
metadata: MessageMetadata
Message metadata
payload: MessagePayload
Message payload with zero-copy optimization
Implementations§
Source§impl Message
impl Message
Sourcepub fn json(id: MessageId, value: impl Serialize) -> Result<Self>
pub fn json(id: MessageId, value: impl Serialize) -> Result<Self>
Create a new message with JSON payload
§Errors
Returns an error if the value cannot be serialized to JSON.
Sourcepub fn binary(id: MessageId, data: Bytes, format: BinaryFormat) -> Self
pub fn binary(id: MessageId, data: Bytes, format: BinaryFormat) -> Self
Create a new message with binary payload
Sourcepub fn serialize(&self, format: SerializationFormat) -> Result<Bytes>
pub fn serialize(&self, format: SerializationFormat) -> Result<Bytes>
Serialize message to bytes using the specified format
§Errors
Returns an error if serialization fails for the specified format.
Sourcepub fn deserialize(bytes: Bytes) -> Result<Self>
pub fn deserialize(bytes: Bytes) -> Result<Self>
Deserialize message from bytes with format auto-detection
§Errors
Returns an error if format detection fails or deserialization fails.
Sourcepub fn deserialize_with_format(
bytes: Bytes,
format: SerializationFormat,
) -> Result<Self>
pub fn deserialize_with_format( bytes: Bytes, format: SerializationFormat, ) -> Result<Self>
Deserialize message from bytes using specified format
Sourcepub fn parse_json<T>(&self) -> Result<T>where
T: for<'de> Deserialize<'de>,
pub fn parse_json<T>(&self) -> Result<T>where
T: for<'de> Deserialize<'de>,
Parse JSON payload to structured data
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin 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