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
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<T: Codec + TlsListElement + Debug> Codec for Vec<T>
Implement Codec
for lists of elements that implement TlsListElement
.
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.