Skip to main content

mlt_core/decoder/id/
model.rs

1use std::ops::Deref;
2
3use crate::decoder::{ColumnDecl, RawPresence, RawStream};
4use crate::utils::PresentValues;
5use crate::utils::analyze::AnalyzeViaDeref;
6use crate::{DecodeState, Lazy};
7
8/// ID column representation, parameterized by decode state.
9///
10/// - `Id<'a>` / `Id<'a, Lazy>` - either raw bytes or decoded, in a [`crate::LazyParsed`] enum.
11/// - `Id<'a, Parsed>` - decoded [`ParsedId`] directly (no enum wrapper).
12pub type Id<'a, S = Lazy> = <S as DecodeState>::LazyOrParsed<RawId<'a>, ParsedId<'a>>;
13
14/// Unparsed ID data as read directly from the tile (borrows from input bytes)
15#[derive(Debug, PartialEq, Clone)]
16pub struct RawId<'a> {
17    pub(crate) presence: RawPresence<'a>,
18    pub(crate) value: RawIdValue<'a>,
19}
20
21/// A sequence of raw ID values, either 32-bit or 64-bit unsigned integers
22#[derive(Debug, PartialEq, Clone)]
23pub enum RawIdValue<'a> {
24    Id32(RawStream<'a>),
25    Id64(RawStream<'a>),
26}
27
28impl RawId<'_> {
29    /// What this column declares, the id width included.
30    pub(crate) fn decl(&self) -> ColumnDecl {
31        ColumnDecl::Id {
32            wide: matches!(self.value, RawIdValue::Id64(_)),
33            optional: self.presence.is_optional(),
34        }
35    }
36}
37
38/// Decoded ID column.
39///
40/// A transparent type over [`PresentValues<'a, u64>`]. All feature-access methods
41/// (`get`, `feature_count`, `dense_values`, `materialize`, `is_present`) are
42/// available via auto-deref.
43///
44/// The lifetime `'a` allows zero-copy decoding when the inner bitvector borrows
45/// from the source bytes. When the presence stream is RLE-decompressed, the inner
46/// `Cow` becomes owned and no longer borrows from the input.
47// TODO: consider converting ParsedId to an enum with u32 vs u64 for performance
48#[derive(Clone, Debug, PartialEq)]
49pub struct ParsedId<'a>(pub(crate) PresentValues<'a, u64>);
50
51impl<'a> Deref for ParsedId<'a> {
52    type Target = PresentValues<'a, u64>;
53
54    #[inline]
55    fn deref(&self) -> &Self::Target {
56        &self.0
57    }
58}
59
60impl AnalyzeViaDeref for ParsedId<'_> {}