Skip to content

Commit

Permalink
Don't throw when READ_WRITE mode is used; add .mcap file extension to…
Browse files Browse the repository at this point in the history
… recorded files (ros2#14)

I may be missing something, but from a cursory glance at [this code](https://github.com/ros2/rosbag2/blob/342d8ed3c1c4ae0411a4a92b60e79a728b8974b8/rosbag2_storage/src/rosbag2_storage/impl/storage_factory_impl.hpp#L108-L135), it appears that the `APPEND` mode is never used. This means we need to support `READ_WRITE`.

This also adds a `.mcap` extension to recorded file names.

Signed-off-by: Jacob Bandes-Storch <jacob@foxglove.dev>
  • Loading branch information
jtbandes authored and james-rms committed Nov 17, 2022
1 parent 0eedd67 commit 4647278
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rosbag2_storage_mcap/src/mcap_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace rosbag2_storage_plugins {

static const char FILE_EXTENSION[] = ".mcap";

/**
* A storage implementation for the MCAP file format.
*/
Expand Down Expand Up @@ -120,11 +122,10 @@ MCAPStorage::~MCAPStorage() {
/** BaseIOInterface **/
void MCAPStorage::open(const rosbag2_storage::StorageOptions& storage_options,
rosbag2_storage::storage_interfaces::IOFlag io_flag) {
relative_path_ = storage_options.uri + FILE_EXTENSION;

switch (io_flag) {
case rosbag2_storage::storage_interfaces::IOFlag::READ_WRITE:
throw std::runtime_error("MCAPStorage does not support READ_WRITE mode");
case rosbag2_storage::storage_interfaces::IOFlag::READ_ONLY: {
relative_path_ = storage_options.uri;
input_ = std::make_unique<std::ifstream>(relative_path_, std::ios::binary);
data_source_ = std::make_unique<mcap::FileStreamReader>(*input_);
mcap_reader_ = std::make_unique<mcap::McapReader>();
Expand All @@ -138,8 +139,11 @@ void MCAPStorage::open(const rosbag2_storage::StorageOptions& storage_options,
linear_iterator_ = std::make_unique<mcap::LinearMessageView::Iterator>(linear_view_->begin());
break;
}
case rosbag2_storage::storage_interfaces::IOFlag::READ_WRITE:
case rosbag2_storage::storage_interfaces::IOFlag::APPEND: {
relative_path_ = storage_options.uri;
// APPEND does not seem to be used; treat it the same as READ_WRITE
io_flag = rosbag2_storage::storage_interfaces::IOFlag::READ_WRITE;

mcap_writer_ = std::make_unique<mcap::McapWriter>();
mcap::McapWriterOptions options{"ros2"};
// TODO(jhurliman): Use storage_options max_bagfile_duration / max_bagfile_size
Expand Down

0 comments on commit 4647278

Please sign in to comment.