mlt_core/decoder/model.rs
1//! Version-agnostic decode-side layer types.
2//!
3//! [`Layer01`] is the in-memory columnar form for *both* tag `0x01` and tag
4//! `0x02` layers - the two differ only in wire format, which lives in
5//! [`super::model01`] and `model02`.
6
7use crate::decoder::model01::Layer01;
8#[cfg(feature = "unstable-v2")]
9use crate::decoder::model02::Layer02;
10use crate::{DecodeState, Lazy, Parsed};
11
12/// A layer that can be one of the known types, or an unknown.
13///
14/// The decode-state type parameter `S` mirrors [`Layer01<'a, S>`]:
15/// - `Layer<'a>` / `Layer<'a, Lazy>` - freshly parsed; columns may still be raw bytes.
16/// - `Layer<'a, Parsed>` - returned by [`Layer::decode_all`]; all columns are decoded. Use `ParsedLayer` alias.
17#[derive(Debug)]
18#[non_exhaustive]
19pub enum Layer<'a, S: DecodeState = Lazy> {
20 /// MVT-compatible layer (tag = 1)
21 Tag01(Layer01<'a, S>),
22 /// Experimental v2 layer (tag = 2).
23 ///
24 /// Carries the same columnar representation as `Tag01` plus the columns only
25 /// v2 has, in a more compact wire format.
26 #[cfg(feature = "unstable-v2")]
27 Tag02(Layer02<'a, S>),
28 /// Unknown layer with tag, size, and value
29 Unknown(Unknown<'a>),
30}
31pub type ParsedLayer<'a> = Layer<'a, Parsed>;
32
33/// Unknown layer data, stored as encoded bytes.
34///
35/// Returned inside [`Layer::Unknown`] for any layer tag that is not recognized
36/// by this version of the library. Consumers can inspect the tag and raw bytes
37/// to forward or log the layer without losing data.
38#[derive(Debug, Clone, Default, PartialEq)]
39pub struct Unknown<'a> {
40 pub(crate) tag: u8,
41 pub(crate) value: &'a [u8],
42}
43
44impl<'a> Unknown<'a> {
45 /// The raw layer tag identifying this unrecognised layer type.
46 #[must_use]
47 pub fn tag(&self) -> u32 {
48 u32::from(self.tag)
49 }
50
51 /// The raw encoded bytes of this layer's body.
52 #[must_use]
53 pub fn data(&self) -> &'a [u8] {
54 self.value
55 }
56}