VLink  2.0.0
A high-performance communication middleware
bag_reader.h File Reference

Abstract player for VLink bag recordings with seek, loop and rate control. More...

#include <cstdint>
#include <future>
#include <memory>
#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"
Include dependency graph for bag_reader.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  vlink::BagReader
 Format-agnostic VLink bag player driven by an internal MessageLoop. More...
 
struct  vlink::BagReader::Info
 Aggregated metadata extracted from the bag header, summary and URL index. More...
 
struct  vlink::BagReader::Info::UrlMeta
 Per-URL accounting entry recorded inside Info::url_metas. More...
 
struct  vlink::BagReader::Config
 Playback parameters consumed by play(). More...
 

Namespaces

 

Detailed Description

Abstract player for VLink bag recordings with seek, loop and rate control.

BagReader is the polymorphic base for VLink offline log playback. It owns a private MessageLoop thread, opens a bag file produced by BagWriter, and replays the stored messages back to user-supplied callbacks honouring their original timing. Concrete subclasses provide format-specific I/O: VDBReader for the SQLite-backed .vdb container and VCAPReader for the MCAP-based .vcap container. create() chooses the right one from the file suffix.

Supported formats and behaviour summary:

Suffix Concrete reader Storage Index source
.vdb / .vdbx VDBReader SQLite SQLite tables (elapsed/URL)
.vcap / .vcapx VCAPReader MCAP MCAP summary + chunk index

Internal playback state machine:

*                     play(cfg)              pause()
*      +------------+ -------> +-----------+ -------> +----------+
*      |  kStopped  |          |  kPlaying |          |  kPaused |
*      +------------+ <------- +-----------+ <------- +----------+
*                    stop() /         resume() / pause_to_next()
*                  end-of-bag
* 

Playback features:

  • Rate multiplier, loop count and time-window filtering through Config.
  • jump() seeks to an arbitrary recording timestamp and may force-resume playback.
  • URL whitelist via Config::filter_urls applies after plugin URL remapping.
  • check() / reindex() / fix() run asynchronously and report their outcome through std::future<bool>.
  • A bound BagPluginInterface may rename URLs, override serialisation types and intercept individual replayed messages.
Example
auto reader = vlink::BagReader::create("/data/drive_log.vdb");
reader->register_ready_callback([] { VLOG_I("bag ready"); });
reader->register_output_callback([](const vlink::Frame& frame) {
// replay each frame in real-time order
VLOG_I("us=", frame.timestamp, " url=", frame.url, " bytes=", frame.data.size());
});
reader->async_run();
cfg.rate = 2.0; // play at 2x speed
cfg.times = vlink::BagReader::kInfinite; // loop forever
reader->play(cfg);
#define VLOG_I(...)
Definition: logger.h:785
Note
Always call async_run() before play(); the loop thread must be alive to dispatch frames. Output callback timestamps are in microseconds, while Config::begin_time and Config::end_time are expressed in milliseconds.