VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
dynamic_data.h 文件参考

Type-erased data container for runtime serialisation and deserialisation. 更多...

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

浏览该文件的源代码.

 Runtime-typed container that serializes any VLink-compatible message type. 更多...

命名空间

详细描述

Type-erased data container for runtime serialisation and deserialisation.

DynamicData stores a serialized payload (Bytes) together with a type-name tag (up to kOffset = 20 bytes) embedded in the leading bytes of the buffer. This allows the payload to be transported through channels that do not know the compile-time message type, and later deserialized back to the concrete type.

Internal layout
[ type name (20 bytes max) | serialized payload ]
^--- type_ ^--- data_.data()

The type name is stored in-place in the first kOffset bytes of the Bytes buffer and exposed as a std::string_view pointing into that buffer.

Restrictions
  • Cannot serialize or deserialize another DynamicData object (static_assert).
  • Cannot serialize CDR types (static_assert).
  • The type name string literal (including NUL) must be shorter than kOffset (20) bytes (static_assert).
Serialisation
MyProtoMsg msg;
msg.set_value(42);
dd.load("MyProtoMsg", msg);
// Store/transport dd ...
MyProtoMsg recovered = dd.as<MyProtoMsg>();
Binary transport (operator<< / operator>>)
vlink::Bytes wire_bytes;
dd >> wire_bytes; // serialize DynamicData to Bytes
dd2 << wire_bytes; // deserialize Bytes back to DynamicData