From e01e1efe57c4f226eed21e2eefb0b459fd3bd0b8 Mon Sep 17 00:00:00 2001 From: Michael Orlov Date: Tue, 21 May 2024 14:12:30 -0700 Subject: [PATCH] Add support for "all" and "exclude" in RecordOptions YAML decoder (#1664) - Rationale: Add support for old options "all" and "exclude" in the YAML parser for backward compatibility with old versions of the config files for the "ros2 bag convert" CLI. Signed-off-by: Michael Orlov --- .../src/rosbag2_transport/record_options.cpp | 9 +++++++++ .../rosbag2_transport/test_record_options.cpp | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/rosbag2_transport/src/rosbag2_transport/record_options.cpp b/rosbag2_transport/src/rosbag2_transport/record_options.cpp index 3e22ac62e7..127d0b8312 100644 --- a/rosbag2_transport/src/rosbag2_transport/record_options.cpp +++ b/rosbag2_transport/src/rosbag2_transport/record_options.cpp @@ -60,6 +60,13 @@ bool convert::decode( { optional_assign(node, "all_topics", record_options.all_topics); optional_assign(node, "all_services", record_options.all_services); + bool record_options_all{false}; // Parse `all` for backward compatability and convenient usage + optional_assign(node, "all", record_options_all); + if (record_options_all) { + record_options.all_topics = true; + record_options.all_services = true; + } + optional_assign(node, "is_discovery_disabled", record_options.is_discovery_disabled); optional_assign>(node, "topics", record_options.topics); optional_assign>(node, "topic_types", record_options.topic_types); @@ -71,6 +78,8 @@ bool convert::decode( node, "topic_polling_interval", record_options.topic_polling_interval); optional_assign(node, "regex", record_options.regex); + // Map exclude to the "exclude_regex" for backward compatability. + optional_assign(node, "exclude", record_options.exclude_regex); optional_assign(node, "exclude_regex", record_options.exclude_regex); optional_assign>(node, "exclude_topics", record_options.exclude_topics); optional_assign>( diff --git a/rosbag2_transport/test/rosbag2_transport/test_record_options.cpp b/rosbag2_transport/test/rosbag2_transport/test_record_options.cpp index 015b1ae09e..9aa5e4d79e 100644 --- a/rosbag2_transport/test/rosbag2_transport/test_record_options.cpp +++ b/rosbag2_transport/test/rosbag2_transport/test_record_options.cpp @@ -59,3 +59,21 @@ TEST(record_options, test_yaml_serialization) CHECK(rmw_serialization_format); #undef CHECK } + +TEST(record_options, test_yaml_decode_for_all_and_exclude) +{ + std::string serialized_record_options = + " all: true\n" + " all_topics: false\n" + " topics: []\n" + " rmw_serialization_format: \"\" # defaults to using the format of the input topic\n" + " regex: \"[xyz]/topic\"\n" + " exclude: \"[x]/topic\"\n"; + + YAML::Node loaded_node = YAML::Load(serialized_record_options); + auto record_options = loaded_node.as(); + ASSERT_EQ(record_options.all_topics, true); + ASSERT_EQ(record_options.all_services, true); + ASSERT_EQ(record_options.regex, "[xyz]/topic"); + ASSERT_EQ(record_options.exclude_regex, "[x]/topic"); +}