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

Self-describing serialised payload tagged with an inline type name. More...

#include <memory>
#include <string_view>
#include <utility>
#include "../serializer.h"
Include dependency graph for dynamic_data.h:

Go to the source code of this file.

Classes

class  vlink::DynamicData
 Type-erased wrapper that pairs an inline type name with a serialised payload. More...
 

Namespaces

 

Detailed Description

Self-describing serialised payload tagged with an inline type name.

DynamicData carries a serialised VLink-compatible message together with a short type-name tag inside a single Bytes buffer. The first kOffset = 20 bytes of the buffer hold the type name (NUL-padded), and the remainder holds the payload as produced by Serializer. This layout lets transports route, log and inspect a payload without knowing its concrete C++ type at compile time – the recipient picks the matching deserialiser at run time using the embedded tag.

Supported dynamic categories (chosen automatically by Serializer):

Category Examples Notes
Protobuf MyProto, std::shared_ptr<P> Encoded with the message's wire format
FlatBuffer MyTable, FlatPtr<T> Encoded via FlatBuilder
POD/Std int, struct Foo (trivial) Standard layout copy
Bytes vlink::Bytes Stored verbatim
String std::string Length-prefixed
Chars char[N], const char* NUL-terminated
Custom Types with explicit Serializer User-provided serialise/deserialise hooks

Two categories are forbidden and rejected by static_assert: nested DynamicData (avoids recursive type-name layout) and CDR types (their wire format does not allow the in-place prefix used here). The type-name literal (including its trailing NUL) must fit in fewer than kOffset bytes.

Buffer layout:

*   +----------------------------+-----------------------------------------+
*   |  type name (20 bytes max)  |  serialised payload                     |
*   +----------------------------+-----------------------------------------+
*   ^                            ^
*   data_.real_data()            data_.real_data() + kOffset
* 
Example
MyProtoMsg msg;
msg.set_value(42);
dd.load("MyProtoMsg", msg); // serialise + tag
// Send over any transport that handles vlink::Bytes:
dd >> wire;
received << wire; // recover the tagged blob
if (received.get_type() == "MyProtoMsg") {
MyProtoMsg out = received.as<MyProtoMsg>(); // deserialise
(void)out;
}