VLink  2.3.0
A high-performance communication middleware
dynamic_data.h 文件参考

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

#include <memory>
#include <string_view>
#include <utility>
#include "../serializer.h"
dynamic_data.h 的引用(Include)关系图:

浏览源代码.

类

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

命名空间

 

详细描述

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, builder types Native table or completed builder payload
POD/Std int, struct Foo (trivial) Standard layout copy
Bytes vlink::Bytes Stored verbatim
String std::string Stored as raw string bytes
Chars char[N], const char* Stored without the trailing NUL
SOME/IP Macro-declared structures Stored as raw SOME/IP payload
Custom Types with explicit Serializer User-provided serialise/deserialise hooks

Nested DynamicData and CDR are rejected for both directions. load() also rejects non-owning FlatBuffers table pointers and POD pointers because those serialization paths cannot reserve the inline type-name prefix. 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;
}