pub trait Message: Sized {
// Required methods
fn encode<W: BufMut>(&self, w: &mut W);
fn decode<B: Buf>(buf: &mut B) -> Result<Self, DecodeError>;
}
Expand description
A trait for messages that are automatically size-prefixed during encoding/decoding.
This trait wraps the existing Encode/Decode traits and automatically handles:
- Prefixing messages with their encoded size during encoding
- Reading the size prefix and validating exact consumption during decoding
- Ensuring no bytes are left over or missing after decoding
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.