Codec

Trait Codec 

Source
pub trait Codec:
    Default
    + Send
    + Sync
    + Sized
    + 'static {
    // Required methods
    fn encode<T: Serialize>(&self, task: &T) -> Result<Vec<u8>, ()>;
    fn encode_into<T: Serialize>(
        &self,
        task: &T,
        buf: &mut Vec<u8>,
    ) -> Result<usize, ()>;
    fn decode<'a, T: Deserialize<'a>>(&self, buf: &'a [u8]) -> Result<T, ()>;
}
Expand description

The codec is immutable, if need changing (like setting up cipher), should have inner mutablilty

Required Methods§

Source

fn encode<T: Serialize>(&self, task: &T) -> Result<Vec<u8>, ()>

Source

fn encode_into<T: Serialize>( &self, task: &T, buf: &mut Vec<u8>, ) -> Result<usize, ()>

sererialized the msg into buf (with std::io::Writer), and return the size written

Source

fn decode<'a, T: Deserialize<'a>>(&self, buf: &'a [u8]) -> Result<T, ()>

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.

Implementors§

Source§

impl Codec for MsgpCodec

Available on crate feature msgpack only.