Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
Mads::BagWriter Class Reference

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
 
BagWriteroperator= (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
 

Detailed Description

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.

Definition at line 126 of file bag.hpp.

Constructor & Destructor Documentation

◆ BagWriter() [1/2]

Mads::BagWriter::BagWriter ( const std::filesystem::path &  path,
bool  enable_crc = true 
)
explicit

Creates (truncating) path and writes the bag header.

Parameters
pathDestination file path.
enable_crcWhether to append a CRC32 to every record (default true, per the P3 spec's "enabled by default").
Exceptions
BagErrorif the file cannot be created for writing.

◆ ~BagWriter()

Mads::BagWriter::~BagWriter ( )

◆ BagWriter() [2/2]

Mads::BagWriter::BagWriter ( const BagWriter )
delete

Member Function Documentation

◆ close()

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.

◆ crc_enabled()

bool Mads::BagWriter::crc_enabled ( ) const
inline

Definition at line 169 of file bag.hpp.

◆ operator=()

BagWriter & Mads::BagWriter::operator= ( const BagWriter )
delete

◆ record_count()

size_t Mads::BagWriter::record_count ( ) const
inline

Number of records written so far.

Definition at line 167 of file bag.hpp.

◆ write()

void Mads::BagWriter::write ( int64_t  timestamp_ns,
const std::string &  topic,
const std::vector< std::string > &  parts 
)

Appends one record.

Parameters
timestamp_nsRecord timestamp, nanoseconds.
topicTopic frame.
partsFrames 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.
Exceptions
BagErroron write failure.

The documentation for this class was generated from the following file: