Plugin interface for VLink/webviz message conversion across visualization backends.
更多...
Plugin interface for VLink/webviz message conversion across visualization backends.
MessageConvertPlugin allows users to implement custom VLink/webviz message conversion logic in a shared library plugin. The plugin receives raw VLink message bytes (Protobuf, FlatBuffers, CDR, POD, or any custom serialisation) and produces a backend-specific payload along with schema/type metadata.
This interface has zero third-party dependencies – it only uses VLink base types (Bytes) and standard C++ types, making it easy to implement in external projects without linking against Protobuf, FlatBuffers, Rerun SDK, or JSON libraries.
A single plugin can support multiple visualization backends by checking the ConvertTarget parameter in each method. The plugin coexists with JSON-based VLink-to-webviz mapping files. When both are present, the plugin is tried first; if it returns false for a given type, the JSON mapping pipeline takes over.
- Supported targets
| Target | Payload format | type_name meaning |
kFoxglove | FlatBuffer / Protobuf binary | Foxglove schema name |
kRerun | JSON string describing components | Rerun archetype name |
- Rerun JSON payload format
- When targeting Rerun, the plugin should produce a UTF-8 JSON string as the payload. The JSON object describes the Rerun archetype components. Each archetype has its own expected fields:
// Points3D example:
{
"positions": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],
"colors": [[255, 0, 0, 255], [0, 255, 0, 255]],
"radii": [0.1, 0.2]
}
// EncodedImage example (binary data is base64-encoded):
{
"media_type": "image/jpeg",
"data_base64": "<base64-encoded image bytes>"
}
// GeoPoints example:
{
"lat_deg": [37.7749, 37.7750],
"lon_deg": [-122.4194, -122.4195]
}
// TextLog example:
{
"text": "Hello world",
"level": "INFO"
}
// Scalars example:
{
"value": 3.14
}
// Transform3D example:
{
"translation": [1.0, 2.0, 3.0],
"rotation_quat": [0.0, 0.0, 0.0, 1.0]
}
// Boxes3D example:
{
"half_sizes": [[1.0, 2.0, 3.0]],
"centers": [[0.0, 0.0, 0.0]],
"quaternions": [[0.0, 0.0, 0.0, 1.0]],
"colors": [[255, 0, 0, 255]],
"labels": ["box1"]
}
// Pinhole example:
{
"image_from_camera": [[fx, 0, cx], [0, fy, cy], [0, 0, 1]],
"resolution": [1920, 1080]
}
Binary archetypes should carry their raw bytes in a data_base64 string. Currently the built-in Rerun JSON bridge supports this for EncodedImage, Image, DepthImage, SegmentationImage, EncodedDepthImage, Asset3D, AssetVideo, and Tensor. Image, DepthImage, and SegmentationImage also require width/height (or resolution). Tensor additionally requires shape and may provide dim_names. Direct VLink-to-Rerun mappings still cover a broader set of archetypes than the plugin JSON bridge.
- Plugin lifecycle
init() is called once after loading, with an optional config string.
can_convert() is called for each discovered VLink serialisation type (with the target backend) to determine if the plugin handles it.
get_schema_info() is called once per type to register the channel/archetype.
convert() is called for every incoming message on matched types.
- The plugin is destroyed when the server shuts down.
- Example implementation (supports both Foxglove and Rerun)
public:
bool init(
const std::string& config)
override {
return true;
}
bool can_convert(
const std::string& vlink_ser, ConvertTarget target)
override {
if (vlink_ser != "my_pkg.MyMessage") return false;
return target == ConvertTarget::kFoxglove || target == ConvertTarget::kRerun;
}
std::string& type_name, std::string& encoding,
std::string& schema_encoding,
std::string& schema_data) override {
if (target == ConvertTarget::kFoxglove) {
type_name = "foxglove.LocationFix";
encoding = "flatbuffers";
schema_encoding = "flatbuffers";
} else if (target == ConvertTarget::kRerun) {
type_name = "GeoPoints";
encoding = "json";
}
return true;
}
bool convert(
const std::string& vlink_ser,
const vlink::Bytes& raw,
ConvertTarget target, vlink::Bytes& payload) override {
if (target == ConvertTarget::kFoxglove) {
} else if (target == ConvertTarget::kRerun) {
std::string json = R"({"lat_deg":[37.77],"lon_deg":[-122.41]})";
}
return true;
}
};
static Bytes deep_copy(uint8_t *data, size_t size, uint8_t offset=0) noexcept
Creates an owned deep copy of an external mutable buffer.
Abstract interface for VLink/webviz message conversion plugins supporting multiple visualization back...
定义 message_convert_plugin.h:239
virtual bool can_convert(const std::string &vlink_ser, ConvertTarget target)=0
Tests whether this plugin can handle the given VLink serialisation type for the specified target back...
virtual bool convert(const std::string &vlink_ser, const Bytes &raw, ConvertTarget target, Bytes &payload)=0
Converts a raw VLink message to a backend-specific payload.
virtual bool init(const std::string &config)=0
Initialises the plugin with an optional configuration string.
virtual bool get_schema_info(const std::string &vlink_ser, ConvertTarget target, std::string &type_name, std::string &encoding, std::string &schema_encoding, std::string &schema_data)=0
Returns schema/type metadata for the given VLink type and target backend.
Plugin interface for VLink/webviz message conversion across visualization backends.
#define VLINK_PLUGIN_DECLARE(ImplementType, VersionMajor, VersionMinor)
Declares a plugin creation and destruction interface.
定义 plugin.h:380
#define VLINK_PLUGIN_REGISTER(InterfaceType)
Macro to register a plugin, automatically deriving its ID from the interface type name.
定义 plugin.h:343