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>
impl<'db> Decoder<'db>
Sourcepub fn new(db: &'db XtceDb) -> Result<Self, DecodeError>
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.
Sourcepub fn with_root(db: &'db XtceDb, name: &str) -> Result<Self, DecodeError>
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.
Sourcepub fn root(&self) -> ContainerId
pub fn root(&self) -> ContainerId
The container decoding starts from.
Sourcepub fn decode<'p>(
&self,
data: &'p [u8],
) -> Result<DecodedPacket<'db, 'p>, DecodeError>
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.
Sourcepub fn decode_into<'p>(
&self,
packet: &mut DecodedPacket<'db, 'p>,
data: &'p [u8],
) -> Result<(), DecodeError>
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.
Sourcepub fn new_packet<'p>(&self, data: &'p [u8]) -> DecodedPacket<'db, 'p>
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.