![]() |
Mads
Multi-Agent Distributed System
|
Sequentially appends BagRecord entries to a bag file. More...
#include <bag.hpp>
Public Member Functions | |
| BagWriter (const std::filesystem::path &path, bool enable_crc=true) | |
Creates (truncating) path and writes the bag header. | |
| ~BagWriter () | |
| BagWriter (const BagWriter &)=delete | |
| BagWriter & | operator= (const BagWriter &)=delete |
| void | write (int64_t timestamp_ns, const std::string &topic, const std::vector< std::string > &parts) |
| Appends one record. | |
| void | close () |
| Finalizes the file: writes the index/footer/trailer and flushes. | |
| size_t | record_count () const |
| Number of records written so far. | |
| bool | crc_enabled () const |
Sequentially appends BagRecord entries to a bag file.
Writes the header immediately (constructor), then one record per write() call, and the trailing index + footer on close() (also invoked by the destructor if the caller never calls it explicitly). A file whose writing process is killed before close() ever runs is still a valid, readable bag – just without the O(1) index, handled by BagReader's linear-scan fallback.
|
explicit |
Creates (truncating) path and writes the bag header.
| path | Destination file path. |
| enable_crc | Whether to append a CRC32 to every record (default true, per the P3 spec's "enabled by default"). |
| BagError | if the file cannot be created for writing. |
| Mads::BagWriter::~BagWriter | ( | ) |
|
delete |
| void Mads::BagWriter::close | ( | ) |
Finalizes the file: writes the index/footer/trailer and flushes.
Idempotent – a second call (or the destructor, after an explicit call) is a no-op. Not calling this at all (process killed, or a test deliberately simulating that) leaves a valid bag with only the records written so far; BagReader recovers it via linear scan.
|
inline |
| void Mads::BagWriter::write | ( | int64_t | timestamp_ns, |
| const std::string & | topic, | ||
| const std::vector< std::string > & | parts | ||
| ) |
Appends one record.
| timestamp_ns | Record timestamp, nanoseconds. |
| topic | Topic frame. |
| parts | Frames after the topic, in wire order; stored byte-for-byte (embedded NUL bytes included), so JSON text and binary blob parts both round-trip identically. |
| BagError | on write failure. |