Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Add set_read_order reader API
Browse files Browse the repository at this point in the history
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
  • Loading branch information
emersonknapp committed Sep 8, 2022
1 parent 2f46d20 commit 91eb4e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rosbag2_storage_mcap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ endif()
if(${rosbag2_storage_VERSION} VERSION_GREATER_EQUAL 0.15.0)
list(APPEND MCAP_COMPILE_DEFS ROSBAG2_STORAGE_MCAP_HAS_YAML_HPP)
endif()
# COMPATIBILITY(foxy, galactic, humble) - 0.17.x is the Rolling release.
# COMPATIBILITY(foxy, galactic, humble) - 0.17.x is Rolling release as of this writing
if(${rosbag2_storage_VERSION} VERSION_GREATER_EQUAL 0.17.0)
list(APPEND MCAP_COMPILE_DEFS ROSBAG2_STORAGE_MCAP_HAS_STORAGE_FILTER_TOPIC_REGEX)
list(APPEND MCAP_COMPILE_DEFS ROSBAG2_STORAGE_MCAP_HAS_SET_READ_ORDER)
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE ${MCAP_COMPILE_DEFS})
Expand Down
20 changes: 20 additions & 0 deletions rosbag2_storage_mcap/src/mcap_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ class MCAPStorage : public rosbag2_storage::storage_interfaces::ReadWriteInterfa
std::string get_storage_identifier() const override;

/** BaseReadInterface **/
#ifdef ROSBAG2_STORAGE_MCAP_HAS_SET_READ_ORDER
void set_read_order(rosbag2_storage::ReadOrder) override;
#endif
bool has_next() override;
std::shared_ptr<rosbag2_storage::SerializedBagMessage> read_next() override;
std::vector<rosbag2_storage::TopicMetadata> get_all_topics_and_types() override;
Expand Down Expand Up @@ -459,6 +462,23 @@ void MCAPStorage::ensure_summary_read() {
}
}

#ifdef ROSBAG2_STORAGE_MCAP_HAS_SET_READ_ORDER
void MCAPStorage::set_read_order(rosbag2_storage::ReadOrder read_order)
{
auto next_read_order = read_order_;
switch (read_order) {
case rosbag2_storage::ReadOrder::TIMESTAMP:
next_read_order = mcap::ReadMessageOptions::ReadOrder::LogTimeOrder;
case rosbag2_storage::ReadOrder::REVERSE_TIMESTAMP:
next_read_order = mcap::ReadMessageOptions::ReadOrder::ReverseLogTimeOrder;
}
if (next_read_order != read_order_) {
read_order_ = next_read_order;
reset_iterator();
}
}
#endif

bool MCAPStorage::has_next() {
if (!linear_iterator_) {
return false;
Expand Down

0 comments on commit 91eb4e4

Please sign in to comment.