lerc/error.rs
1use alloc::string::String;
2
3/// Errors that can occur during LERC encoding or decoding.
4#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5pub enum LercError {
6 /// The data does not start with valid LERC magic bytes.
7 #[error("invalid LERC magic bytes")]
8 InvalidMagic,
9 /// The LERC version in the header is not supported.
10 #[error("unsupported LERC version: {0}")]
11 UnsupportedVersion(i32),
12 /// The computed checksum does not match the expected value.
13 #[error("checksum mismatch: expected {expected:#010x}, computed {computed:#010x}")]
14 ChecksumMismatch {
15 /// Expected checksum from the header.
16 expected: u32,
17 /// Checksum computed from the data.
18 computed: u32,
19 },
20 /// The input buffer is too small to read the required bytes.
21 #[error("buffer too small: need {needed} bytes, have {available}")]
22 BufferTooSmall {
23 /// Minimum number of bytes required.
24 needed: usize,
25 /// Actual number of bytes available.
26 available: usize,
27 },
28 /// The data is structurally invalid or internally inconsistent.
29 #[error("invalid data: {0}")]
30 InvalidData(String),
31 /// The data type code in the header is not recognized.
32 #[error("invalid data type: {0}")]
33 InvalidDataType(i32),
34 /// The encoding mode is not supported by this implementation.
35 #[error("unsupported encoding: {0}")]
36 UnsupportedEncoding(u8),
37 /// A block-level integrity check failed during decoding.
38 #[error("block integrity check failed")]
39 IntegrityCheckFailed,
40 /// The requested pixel type does not match the blob's data type.
41 #[error("type mismatch: expected {expected:?}, actual {actual:?}")]
42 TypeMismatch {
43 /// The data type requested by the caller.
44 expected: crate::types::DataType,
45 /// The actual data type found in the blob.
46 actual: crate::types::DataType,
47 },
48 /// The output buffer is too small to hold the decoded pixel data.
49 #[error("output buffer too small: need {needed} elements, have {available}")]
50 OutputBufferTooSmall {
51 /// Minimum number of elements required.
52 needed: usize,
53 /// Actual number of elements available.
54 available: usize,
55 },
56}
57
58/// A specialized `Result` type for LERC operations.
59pub type Result<T> = core::result::Result<T, LercError>;