VLink  2.0.0
A high-performance communication middleware
bag_writer.h 文件参考

Abstract VLink bag recorder with split, compression, schema embedding and a global hook. 更多...

#include <chrono>
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "../base/functional.h"
#include "../base/macros.h"
#include "../base/message_loop.h"
#include "../impl/types.h"
#include "./bag_plugin_interface.h"
bag_writer.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

class  vlink::BagWriter
 Asynchronous VLink message recorder built on top of MessageLoop. 更多...
 
struct  vlink::BagWriter::Config
 Recording behaviour, split policy and resource budgets. 更多...
 

命名空间

 

详细描述

Abstract VLink bag recorder with split, compression, schema embedding and a global hook.

BagWriter is the polymorphic base for VLink offline recording. It exposes a non-blocking push() entry point that enqueues serialised messages onto a private MessageLoop, which then persists them through the concrete backend. Two backends ship with VLink:

  • VDBWriter for SQLite-backed .vdb / .vdbx containers; default codec is LZAV for kCompressAuto and kCompressLzav selectors.
  • VCAPWriter for MCAP-format .vcap / .vcapx containers; kCompressAuto and kCompressZstd select Zstandard when Zstd support is compiled in.

Writer state machine:

*                async_run()                push()              flush()/dtor
*   +---------+ ----------> +-----------+ ---------> +---------+ ----------> +---------+
*   |  Open   |             |  Running  | <--------- | Pending |             |  Closed |
*   +---------+             +-----------+   ack      +---------+             +---------+
*                                ^                                              ^
*                                |                                              |
*                                +--- split_by_size / split_by_time -- rotate --+
* 

On-disk layout produced by the writers:

*   +---------+----------------+---------------+----------------+--------+
*   | Header  |  URL index     |  Schema index | Message stream | Footer |
*   +---------+----------------+---------------+----------------+--------+
*      tag        url_metas       schema_data       payloads      finalisation
*      app
*      timezone
* 

Feature highlights:

  • Asynchronous record path with optional synchronous immediate writes.
  • File splitting by byte size and/or by wall-clock interval.
  • Optional WAL mode for SQLite crash resilience.
  • URL-level loss reporting via set_url_loss().
  • Schema embedding through push_schema() for offline introspection.
  • Process-global writer triggered by the VLINK_BAG_PATH environment variable.
Example
cfg.split_by_size = 1024LL * 1024LL * 512; // 512 MiB per split
auto writer = vlink::BagWriter::create("/data/drive_log.vdb", cfg);
writer->async_run();
frame.timestamp = -1; // < 0 => writer auto-assigns from its clock (0 is verbatim)
frame.url = "dds://camera/front";
frame.ser_type = "demo.proto.Image";
frame.data = bytes;
writer->push(frame);
Global writer
// Set VLINK_BAG_PATH=/data/global.vdb before process launch.
if (auto* gw = vlink::BagWriter::global_get(); gw != nullptr) {
vlink::Frame frame;
frame.timestamp = -1; // < 0 => auto-assign (0 would be recorded verbatim)
frame.url = "intra://debug";
frame.ser_type = "raw";
frame.data = bytes;
gw->push(frame);
}
注解
push() is thread-safe. immediate=true bypasses the queue and writes on the caller's thread; this should be reserved for finalisation or test code because it can block long enough to violate real-time deadlines.