Trait Codec
Source pub trait Codec<T> {
// Required methods
fn encode(&self, value: &T) -> Result<Vec<u8>>;
fn decode(&self, bytes: &[u8]) -> Result<T>;
}
Expand description
Encodes and decodes values of type T to and from byte buffers.
A codec is the bridge between in-memory values and the bytes carried by a
Transport or persisted by a
Store.
Encodes a value into a byte buffer.
§Arguments
value - the value to serialize.
§Returns
A byte buffer containing the encoded representation of value.
§Errors
Returns Error::Codec if the value cannot
be encoded.
Decodes a value from a byte buffer.
§Arguments
bytes - the encoded representation to deserialize.
§Returns
The value decoded from bytes.
§Errors
Returns Error::Codec if bytes is not a
valid encoding of T.
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".