Skip to main content

moqtap_codec/
error.rs

1/// Maximum control message payload length: 2^16 - 1 bytes.
2pub const MAX_MESSAGE_LENGTH: usize = 65535;
3/// Maximum reason phrase length: 1024 bytes.
4pub const MAX_REASON_PHRASE_LENGTH: usize = 1024;
5/// Maximum GOAWAY new session URI length: 8192 bytes.
6pub const MAX_GOAWAY_URI_LENGTH: usize = 8192;
7/// Maximum full track name length: 4096 bytes.
8pub const MAX_FULL_TRACK_NAME_LENGTH: usize = 4096;
9/// Maximum track namespace tuple size: 32 elements.
10pub const MAX_NAMESPACE_TUPLE_SIZE: usize = 32;
11
12/// Errors produced during MoQT message encoding and decoding.
13#[derive(Debug, thiserror::Error, PartialEq, Eq, Clone)]
14pub enum CodecError {
15    /// Unknown or unsupported message type identifier.
16    #[error("unknown message type: 0x{0:x}")]
17    UnknownMessageType(u64),
18    /// Not enough bytes in the buffer to complete decoding.
19    #[error("insufficient bytes")]
20    UnexpectedEnd,
21    /// Control message payload exceeds [`MAX_MESSAGE_LENGTH`].
22    #[error("message too long: {0} bytes (max {MAX_MESSAGE_LENGTH})")]
23    MessageTooLong(usize),
24    /// Variable-length integer encoding/decoding error.
25    #[error("varint error: {0}")]
26    VarInt(#[from] crate::varint::VarIntError),
27    /// Key-value pair encoding/decoding error.
28    #[error("kvp error: {0}")]
29    Kvp(#[from] crate::kvp::KvpError),
30    /// A decoded field value is not valid for its type.
31    #[error("invalid field value")]
32    InvalidField,
33    /// Namespace tuple element count is outside the 1..=32 range.
34    #[error("namespace tuple must have 1-{MAX_NAMESPACE_TUPLE_SIZE} elements, got {0}")]
35    InvalidNamespaceTupleSize(usize),
36    /// Full track name exceeds [`MAX_FULL_TRACK_NAME_LENGTH`].
37    #[error("full track name exceeds {MAX_FULL_TRACK_NAME_LENGTH} bytes")]
38    TrackNameTooLong,
39    /// Reason phrase exceeds [`MAX_REASON_PHRASE_LENGTH`].
40    #[error("reason phrase exceeds {MAX_REASON_PHRASE_LENGTH} bytes")]
41    ReasonPhraseTooLong,
42    /// GOAWAY URI exceeds [`MAX_GOAWAY_URI_LENGTH`].
43    #[error("GOAWAY URI exceeds {MAX_GOAWAY_URI_LENGTH} bytes")]
44    GoAwayUriTooLong,
45    /// Draft not implemented or not enabled via feature flag.
46    #[error("unsupported draft: {0}")]
47    UnsupportedDraft(String),
48}