use std::collections::BTreeMap;
use crate::{parse::parse_ros_message_file, MessageFile};
const SERVICE_EVENT_INFO: &str = r##"
uint8 REQUEST_SENT = 0
uint8 REQUEST_RECEIVED = 1
uint8 RESPONSE_SENT = 2
uint8 RESPONSE_RECEIVED = 3
# The type of event this message represents
uint8 event_type
# Timestamp for when the event occurred (sent or received time)
builtin_interfaces/Time stamp
# Unique identifier for the client that sent the service request
# Note, this is only unique for the current session.
# The size here has to match the size of rmw_dds_common/msg/Gid,
# but unfortunately we cannot use that message directly due to a
# circular dependency.
char[16] client_gid
# Sequence number for the request
# Combined with the client ID, this creates a unique ID for the service transaction
int64 sequence_number
"##;
const TIME_MSG: &str = r##"
# This message communicates ROS Time defined here:
# https://design.ros2.org/articles/clock_and_time.html
# The seconds component, valid over all int32 values.
int32 sec
# The nanoseconds component, valid in the range [0, 1e9), to be added to the seconds component.
# e.g.
# The time -1.7 seconds is represented as {sec: -2, nanosec: 3e8}
# The time 1.7 seconds is represented as {sec: 1, nanosec: 7e8}
uint32 nanosec
"##;
const DURATION_MSG: &str = r##"
# Duration defines a period between two time points.
# Messages of this datatype are of ROS Time following this design:
# https://design.ros2.org/articles/clock_and_time.html
# The seconds component, valid over all int32 values.
int32 sec
# The nanoseconds component, valid in the range [0, 1e9), to be added to the seconds component.
# e.g.
# The duration -1.7 seconds is represented as {sec: -2, nanosec: 3e8}
# The duration 1.7 seconds is represented as {sec: 1, nanosec: 7e8}
uint32 nanosec
"##;
pub fn get_builtin_interfaces() -> BTreeMap<String, MessageFile> {
let mut map = BTreeMap::new();
let parsed = parse_ros_message_file(
TIME_MSG,
"Time",
&crate::utils::Package {
name: "builtin_interfaces".to_string(),
path: "/tmp/roslibrust_builtin".into(),
version: Some(crate::utils::RosVersion::ROS2),
},
std::path::Path::new("/tmp/roslibrust_builtin/msg/Time.msg"),
)
.expect("Internal representation of Time is invalid");
let time_msg =
MessageFile::resolve(parsed, &map).expect("Internal representation of Time is invalid");
map.insert(time_msg.get_full_name(), time_msg);
let parsed = parse_ros_message_file(
DURATION_MSG,
"Duration",
&crate::utils::Package {
name: "builtin_interfaces".to_string(),
path: "/tmp/roslibrust_builtin".into(),
version: Some(crate::utils::RosVersion::ROS2),
},
std::path::Path::new("/tmp/roslibrust_builtin/msg/Duration.msg"),
)
.expect("Internal representation of Duration is invalid");
let duration_msg =
MessageFile::resolve(parsed, &map).expect("Internal representation of Duration is invalid");
map.insert(duration_msg.get_full_name(), duration_msg);
let parsed = parse_ros_message_file(
SERVICE_EVENT_INFO,
"ServiceEventInfo",
&crate::utils::Package {
name: "service_msgs".to_string(),
path: "/tmp/roslibrust_builtin".into(),
version: Some(crate::utils::RosVersion::ROS2),
},
std::path::Path::new("/tmp/roslibrust_builtin/msg/ServiceEventInfo.msg"),
)
.expect("Internal representation of ServiceEventInfo is invalid");
let service_event_info = MessageFile::resolve(parsed, &map)
.expect("Internal representation of ServiceEventInfo is invalid");
map.insert(service_event_info.get_full_name(), service_event_info);
map
}