Skip to content

Commit e01e1ef

Browse files
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 <[email protected]>
1 parent 8523995 commit e01e1ef

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

rosbag2_transport/src/rosbag2_transport/record_options.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ bool convert<rosbag2_transport::RecordOptions>::decode(
6060
{
6161
optional_assign<bool>(node, "all_topics", record_options.all_topics);
6262
optional_assign<bool>(node, "all_services", record_options.all_services);
63+
bool record_options_all{false}; // Parse `all` for backward compatability and convenient usage
64+
optional_assign<bool>(node, "all", record_options_all);
65+
if (record_options_all) {
66+
record_options.all_topics = true;
67+
record_options.all_services = true;
68+
}
69+
6370
optional_assign<bool>(node, "is_discovery_disabled", record_options.is_discovery_disabled);
6471
optional_assign<std::vector<std::string>>(node, "topics", record_options.topics);
6572
optional_assign<std::vector<std::string>>(node, "topic_types", record_options.topic_types);
@@ -71,6 +78,8 @@ bool convert<rosbag2_transport::RecordOptions>::decode(
7178
node, "topic_polling_interval", record_options.topic_polling_interval);
7279

7380
optional_assign<std::string>(node, "regex", record_options.regex);
81+
// Map exclude to the "exclude_regex" for backward compatability.
82+
optional_assign<std::string>(node, "exclude", record_options.exclude_regex);
7483
optional_assign<std::string>(node, "exclude_regex", record_options.exclude_regex);
7584
optional_assign<std::vector<std::string>>(node, "exclude_topics", record_options.exclude_topics);
7685
optional_assign<std::vector<std::string>>(

rosbag2_transport/test/rosbag2_transport/test_record_options.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,21 @@ TEST(record_options, test_yaml_serialization)
5959
CHECK(rmw_serialization_format);
6060
#undef CHECK
6161
}
62+
63+
TEST(record_options, test_yaml_decode_for_all_and_exclude)
64+
{
65+
std::string serialized_record_options =
66+
" all: true\n"
67+
" all_topics: false\n"
68+
" topics: []\n"
69+
" rmw_serialization_format: \"\" # defaults to using the format of the input topic\n"
70+
" regex: \"[xyz]/topic\"\n"
71+
" exclude: \"[x]/topic\"\n";
72+
73+
YAML::Node loaded_node = YAML::Load(serialized_record_options);
74+
auto record_options = loaded_node.as<rosbag2_transport::RecordOptions>();
75+
ASSERT_EQ(record_options.all_topics, true);
76+
ASSERT_EQ(record_options.all_services, true);
77+
ASSERT_EQ(record_options.regex, "[xyz]/topic");
78+
ASSERT_EQ(record_options.exclude_regex, "[x]/topic");
79+
}

0 commit comments

Comments
 (0)