mcap2arrow_core/
message_encoding.rs1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub enum MessageEncoding {
7 Ros1,
9 Cdr,
11 Protobuf,
13 FlatBuffer,
15 Cbor,
17 MsgPack,
19 Json,
21 Unknown(String),
23}
24
25impl MessageEncoding {
26 pub fn as_str(&self) -> &str {
27 match self {
28 Self::Ros1 => "ros1",
29 Self::Cdr => "cdr",
30 Self::Protobuf => "protobuf",
31 Self::FlatBuffer => "flatbuffer",
32 Self::Cbor => "cbor",
33 Self::MsgPack => "msgpack",
34 Self::Json => "json",
35 Self::Unknown(s) => s,
36 }
37 }
38}
39
40impl From<&str> for MessageEncoding {
41 fn from(s: &str) -> Self {
42 match s {
43 "ros1" => Self::Ros1,
44 "cdr" => Self::Cdr,
45 "protobuf" => Self::Protobuf,
46 "flatbuffer" => Self::FlatBuffer,
47 "cbor" => Self::Cbor,
48 "msgpack" => Self::MsgPack,
49 "json" => Self::Json,
50 other => Self::Unknown(other.to_string()),
51 }
52 }
53}
54
55impl fmt::Display for MessageEncoding {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 f.write_str(self.as_str())
58 }
59}