Skip to content

Commit

Permalink
Fix set_topic_filter
Browse files Browse the repository at this point in the history
Signed-off-by: Jesper Smith <[email protected]>
  • Loading branch information
jespersmith committed Nov 14, 2024
1 parent bff7ed4 commit 6e50655
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 6 additions & 9 deletions rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.");
}
}

Expand Down Expand Up @@ -252,7 +250,6 @@ void SequentialReader::load_current_file()
}
// set filters
storage_->seek(seek_time_);
set_filter(topics_filter_);
}

void SequentialReader::load_next_file()
Expand Down
8 changes: 7 additions & 1 deletion rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rosbag2_storage::TopicMetadata>{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<rosbag2_storage::TopicMetadata>{topic_with_type, topic2_with_type};

auto message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
message->topic_name = topic_with_type.name;
Expand All @@ -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_));
Expand Down

0 comments on commit 6e50655

Please sign in to comment.