1use crate::{ScalarType, SyncDefaults, ToleranceMode};
4
5#[cfg(feature = "alloc")]
6use alloc::vec::Vec;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum RefList<'a, T> {
15 Borrowed(&'a [T]),
16 #[cfg(feature = "alloc")]
17 Owned(Vec<T>),
18}
19
20impl<'a, T> RefList<'a, T> {
21 pub const fn borrowed(items: &'a [T]) -> Self {
22 Self::Borrowed(items)
23 }
24
25 pub fn as_slice(&self) -> &[T] {
26 match self {
27 Self::Borrowed(items) => items,
28 #[cfg(feature = "alloc")]
29 Self::Owned(items) => items,
30 }
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub enum FieldTypeRef<'a> {
36 Scalar(ScalarType),
37 String,
38 List(ScalarType),
39 Enum {
41 variant_count: u16,
42 },
43 EnumNamed(&'a str),
45}
46
47#[derive(Debug, Clone, PartialEq)]
48pub struct SchemaRef<'a> {
49 pub messages: RefList<'a, MessageRef<'a>>,
50}
51
52#[derive(Debug, Clone, PartialEq)]
53pub struct MessageRef<'a> {
54 pub name: &'a str,
55 pub id: u8,
56 pub sync: Option<SyncDefaults>,
57 pub fields: RefList<'a, FieldRef<'a>>,
58}
59
60#[derive(Debug, Clone, Copy, PartialEq)]
61pub struct PredictorRef<'a> {
62 pub kind: PredictorKindRef<'a>,
63 pub window: Option<u8>,
64 pub alpha: Option<f64>,
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq)]
69pub enum PredictorKindRef<'a> {
70 Linear,
71 Quadratic,
72 Cubic,
73 Ewma,
74 HoldLast,
75 Custom(&'a str),
76}
77
78#[derive(Debug, Clone, PartialEq)]
79pub struct FieldRef<'a> {
80 pub name: &'a str,
81 pub ty: FieldTypeRef<'a>,
82 pub quantise: Option<f64>,
83 pub range: Option<(f64, f64)>,
84 pub predictor: Option<PredictorRef<'a>>,
85 pub tolerance_abs: Option<f64>,
86 pub tolerance_rel: Option<f64>,
87 pub tolerance_mode: ToleranceMode,
88 pub refresh: Option<u16>,
89 pub reset: Option<u16>,
90 pub max_len: Option<u16>,
91}