Skip to main content

rmt_flute/
error.rs

1//! Error type for the multicast object-delivery wire formats
2//! (RFC 5651 LCT / RFC 5775 ALC / RFC 6726 FLUTE / RFC 5740 NORM).
3
4/// Result alias for this crate's parsing / serialization.
5pub type Result<T> = core::result::Result<T, Error>;
6
7/// A parse / serialize error.
8#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
9#[non_exhaustive]
10pub enum Error {
11    /// Input shorter than required.
12    #[error("buffer too short: need {need}, have {have} ({what})")]
13    BufferTooShort {
14        /// Bytes required.
15        need: usize,
16        /// Bytes available.
17        have: usize,
18        /// What was being parsed.
19        what: &'static str,
20    },
21    /// The output buffer passed to `serialize_into` was too small.
22    #[error("output buffer too small: need {need}, have {have}")]
23    OutputBufferTooSmall {
24        /// Bytes required.
25        need: usize,
26        /// Bytes available.
27        have: usize,
28    },
29    /// A field value did not fit in its wire bit-width.
30    #[error("field {what} value {value} does not fit in {bits} bits")]
31    FieldTooWide {
32        /// The over-wide field name.
33        what: &'static str,
34        /// The offending value.
35        value: u64,
36        /// The field width on the wire.
37        bits: u32,
38    },
39    /// A reserved / version field carried an unexpected value.
40    #[error("invalid field {what}: {reason}")]
41    InvalidField {
42        /// The field name.
43        what: &'static str,
44        /// Why it is invalid.
45        reason: &'static str,
46    },
47    /// A header-extension was malformed (bad HET/HEL or truncated content).
48    #[error("invalid header extension: {reason}")]
49    InvalidExtension {
50        /// Why the extension is invalid.
51        reason: &'static str,
52    },
53    /// A length field (`HDR_LEN` / `hdr_len`) was inconsistent with the bytes
54    /// the parser computed from the flags / fixed fields.
55    #[error("inconsistent length {length}: {reason}")]
56    InconsistentLength {
57        /// The length field value (in 32-bit words).
58        length: u8,
59        /// Why it is inconsistent.
60        reason: &'static str,
61    },
62}