Skip to main content

FomCodec

Struct FomCodec 

Source
pub struct FomCodec { /* private fields */ }
Expand description

Encodes and decodes values of the data types of one FDD.

The codec is a snapshot: it owns a resolved copy of the data type, attribute and parameter tables and does not follow later changes of the Fdd. Build a new one after Fdd::merge; handles stay valid because the FDD is append-only. Lookups by handle are table accesses, lookups by data type name are one ordered map access.

See the module documentation for the mapping between data types and Values.

Implementations§

Source§

impl FomCodec

Source

pub fn new(fdd: &Fdd) -> Result<Self, CodecError>

Resolves the data types of fdd.

Fails with CodecError::RecursiveDataType when a data type contains itself, directly or through other data types, and with CodecError::NestingTooDeep when data types nest deeper than 64 levels. Data types that cannot be resolved for another reason (user-defined encodings, missing definitions) are not errors: their values are Value::Raw, and FomCodec::raw_reason tells why.

Source

pub fn data_type_names(&self) -> impl Iterator<Item = &str>

Names of all data types, in alphabetical order.

Source

pub fn has_data_type(&self, data_type: &str) -> bool

True if the FDD defines a data type of this name.

Source

pub fn octet_boundary(&self, data_type: &str) -> Option<usize>

Octet boundary of a data type: its encoding starts at a multiple of it.

Source

pub fn raw_reason(&self, data_type: &str) -> Option<&str>

Why the values of a data type are Value::Raw: a user-defined encoding, an unsupported or missing definition. None for a data type that is resolved, and for an unknown name.

Source

pub fn attribute_data_type(&self, attribute: AttributeId) -> Option<&str>

Name of the data type of an attribute, as the FDD gives it.

Source

pub fn parameter_data_type(&self, parameter: ParameterId) -> Option<&str>

Name of the data type of a parameter, as the FDD gives it.

Source

pub fn encode( &self, data_type: &str, value: &Value, ) -> Result<Vec<u8>, CodecError>

Encodes value as the data type called data_type.

Source

pub fn decode(&self, data_type: &str, bytes: &[u8]) -> Result<Value, CodecError>

Decodes bytes, which must hold exactly one value of the data type called data_type: octets after the value are an error.

Source

pub fn decode_prefix( &self, data_type: &str, bytes: &[u8], ) -> Result<(Value, usize), CodecError>

Decodes one value from the start of bytes and returns it with the number of octets it used; octets after the value are ignored.

Source

pub fn encode_attribute( &self, attribute: AttributeId, value: &Value, ) -> Result<Vec<u8>, CodecError>

Encodes the value of an attribute as the data type the FDD gives it. An attribute without a usable data type takes Value::Raw (or bytes) as it is.

Source

pub fn decode_attribute( &self, attribute: AttributeId, bytes: &[u8], ) -> Result<Value, CodecError>

Decodes the value of an attribute; strict like FomCodec::decode. An attribute without a usable data type gives Value::Raw.

Source

pub fn encode_parameter( &self, parameter: ParameterId, value: &Value, ) -> Result<Vec<u8>, CodecError>

Encodes the value of a parameter as the data type the FDD gives it.

Source

pub fn decode_parameter( &self, parameter: ParameterId, bytes: &[u8], ) -> Result<Value, CodecError>

Decodes the value of a parameter; strict like FomCodec::decode.

Source

pub fn encode_attributes<I, N, V>( &self, class: ObjectClassId, values: I, ) -> Result<BTreeMap<AttributeId, Vec<u8>>, CodecError>
where I: IntoIterator<Item = (N, V)>, N: AsRef<str>, V: Borrow<Value>,

Encodes attribute values given by attribute name, for example a &BTreeMap<String, Value>. Every name must be an available attribute of class (declared or inherited).

Source

pub fn decode_attributes<I, K, B>( &self, class: ObjectClassId, values: I, ) -> Result<BTreeMap<String, Value>, CodecError>
where I: IntoIterator<Item = (K, B)>, K: Borrow<AttributeId>, B: AsRef<[u8]>,

Decodes attribute values given by handle, for example a &BTreeMap<AttributeId, Vec<u8>>, into a map by attribute name. Every handle must be an available attribute of class.

Source

pub fn encode_parameters<I, N, V>( &self, class: InteractionClassId, values: I, ) -> Result<BTreeMap<ParameterId, Vec<u8>>, CodecError>
where I: IntoIterator<Item = (N, V)>, N: AsRef<str>, V: Borrow<Value>,

Encodes parameter values given by parameter name, for example a &BTreeMap<String, Value>. Every name must be an available parameter of class (declared or inherited).

Source

pub fn decode_parameters<I, K, B>( &self, class: InteractionClassId, values: I, ) -> Result<BTreeMap<String, Value>, CodecError>
where I: IntoIterator<Item = (K, B)>, K: Borrow<ParameterId>, B: AsRef<[u8]>,

Decodes parameter values given by handle, for example a &BTreeMap<ParameterId, Vec<u8>>, into a map by parameter name. Every handle must be an available parameter of class.

Trait Implementations§

Source§

impl Clone for FomCodec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FomCodec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for FomCodec

§

impl Freeze for FomCodec
where *const u8 is !null: Freeze, PhantomData<Node>: Freeze, *const LeafNode<String, usize> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, usize)>>: Freeze, &'static str: Freeze, PhantomData<Member>: Freeze, PhantomData<Class>: Freeze,

§

impl Move for FomCodec

§

impl RefUnwindSafe for FomCodec

§

impl Send for FomCodec
where RawVecInner: Send, NodeRef<Owned, String, usize, LeafOrInternal>: Send, BoxRaw<(String, usize)>: Send, NodeRef<Owned, i128, usize, LeafOrInternal>: Send, BoxRaw<(i128, usize)>: Send, &'static str: Send, NodeRef<Owned, String, u32, LeafOrInternal>: Send, BoxRaw<(String, u32)>: Send,

§

impl Sync for FomCodec
where RawVecInner: Sync, NodeRef<Owned, String, usize, LeafOrInternal>: Sync, BoxRaw<(String, usize)>: Sync, NodeRef<Owned, i128, usize, LeafOrInternal>: Sync, BoxRaw<(i128, usize)>: Sync, NodeRef<Owned, String, u32, LeafOrInternal>: Sync, BoxRaw<(String, u32)>: Sync,

§

impl Unpin for FomCodec
where *const u8 is !null: Unpin, *const LeafNode<String, usize> is !null: Unpin, Box<(String, usize)>: Unpin, *const LeafNode<i128, usize> is !null: Unpin, Box<(i128, usize)>: Unpin, &'static str: Unpin, *const LeafNode<String, u32> is !null: Unpin, Box<(String, u32)>: Unpin,

§

impl UnsafeUnpin for FomCodec
where *const u8 is !null: UnsafeUnpin, PhantomData<Node>: UnsafeUnpin, *const LeafNode<String, usize> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, usize)>>: UnsafeUnpin, &'static str: UnsafeUnpin, PhantomData<Member>: UnsafeUnpin, PhantomData<Class>: UnsafeUnpin,

§

impl UnwindSafe for FomCodec

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.