cadmpeg_ir/decode/probe.rs
1// SPDX-License-Identifier: Apache-2.0
2//! Committed-parse failure types.
3//!
4//! Reverse-engineered decoding is speculative: try an interpretation, and a
5//! miss means try the next. Leaf reads stay `Option` so the probe path builds
6//! no errors and makes no allocations. The commit transition is realized by the
7//! `req_*` mirror API on [`View`](super::View): a committed required read
8//! returns `Result<T, ParseError>`, so once an interpretation is accepted a
9//! failure is classified and cannot be turned back into "try the next
10//! candidate".
11
12use super::error::SourceLocation;
13
14/// A classified failure after commitment, with its location.
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct ParseError {
17 /// Where the failure occurred.
18 pub location: SourceLocation,
19 /// What kind of failure it was.
20 pub kind: ParseErrorKind,
21}
22
23/// The classified reason a committed parse failed.
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum ParseErrorKind {
26 /// A required read extended past the view's end.
27 UnexpectedEof {
28 /// How many bytes the read needed.
29 needed: u64,
30 /// How many bytes remained in the view.
31 remaining: u64,
32 },
33 /// A value inside the view was inconsistent.
34 InvalidValue,
35 /// The framing inside the view was inconsistent.
36 InvalidFraming,
37}