Trait foca::Codec

source ·
pub trait Codec<T> {
    type Error: Debug + Display + Send + Sync + 'static;

    // Required methods
    fn encode_header(
        &mut self,
        header: &Header<T>,
        buf: impl BufMut
    ) -> Result<(), Self::Error>;
    fn decode_header(&mut self, buf: impl Buf) -> Result<Header<T>, Self::Error>;
    fn encode_member(
        &mut self,
        member: &Member<T>,
        buf: impl BufMut
    ) -> Result<(), Self::Error>;
    fn decode_member(&mut self, buf: impl Buf) -> Result<Member<T>, Self::Error>;
}
Expand description

A Codec is responsible to encoding and decoding the data that is sent between cluster members.

So you can paint your bike shed however you like.

Required Associated Types§

source

type Error: Debug + Display + Send + Sync + 'static

The codec error type. Will be wrapped by crate::Error.

Required Methods§

source

fn encode_header( &mut self, header: &Header<T>, buf: impl BufMut ) -> Result<(), Self::Error>

Encodes a foca::Header into the given buffer.

source

fn decode_header(&mut self, buf: impl Buf) -> Result<Header<T>, Self::Error>

Decode a Header from the given buffer.

Implementations MUST read a single item from the buffer and advance the cursor accordingly.

Implementations may assume the data in the buffer is contiguous.

source

fn encode_member( &mut self, member: &Member<T>, buf: impl BufMut ) -> Result<(), Self::Error>

Encodes a Member into the given buffer.

Implementations MUST NOT leave the buffer dirty when there’s not enough space to encode the item.

source

fn decode_member(&mut self, buf: impl Buf) -> Result<Member<T>, Self::Error>

Decode a Member from the given buffer.

Implementations MUST read a single item from the buffer and advance the cursor accordingly.

Implementations may assume the data in the buffer is contiguous.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, C, T> Codec<T> for &'a mut C
where C: Codec<T>,

§

type Error = <C as Codec<T>>::Error

source§

fn encode_header( &mut self, header: &Header<T>, buf: impl BufMut ) -> Result<(), Self::Error>

source§

fn decode_header(&mut self, buf: impl Buf) -> Result<Header<T>, Self::Error>

source§

fn encode_member( &mut self, member: &Member<T>, buf: impl BufMut ) -> Result<(), Self::Error>

source§

fn decode_member(&mut self, buf: impl Buf) -> Result<Member<T>, Self::Error>

Implementors§

source§

impl<T> Codec<T> for PostcardCodec
where T: Serialize + for<'de> Deserialize<'de>,

§

type Error = Error

source§

impl<T, O> Codec<T> for BincodeCodec<O>
where T: Serialize + for<'de> Deserialize<'de>, O: Options + Copy,