Skip to main content

xtce_decode/
lib.rs

1//! Decode CCSDS telemetry packets against an XTCE definition.
2//!
3//! ```no_run
4//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
5//! use xtce_decode::{Decoder, ccsds::PacketIter};
6//! use xtce_model::XtceDb;
7//!
8//! let db = XtceDb::from_path("definition.xml")?;
9//! let decoder = Decoder::new(&db)?;
10//!
11//! let stream = std::fs::read("telemetry.bin")?;
12//! for packet in PacketIter::new(&stream, 0) {
13//!     let decoded = decoder.decode(packet?.bytes())?;
14//!     for (name, value) in decoded.iter_named() {
15//!         println!("{name} = {} (raw {})", value.eng, value.raw);
16//!     }
17//! }
18//! # Ok(())
19//! # }
20//! ```
21//!
22//! # Guarantees
23//!
24//! * **No panics.** Every failure is a [`DecodeError`]. A corrupt or hostile packet must not
25//!   take down a process sitting on a live downlink, so the library code denies `unwrap`,
26//!   `expect` and `panic!` outright.
27//! * **No allocation for aligned reads.** Byte-aligned binary and string fields borrow
28//!   straight from the packet.
29//! * **Raw and engineering values are both kept.** XTCE treats them as distinct, restriction
30//!   criteria may test either, and differential testing needs both.
31
32#![deny(missing_docs)]
33#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
34#![deny(clippy::todo, clippy::unimplemented)]
35#![warn(clippy::pedantic)]
36#![allow(clippy::module_name_repetitions)]
37// Tests are allowed to assert loudly; the no-panic rule is about library code reached by a
38// live downlink, not about test setup.
39#![cfg_attr(
40    test,
41    allow(
42        clippy::unwrap_used,
43        clippy::expect_used,
44        clippy::panic,
45        // Exact float equality is the assertion, not an accident: these tests check that a
46        // calibrator produced a specific bit pattern.
47        clippy::float_cmp,
48        clippy::unreadable_literal
49    )
50)]
51// This crate exists to reinterpret bit patterns. Every `as` here narrows a field of known
52// width, with the mask or width check that makes it exact immediately alongside; and every
53// integer-to-float conversion is the one the XTCE data model specifies. Flagging them
54// individually would mean an `#[allow]` on almost every line of the hot path.
55#![allow(
56    clippy::cast_possible_truncation,
57    clippy::cast_possible_wrap,
58    clippy::cast_precision_loss,
59    clippy::cast_sign_loss,
60    clippy::cast_lossless
61)]
62
63pub mod bits;
64pub mod calibrate;
65pub mod ccsds;
66pub mod charset;
67mod decoder;
68pub mod error;
69pub mod value;
70
71pub use bits::{BitCursor, BitError};
72pub use ccsds::{FramingError, PacketIter, PacketReadError, PacketReader, SpacePacketBytes};
73pub use decoder::Decoder;
74pub use error::DecodeError;
75pub use value::{DecodedPacket, EngValue, ParameterValue, RawValue};