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

JSON-driven substring rewriter for VLink topic URLs. More...

#include <string>
#include <unordered_map>
#include <vector>
#include "../base/macros.h"
Include dependency graph for url_remap.h:

Go to the source code of this file.

Classes

class  vlink::UrlRemap
 Loads a JSON rewrite table and substitutes VLink URLs at runtime. More...
 

Namespaces

 

Detailed Description

JSON-driven substring rewriter for VLink topic URLs.

UrlRemap turns a flat JSON dictionary into a runtime topic-renaming layer. Each entry maps a fragment that should appear in an input URL to the replacement URL emitted to the transport, allowing operators to switch backends, redirect topics, or stage migrations without rebuilding application binaries.

Rewrite rules
Source key (substring of input) Target value (replacement URL) Effect
"intra://sensor/lidar" "dds://vehicle/lidar" promote local topic to DDS
"shm://camera/front" "zenoh://camera/front" switch transport to Zenoh
"dds://" "ddst://" force TCP DDS transport globally
"fdbus://" "intra://" merge to intra-process bus

Lookup is linear in the configured order; the first key that occurs as a substring of the input URL wins. Results are cached so repeated lookups for the same input are O(1).

Environment-driven remap
+-------------------------+ load(path) +---------------------+ convert(url)
| VLINK_URL_REMAP=path | ----------------> | UrlRemap (JSON map) | -----------------> rewritten URL
| or load(path) at init | | + result cache | cache hit -> O(1)
+-------------------------+ +---------------------+
|
v
transports receive
the rewritten URL
Example
if (remap.load("/etc/vlink/remap.json")) {
auto target = remap.convert("intra://sensor/lidar");
} else {
VLOG_W("remap unavailable: ", remap.get_error_string());
}
remap.reload("/etc/vlink/remap-v2.json");
#define VLOG_W(...)
Definition: logger.h:787
Note
  • UrlRemap is not thread-safe; serialise calls externally or confine to a single thread.
  • convert() returns its input unchanged when the table is empty or unloaded.