Skip to main content

crdt_graph/flatbuffers/
mod.rs

1#[allow(unused_imports, dead_code, clippy::all)]
2#[path = "crdt_graph_generated.rs"]
3mod crdt_graph_generated;
4
5#[allow(unused_imports, dead_code, clippy::all)]
6#[path = "crdt_graph_with_data_generated.rs"]
7mod crdt_graph_with_data_generated;
8
9#[allow(unused_imports, dead_code, clippy::all)]
10#[path = "crdt_graph_with_str_data_generated.rs"]
11mod crdt_graph_with_str_data_generated;
12
13pub mod bytes;
14pub mod simple;
15pub mod string;
16
17use uuid::Uuid;
18
19/// Error type for FlatBuffer decoding.
20#[derive(Debug)]
21pub enum DecodeError {
22    /// The buffer failed FlatBuffer verification.
23    InvalidBuffer(flatbuffers::InvalidFlatbuffer),
24    /// An operation had an unknown or NONE union type.
25    UnknownOperationType,
26}
27
28impl std::fmt::Display for DecodeError {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        match self {
31            DecodeError::InvalidBuffer(e) => write!(f, "invalid flatbuffer: {e}"),
32            DecodeError::UnknownOperationType => write!(f, "unknown operation type in union"),
33        }
34    }
35}
36
37impl std::error::Error for DecodeError {
38    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
39        match self {
40            DecodeError::InvalidBuffer(e) => Some(e),
41            DecodeError::UnknownOperationType => None,
42        }
43    }
44}
45
46impl From<flatbuffers::InvalidFlatbuffer> for DecodeError {
47    fn from(e: flatbuffers::InvalidFlatbuffer) -> Self {
48        DecodeError::InvalidBuffer(e)
49    }
50}
51
52/// Convert a FlatBuffers UUID struct (a `[u8; 16]` newtype) back to `uuid::Uuid`.
53fn uuid_from_fb(fb: &[u8; 16]) -> Uuid {
54    Uuid::from_bytes(*fb)
55}