Skip to main content

mcap2arrow_core/
schema_encoding.rs

1use std::fmt;
2
3/// Schema encodings defined in the mcap spec registry.
4/// <https://mcap.dev/spec/registry>
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub enum SchemaEncoding {
7    /// No schema (self-describing formats like JSON)
8    None,
9    /// Protocol Buffers (`protobuf`)
10    Protobuf,
11    /// FlatBuffers (`flatbuffer`)
12    FlatBuffer,
13    /// ROS 1 Message (`ros1msg`)
14    Ros1Msg,
15    /// ROS 2 Message (`ros2msg`)
16    Ros2Msg,
17    /// ROS 2 IDL (`ros2idl`)
18    Ros2Idl,
19    /// OMG IDL (`omgidl`)
20    OmgIdl,
21    /// JSON Schema (`jsonschema`)
22    JsonSchema,
23    /// Unknown/custom encoding
24    Unknown(String),
25}
26
27impl SchemaEncoding {
28    pub fn as_str(&self) -> &str {
29        match self {
30            Self::None => "",
31            Self::Protobuf => "protobuf",
32            Self::FlatBuffer => "flatbuffer",
33            Self::Ros1Msg => "ros1msg",
34            Self::Ros2Msg => "ros2msg",
35            Self::Ros2Idl => "ros2idl",
36            Self::OmgIdl => "omgidl",
37            Self::JsonSchema => "jsonschema",
38            Self::Unknown(s) => s,
39        }
40    }
41}
42
43impl From<&str> for SchemaEncoding {
44    fn from(s: &str) -> Self {
45        match s {
46            "" => Self::None,
47            "protobuf" => Self::Protobuf,
48            "flatbuffer" => Self::FlatBuffer,
49            "ros1msg" => Self::Ros1Msg,
50            "ros2msg" => Self::Ros2Msg,
51            "ros2idl" => Self::Ros2Idl,
52            "omgidl" => Self::OmgIdl,
53            "jsonschema" => Self::JsonSchema,
54            other => Self::Unknown(other.to_string()),
55        }
56    }
57}
58
59impl fmt::Display for SchemaEncoding {
60    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61        f.write_str(self.as_str())
62    }
63}