Class Reader
Defined in File reader.hpp
Class Documentation
-
class Reader
The Reader allows opening and reading messages of a bag.
Public Functions
-
explicit Reader(std::unique_ptr<reader_interfaces::BaseReaderInterface> reader_impl = std::make_unique<readers::SequentialReader>())
-
~Reader()
-
void open(const std::string &uri)
Opens an existing bagfile and prepare it for reading messages. The bagfile must exist. This must be called before any other function is used.
See also
rmw_get_serialization_format. For specifications, please see
See also
open, which let’s you specify more storage and converter options.
Note
This will open URI with the default storage options
using default storage backend
using no converter options, storing messages with the incoming serialization format
- Parameters:
storage_uri – URI of the storage to open.
-
void open(const rosbag2_storage::StorageOptions &storage_options, const ConverterOptions &converter_options = ConverterOptions())
Throws if file could not be opened. This must be called before any other function is used. The rosbag is automatically closed on destruction.
If the
output_serialization_format
within theconverter_options
is not the same as the format of the underlying stored data, a converter will be used to automatically convert the data to the specified output format. Throws if the converter plugin does not exist.- Parameters:
storage_options – Options to configure the storage
converter_options – Options for specifying the output data format
-
void close()
Closing the reader instance.
-
bool has_next()
Ask whether the underlying bagfile contains at least one more message.
- Throws:
runtime_error – if the Reader is not open.
- Returns:
true if storage contains at least one more message
-
std::shared_ptr<rosbag2_storage::SerializedBagMessage> read_next()
Read next message from storage. Will throw if no more messages are available. The message will be serialized in the format given to
open
.Expected usage: if (writer.has_next()) message = writer.read_next();
- Throws:
runtime_error – if the Reader is not open.
- Returns:
next message in serialized form
-
template<class MessageT>
inline MessageT read_next() Read next message from storage. Will throw if no more messages are available. The message will be serialized in the format given to
open
.Expected usage: if (writer.has_next()) message = writer.read_next();
- Throws:
runtime_error – if the Reader is not open.
- Returns:
next message in non-serialized form
-
const rosbag2_storage::BagMetadata &get_metadata() const
Ask bagfile for its full metadata.
-
std::vector<rosbag2_storage::TopicMetadata> get_all_topics_and_types() const
Ask bagfile for all topics (including their type identifier) that were recorded.
- Throws:
runtime_error – if the Reader is not open.
- Returns:
vector of topics with topic name and type as std::string
-
void set_filter(const rosbag2_storage::StorageFilter &storage_filter)
Set filters to adhere to during reading.
- Parameters:
storage_filter – Filter to apply to reading
- Throws:
runtime_error – if the Reader is not open.
-
void reset_filter()
Reset all filters for reading.
-
void seek(const rcutils_time_point_value_t ×tamp)
Skip to a specific timestamp for reading.
-
inline reader_interfaces::BaseReaderInterface &get_implementation_handle() const
-
void add_event_callbacks(bag_events::ReaderEventCallbacks &callbacks)
Add callbacks for events that may occur during bag reading.
- Parameters:
callbacks – the structure containing the callback to add for each event.
-
explicit Reader(std::unique_ptr<reader_interfaces::BaseReaderInterface> reader_impl = std::make_unique<readers::SequentialReader>())