VLink  2.1.0
A high-performance communication middleware
serializer.h 文件参考

Compile-time codec dispatch for VLink message payloads. 更多...

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

浏览源代码.

命名空间

 
 Serializer
 Compile-time codec detection and dispatch for VLink message payloads.
 
 

枚举

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 codec to use for a given C++ message type. 更多...
 

函数

constexpr bool vlink::Serializer::is_supported (Type type) noexcept
 Reports whether type identifies a usable codec. 更多...
 

详细描述

Compile-time codec dispatch for VLink message payloads.

The Serializer namespace is the codec router used by every VLink primitive. Given a C++ type T it determines, at compile time, which encoding family applies (raw bytes, Protobuf, FlatBuffers, FastDDS CDR, standard-layout POD, etc.) and dispatches serialize() / deserialize() to the appropriate code path with zero runtime cost.

Application code rarely calls these helpers directly; Publisher, Subscriber, Client, Server, Setter, and Getter call them internally as part of their publish() / listen() / invoke() / set() / get() implementations.

Codec Table – Serializer::Type Enum
Constant C++ criterion Trait Notes
kBytesType T is Bytes is_bytes_type Pass-through.
kDynamicType Has is_vlink_dynamic_data() is_dynamic_type Dynamic data.
kCdrType FastDDS IDL or ROS 2 type is_cdr_type CDR bytes.
kProtoType Protobuf-like value is_proto_type Protobuf value.
kProtoPtrType Protobuf-like pointer is_proto_ptr_type Caller-owned.
kFlatTableType FlatBuffers NativeTable is_flat_table_type Object API.
kFlatPtrType Pointer to flatbuffers::Table is_flat_ptr_type Zero-copy view.
kFlatBuilderType Has fbb_ and Finish() is_flat_builder_type Builder.
kCustomType Has operator>>/<<(Bytes&) is_custom_type Custom codec.
kStringType T is std::string is_string_type Byte string.
kCharsType Character pointer or array is_chars_type Serialise only.
kStreamType Supports std::stringstream is_stream_type Fallback.
kStandardType Trivial standard-layout value is_standard_type Byte copy.
kStandardPtrType Pointer to trivial standard type is_standard_ptr_type Zero-copy pointer.

Most value-like detectors unwrap std::shared_ptr<T> before matching (e.g. Protobuf values, CDR values, FlatBuffers native tables, custom codecs, strings, stream types, and standard-layout values).

Detection Precedence Flow
*   get_type_of<T>() probes traits in this fixed order; first match wins:
*
*     Bytes  --(no)-->  Dynamic  --(no)-->  CDR  --(no)-->  Proto
*                                                              |
*                                                              v (no)
*     FlatPtr  <--(no)--  FlatTable  <--(no)--  ProtoPtr  <--(no)--+
*         |
*         v (no)
*     FlatBuilder  --(no)-->  Custom  --(no)-->  String  --(no)-->  Chars
*                                                                      |
*                                                                      v (no)
*     Stream  <--(no)--  StandardPtr  <--(no)--  Standard  <--(no)----+
*                                                                      |
*                                                                      v (no)
*                                                                kUnknownType
* 
Type Detection Example
constexpr auto t = vlink::Serializer::get_type_of<MyProto>(); // -> kProtoType
constexpr auto u = vlink::Serializer::get_type_of<int>(); // -> kStandardType (POD)
constexpr auto v = vlink::Serializer::get_type_of<std::string>(); // -> kStringType
constexpr auto w = vlink::Serializer::get_type_of<const char*>(); // -> kCharsType
Serialise and Deserialise
MyProto msg;
MyProto out;
Custom Codec
struct MyCustomMsg {
int x;
void operator>>(vlink::Bytes& out) const { ... } // serialise
void operator<<(const vlink::Bytes& in) { ... } // deserialise
};
// vlink::Serializer::get_type_of<MyCustomMsg>() == vlink::Serializer::kCustomType
Explicit Codec Selection
CDR serialization produces a byte stream containing the 4-byte DDS encapsulation header. Use the explicit overload when the codec cannot be inferred from T:
vlink::Serializer::serialize<vlink::Serializer::kCdrType>(msg, bytes, vlink::TransportType::kDds);
注解
Most entry points are header-defined templates; a few non-template overloads are declared static or inline where appropriate.
参见
base/bytes.h, impl/types.h