@@ -932,3 +932,62 @@ TEST(TestConversion, rcl_interfaces__ParameterEvent_cpp)
932
932
EXPECT_EQ (msg_from_yaml.new_parameters [0 ].value .type , 1u );
933
933
EXPECT_EQ (msg_from_yaml.new_parameters [0 ].value .bool_value , true );
934
934
}
935
+
936
+ TEST (TestConversion, PartialConversion_std_msgs__Header_cpp)
937
+ {
938
+ // Start with a ROS message, like a std_msgs/Header
939
+ std_msgs::msg::Header msg;
940
+ msg.frame_id = " my_frame" ;
941
+ builtin_interfaces::msg::Time stamp;
942
+ stamp.sec = 4 ;
943
+ stamp.nanosec = 20u ;
944
+ msg.stamp = stamp;
945
+
946
+ // Convert solely the 'sec' member of the timestamp to a YAML representation
947
+ InterfaceTypeName interface{" std_msgs" , " Header" };
948
+ RosMessage_Cpp ros_msg;
949
+ ros_msg.type_info = dynmsg::cpp::get_type_info (interface);
950
+ ros_msg.data = reinterpret_cast <uint8_t *>(&msg);
951
+ YAML::Node yaml_msg = dynmsg::cpp::selected_member_to_yaml (ros_msg, " stamp/sec" );
952
+ std::cout << " 'sec' as YAML:" << std::endl;
953
+ std::cout << yaml_msg << std::endl << std::endl;
954
+
955
+ EXPECT_EQ (yaml_msg.as <int >(), 4 );
956
+ }
957
+
958
+ TEST (TestConversion, PartialConversion_rcl_interfaces__ParameterEvent_cpp)
959
+ {
960
+ // Start with a ROS message, like a rcl_interfaces/ParameterEvent
961
+ rcl_interfaces::msg::ParameterEvent msg;
962
+
963
+ builtin_interfaces::msg::Time stamp;
964
+ stamp.sec = 4 ;
965
+ stamp.nanosec = 20u ;
966
+
967
+ rcl_interfaces::msg::ParameterValue param_value;
968
+ param_value.type = 1u ;
969
+ param_value.bool_value = true ;
970
+
971
+ rcl_interfaces::msg::Parameter param;
972
+ param.name = " the_param_name" ;
973
+ param.value = param_value;
974
+
975
+ msg.stamp = stamp;
976
+ msg.node = " /my/node" ;
977
+ msg.new_parameters .push_back (param);
978
+
979
+ // Convert solely the parameter array to a YAML representation
980
+ InterfaceTypeName interface{" rcl_interfaces" , " ParameterEvent" };
981
+ RosMessage_Cpp ros_msg;
982
+ ros_msg.type_info = dynmsg::cpp::get_type_info (interface);
983
+ ros_msg.data = reinterpret_cast <uint8_t *>(&msg);
984
+ YAML::Node yaml_msg = dynmsg::cpp::selected_member_to_yaml (ros_msg, " new_parameters" );
985
+ std::cout << " partial message to YAML:" << std::endl;
986
+ std::cout << yaml_msg << std::endl << std::endl;
987
+
988
+ EXPECT_TRUE (yaml_msg.IsSequence ());
989
+ EXPECT_EQ (yaml_msg.size (), 1 );
990
+ EXPECT_STREQ (yaml_msg[0 ][" name" ].as <std::string>().c_str (), " the_param_name" );
991
+ EXPECT_EQ (yaml_msg[0 ][" value" ][" type" ].as <int >(), 1u );
992
+ EXPECT_EQ (yaml_msg[0 ][" value" ][" bool_value" ].as <bool >(), true );
993
+ }
0 commit comments