cadmpeg_core/decode/space.rs
1// SPDX-License-Identifier: Apache-2.0
2//! Session-local address-space identifiers and byte ranges.
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 within a single decode session; a [`View`](crate::decode::View)
7//! carries the id so error locations fall out of the type. Coordinates are
8//! absolute 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(usize);
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(super) const fn from_index(index: usize) -> Self {
23 Self(index)
24 }
25
26 /// Returns the dense index of this space.
27 pub fn index(self) -> usize {
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}