Skip to main content

bunny_codec/compressed/
error.rs

1use std::fmt;
2
3/// Error returned when a Bunny compressed mesh byte stream is invalid.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum CompressedMeshError {
6    /// The magic bytes are not `BUNNYQZ!`.
7    InvalidMagic,
8    /// The profile version is not supported.
9    UnsupportedVersion,
10    /// Reserved header flags are non-zero.
11    UnsupportedFlags,
12    /// The triangle index width field is not canonical.
13    InvalidIndexWidth,
14    /// A vertex or triangle count is zero or exceeds the profile limit.
15    InvalidCount,
16    /// The encoded quantization bounds are inverted.
17    InvalidBounds,
18    /// The declared payload length does not match the canonical layout.
19    InvalidPayloadLength,
20    /// The input ends before the declared byte range.
21    PayloadTooShort,
22    /// The input has bytes after the declared payload.
23    TrailingData,
24    /// A requested record or triangle vertex index is out of bounds.
25    IndexOutOfBounds,
26    /// A checked integer conversion or offset calculation overflowed.
27    IntegerOverflow,
28}
29
30impl fmt::Display for CompressedMeshError {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        let message = match self {
33            Self::InvalidMagic => "compressed mesh magic bytes are invalid",
34            Self::UnsupportedVersion => "compressed mesh version is unsupported",
35            Self::UnsupportedFlags => "compressed mesh reserved flags are non-zero",
36            Self::InvalidIndexWidth => "compressed mesh index width is invalid",
37            Self::InvalidCount => "compressed mesh count is invalid",
38            Self::InvalidBounds => "compressed mesh quantization bounds are invalid",
39            Self::InvalidPayloadLength => "compressed mesh payload length is invalid",
40            Self::PayloadTooShort => "compressed mesh payload is shorter than declared",
41            Self::TrailingData => "compressed mesh payload has trailing bytes",
42            Self::IndexOutOfBounds => "compressed mesh index is out of bounds",
43            Self::IntegerOverflow => "compressed mesh offset calculation overflowed",
44        };
45        f.write_str(message)
46    }
47}
48
49impl std::error::Error for CompressedMeshError {}