rtcp_packet/error.rs
1//! Error type for RTCP packet parsing/serialization.
2//!
3//! Field-by-field semantics are documented in the curated spec oracle,
4//! `rtcp-packet/docs/rtcp.md` (RFC 3550 §6).
5
6/// Result alias for `rtcp-packet` parsing/serialization.
7pub type Result<T> = core::result::Result<T, Error>;
8
9/// An RTCP packet parse / serialize error.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13 /// Input (on parse) or output buffer (on serialize) shorter than required.
14 #[error("buffer too short: need {need}, have {have} ({what})")]
15 BufferTooShort {
16 /// Bytes required.
17 need: usize,
18 /// Bytes available.
19 have: usize,
20 /// What was being parsed/serialized.
21 what: &'static str,
22 },
23 /// Output buffer passed to `serialize_into` was smaller than
24 /// `serialized_len()`.
25 #[error("serialize: output buffer too small — need {need}, have {have}")]
26 OutputBufferTooSmall {
27 /// Bytes required.
28 need: usize,
29 /// Bytes available.
30 have: usize,
31 },
32 /// A field value did not fit its wire bit-width, or the two's-complement
33 /// version field was not `2` (RFC 3550 §6.4.1: "The version defined by
34 /// this specification is two (2)"), or a derived count (report/source
35 /// count, item/reason length) overflowed its field, or SDES/BYE text was
36 /// not valid UTF-8 (RFC 3550 §6.5: "encoded according to the UTF-8
37 /// encoding").
38 #[error("field {field} value {value} invalid: {reason}")]
39 InvalidValue {
40 /// The offending field/derived-count name.
41 field: &'static str,
42 /// The offending value.
43 value: u64,
44 /// Why it is invalid.
45 reason: &'static str,
46 },
47 /// A caller-supplied argument violated a documented precondition (e.g. an
48 /// empty [`CompoundPacket`](crate::CompoundPacket) or one not starting
49 /// with SR/RR per RFC 3550 §6.1).
50 #[error("invalid input: {0}")]
51 InvalidInput(&'static str),
52}