VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
bag_writer.h File Reference

Abstract base class for VLink bag file recording with split, compression and global writer support. More...

#include <chrono>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <unordered_set>
#include "../base/bytes.h"
#include "../base/macros.h"
#include "../base/message_loop.h"
#include "../impl/types.h"
Include dependency graph for bag_writer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

 Abstract asynchronous message recorder backed by a MessageLoop event queue. More...
 Configuration for recording behaviour, splitting, compression, and limits. More...

Namespaces

Detailed Description

Abstract base class for VLink bag file recording with split, compression and global writer support.

BagWriter is an abstract MessageLoop-based recorder that captures VLink messages (URL + serialisation type + payload) to a bag file. Concrete implementations are DatabaseWriter (SQLite-backed) and McapWriter (MCAP-format).

Key features:

  • Asynchronous recording via the inherited MessageLoop queue.
  • Pluggable compression: none, auto, Zstd, LZ4, LZAV.
  • File splitting by size or by time, with optional time-stamped names.
  • WAL (Write-Ahead Log) mode for crash resilience.
  • Global singleton writer activated by the VLINK_BAG_PATH environment variable.
  • Schema embedding for offline introspection.
Creating a writer
auto writer = vlink::BagWriter::create("/data/log.vdb");
writer->async_run();
writer->push("dds://my/topic", "demo.proto.PointCloud", vlink::SchemaType::kProtobuf,
Global writer
// Set VLINK_BAG_PATH=/data/log.vdb before launching the process.
// Then retrieve the global instance anywhere:
if (gw) {
gw->push("intra://my/topic", "raw", vlink::SchemaType::kRaw, vlink::ActionType::kPublish, data);
}
Note
  • create() selects the concrete implementation based on the file extension (.vcap / .vcapx -> McapWriter, otherwise -> DatabaseWriter).
  • push() is thread-safe and non-blocking; recording is done on the loop thread.
  • The immediate flag bypasses the task queue and writes synchronously (use with care).