pub trait ZvtSerializerImpl<L = Empty, E = Default, TE = Default>: Sized{
// Provided methods
fn serialize_tagged(&self, tag: Option<Tag>) -> Vec<u8> ⓘ { ... }
fn deserialize_tagged(
bytes: &[u8],
tag: Option<Tag>,
) -> Result<(Self, &[u8]), ZVTError> { ... }
}
Expand description
The implementation for serializing/deserializing a Zvt struct.
Trait implements the basic logic of the Zvt protocol. Every package consists of up to three fields:
<BMP-NUMBER>
<LENGTH>
<DATA>
.
The BMP-NUMBER and LENGTH are optional; The DATA may be encoded in different ways.
§Parameters:
L
: The trait length::Length encodes/decodes the<LENGTH>
field. Use length::Empty to omit the length.E
: The trait encoding::Encoding encodes/decodes the given data an generates the DATA field. In order to use this trait with custom types, you have to implement the encoding::Encoding trait for your type.TE
: The trait encoding::Encoding which encodes/decodes the Tag the<BMP-NUMBER>
field.
Provided Methods§
fn serialize_tagged(&self, tag: Option<Tag>) -> Vec<u8> ⓘ
fn deserialize_tagged( bytes: &[u8], tag: Option<Tag>, ) -> Result<(Self, &[u8]), ZVTError>
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§
impl<L, E, TE> ZvtSerializerImpl<L, E, TE> for u8
impl<L, E, TE> ZvtSerializerImpl<L, E, TE> for u16
impl<L, E, TE> ZvtSerializerImpl<L, E, TE> for u32
impl<L, E, TE> ZvtSerializerImpl<L, E, TE> for u64
impl<L, E, TE> ZvtSerializerImpl<L, E, TE> for usize
impl<L, E, TE> ZvtSerializerImpl<L, E, TE> for String
impl<L, E, TE> ZvtSerializerImpl<L, E, TE> for NaiveDateTime
Source§impl<T, L, E, TE> ZvtSerializerImpl<L, E, TE> for Option<T>
The implementation for serializing/deserializing a optional Zvt fields.
impl<T, L, E, TE> ZvtSerializerImpl<L, E, TE> for Option<T>
The implementation for serializing/deserializing a optional Zvt fields.
Optional fields don’t generate anything if the data field is None. They generate the same output if the data field is provided.
When deserializing optional fields behave differently depending if a Tag is provided or not. If the Tag is None the deserialization always succeeds returning None as the result. If the Tag is provided, then the serialization error is propagated.
Source§impl<T, L, E, TE> ZvtSerializerImpl<L, E, TE> for Vec<T>
The implementation for serializing/deserializing Vec
impl<T, L, E, TE> ZvtSerializerImpl<L, E, TE> for Vec<T>
The implementation for serializing/deserializing Vec
The Zvt protocol does not define a consistent handling of vectors. However, in most cases it assumes that every element is tagged and not the vector itself. Therefore we provide a default serialization/deserialization which does exactly this.
The serialization will return an empty vector for an empty input. Otherwise it will tag every element independently and collect the results.
The deserialization will deserialize the input until a failure occurs - this indicates that there are no more elements in the vector - and return the results. This means that all elements in the vector must be placed consecutively to each other.
Source§impl<TE: Encoding<Tag>> ZvtSerializerImpl<Tlv, Custom, TE> for Vec<u8>
Custom ZvtSerializerImpl which will just copy the data.
impl<TE: Encoding<Tag>> ZvtSerializerImpl<Tlv, Custom, TE> for Vec<u8>
Custom ZvtSerializerImpl which will just copy the data.