pub trait Encode {
// Required methods
fn encoded_len(&self) -> usize;
fn encode(
&self,
buf: &mut BytesMut,
ctx: Option<&dyn EncodeContext>,
) -> Result<(), EncodeError>;
// Provided method
fn encode_to_bytes(
&self,
ctx: Option<&dyn EncodeContext>,
) -> Result<Bytes, EncodeError> { ... }
}Available on crate feature
ipc only.Expand description
Describes how to encode a message.
Required Methods§
Sourcefn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the number of bytes this message will encode to.
Sourcefn encode(
&self,
buf: &mut BytesMut,
ctx: Option<&dyn EncodeContext>,
) -> Result<(), EncodeError>
fn encode( &self, buf: &mut BytesMut, ctx: Option<&dyn EncodeContext>, ) -> Result<(), EncodeError>
Encodes the message into the provided buffer.
The buffer must have at least self.encoded_len() bytes of capacity. If not, the encoding
may or may not fail with an error, depending on the implementation.
Provided Methods§
Sourcefn encode_to_bytes(
&self,
ctx: Option<&dyn EncodeContext>,
) -> Result<Bytes, EncodeError>
fn encode_to_bytes( &self, ctx: Option<&dyn EncodeContext>, ) -> Result<Bytes, EncodeError>
Encodes the message into a freshly allocated Bytes.