pub trait DeserializerAdapter<D> {
type Error: Error;
type Decoded;
// Required methods
fn supported_encodings() -> &'static [RepresentationIdentifier];
fn transform_decoded(decoded: Self::Decoded) -> D;
// Provided methods
fn from_bytes_with<S>(
input_bytes: &[u8],
encoding: RepresentationIdentifier,
decoder: S
) -> Result<D, S::Error>
where S: Decode<Self::Decoded> { ... }
fn from_bytes(
input_bytes: &[u8],
encoding: RepresentationIdentifier
) -> Result<D, Self::Error>
where Self: DefaultDecoder<D> { ... }
}
Expand description
trait for connecting a Deserializer implementation and DataReader together - no_key version.
Deserialization is done in two steps: decode and transform. The basic pipeline is:
byte slice → decode → value of type Self::Decoded
→ call
Self::transform_decoded
→ value of type D
The transform step may be an identity function, which means that
Self::Decoded
and D
are the same.
The decoding step can be parameterized at run time, if the decoder is
defined suitaby. If there is no need for such parameterization (i.e.
decoder object), use subtrait DefaultDecoder
, which defines decoding
that needs no decoder “seed” object at run time. In that case decoding is
dependent only on the type of the decoder and incoming byte stream.
Required Associated Types§
Required Methods§
sourcefn supported_encodings() -> &'static [RepresentationIdentifier]
fn supported_encodings() -> &'static [RepresentationIdentifier]
Which data representations can the DeserializerAdapter read? See RTPS specification Section 10 and Table 10.3
sourcefn transform_decoded(decoded: Self::Decoded) -> D
fn transform_decoded(decoded: Self::Decoded) -> D
Transform the Self::Decoded
type returned by the decoder into a
value of type D
.
If Self::Decoded
is set to D
, this method can be the identity
function.
Provided Methods§
sourcefn from_bytes_with<S>(
input_bytes: &[u8],
encoding: RepresentationIdentifier,
decoder: S
) -> Result<D, S::Error>
fn from_bytes_with<S>( input_bytes: &[u8], encoding: RepresentationIdentifier, decoder: S ) -> Result<D, S::Error>
Deserialize data from bytes to an object using the given decoder.
encoding
must be something given by supported_encodings()
, or
implementation may fail with Err or panic!()
.
sourcefn from_bytes(
input_bytes: &[u8],
encoding: RepresentationIdentifier
) -> Result<D, Self::Error>where
Self: DefaultDecoder<D>,
fn from_bytes(
input_bytes: &[u8],
encoding: RepresentationIdentifier
) -> Result<D, Self::Error>where
Self: DefaultDecoder<D>,
Deserialize data from bytes to an object.
encoding
must be something given by supported_encodings()
, or
implementation may fail with Err or panic!()
.
Only usable if the adapter has a default decoder, i.e. implements
DefaultDecoder
.