dora_message/
lib.rs

1//! Enable serialisation and deserialisation of capnproto messages
2//!
3
4#![allow(clippy::missing_safety_doc)]
5
6pub use uhlc;
7
8pub mod common;
9pub mod config;
10pub mod descriptor;
11pub mod id;
12pub mod metadata;
13
14pub mod coordinator_to_daemon;
15pub mod daemon_to_coordinator;
16
17pub mod daemon_to_daemon;
18
19pub mod daemon_to_node;
20pub mod node_to_daemon;
21
22pub mod cli_to_coordinator;
23pub mod coordinator_to_cli;
24
25pub use arrow_data;
26pub use arrow_schema;
27use uuid::{Timestamp, Uuid};
28
29/// Unique identifier for a dataflow instance.
30///
31/// Dora assigns each dataflow instance a unique ID on start.
32pub type DataflowId = uuid::Uuid;
33
34#[derive(
35    Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
36)]
37pub struct SessionId(uuid::Uuid);
38
39impl SessionId {
40    pub fn generate() -> Self {
41        Self(Uuid::new_v7(Timestamp::now(uuid::NoContext)))
42    }
43
44    pub fn uuid(&self) -> uuid::Uuid {
45        self.0
46    }
47}
48
49#[derive(
50    Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
51)]
52pub struct BuildId(uuid::Uuid);
53
54impl BuildId {
55    pub fn generate() -> Self {
56        Self(Uuid::new_v7(Timestamp::now(uuid::NoContext)))
57    }
58}
59
60impl std::fmt::Display for BuildId {
61    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        write!(f, "BuildId({})", self.0)
63    }
64}
65
66fn current_crate_version() -> semver::Version {
67    let crate_version_raw = env!("CARGO_PKG_VERSION");
68
69    semver::Version::parse(crate_version_raw).unwrap()
70}
71
72fn versions_compatible(
73    crate_version: &semver::Version,
74    specified_version: &semver::Version,
75) -> Result<bool, String> {
76    let req = semver::VersionReq::parse(&crate_version.to_string()).map_err(|error| {
77        format!("failed to parse crate version `{crate_version}` as `VersionReq`: {error}")
78    })?;
79    let specified_dora_req = semver::VersionReq::parse(&specified_version.to_string())
80        .map_err(|error| {
81            format!(
82                "failed to parse specified dora version `{specified_version}` as `VersionReq`: {error}",
83            )
84        })?;
85    let matches = req.matches(specified_version) || specified_dora_req.matches(crate_version);
86    Ok(matches)
87}