105 explicit BagError(
const std::string &msg) : std::runtime_error(msg) {}
136 explicit BagWriter(
const std::filesystem::path &path,
bool enable_crc =
true);
153 void write(int64_t timestamp_ns,
const std::string &topic,
154 const std::vector<std::string> &parts);
173 std::filesystem::path _path;
175 bool _closed =
false;
176 std::vector<uint64_t> _offsets;
177 std::optional<int64_t> _first_ts, _last_ts;
232 std::optional<BagRecord>
next();
238 bool try_load_footer(uint64_t file_size);
243 void linear_scan(uint64_t file_size);
254 std::optional<BagRecord> read_record_at(uint64_t offset, uint64_t file_size,
257 mutable std::ifstream _in;
258 std::filesystem::path _path;
259 uint32_t _format_ver = 0;
260 bool _crc_enabled =
false;
261 bool _has_index =
false;
262 bool _truncated =
false;
263 std::vector<uint64_t> _offsets;
264 std::optional<int64_t> _first_ts, _last_ts;
Error thrown by BagWriter/BagReader for any I/O or format problem (bad magic, unsupported format_ver,...
BagError(const std::string &msg)
Reads a bag file written by BagWriter (or a compatible/truncated one), transparently using the traili...
BagRecord read(size_t index) const
Random access to record index (0-based).
std::optional< BagRecord > next()
BagReader(const std::filesystem::path &path)
Opens and parses path.
void rewind()
Resets sequential iteration (next()) to the first record.
bool truncated() const
True if the file was missing a valid footer/trailer and some trailing bytes could not be recovered as...
std::optional< int64_t > first_timestamp() const
Timestamp of the first record, if any.
bool crc_enabled() const
Whether per-record CRC32 is present (mirrors the header flag).
size_t record_count() const
Number of complete, valid records found (indexed or recovered).
std::optional< int64_t > last_timestamp() const
Timestamp of the last record, if any.
Sequentially appends BagRecord entries to a bag file.
void write(int64_t timestamp_ns, const std::string &topic, const std::vector< std::string > &parts)
Appends one record.
size_t record_count() const
Number of records written so far.
BagWriter(const std::filesystem::path &path, bool enable_crc=true)
Creates (truncating) path and writes the bag header.
BagWriter & operator=(const BagWriter &)=delete
void close()
Finalizes the file: writes the index/footer/trailer and flushes.
BagWriter(const BagWriter &)=delete
constexpr uint32_t BAG_FORMAT_VERSION
std::vector< std::string > parts