ros2_rust
ros2_rust copied to clipboard
support `rclrs::SerializedMessage`
Hi all,
In rosbag2, receiving topic messages of unknown types is achieved through type rclcpp::SerializedMessage, which is not effective in rust through type std_msgs::msg::ByteMultiArray. I hope to add support for type rclcpp::SerializedMessage, so that after specifying a topic, I can receive messages of any unknown type.
example code:
fn main() -> Result<(), rclrs::RclrsError> {
let context = rclrs::Context::new(std::env::args())?;
let node = rclrs::create_node(&context, "test_rosbag")?;
let _subscription = node.create_subscription::<std_msgs::msg::ByteMultiArray, _>(
"/odom",
rclrs::QOS_PROFILE_DEFAULT,
move |msg: rclrs::ReadOnlyLoanedMessage<'_, std_msgs::msg::ByteMultiArray>| {
println!("I heard {} bytes", msg.data.len());
},
)?;
rclrs::spin(node).map_err(|err| err.into())
}
then publish:
ros2 topic pub /odom std_msgs/String "{data: aabbcc}"
and then the node cannot received the message