dora_message/
metadata.rs

1use std::collections::BTreeMap;
2
3use arrow_schema::DataType;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7pub struct Metadata {
8    metadata_version: u16,
9    timestamp: uhlc::Timestamp,
10    pub type_info: ArrowTypeInfo,
11    pub parameters: MetadataParameters,
12}
13
14impl Metadata {
15    pub fn new(timestamp: uhlc::Timestamp, type_info: ArrowTypeInfo) -> Self {
16        Self::from_parameters(timestamp, type_info, Default::default())
17    }
18
19    pub fn from_parameters(
20        timestamp: uhlc::Timestamp,
21        type_info: ArrowTypeInfo,
22        parameters: MetadataParameters,
23    ) -> Self {
24        Self {
25            metadata_version: 0,
26            timestamp,
27            parameters,
28            type_info,
29        }
30    }
31
32    pub fn timestamp(&self) -> uhlc::Timestamp {
33        self.timestamp
34    }
35
36    pub fn open_telemetry_context(&self) -> String {
37        if let Some(Parameter::String(otel)) = self.parameters.get("open_telemetry_context") {
38            otel.to_string()
39        } else {
40            "".to_string()
41        }
42    }
43}
44
45pub type MetadataParameters = BTreeMap<String, Parameter>;
46
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48pub struct ArrowTypeInfo {
49    pub data_type: DataType,
50    pub len: usize,
51    pub null_count: usize,
52    pub validity: Option<Vec<u8>>,
53    pub offset: usize,
54    pub buffer_offsets: Vec<BufferOffset>,
55    pub child_data: Vec<ArrowTypeInfo>,
56}
57
58#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
59pub enum Parameter {
60    Bool(bool),
61    Integer(i64),
62    String(String),
63    ListInt(Vec<i64>),
64    Float(f64),
65    ListFloat(Vec<f64>),
66    ListString(Vec<String>),
67}
68
69#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
70pub struct BufferOffset {
71    pub offset: usize,
72    pub len: usize,
73}