pub struct Complex<Message> {
pub data: Bytes,
pub message: OnceLock<Message>,
}Expand description
A lazy-deserialized message.
It holds the raw wire bytes (data) and only parses them into a Message on
first access, caching the result in a OnceLock. When written out, BinWrite
emits the original raw bytes and never re-serializes.
§Why it is fast
- No parse cost unless needed. A message that is only forwarded or logged is never deserialized, so it skips the full decode cost entirely.
- No re-serialize cost. Writing emits the stored raw bytes, avoiding a re-encode of the already-parsed message.
- Cheap clone. Cloning copies only the reference-counted
Bytesand resets the cache, so it does not deep-copy the message.super_cloneis used when the cached message must also be cloned.
Fields§
§data: BytesThe raw wire bytes of the message.
message: OnceLock<Message>The lazily-parsed message cache.
Implementations§
Source§impl<Message> Complex<Message>
impl<Message> Complex<Message>
Sourcepub fn from_message(message: Message) -> Self
pub fn from_message(message: Message) -> Self
Create a Complex from a parsed message, serializing it to raw bytes.
Trait Implementations§
Source§impl<Message: BinWrite> BinWrite for Complex<Message>
impl<Message: BinWrite> BinWrite for Complex<Message>
Source§fn write_options<W: Write>(
&self,
writer: &mut W,
_endian: Endian,
_args: Self::Args<'_>,
) -> BinResult<()>
fn write_options<W: Write>( &self, writer: &mut W, _endian: Endian, _args: Self::Args<'_>, ) -> BinResult<()>
Source§fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
Write
Self to the writer assuming big-endian byte order. Read moreSource§fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
Write
Self to the writer assuming little-endian byte order. Read moreSource§impl<Message> From<&Complex<Message>> for MessageType
impl<Message> From<&Complex<Message>> for MessageType
Source§impl<Message> From<&Complex<Message>> for MessageType
impl<Message> From<&Complex<Message>> for MessageType
Source§impl<Message> From<&Complex<Message>> for MessageType
impl<Message> From<&Complex<Message>> for MessageType
Auto Trait Implementations§
impl<Message> !Freeze for Complex<Message>
impl<Message> RefUnwindSafe for Complex<Message>where
OnceLock<Message>: RefUnwindSafe,
impl<Message> Send for Complex<Message>
impl<Message> Sync for Complex<Message>
impl<Message> Unpin for Complex<Message>
impl<Message> UnsafeUnpin for Complex<Message>where
OnceLock<Message>: UnsafeUnpin,
impl<Message> UnwindSafe for Complex<Message>where
OnceLock<Message>: UnwindSafe,
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