Skip to main content

mlt_core/frames/v01/
model.rs

1use geo_types::Geometry as GeoGeometry;
2use num_enum::TryFromPrimitive;
3
4use crate::v01::{
5    EncodedGeometry, EncodedId, EncodedProperty, Geometry, GeometryValues, Id, IdValues, Property,
6    StagedProperty,
7};
8
9/// Column definition
10#[derive(Debug, PartialEq)]
11pub struct Column<'a> {
12    pub typ: ColumnType,
13    pub name: Option<&'a str>,
14    pub children: Vec<Column<'a>>,
15}
16
17/// Owned variant of [`Column`].
18#[derive(Debug, PartialEq, Clone)]
19pub struct OwnedColumn {
20    pub typ: ColumnType,
21    pub name: Option<String>,
22    pub children: Vec<OwnedColumn>,
23}
24
25/// Column data type, as stored in the tile
26#[derive(Debug, Clone, Copy, PartialEq, TryFromPrimitive)]
27#[repr(u8)]
28pub enum ColumnType {
29    Id = 0,
30    OptId = 1,
31    LongId = 2,
32    OptLongId = 3,
33    Geometry = 4,
34    Bool = 10,
35    OptBool = 11,
36    I8 = 12,
37    OptI8 = 13,
38    U8 = 14,
39    OptU8 = 15,
40    I32 = 16,
41    OptI32 = 17,
42    U32 = 18,
43    OptU32 = 19,
44    I64 = 20,
45    OptI64 = 21,
46    U64 = 22,
47    OptU64 = 23,
48    F32 = 24,
49    OptF32 = 25,
50    F64 = 26,
51    OptF64 = 27,
52    Str = 28,
53    OptStr = 29,
54    SharedDict = 30,
55}
56
57/// Representation of a feature table layer encoded as MLT tag `0x01`
58#[derive(Debug, PartialEq)]
59pub struct Layer01<'a> {
60    pub name: &'a str,
61    pub extent: u32,
62    pub id: Option<Id<'a>>,
63    pub geometry: Geometry<'a>,
64    pub properties: Vec<Property<'a>>,
65    #[cfg(fuzzing)]
66    pub layer_order: Vec<crate::frames::v01::fuzzing::LayerOrdering>,
67}
68
69/// Columnar layer data being prepared for encoding (stage 2 of the encoding pipeline).
70///
71/// Holds fully-owned columnar data. Constructed directly (synthetics, benches) or
72/// converted from [`TileLayer01`].
73/// Consumed by encoding to produce [`EncodedLayer01`].
74#[derive(Debug, PartialEq, Clone)]
75#[cfg_attr(all(not(test), feature = "arbitrary"), derive(arbitrary::Arbitrary))]
76pub struct StagedLayer01 {
77    pub name: String,
78    pub extent: u32,
79    pub id: Option<IdValues>,
80    pub geometry: GeometryValues,
81    pub properties: Vec<StagedProperty>,
82}
83
84/// Wire-ready layer data (stage 3 of the encoding pipeline).
85///
86/// Produced by encoding a [`StagedLayer01`]. Can be serialised directly to bytes
87/// via [`EncodedLayer01::write_to`].
88#[derive(Debug, PartialEq, Clone)]
89pub struct EncodedLayer01 {
90    pub name: String,
91    pub extent: u32,
92    pub id: Option<EncodedId>,
93    pub geometry: EncodedGeometry,
94    pub properties: Vec<EncodedProperty>,
95    #[cfg(fuzzing)]
96    pub layer_order: Vec<crate::frames::v01::fuzzing::LayerOrdering>,
97}
98
99/// Row-oriented working form for the optimizer.
100///
101/// All features are stored as a flat [`Vec<TileFeature>`] so that sorting is
102/// a single `sort_by_cached_key` call.  The `property_names` vec is parallel
103/// to every `TileFeature::properties` slice in this layer.
104#[derive(Debug, Clone)]
105pub struct TileLayer01 {
106    pub name: String,
107    pub extent: u32,
108    /// Column names, parallel to `TileFeature::properties`.
109    pub property_names: Vec<String>,
110    pub features: Vec<TileFeature>,
111}
112
113/// A single map feature in row form.
114#[derive(Debug, Clone, PartialEq)]
115pub struct TileFeature {
116    pub id: Option<u64>,
117    /// Geometry in `geo_types` / `Geom32` form.
118    pub geometry: GeoGeometry<i32>,
119    /// One value per property column, in the same order as
120    /// [`TileLayer01::property_names`].
121    pub properties: Vec<PropValue>,
122}
123
124/// A single typed value for one property of one feature.
125///
126/// Mirrors the scalar variants of `ParsedProperty` at the per-feature
127/// level. `SharedDict` items are flattened: each sub-field becomes its own
128/// `PropValue::Str` entry in `TileFeature::properties`, with the
129/// corresponding entry in `TileLayer01::property_names` set to
130/// `"prefix:suffix"`.
131#[derive(Debug, Clone, PartialEq)]
132pub enum PropValue {
133    Bool(Option<bool>),
134    I8(Option<i8>),
135    U8(Option<u8>),
136    I32(Option<i32>),
137    U32(Option<u32>),
138    I64(Option<i64>),
139    U64(Option<u64>),
140    F32(Option<f32>),
141    F64(Option<f64>),
142    Str(Option<String>),
143}