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

Compile-time type-detection and serialisation utilities for VLink messages. 更多...

#include <string>
#include "./base/bytes.h"
#include "./impl/types.h"
#include "./internal/serializer-inl.h"
serializer.h 的引用(Include)关系图:
此图展示该文件被哪些文件直接或间接地引用了:

浏览该文件的源代码.

命名空间

namespace  Serializer
 Compile-time type detection and codec dispatch for VLink messages.

枚举

enum  vlink::Serializer::Type : uint8_t {
  vlink::Serializer::kUnknownType = 0 , vlink::Serializer::kBytesType = 1 , vlink::Serializer::kDynamicType = 2 , vlink::Serializer::kCustomType = 3 ,
  vlink::Serializer::kCdrType = 4 , vlink::Serializer::kProtoType = 5 , vlink::Serializer::kProtoPtrType = 6 , vlink::Serializer::kFlatTableType = 7 ,
  vlink::Serializer::kFlatPtrType = 8 , vlink::Serializer::kFlatBuilderType = 9 , vlink::Serializer::kStringType = 10 , vlink::Serializer::kCharsType = 11 ,
  vlink::Serializer::kStreamType = 12 , vlink::Serializer::kStandardType = 13 , vlink::Serializer::kStandardPtrType = 14
}
 Identifies the serialisation codec to use for a given C++ type. 更多...

函数

constexpr bool vlink::Serializer::is_supported (Type type) noexcept
 Returns true when type identifies a supported serializer.

详细描述

Compile-time type-detection and serialisation utilities for VLink messages.

The Serializer namespace provides a unified serialisation and deserialisation interface that automatically selects the correct codec based on the C++ type of the message via constexpr if chains.

Supported Serializer Types
Type constant C++ Type Criteria Notes
kBytesType T == Bytes Pass-through, no-copy.
kDynamicType Has is_vlink_dynamic_data() member Dynamic type via operator>>/<<
kCdrType Has serialize(Cdr&) and deserialize(Cdr&) FastDDS CDR codec.
kProtoType Has SerializeToArray() and ParseFromArray() Protobuf by value.
kProtoPtrType Pointer with SerializeToArray / ParseFromArray Arena-managed proto pointer.
kFlatTableType Inherits flatbuffers::NativeTable FlatBuffers native table.
kFlatPtrType Pointer to flatbuffers::Table subclass Zero-copy FlatBuffers read.
kFlatBuilderType Has fbb_ member and Finish() FlatBuffers builder.
kCustomType Has operator>>(Bytes&) and operator<<(const Bytes&) User-defined codec.
kStringType T == std::string UTF-8 string.
kCharsType Constructible as std::string but not std::string C string literal / char*.
kStreamType Has operator<< and operator>> with stringstream Stream-based text encoding.
kStandardType Trivial standard-layout value (POD) Byte-copied directly.
kStandardPtrType Pointer to trivial standard-layout type Zero-copy POD pointer.
Type Detection
// At compile time, get the Type enumerator for any message type:
constexpr auto t = Serializer::get_type_of<MyMsg>(); // e.g. kProtoType
static_assert(Serializer::is_supported(t), "");
Serialize and Deserialize
MyProto msg;
Bytes bytes;
Serializer::serialize(msg, bytes); // MyProto -> Bytes
MyProto out;
Serializer::deserialize(bytes, out); // Bytes -> MyProto
Custom Type
Implement operator>> and operator<< on your type:
struct MyCustomMsg {
int x;
void operator>>(vlink::Bytes& out) const { ... } // serialize
void operator<<(const vlink::Bytes& in) { ... } // deserialize
};
// Now Serializer::get_type_of<MyCustomMsg>() == kCustomType
Transport-aware Serialization
Some transports (e.g. dds://) use a special fast-path for CDR types (pointer passing instead of byte-copy). Pass the TransportType to the explicit overloads to activate the transport-specific path:
Serializer::serialize<kCdrType>(msg, bytes, TransportType::kDds);
注解
All functions in this namespace are static and inline. The namespace name starts with a capital letter by convention (matches VLink style). Direct use by application code is rarely needed; the framework calls these functions automatically inside publish(), listen(), invoke(), etc.