pub trait Message: Sized + Debug {
const ID: u64;
// Required methods
fn encode_msg<W: BufMut>(&self, w: &mut W, version: Version);
fn decode_msg<B: Buf>(
buf: &mut B,
version: Version,
) -> Result<Self, DecodeError>;
}Expand description
A trait for messages that are 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 Associated Constants§
Required Methods§
Sourcefn encode_msg<W: BufMut>(&self, w: &mut W, version: Version)
fn encode_msg<W: BufMut>(&self, w: &mut W, version: Version)
Encode this message with a size prefix.
Sourcefn decode_msg<B: Buf>(
buf: &mut B,
version: Version,
) -> Result<Self, DecodeError>
fn decode_msg<B: Buf>( buf: &mut B, version: Version, ) -> Result<Self, DecodeError>
Decode a size-prefixed message, ensuring exact size consumption.
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.