CPP Message Introspection as YAML
Hi,
I am trying to make a generic cpp subscriber and convert the serialized message to YAML using (https://github.com/osrf/dynamic_message_introspection/). I have written the following callback:
[this, topic_name, topic_type](const std::shared_ptr<rclcpp::SerializedMessage>& message) {
auto library = rosbag2_cpp::get_typesupport_library(
topic_type, "rosidl_typesupport_cpp");
auto message_type_support = rosbag2_cpp::get_typesupport_handle(
topic_type, "rosidl_typesupport_cpp", library);
auto interface_type = get_topic_type(this->get_node_base_interface()->get_rcl_node_handle(), topic_name);
RosMessage dynamicmsg;
dynmsg::c::ros_message_init(interface_type, &dynamicmsg);
rclcpp::SerializationBase ser(message_type_support);
ser.deserialize_message(message.get(), dynamicmsg.data);
auto msg_yml = dynmsg::c::message_to_yaml(dynamicmsg);
std::cout << msg_yml << '\n';
}
I'm getting jumbled data in the resulting print. I assume I'm missing some conversion or cast. TIA
Asked by ngolombek on 2023-07-31 13:39:27 UTC
Comments