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

Reads a bag file written by BagWriter (or a compatible/truncated one), transparently using the trailing index when present and falling back to a linear scan otherwise. More...

#include <bag.hpp>

Public Member Functions

 BagReader (const std::filesystem::path &path)
 Opens and parses path.
 
size_t record_count () const
 Number of complete, valid records found (indexed or recovered).
 
std::optional< int64_t > first_timestamp () const
 Timestamp of the first record, if any.
 
std::optional< int64_t > last_timestamp () const
 Timestamp of the last record, if any.
 
bool truncated () const
 True if the file was missing a valid footer/trailer and some trailing bytes could not be recovered as a complete, CRC-valid record (e.g. the writer process was killed mid-record). False for a complete file, whether or not it happens to have a footer.
 
bool has_index () const
 
bool crc_enabled () const
 Whether per-record CRC32 is present (mirrors the header flag).
 
BagRecord read (size_t index) const
 Random access to record index (0-based).
 
void rewind ()
 Resets sequential iteration (next()) to the first record.
 
std::optional< BagRecordnext ()
 

Detailed Description

Reads a bag file written by BagWriter (or a compatible/truncated one), transparently using the trailing index when present and falling back to a linear scan otherwise.

Definition at line 185 of file bag.hpp.

Constructor & Destructor Documentation

◆ BagReader()

Mads::BagReader::BagReader ( const std::filesystem::path &  path)
explicit

Opens and parses path.

Exceptions
BagErrorif the file cannot be opened, the magic is wrong, or format_ver is newer than BAG_FORMAT_VERSION.

Member Function Documentation

◆ crc_enabled()

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

Whether per-record CRC32 is present (mirrors the header flag).

Definition at line 217 of file bag.hpp.

◆ first_timestamp()

std::optional< int64_t > Mads::BagReader::first_timestamp ( ) const
inline

Timestamp of the first record, if any.

Definition at line 199 of file bag.hpp.

◆ has_index()

bool Mads::BagReader::has_index ( ) const
inline

True if a valid footer/index was found (O(1) path); false if this reader recovered its record list via a linear scan.

Definition at line 214 of file bag.hpp.

◆ last_timestamp()

std::optional< int64_t > Mads::BagReader::last_timestamp ( ) const
inline

Timestamp of the last record, if any.

Definition at line 202 of file bag.hpp.

◆ next()

std::optional< BagRecord > Mads::BagReader::next ( )

Sequential iteration; returns std::nullopt once every recovered record has been returned.

◆ read()

BagRecord Mads::BagReader::read ( size_t  index) const

Random access to record index (0-based).

Exceptions
BagErrorif index is out of range, the record is corrupt, or a CRC mismatch is detected.

◆ record_count()

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

Number of complete, valid records found (indexed or recovered).

Definition at line 196 of file bag.hpp.

◆ rewind()

void Mads::BagReader::rewind ( )
inline

Resets sequential iteration (next()) to the first record.

Definition at line 228 of file bag.hpp.

◆ truncated()

bool Mads::BagReader::truncated ( ) const
inline

True if the file was missing a valid footer/trailer and some trailing bytes could not be recovered as a complete, CRC-valid record (e.g. the writer process was killed mid-record). False for a complete file, whether or not it happens to have a footer.

Definition at line 210 of file bag.hpp.


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