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§
Sourcefn octet_boundary(&self) -> usize
fn octet_boundary(&self) -> usize
Octet boundary of this element.
Sourcefn encode_into(&self, writer: &mut ByteWriter<'_>) -> Result<(), EncoderError>
fn encode_into(&self, writer: &mut ByteWriter<'_>) -> Result<(), EncoderError>
Appends the padding this element needs and its encoding.
Sourcefn decode_from(
&mut self,
reader: &mut ByteReader<'_>,
) -> Result<(), DecoderError>
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.
Sourcefn clone_element(&self) -> Box<DynElement>
fn clone_element(&self) -> Box<DynElement>
A boxed copy of this element.
Provided Methods§
Sourcefn encoded_length(&self) -> Result<usize, EncoderError>
fn encoded_length(&self) -> Result<usize, EncoderError>
Length in octets of the encoding when it starts at an aligned offset.
Sourcefn is_same_type_as(&self, other: &DynElement) -> bool
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.
Sourcefn to_bytes(&self) -> Result<Vec<u8>, EncoderError>
fn to_bytes(&self) -> Result<Vec<u8>, EncoderError>
Encodes this element as an outermost value.
Sourcefn append_to(&self, buffer: &mut Vec<u8>) -> Result<(), EncoderError>
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.
Sourcefn decode_slice(&mut self, bytes: &[u8]) -> Result<(), DecoderError>
fn decode_slice(&mut self, bytes: &[u8]) -> Result<(), DecoderError>
Decodes this element from the start of bytes; octets after the value are ignored.
Sourcefn decode_slice_strict(&mut self, bytes: &[u8]) -> Result<(), DecoderError>
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
impl dyn DataElement
Sourcepub fn is<T: DataElement>(&self) -> bool
pub fn is<T: DataElement>(&self) -> bool
True if the element is a T.
Sourcepub fn downcast_ref<T: DataElement>(&self) -> Option<&T>
pub fn downcast_ref<T: DataElement>(&self) -> Option<&T>
The element as a T, if it is one.
Sourcepub fn downcast_mut<T: DataElement>(&mut self) -> Option<&mut T>
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.
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".