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("buffer too short: need {need}, have {have} ({what})")]
12 BufferTooShort {
13 /// Bytes required.
14 need: usize,
15 /// Bytes available.
16 have: usize,
17 /// What was being parsed.
18 what: &'static str,
19 },
20 /// The output buffer passed to `serialize_into` was too small.
21 #[error("output buffer too small: need {need}, have {have}")]
22 OutputBufferTooSmall {
23 /// Bytes required.
24 need: usize,
25 /// Bytes available.
26 have: usize,
27 },
28 /// The box type at bytes `[4:8]` was not `emsg`.
29 #[error("not an emsg box: type {found:?}")]
30 NotEmsg {
31 /// The 4-byte box type actually found.
32 found: [u8; 4],
33 },
34 /// The `size` field is inconsistent with the available bytes (it must be at
35 /// least the fixed header + cover the box, and 0 / 1 large-size forms are
36 /// not supported for `emsg`).
37 #[error("invalid emsg box size {size}: {reason}")]
38 InvalidSize {
39 /// The `size` field value.
40 size: u32,
41 /// Why it is invalid.
42 reason: &'static str,
43 },
44 /// The `FullBox` `version` was neither 0 nor 1.
45 #[error("unsupported emsg version {version} (expected 0 or 1)")]
46 UnsupportedVersion {
47 /// The version byte read from the wire.
48 version: u8,
49 },
50 /// A null-terminated UTF-8 string field was malformed (no terminator, or
51 /// invalid UTF-8).
52 #[error("invalid {field} string: {reason}")]
53 InvalidString {
54 /// Which string field (`scheme_id_uri` / `value`).
55 field: &'static str,
56 /// Why it is invalid.
57 reason: &'static str,
58 },
59 /// A field value did not fit in its wire bit-width (e.g. a box larger than
60 /// `u32::MAX`).
61 #[error("field {what} value {value} does not fit in {bits} bits")]
62 FieldTooWide {
63 /// The over-wide field name.
64 what: &'static str,
65 /// The offending value.
66 value: u64,
67 /// The field width on the wire.
68 bits: u32,
69 },
70}