mp4_emsg/error.rs
1//! Error type for `emsg` (MPEG-DASH Event Message Box) parsing and serialization.
2
3/// Result alias for `emsg` parsing.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// An `emsg` parse / serialize error.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 /// Input shorter than required.
11 #[error(transparent)]
12 BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
13 /// The output buffer passed to `serialize_into` was too small.
14 #[error(transparent)]
15 OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
16 /// The box type at bytes `[4:8]` was not `emsg`.
17 #[error("not an emsg box: type {found:?}")]
18 NotEmsg {
19 /// The 4-byte box type actually found.
20 found: [u8; 4],
21 },
22 /// The `size` field is inconsistent with the available bytes (it must be at
23 /// least the fixed header + cover the box, and 0 / 1 large-size forms are
24 /// not supported for `emsg`).
25 #[error("invalid emsg box size {size}: {reason}")]
26 InvalidSize {
27 /// The `size` field value.
28 size: u32,
29 /// Why it is invalid.
30 reason: &'static str,
31 },
32 /// The `FullBox` `version` was neither 0 nor 1.
33 #[error(transparent)]
34 UnsupportedVersion(#[from] broadcast_common::error::UnsupportedVersion),
35 /// A null-terminated UTF-8 string field was malformed (no terminator, or
36 /// invalid UTF-8).
37 #[error("invalid {field} string: {reason}")]
38 InvalidString {
39 /// Which string field (`scheme_id_uri` / `value`).
40 field: &'static str,
41 /// Why it is invalid.
42 reason: &'static str,
43 },
44 /// A value did not fit the wire field it is written to.
45 #[error(transparent)]
46 FieldOverflow(#[from] broadcast_common::error::FieldOverflow),
47}