Class SequentialCompressionWriter

Inheritance Relationships

Base Type

  • public rosbag2_cpp::writers::SequentialWriter

Class Documentation

class SequentialCompressionWriter : public rosbag2_cpp::writers::SequentialWriter

Public Functions

explicit SequentialCompressionWriter(const rosbag2_compression::CompressionOptions &compression_options = rosbag2_compression::CompressionOptions())
SequentialCompressionWriter(const rosbag2_compression::CompressionOptions &compression_options, std::unique_ptr<rosbag2_compression::CompressionFactory> compression_factory, std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory, std::shared_ptr<rosbag2_cpp::SerializationFormatConverterFactoryInterface> converter_factory, std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io)
~SequentialCompressionWriter() override
void create_topic(const rosbag2_storage::TopicMetadata &topic_with_type) override

Create a new topic in the underlying storage. Needs to be called for every topic used within a message which is passed to write(…).

Parameters:

topic_with_type – name and type identifier of topic to be created

Throws:

runtime_error – if the Writer is not open.

void create_topic(const rosbag2_storage::TopicMetadata &topic_with_type, const rosbag2_storage::MessageDefinition &message_definition) override

Create a new topic in the underlying storage. Needs to be called for every topic used within a message which is passed to write(…).

Parameters:
  • topic_with_type – name and type identifier of topic to be created

  • message_definition – definition of topic_with_type.type

Throws:

runtime_error – if the Writer is not open.

void remove_topic(const rosbag2_storage::TopicMetadata &topic_with_type) override

Remove a new topic in the underlying storage. If creation of subscription fails remove the topic from the db (more of cleanup)

Parameters:

topic_with_type – name and type identifier of topic to be created

Throws:

runtime_error – if the Writer is not open.

void write(std::shared_ptr<const rosbag2_storage::SerializedBagMessage> message) override

If the compression mode is FILE, write a message to a bagfile. If the compression mode is MESSAGE, pushes the message into a queue that will be processed by the compression threads.

The topic needs to have been created before writing is possible.

Parameters:

message – to be written to the bagfile

Throws:

runtime_error – if the Writer is not open.

void open(const rosbag2_storage::StorageOptions &storage_options, const rosbag2_cpp::ConverterOptions &converter_options) override

Opens a new bagfile and prepare it for writing messages. The bagfile must not exist. This must be called before any other function is used.

Parameters:
  • storage_options – Options to configure the storage

  • converter_options – options to define in which format incoming messages are stored

void close() override

Attempt to compress the last open file and reset the storage and storage factory. This method must be exception safe because it is called by the destructor.

Protected Functions

virtual void compress_file(BaseCompressorInterface &compressor, const std::string &file_relative_to_bag)

Compress a file and update the metadata file path.

Note: this may log an error without raising an exception in the case that the input file could not be deleted after compressing. This is an error and should never happen, but given that the desired output is created, execution will not be halted.

Parameters:
  • compressor – An initialized compression context.

  • file_relative_to_bag – Relative path of the file to compress, as stored in metadata - meaning the path is relative to the bag base folder.

virtual std::shared_ptr<rosbag2_storage::SerializedBagMessage> compress_message(BaseCompressorInterface &compressor, std::shared_ptr<const rosbag2_storage::SerializedBagMessage> message)

Checks if the compression by message option is specified and a compressor exists.

If the above conditions are satisfied, compresses the serialized bag message.

Parameters:
  • compressor – An initialized compression context.

  • message – The message to compress.

Returns:

The compressed message.

virtual void setup_compression()

Initializes the compressor if a compression mode is specified.

Throws:
  • std::invalid_argument – if compression_options isn’t supported.

  • rcpputils::IllegalStateException – if compressor could not be created

virtual void setup_compressor_threads()

Initializes a number of threads to do file or message compression equal to the value of the compression_threads parameter.

Throws:

rcpputils::IllegalStateException – if compressor could not be created

virtual void stop_compressor_threads()

Signals all compressor threads to stop working and then waits for them to exit.