Trait links_nonblocking::prelude::Messenger
source · pub trait Messenger: Framer + Debug + Send + Sync + 'static {
type SendT: Debug;
type RecvT: Debug;
// Required methods
fn serialize<const MAX_MSG_SIZE: usize>(
msg: &Self::SendT
) -> Result<([u8; MAX_MSG_SIZE], usize), Error>;
fn deserialize(frame: &[u8]) -> Result<Self::RecvT, Error>;
}
Expand description
Trait defining serialize
& deserialize
methods for Send
& Recv
types
Required Associated Types§
Required Methods§
sourcefn serialize<const MAX_MSG_SIZE: usize>(
msg: &Self::SendT
) -> Result<([u8; MAX_MSG_SIZE], usize), Error>
fn serialize<const MAX_MSG_SIZE: usize>( msg: &Self::SendT ) -> Result<([u8; MAX_MSG_SIZE], usize), Error>
Serializes application message of type Self::SendT
into an array of size MAX_MSG_SIZE
and return it along with the number
of bytes written as a tuple.
§Important
- to avoid a copy of this array on the stack during function call remember to
#[inline]
implementation of this function
sourcefn deserialize(frame: &[u8]) -> Result<Self::RecvT, Error>
fn deserialize(frame: &[u8]) -> Result<Self::RecvT, Error>
Deserializes application message from a byte slice and returns a concrete message of type Self::RecvT
.
Object Safety§
This trait is not object safe.