Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<'db> { /* private fields */ }
Expand description

Decodes packets against one XTCE database, starting from one root container.

Immutable and cheap to clone, so a single decoder can be shared across threads.

Implementations§

Source§

impl<'db> Decoder<'db>

Source

pub fn new(db: &'db XtceDb) -> Result<Self, DecodeError>

Builds a decoder rooted at the database’s default root container.

§Errors

DecodeError::AmbiguousRoot when no conventional root name is present and more than one container has no base.

Source

pub fn with_root(db: &'db XtceDb, name: &str) -> Result<Self, DecodeError>

Builds a decoder rooted at a named container.

§Errors

DecodeError::NoSuchContainer if the name does not resolve.

Source

pub fn db(&self) -> &'db XtceDb

The database being decoded against.

Source

pub fn root(&self) -> ContainerId

The container decoding starts from.

Source

pub fn decode<'p>( &self, data: &'p [u8], ) -> Result<DecodedPacket<'db, 'p>, DecodeError>

Decodes one packet.

Starts at the root container, decodes its entry list, then descends to whichever inheritor’s restriction criteria the decoded values satisfy, repeating until a concrete container is reached.

§Errors

See DecodeError. Notably, a packet whose type the definition does not describe yields DecodeError::UnrecognizedPacket rather than a partial result.

Source

pub fn decode_into<'p>( &self, packet: &mut DecodedPacket<'db, 'p>, data: &'p [u8], ) -> Result<(), DecodeError>

Decodes one packet into an existing buffer, reusing its allocations.

Decoding a stream this way allocates nothing after the first packet. All the packets must share a lifetime, which they do when they are slices of one buffer — the usual case for a file or a receive window.

let decoder = xtce_decode::Decoder::new(&db)?;
let mut packet = decoder.new_packet(&stream);
for framed in xtce_decode::PacketIter::new(&stream, 0) {
    decoder.decode_into(&mut packet, framed?.bytes())?;
    println!("{} parameters", packet.len());
}
§Errors

As Self::decode. On failure the buffer holds whatever was decoded before the error, which is useful for diagnosis and must not be mistaken for a complete packet.

Source

pub fn new_packet<'p>(&self, data: &'p [u8]) -> DecodedPacket<'db, 'p>

An empty packet buffer sized for this decoder, for use with Self::decode_into.

Trait Implementations§

Source§

impl<'db> Clone for Decoder<'db>

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<'db> Copy for Decoder<'db>

Auto Trait Implementations§

§

impl<'db> Forget for Decoder<'db>

§

impl<'db> Freeze for Decoder<'db>

§

impl<'db> Move for Decoder<'db>

§

impl<'db> RefUnwindSafe for Decoder<'db>

§

impl<'db> Send for Decoder<'db>

§

impl<'db> Sync for Decoder<'db>

§

impl<'db> Unpin for Decoder<'db>

§

impl<'db> UnsafeUnpin for Decoder<'db>

§

impl<'db> UnwindSafe for Decoder<'db>

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.