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§
sourcefn encode(&self, bytes: &mut Vec<u8>)
fn encode(&self, bytes: &mut Vec<u8>)
Function for encoding itself by appending itself to the provided vec of bytes.
sourcefn read(_: &mut Reader<'_>) -> Result<Self, InvalidMessage>
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§
sourcefn get_encoding(&self) -> Vec<u8>
fn get_encoding(&self) -> Vec<u8>
Convenience function for encoding the implementation into a vec and returning it
sourcefn read_bytes(bytes: &[u8]) -> Result<Self, InvalidMessage>
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
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl<T: Codec + TlsListElement + Debug> Codec for Vec<T>
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.