mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-12 10:03:51 +00:00
PdfCraft's pdfcraft-prc crate (revision 80e26e674d1aa33078e83c8139875047f3289eb6), moved whole with its tests. It reads PRC (ISO 14739-1), the model format of PDF 3D annotations: the container, the bit-level primitives, the schema, tessellations and the product tree. The code is unchanged. The package and its README are renamed, the doctests and tests import craft_prc, and the Double code table taken from prc-rs (MIT) has its row in ATTRIBUTION.md and its licence in licenses/prc-rs.
47 lines
1.8 KiB
Rust
47 lines
1.8 KiB
Rust
//! The crate's error type.
|
|
|
|
/// Why a PRC stream could not be read.
|
|
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
|
#[non_exhaustive]
|
|
pub enum PrcError {
|
|
/// The data does not start with the `PRC` magic [WD 6.1.1].
|
|
#[error("not a PRC stream: missing the \"PRC\" magic")]
|
|
NotPrc,
|
|
/// A value ran past the end of its byte or bit stream.
|
|
#[error("PRC data truncated while reading {0}")]
|
|
Truncated(&'static str),
|
|
/// A structural field holds a value the format forbids.
|
|
#[error("malformed PRC: {0}")]
|
|
Malformed(String),
|
|
/// No `Double` code of up to 22 bits matched [WD 11.17].
|
|
#[error("PRC Double: no code matches the next 22 bits")]
|
|
UnknownDoubleCode,
|
|
/// A section is not a valid zlib stream.
|
|
#[error("PRC {section} section does not inflate: {reason}")]
|
|
Inflate {
|
|
/// The section's name.
|
|
section: &'static str,
|
|
/// The decoder's message.
|
|
reason: String,
|
|
},
|
|
/// The inflated sections and copied blocks together exceed the ceiling
|
|
/// ([`crate::MAX_INFLATED_BYTES`] or the caller's limit).
|
|
#[error("PRC sections inflate past the {limit}-byte ceiling")]
|
|
TooLarge {
|
|
/// The ceiling that was hit.
|
|
limit: usize,
|
|
},
|
|
/// The arrays read from one stream hold more elements than [`crate::MAX_DECODED_ELEMENTS`].
|
|
/// One bit can decode to a 4- or 8-byte element, so the inflation ceiling alone does not
|
|
/// bound the memory the arrays take.
|
|
#[error("PRC arrays decode past the {limit}-element ceiling")]
|
|
TooManyElements {
|
|
/// The ceiling that was hit.
|
|
limit: usize,
|
|
},
|
|
/// A construct this reader does not decode; the part of the file holding it cannot be
|
|
/// read past.
|
|
#[error("PRC {0} is not supported")]
|
|
Unsupported(&'static str),
|
|
}
|