CPP Message Introspection as YAML

asked 2023-07-31 13:39:27 -0500

ngolombek gravatar image

Hi,

I am trying to make a generic cpp subscriber and convert the serialized message to YAML using (https://github.com/osrf/dynamic_messa...). 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

edit retag flag offensive close merge delete