Skip to main content

cadmpeg_ir/decode/
space.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Address-space identifiers.
3//!
4//! Every byte a decode reads belongs to exactly one address space: the root
5//! input, an inflated entry, a reconstructed stream. A [`SpaceId`] names one
6//! space; a [`View`](crate::decode::View) carries the id so error locations
7//! and error attribution fall out of the type. Coordinates are absolute
8//! within a space: offset zero is that space's first byte.
9
10/// Names one address space within a single decode.
11///
12/// Ids are dense and assigned in registration order; the root is always
13/// [`SpaceId::ROOT`]. Error locations use the id to qualify offsets.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
15pub struct SpaceId(u32);
16
17impl SpaceId {
18    /// The root input space, registered first by every decode.
19    pub const ROOT: SpaceId = SpaceId(0);
20
21    /// Creates a session-local address-space identifier.
22    pub(crate) const fn from_index(index: u32) -> Self {
23        Self(index)
24    }
25
26    /// Returns the dense index of this space.
27    pub fn index(self) -> u32 {
28        self.0
29    }
30}
31
32/// A half-open byte range `[start, end)` within one space.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub struct ByteRange {
35    /// Inclusive start offset.
36    pub start: u64,
37    /// Exclusive end offset.
38    pub end: u64,
39}