VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::BagWriter类 参考abstract

Abstract asynchronous message recorder backed by a MessageLoop event queue. 更多...

#include <bag_writer.h>

类 vlink::BagWriter 继承关系图:
vlink::BagWriter 的协作图:

struct  Config
 Configuration for recording behaviour, splitting, compression, and limits. 更多...

Public 类型

enum  CompressType : uint8_t {
  kCompressNone = 0 , kCompressAuto = 1 , kCompressZstd = 2 , kCompressLz4 = 3 ,
  kCompressLzav = 4
}
 Compression algorithm applied to each recorded payload. 更多...
using SplitCallback = std::function<void(int split_index, const std::string& split_filename)>
 Callback fired when a split occurs.
using SchemaCallback = std::function<SchemaData(const std::string& ser_type, SchemaType schema_type)>
 Callback that resolves a serialisation type string to a SchemaData.
using SystemClock = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>
 System clock type used for file-name timestamp generation.
 Queue implementation type. 更多...
 Idle strategy controlling CPU and latency trade-offs. 更多...
 Pre-defined task priority levels for kPriorityType loops. 更多...

Public 成员函数

 BagWriter (const std::string &path, const Config &config={})
 Constructs a BagWriter for path with the given config.
virtual ~BagWriter ()
 Destructor – stops the recording loop and flushes pending writes.
virtual void register_split_callback (SplitCallback &&callback, bool before)=0
 Registers a callback invoked when a file split occurs.
virtual void register_schema_callback (SchemaCallback &&callback)=0
 Registers a callback that resolves serialisation type strings to SchemaData.
virtual bool push_schema (const SchemaData &schema_data, bool immediate=false)=0
 Embeds a SchemaData into the bag for later offline introspection.
virtual int64_t push (const std::string &url, const std::string &ser_type, SchemaType schema_type, ActionType action_type, const Bytes &data, int64_t *microseconds_timestamp=nullptr, bool immediate=false)=0
 Records one message to the bag.
virtual bool is_dumping () const =0
 Returns true if the writer is actively recording to disk.
virtual bool is_split_mode () const =0
 Returns true if the writer is in split-file mode.
virtual int get_split_index () const =0
 Returns the zero-based index of the current split file.
virtual void set_url_loss (const std::string &url, double loss)=0
 Sets the expected message loss ratio for a given URL.

静态 Public 成员函数

static std::shared_ptr< BagWritercreate (const std::string &path, const Config &config={})
 Creates a concrete BagWriter instance for path.
static std::shared_ptr< BagWriterfilter_get (const std::string &path)
 Returns an existing writer for path, or creates and starts a new one.
static BagWriterglobal_get ()
 Returns the process-global BagWriter activated by the VLINK_BAG_PATH environment variable.

Protected 成员函数

void get_url_meta (const std::string &url, const std::string &ser, int &url_index, int &ser_index) const
void get_url_meta (int url_index, int ser_index, std::string &url, std::string &ser) const

静态 Protected 成员函数

static const std::string & get_default_tag_name ()
static const std::string & get_default_app_name ()
static SchemaPluginInterfaceget_schema_interface ()
static int32_t get_default_timezone_diff ()
static std::string_view convert_action (ActionType type)
static std::string get_format_date (SystemClock *current=nullptr, bool file_format=false)

详细描述

Abstract asynchronous message recorder backed by a MessageLoop event queue.

Must be constructed via create() (for managed lifetime) or directly (for custom ownership). After construction call async_run() to start the recording loop, then use push() to record messages.

成员类型定义说明

◆ SchemaCallback

using vlink::BagWriter::SchemaCallback = std::function<SchemaData(const std::string& ser_type, SchemaType schema_type)>

Callback that resolves a serialisation type string to a SchemaData.

When a new URL with an unknown ser_type appears, this callback is invoked to retrieve the corresponding schema for embedding in the bag. The extra schema_type hint lets callers distinguish schema families that share the same concrete type name.

◆ SplitCallback

using vlink::BagWriter::SplitCallback = std::function<void(int split_index, const std::string& split_filename)>

Callback fired when a split occurs.

Called with the zero-based split index and the path of the newly created file. The before parameter of register_split_callback() controls whether the callback fires before or after the new file is opened.

◆ SystemClock

using vlink::BagWriter::SystemClock = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>

System clock type used for file-name timestamp generation.

成员枚举类型说明

◆ CompressType

Compression algorithm applied to each recorded payload.

Kind Algorithm Notes
kCompressNone No compress Raw bytes stored as-is
kCompressAuto Auto select Picks best algorithm per payload
kCompressZstd Zstandard Good ratio, moderate speed
kCompressLz4 LZ4 Fast compression/decompression
kCompressLzav LZAV Fast, lightweight, built-in
枚举值
kCompressNone 

No compression.

kCompressAuto 

Automatic algorithm selection.

kCompressZstd 

Zstandard compression.

kCompressLz4 

LZ4 compression.

kCompressLzav 

LZAV built-in compression.

构造及析构函数说明

◆ BagWriter()

vlink::BagWriter::BagWriter ( const std::string & path,
const Config & config = {} )
explicit

Constructs a BagWriter for path with the given config.

Opens or creates the output file. Must call async_run() before writing.

参数
pathOutput file path.
configRecording configuration.
这是这个函数的调用关系图:

◆ ~BagWriter()

virtual vlink::BagWriter::~BagWriter ( )
virtual

Destructor – stops the recording loop and flushes pending writes.

成员函数说明

◆ convert_action()

std::string_view vlink::BagWriter::convert_action ( ActionType type)
staticprotected

◆ create()

std::shared_ptr< BagWriter > vlink::BagWriter::create ( const std::string & path,
const Config & config = {} )
staticnodiscard

Creates a concrete BagWriter instance for path.

Selects the implementation based on the file extension:

参数
pathOutput file path.
configRecording configuration. Defaults to Config{}.
返回
Shared pointer to the new writer.

◆ filter_get()

std::shared_ptr< BagWriter > vlink::BagWriter::filter_get ( const std::string & path)
staticnodiscard

Returns an existing writer for path, or creates and starts a new one.

Searches the global writer registry. If a writer matching path is alive, returns a shared pointer to it. Otherwise creates a new writer for path, calls async_run() on it, registers it in the global registry, and returns it. The writer is automatically removed from the registry when the last shared pointer to it is released.

参数
pathOutput file path.
返回
Shared pointer to the writer (never nullptr).

◆ get_default_app_name()

const std::string & vlink::BagWriter::get_default_app_name ( )
staticprotected

◆ get_default_tag_name()

const std::string & vlink::BagWriter::get_default_tag_name ( )
staticprotected

◆ get_default_timezone_diff()

int32_t vlink::BagWriter::get_default_timezone_diff ( )
staticprotected

◆ get_format_date()

std::string vlink::BagWriter::get_format_date ( SystemClock * current = nullptr,
bool file_format = false )
staticprotected
函数调用图:

◆ get_schema_interface()

SchemaPluginInterface * vlink::BagWriter::get_schema_interface ( )
staticprotected

◆ get_split_index()

virtual int vlink::BagWriter::get_split_index ( ) const
nodiscardpure virtual

Returns the zero-based index of the current split file.

Returns 0 if split mode is not active.

返回
Current split file index.

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.

◆ get_url_meta() [1/2]

void vlink::BagWriter::get_url_meta ( const std::string & url,
const std::string & ser,
int & url_index,
int & ser_index ) const
protected

◆ get_url_meta() [2/2]

void vlink::BagWriter::get_url_meta ( int url_index,
int ser_index,
std::string & url,
std::string & ser ) const
protected

◆ global_get()

BagWriter * vlink::BagWriter::global_get ( )
static

Returns the process-global BagWriter activated by the VLINK_BAG_PATH environment variable.

The global writer is created automatically on first access if VLINK_BAG_PATH is set. Returns nullptr if the environment variable is not set.

返回
Raw pointer to the global writer, or nullptr.
函数调用图:

◆ is_dumping()

virtual bool vlink::BagWriter::is_dumping ( ) const
nodiscardpure virtual

Returns true if the writer is actively recording to disk.

返回
true if the backing file is open and being written.

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.

◆ is_split_mode()

virtual bool vlink::BagWriter::is_split_mode ( ) const
nodiscardpure virtual

Returns true if the writer is in split-file mode.

返回
true when Config::split_by_size or Config::split_by_time is non-zero.

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.

◆ push()

virtual int64_t vlink::BagWriter::push ( const std::string & url,
const std::string & ser_type,
SchemaType schema_type,
ActionType action_type,
const Bytes & data,
int64_t * microseconds_timestamp = nullptr,
bool immediate = false )
pure virtual

Records one message to the bag.

The message is enqueued on the recording loop and written asynchronously. If microseconds_timestamp is nullptr, the current system time is used.

参数
urlVLink URL of the topic (e.g., "dds://my/topic").
ser_typeSerialisation type string (e.g., "demo.proto.PointCloud", "raw").
schema_typeCoarse schema family for the payload.
action_typeAction type (kPublish, kRequest, etc.).
dataSerialized payload bytes.
microseconds_timestampOptional pointer to a custom timestamp (microseconds).
immediateIf true, writes synchronously bypassing the queue.
返回
Sequence number (monotonically increasing) of the recorded message, or a negative value on error.

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.

◆ push_schema()

virtual bool vlink::BagWriter::push_schema ( const SchemaData & schema_data,
bool immediate = false )
pure virtual

Embeds a SchemaData into the bag for later offline introspection.

参数
schema_dataSchema descriptor to store.
immediateIf true, merges synchronously; otherwise enqueues.
返回
false only when the immediate merge fails.

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.

◆ register_schema_callback()

virtual void vlink::BagWriter::register_schema_callback ( SchemaCallback && callback)
pure virtual

Registers a callback that resolves serialisation type strings to SchemaData.

Called when a push() introduces a URL with an unknown ser_type.

参数
callbackFunction mapping ser_type string to SchemaData.

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.

◆ register_split_callback()

virtual void vlink::BagWriter::register_split_callback ( SplitCallback && callback,
bool before )
pure virtual

Registers a callback invoked when a file split occurs.

参数
callbackCalled with (split_index, new_filename) on each split.
beforeIf true, the callback fires before the new file is opened; if false, it fires after.

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.

◆ set_url_loss()

virtual void vlink::BagWriter::set_url_loss ( const std::string & url,
double loss )
pure virtual

Sets the expected message loss ratio for a given URL.

Stored as metadata in the bag. Used for post-processing diagnostics to distinguish intentional drops from unexpected loss.

参数
urlTopic URL.
lossLoss ratio in the range [0.0, 1.0].

vlink::DatabaseWriter , 以及 vlink::McapWriter 内被实现.


该类的文档由以下文件生成: