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
29pub type DataflowId = uuid::Uuid;
30
31#[derive(
32    Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
33)]
34pub struct SessionId(uuid::Uuid);
35
36impl SessionId {
37    pub fn generate() -> Self {
38        Self(Uuid::new_v7(Timestamp::now(uuid::NoContext)))
39    }
40
41    pub fn uuid(&self) -> uuid::Uuid {
42        self.0
43    }
44}
45
46#[derive(
47    Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
48)]
49pub struct BuildId(uuid::Uuid);
50
51impl BuildId {
52    pub fn generate() -> Self {
53        Self(Uuid::new_v7(Timestamp::now(uuid::NoContext)))
54    }
55}
56
57impl std::fmt::Display for BuildId {
58    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59        write!(f, "BuildId({})", self.0)
60    }
61}
62
63fn current_crate_version() -> semver::Version {
64    let crate_version_raw = env!("CARGO_PKG_VERSION");
65
66    semver::Version::parse(crate_version_raw).unwrap()
67}
68
69fn versions_compatible(
70    crate_version: &semver::Version,
71    specified_version: &semver::Version,
72) -> Result<bool, String> {
73    let req = semver::VersionReq::parse(&crate_version.to_string()).map_err(|error| {
74        format!("failed to parse crate version `{crate_version}` as `VersionReq`: {error}")
75    })?;
76    let specified_dora_req = semver::VersionReq::parse(&specified_version.to_string())
77        .map_err(|error| {
78            format!(
79                "failed to parse specified dora version `{specified_version}` as `VersionReq`: {error}",
80            )
81        })?;
82    let matches = req.matches(specified_version) || specified_dora_req.matches(crate_version);
83    Ok(matches)
84}