Trait Codec

Source
pub trait Codec: Debug + Sized {
    // Required methods
    fn encode(&self, bytes: &mut Vec<u8>);
    fn read(: &mut Reader<'_>) -> Result<Self, InvalidMessage>;

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

Trait for implementing encoding and decoding functionality on something.

Required Methods§

Source

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

Function for encoding itself by appending itself to the provided vec of bytes.

Source

fn read(: &mut Reader<'_>) -> Result<Self, InvalidMessage>

Function for decoding itself from the provided reader will return Some if the decoding was successful or None if it was not.

Provided Methods§

Source

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

Convenience function for encoding the implementation into a vec and returning it

Source

fn read_bytes(bytes: &[u8]) -> Result<Self, InvalidMessage>

Function for wrapping a call to the read function in a Reader for the slice of bytes provided

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.

Implementations on Foreign Types§

Source§

impl Codec for u8

Source§

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

Source§

fn read(r: &mut Reader<'_>) -> Result<Self, InvalidMessage>

Source§

impl Codec for u16

Source§

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

Source§

fn read(r: &mut Reader<'_>) -> Result<Self, InvalidMessage>

Source§

impl Codec for u32

Source§

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

Source§

fn read(r: &mut Reader<'_>) -> Result<Self, InvalidMessage>

Source§

impl Codec for u64

Source§

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

Source§

fn read(r: &mut Reader<'_>) -> Result<Self, InvalidMessage>

Source§

impl<T: Codec + TlsListElement + Debug> Codec for Vec<T>

Implement Codec for lists of elements that implement TlsListElement.

TlsListElement provides the size of the length prefix for the list.

Source§

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

Source§

fn read(r: &mut Reader<'_>) -> Result<Self, InvalidMessage>

Implementors§