erosbag_core/topics/
topic.rs

1use crate::ros_messages::RosMessageType;
2use crate::topics::qos_profile::QualityOfServiceProfile;
3use std::str::FromStr;
4
5#[derive(Debug, Clone, Eq, PartialEq, Hash)]
6pub struct TopicMetadata {
7    pub message_type: RosMessageType,
8    pub serialization_format: TopicSerializationFormat,
9    pub offered_qos_profiles: Vec<QualityOfServiceProfile>,
10}
11
12impl TopicMetadata {
13    pub fn new(
14        message_type: RosMessageType,
15        serialization_format: TopicSerializationFormat,
16        offered_qos_profiles: Vec<QualityOfServiceProfile>,
17    ) -> Self {
18        Self {
19            message_type,
20            serialization_format,
21            offered_qos_profiles,
22        }
23    }
24}
25
26#[derive(Debug, Clone, Eq, PartialEq, Hash)]
27pub struct TopicMetadataWithName {
28    pub name: String,
29    pub topic: TopicMetadata,
30}
31
32impl TopicMetadataWithName {
33    pub fn new(name: String, topic: TopicMetadata) -> Self {
34        Self { name, topic }
35    }
36
37    pub fn from(
38        name: String,
39        message_type: RosMessageType,
40        serialization_format: TopicSerializationFormat,
41        offered_qos_profiles: Vec<QualityOfServiceProfile>,
42    ) -> Self {
43        let topic = TopicMetadata::new(message_type, serialization_format, offered_qos_profiles);
44
45        Self { name, topic }
46    }
47}
48
49#[derive(Debug, Clone, Eq, PartialEq, Hash)]
50pub enum TopicSerializationFormat {
51    CDR,
52}
53
54impl FromStr for TopicSerializationFormat {
55    type Err = ();
56
57    fn from_str(input: &str) -> Result<TopicSerializationFormat, Self::Err> {
58        match input {
59            "cdr" => Ok(TopicSerializationFormat::CDR),
60            _ => Err(()),
61        }
62    }
63}
64
65impl TopicSerializationFormat {
66    pub fn as_str(&self) -> &'static str {
67        match self {
68            TopicSerializationFormat::CDR => "cdr",
69        }
70    }
71}