Class SequentialReader

Inheritance Relationships

Base Type

Class Documentation

class SequentialReader : public rosbag2_cpp::reader_interfaces::BaseReaderInterface

Public Functions

SequentialReader(std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory = std::make_unique<rosbag2_storage::StorageFactory>(), std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory = std::make_shared<SerializationFormatConverterFactory>(), std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io = std::make_unique<rosbag2_storage::MetadataIo>())
virtual ~SequentialReader()
virtual void open(const rosbag2_storage::StorageOptions &storage_options, const ConverterOptions &converter_options) override
virtual void close() override
virtual bool set_read_order(const rosbag2_storage::ReadOrder &order) override

Note

Calling set_read_order(order) concurrently with has_next(), seek(t), has_next_file() or load_next_file() will cause undefined behavior.

Throws:

runtime_error – if the Reader is not open.

virtual bool has_next() override
virtual std::shared_ptr<rosbag2_storage::SerializedBagMessage> read_next() override
virtual const rosbag2_storage::BagMetadata &get_metadata() const override
virtual std::vector<rosbag2_storage::TopicMetadata> get_all_topics_and_types() const override
virtual void get_all_message_definitions(std::vector<rosbag2_storage::MessageDefinition> &definitions) override
virtual void set_filter(const rosbag2_storage::StorageFilter &storage_filter) override
virtual void reset_filter() override
virtual void seek(const rcutils_time_point_value_t &timestamp) override

seek(t) will cause subsequent reads to return messages that satisfy timestamp >= time t.

virtual bool has_next_file() const

Ask whether there is another storage file to read from the list of relative file paths.

Returns:

true if iteration is not on the last file

virtual bool has_prev_file() const

Ask whether there is a previous file to read from the list of relative file paths.

Returns:

true if iteration is not on the first file

virtual std::string get_current_file() const

Return the relative file path pointed to by the current file iterator.

virtual std::string get_current_uri() const

Return the URI of the current file (i.e. no extensions).

virtual void add_event_callbacks(const bag_events::ReaderEventCallbacks &callbacks) override

Add callbacks for events that may occur during bag reading.

Parameters:

callbacks – the structure containing the callback to add for each event.

bool has_callback_for_event(const bag_events::BagEvent event) const

Check if a callback is registered for the given event.

Returns:

True if there is any callback registered for the event, false otherwise.

Protected Functions

virtual void load_current_file()

Opens the current file and sets up the filters in the new storage.

virtual void load_next_file()

Increment the current file iterator to point to the next file in the list of relative file paths, and opens that file by calling open_current_file()

Expected usage: if (has_next_file()) load_next_file();

virtual void load_prev_file()

Increment the current file iterator to point to the previous file in the list of relative file paths, and opens that file by calling open_current_file()

Expected usage: if (has_prev_file()) load_prev_file();

virtual void check_topics_serialization_formats(const std::vector<rosbag2_storage::TopicInformation> &topics)

Checks if all topics in the bagfile have the same RMW serialization format. Currently a bag file can only be played if all topics have the same serialization format.

Parameters:

topics – Vector of TopicInformation with metadata.

Throws:

runtime_error – if any topic has a different serialization format from the rest.

virtual void check_converter_serialization_format(const std::string &converter_serialization_format, const std::string &storage_serialization_format)

Checks if the serialization format of the converter factory is the same as that of the storage factory. If not, changes the serialization format of the converter factory to use the serialization format of the storage factory.

Parameters:
  • converter_serialization_format

  • storage_serialization_format

virtual void fill_topics_metadata()

Fill topics_metadata_ cache vector with information from metadata_

inline virtual void preprocess_current_file()

Prepare current file for opening by the storage implementation. This may be used by subclasses, for example decompressing. This should be a once-per-file operation, meaning that subsequent opening of the same file will not trigger another preprocessing.

Protected Attributes

std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory_ = {}
std::shared_ptr<rosbag2_storage::storage_interfaces::ReadOnlyInterface> storage_ = {}
std::unique_ptr<Converter> converter_ = {}
std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io_ = {}
rosbag2_storage::BagMetadata metadata_ = {}
rcutils_time_point_value_t seek_time_ = 0
rosbag2_storage::StorageFilter topics_filter_ = {}
std::vector<rosbag2_storage::TopicMetadata> topics_metadata_ = {}
std::vector<std::string> file_paths_ = {}
std::vector<std::string>::iterator current_file_iterator_ = {}
std::unordered_set<std::string> preprocessed_file_paths_
std::string base_folder_