No default value was set for compression_format when deserializing RecordOptions YAML
Description
When using YAML::Node::as<rosbag2_transport::RecordOptions>() to parse the configuration, if the compression_format field is not explicitly provided in the YAML, convert<RecordOptions>::decode() only performs conditional assignment through optional_assign and does not set a semantic default value for this field, resulting in RecordOptions.compression_format being an empty string after deserialization.
Expected Behavior
When the compression_format field is missing in the YAML configuration, RecordOptions.compression_format should automatically use the default value "cdr".
Actual Behavior
Received an empty string after deserialization.
To Reproduce
Test Case
#include <gtest/gtest.h>
#include <string>
#include "rosbag2_transport/record_options.hpp"
TEST(record_options, test)
{
std::string yaml_config =
" all: false\n"
" all_topics: true\n"
" services: [\"service1\", \"service2\"]\n"
" exclude_topics: [\"excluded_topic1\"]\n"
" compression_mode: \"none\"\n";
YAML::Node loaded_node = YAML::Load(yaml_config);
auto options = loaded_node.as<rosbag2_transport::RecordOptions>();
EXPECT_TRUE(options.all_topics);
EXPECT_FALSE(options.all_services);
EXPECT_EQ(options.services.size(), 2);
EXPECT_EQ(options.exclude_topics.size(), 1);
EXPECT_EQ(options.compression_mode, "none");
EXPECT_EQ(options.compression_format, "cdr");
EXPECT_TRUE(options.topics.empty());
}
Output
[ RUN ] record_options.test
/home/shangzh/rosbag2_ws/rosbag2/rosbag2_transport/test/rosbag2_transport/test_record_options.cpp:22: Failure
Expected equality of these values:
options.compression_format
Which is: ""
"cdr"
[ FAILED ] record_options.test (1 ms)
[----------] 1 test from record_options (1 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (1 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] record_options.test
1 FAILED TEST
System (please complete the following information)
OS: ubuntu 24.04 ROS 2 Distro: ros 2 jazzy Install Method: source Version: ros 2 jazzy build options: --mixin asan-gcc