Trait puffin::codec::CodecP

source ·
pub trait CodecP: Debug {
    // Required methods
    fn encode(&self, bytes: &mut Vec<u8>);
    fn read(&mut self, _: &mut Reader<'_>) -> Result<(), Error>;

    // Provided methods
    fn get_encoding(&self) -> Vec<u8>  { ... }
    fn read_bytes(&mut self, bytes: &[u8]) -> Result<(), Error> { ... }
}
Expand description

Things we can encode and read from a Reader. Used by puffin as it does not require to be Sized (we rely on <dyn T> for T:CodecP.

Required Methods§

source

fn encode(&self, bytes: &mut Vec<u8>)

Encode yourself by appending onto bytes.

source

fn read(&mut self, _: &mut Reader<'_>) -> Result<(), Error>

Decode yourself by fiddling with the Reader. Return Some if it worked, None if not.

Provided Methods§

source

fn get_encoding(&self) -> Vec<u8>

Convenience function to get the results of encode().

source

fn read_bytes(&mut self, bytes: &[u8]) -> Result<(), Error>

Read one of these from the front of bytes and return it.

Implementors§

source§

impl<T: Codec> CodecP for T