Skip to main content

DataElement

Trait DataElement 

Source
pub trait DataElement:
    Any
    + Debug
    + Send
    + Sync {
    // Required methods
    fn octet_boundary(&self) -> usize;
    fn encode_into(
        &self,
        writer: &mut ByteWriter<'_>,
    ) -> Result<(), EncoderError>;
    fn decode_from(
        &mut self,
        reader: &mut ByteReader<'_>,
    ) -> Result<(), DecoderError>;
    fn clone_element(&self) -> Box<DynElement>;

    // Provided methods
    fn encoded_length(&self) -> Result<usize, EncoderError> { ... }
    fn is_same_type_as(&self, other: &DynElement) -> bool { ... }
    fn to_bytes(&self) -> Result<Vec<u8>, EncoderError> { ... }
    fn append_to(&self, buffer: &mut Vec<u8>) -> Result<(), EncoderError> { ... }
    fn decode_slice(&mut self, bytes: &[u8]) -> Result<(), DecoderError> { ... }
    fn decode_slice_strict(&mut self, bytes: &[u8]) -> Result<(), DecoderError> { ... }
}
Expand description

A value that knows its HLA encoding at run time.

Every typed value (Decode + Clone + Debug) is a data element, and so are the dynamic containers (HLAfixedRecord, HLAvariableArray…), which hold boxed data elements and can therefore describe datatypes that are only known at run time, for example from a FOM.

Elements align themselves: DataElement::encode_into and DataElement::decode_from first move to the next multiple of the element’s octet boundary, counted from the start of the outermost value.

Required Methods§

Source

fn octet_boundary(&self) -> usize

Octet boundary of this element.

Source

fn encode_into(&self, writer: &mut ByteWriter<'_>) -> Result<(), EncoderError>

Appends the padding this element needs and its encoding.

Source

fn decode_from( &mut self, reader: &mut ByteReader<'_>, ) -> Result<(), DecoderError>

Skips the padding this element needs and replaces its value by the decoded one.

After an error the element holds an unspecified but valid value. Never panics.

Source

fn clone_element(&self) -> Box<DynElement>

A boxed copy of this element.

Provided Methods§

Source

fn encoded_length(&self) -> Result<usize, EncoderError>

Length in octets of the encoding when it starts at an aligned offset.

Source

fn is_same_type_as(&self, other: &DynElement) -> bool

True if other has the same datatype: the same Rust type and, for dynamic containers, the same structure.

Source

fn to_bytes(&self) -> Result<Vec<u8>, EncoderError>

Encodes this element as an outermost value.

Source

fn append_to(&self, buffer: &mut Vec<u8>) -> Result<(), EncoderError>

Appends the encoding to buffer as a new outermost value: padding is computed from the first appended octet. On error buffer is left unchanged.

Source

fn decode_slice(&mut self, bytes: &[u8]) -> Result<(), DecoderError>

Decodes this element from the start of bytes; octets after the value are ignored.

Source

fn decode_slice_strict(&mut self, bytes: &[u8]) -> Result<(), DecoderError>

Decodes this element from bytes, which must hold exactly one value.

Implementations§

Source§

impl dyn DataElement

Source

pub fn is<T: DataElement>(&self) -> bool

True if the element is a T.

Source

pub fn downcast_ref<T: DataElement>(&self) -> Option<&T>

The element as a T, if it is one.

Source

pub fn downcast_mut<T: DataElement>(&mut self) -> Option<&mut T>

The element as a mutable T, if it is one.

Trait Implementations§

Source§

impl PartialEq for dyn DataElement

Two elements are equal when they have the same datatype and the same encoding. An element that cannot be encoded (a variant record without a variant for its discriminant) equals nothing.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§