diff --git a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp index fd579ccb8..1f0e473ee 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp @@ -185,9 +185,7 @@ void SequentialReader::set_filter(const rosbag2_storage::StorageFilter & storage { // Empty filter. Add all topics with a supported serialization format. for (const auto & topic : topics_metadata_) { - if (topic.serialization_format != storage_serialization_format) { - topics_filter_.topics.push_back(topic.name); - } + topics_filter_.topics.push_back(topic.name); } } else { // Non-empty filter. Add all requested topics with a supported serialization format. @@ -201,12 +199,12 @@ void SequentialReader::set_filter(const rosbag2_storage::StorageFilter & storage ROSBAG2_CPP_LOG_WARN( "Requested topic %s not found or has unsupported serialization format.", topic.c_str()); } + } - // Edge case: we cannot find any supported topic. - // To avoid reading all messages, throw an error. - if (topics_filter_.topics.empty()) { - throw std::runtime_error("No topics found that match the filter."); - } + // Edge case: we cannot find any supported topic. + // To avoid reading all messages, throw an error. + if (topics_filter_.topics.empty()) { + throw std::runtime_error("No topics found that match the filter."); } } @@ -252,7 +250,6 @@ void SequentialReader::load_current_file() } // set filters storage_->seek(seek_time_); - set_filter(topics_filter_); } void SequentialReader::load_next_file() diff --git a/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp b/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp index 6e6331a1e..4c5eac976 100644 --- a/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp +++ b/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp @@ -58,7 +58,12 @@ class SequentialReaderTest : public Test topic_with_type.name = "topic"; topic_with_type.type = "test_msgs/BasicTypes"; topic_with_type.serialization_format = storage_serialization_format_; - auto topics_and_types = std::vector{topic_with_type}; + rosbag2_storage::TopicMetadata topic2_with_type; + topic2_with_type.name = "topic2"; + topic2_with_type.type = "test_msgs/BasicTypes"; + topic2_with_type.serialization_format = storage_serialization_format_; + auto topics_and_types = + std::vector{topic_with_type, topic2_with_type}; auto message = std::make_shared(); message->topic_name = topic_with_type.name; @@ -72,6 +77,7 @@ class SequentialReaderTest : public Test metadata_.relative_file_paths = {bag_file_1_path_.string(), bag_file_2_path_.string()}; metadata_.version = 4; metadata_.topics_with_message_count.push_back({{topic_with_type}, 6}); + metadata_.topics_with_message_count.push_back({{topic2_with_type}, 1}); metadata_.storage_identifier = "mock_storage"; EXPECT_CALL(*metadata_io, read_metadata(_)).WillRepeatedly(Return(metadata_));