VLink  2.0.0
A high-performance communication middleware
vlink::Serializer 命名空间参考

枚举

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

函数

constexpr bool is_supported (Type type) noexcept
 Reports whether type identifies a usable codec. 更多...
 
template<typename T >
constexpr Type get_type_of () noexcept
 Resolves the codec Type for T at compile time. 更多...
 
template<Type TypeT, typename T >
std::string get_serialized_type () noexcept
 Returns the serialised type-name string for T with explicit codec tag. 更多...
 
template<typename T >
std::string get_serialized_type () noexcept
 Returns the serialised type-name string for T with explicit codec tag. 更多...
 
template<Type TypeT, typename T >
size_t get_serialized_size (const T &src) noexcept
 Returns a serialised-size hint for src with explicit codec tag. 更多...
 
template<typename T >
size_t get_serialized_size (const T &src) noexcept
 Returns a serialised-size hint for src with explicit codec tag. 更多...
 
template<Type TypeT, typename T >
bool serialize (const T &src, Bytes &des, [[maybe_unused]] TransportType transport, [[maybe_unused]] uint8_t offset)
 
template<typename T >
bool serialize (const T &src, Bytes &des)
 Serialises src into des (codec and transport auto-detected). 更多...
 
template<Type TypeT, typename T >
bool deserialize (const Bytes &src, T &des, [[maybe_unused]] TransportType transport)
 
template<typename T >
bool deserialize (const Bytes &src, T &des)
 Deserialises src into des (codec and transport auto-detected). 更多...
 
template<typename SrcT , typename DesT >
bool convert (const SrcT &src, DesT &des)
 Converts between two types where at least one side is Bytes. 更多...
 
template<typename T >
constexpr auto & deref (const T &t) noexcept
 Dereferences a value, unwrapping std::shared_ptr when present. 更多...
 
template<typename T >
constexpr bool is_bytes_type () noexcept
 Reports whether T is exactly Bytes. 更多...
 
template<typename T >
constexpr bool is_dynamic_type () noexcept
 Reports whether T is a VLink dynamic data type. 更多...
 
template<typename T >
constexpr bool is_cdr_type () noexcept
 Reports whether T is a FastDDS CDR-serialisable type. 更多...
 
template<typename T >
constexpr bool is_proto_type () noexcept
 Reports whether T is a Protobuf-like message value type. 更多...
 
template<typename T >
constexpr bool is_proto_ptr_type () noexcept
 Reports whether T is a raw pointer to a Protobuf-like message. 更多...
 
template<typename T >
constexpr bool is_flat_table_type () noexcept
 Reports whether T is a FlatBuffers NativeTable type. 更多...
 
template<typename T >
constexpr bool is_flat_builder_type () noexcept
 Reports whether T is a FlatBuffers builder type. 更多...
 
template<typename T >
constexpr bool is_flat_ptr_type () noexcept
 Reports whether T is a raw pointer to a flatbuffers::Table. 更多...
 
template<typename T >
constexpr bool is_custom_type () noexcept
 Reports whether T provides a custom operator>>/<< codec. 更多...
 
template<typename T >
constexpr bool is_string_type () noexcept
 Reports whether T is std::string after unwrapping shared_ptr. 更多...
 
template<typename T >
constexpr bool is_chars_type () noexcept
 Reports whether std::string is constructible from T (but T is not string). 更多...
 
template<typename T >
constexpr bool is_stream_type () noexcept
 Reports whether T supports bidirectional std::stringstream streaming. 更多...
 
template<typename T >
constexpr bool is_standard_type () noexcept
 Reports whether T is a trivial standard-layout value (POD). 更多...
 
template<typename T >
constexpr bool is_standard_ptr_type () noexcept
 Reports whether T is a pointer to a trivial standard-layout type. 更多...
 

枚举类型说明

◆ Type

enum vlink::Serializer::Type : uint8_t

Identifies the codec to use for a given C++ message type.

Resolved at compile time by get_type_of<T>() and stored as a constexpr member on every primitive class, so all codec dispatch is zero-cost at runtime.

枚举值
kUnknownType 

Unsupported type; is_supported() returns false.

kBytesType 

Bytes – raw byte pass-through.

kDynamicType 

VLink dynamic typed data.

kCustomType 

User-defined codec via operator>>/<<.

kCdrType 

FastDDS CDR via serialize(Cdr&) / deserialize(Cdr&).

kProtoType 

Protobuf-like value.

kProtoPtrType 

Protobuf-like raw pointer; caller-owned.

kFlatTableType 

FlatBuffers NativeTable (object API).

kFlatPtrType 

Pointer to flatbuffers::Table (zero-copy view).

kFlatBuilderType 

FlatBuffers builder (fbb_ + Finish()).

kStringType 

std::string – UTF-8 text.

kCharsType 

C string / char*.

kStreamType 

Stream-serialisable via std::stringstream.

kStandardType 

Trivial standard-layout struct (POD value).

kStandardPtrType 

Pointer to trivial standard-layout struct (POD pointer).

函数说明

◆ convert()

template<typename SrcT , typename DesT >
bool vlink::Serializer::convert ( const SrcT &  src,
DesT &  des 
)
inline

Converts between two types where at least one side is Bytes.

A compile-time static_assert enforces that SrcT or DesT (or both) is Bytes. The three cases are:

模板参数
SrcTSource type.
DesTDestination type.
参数
srcSource value.
desDestination value.
返回
true on success.
函数调用图:

◆ deref()

template<typename T >
constexpr auto& vlink::Serializer::deref ( const T &  t)
inlineconstexprnoexcept

Dereferences a value, unwrapping std::shared_ptr when present.

If T is std::shared_ptr<U>, returns *t; otherwise returns t. Internal helper so codec code can treat both value and shared-pointer inputs uniformly.

模板参数
TInput type (value or shared_ptr).
参数
tInput value.
返回
Reference to the underlying value.
函数调用图:
这是这个函数的调用关系图:

◆ deserialize() [1/2]

template<typename T >
bool vlink::Serializer::deserialize ( const Bytes src,
T &  des 
)
inline

Deserialises src into des (codec and transport auto-detected).

模板参数
TC++ message type.
参数
srcSource Bytes buffer.
desDestination value.
返回
true on success.

◆ deserialize() [2/2]

template<Type TypeT, typename T >
bool vlink::Serializer::deserialize ( const Bytes src,
T &  des,
[[maybe_unused] ] TransportType  transport 
)
inline
函数调用图:
这是这个函数的调用关系图:

◆ get_serialized_size() [1/2]

template<Type TypeT, typename T >
size_t vlink::Serializer::get_serialized_size ( const T &  src)
inlinenoexcept

Returns a serialised-size hint for src with explicit codec tag.

Returns a serialised-size hint for src (codec auto-detected).

Used to size loaned buffers ahead of serialisation. The returned value is an exact byte count only for codecs that can produce one cheaply; it is 0 for codecs that cannot report an upfront size (e.g. kBytesType, kStringType, kFlatTableType, kStandardType).

模板参数
TypeTCodec kind.
TC++ message type.
参数
srcSource value to measure.
返回
Byte-count hint; 0 if unknown.
函数调用图:

◆ get_serialized_size() [2/2]

template<typename T >
size_t vlink::Serializer::get_serialized_size ( const T &  src)
inlinenoexcept

Returns a serialised-size hint for src with explicit codec tag.

Returns a serialised-size hint for src (codec auto-detected).

Used to size loaned buffers ahead of serialisation. The returned value is an exact byte count only for codecs that can produce one cheaply; it is 0 for codecs that cannot report an upfront size (e.g. kBytesType, kStringType, kFlatTableType, kStandardType).

模板参数
TypeTCodec kind.
TC++ message type.
参数
srcSource value to measure.
返回
Byte-count hint; 0 if unknown.

◆ get_serialized_type() [1/2]

template<Type TypeT, typename T >
std::string vlink::Serializer::get_serialized_type ( )
inlinenoexcept

Returns the serialised type-name string for T with explicit codec tag.

Returns the serialised type-name string for T (codec auto-detected).

Used by the framework for cross-peer type matching (DDS topic type name, Protobuf fully-qualified name, FlatBuffers table name, etc.). Returns an empty string for codecs with no meaningful type name (e.g. kBytesType).

模板参数
TypeTExplicit codec kind.
TC++ message type.
返回
Type-name string; empty if not applicable.
函数调用图:

◆ get_serialized_type() [2/2]

template<typename T >
std::string vlink::Serializer::get_serialized_type ( )
inlinenoexcept

Returns the serialised type-name string for T with explicit codec tag.

Returns the serialised type-name string for T (codec auto-detected).

Used by the framework for cross-peer type matching (DDS topic type name, Protobuf fully-qualified name, FlatBuffers table name, etc.). Returns an empty string for codecs with no meaningful type name (e.g. kBytesType).

模板参数
TypeTExplicit codec kind.
TC++ message type.
返回
Type-name string; empty if not applicable.
这是这个函数的调用关系图:

◆ get_type_of()

template<typename T >
constexpr Type vlink::Serializer::get_type_of ( )
inlineconstexprnoexcept

Resolves the codec Type for T at compile time.

Evaluates the if-constexpr chain documented above and returns the first matching enumerator. Returns kUnknownType if no codec matches.

模板参数
TC++ message type to classify.
返回
Resolved Type enumerator.

◆ is_bytes_type()

template<typename T >
constexpr bool vlink::Serializer::is_bytes_type ( )
inlineconstexprnoexcept

Reports whether T is exactly Bytes.

模板参数
TType to test.
返回
true for Bytes.

◆ is_cdr_type()

template<typename T >
constexpr bool vlink::Serializer::is_cdr_type ( )
inlineconstexprnoexcept

Reports whether T is a FastDDS CDR-serialisable type.

Requires fastcdr to be available, plus either both serialize(Cdr&) and deserialize(Cdr&) methods, or a type name carrying the VLINK_FASTDDS_IDL_PREFIX prefix.

模板参数
TType to test.
返回
true for CDR types when fastcdr is available.

◆ is_chars_type()

template<typename T >
constexpr bool vlink::Serializer::is_chars_type ( )
inlineconstexprnoexcept

Reports whether std::string is constructible from T (but T is not string).

Matches char*, const char*, and string literal types.

模板参数
TType to test.
返回
true for C-string-compatible types.

◆ is_custom_type()

template<typename T >
constexpr bool vlink::Serializer::is_custom_type ( )
inlineconstexprnoexcept

Reports whether T provides a custom operator>>/<< codec.

Checked via Traits::Operatorable for operator>>(Bytes&) and operator<<(const Bytes&).

模板参数
TType to test.
返回
true for custom-codec types.

◆ is_dynamic_type()

template<typename T >
constexpr bool vlink::Serializer::is_dynamic_type ( )
inlineconstexprnoexcept

Reports whether T is a VLink dynamic data type.

Dynamic types expose an is_vlink_dynamic_data() member.

模板参数
TType to test.
返回
true for dynamic data types.

◆ is_flat_builder_type()

template<typename T >
constexpr bool vlink::Serializer::is_flat_builder_type ( )
inlineconstexprnoexcept

Reports whether T is a FlatBuffers builder type.

Requires flatbuffers and the type to expose both an fbb_ member and a Finish() method.

模板参数
TType to test.
返回
true for FlatBuffers builder types.

◆ is_flat_ptr_type()

template<typename T >
constexpr bool vlink::Serializer::is_flat_ptr_type ( )
inlineconstexprnoexcept

Reports whether T is a raw pointer to a flatbuffers::Table.

模板参数
TPointer type to test.
返回
true for FlatBuffers Table pointer types.

◆ is_flat_table_type()

template<typename T >
constexpr bool vlink::Serializer::is_flat_table_type ( )
inlineconstexprnoexcept

Reports whether T is a FlatBuffers NativeTable type.

Requires flatbuffers and the type (or its shared_ptr element type) to derive from flatbuffers::NativeTable.

模板参数
TType to test.
返回
true for FlatBuffers NativeTable types.

◆ is_proto_ptr_type()

template<typename T >
constexpr bool vlink::Serializer::is_proto_ptr_type ( )
inlineconstexprnoexcept

Reports whether T is a raw pointer to a Protobuf-like message.

The pointee is not owned by the serialiser and must be non-null whenever the codec path dereferences it.

模板参数
TPointer type to test.
返回
true for Protobuf-compatible pointer types.

◆ is_proto_type()

template<typename T >
constexpr bool vlink::Serializer::is_proto_type ( )
inlineconstexprnoexcept

Reports whether T is a Protobuf-like message value type.

Requires Protobuf to be available and the type to expose SerializeToArray() and ParseFromArray() methods.

模板参数
TType to test.
返回
true for Protobuf-compatible value types.

◆ is_standard_ptr_type()

template<typename T >
constexpr bool vlink::Serializer::is_standard_ptr_type ( )
inlineconstexprnoexcept

Reports whether T is a pointer to a trivial standard-layout type.

Matches U* where std::is_trivial_v<U> && std::is_standard_layout_v<U>. The pointer is reinterpreted (not copied through) for zero-copy use.

模板参数
TPointer type to test.
返回
true for POD-pointer types.

◆ is_standard_type()

template<typename T >
constexpr bool vlink::Serializer::is_standard_type ( )
inlineconstexprnoexcept

Reports whether T is a trivial standard-layout value (POD).

Matches non-pointer types where both std::is_trivial_v and std::is_standard_layout_v hold. Such types are byte-copied into and out of a Bytes buffer of sizeof(T) bytes.

模板参数
TType to test.
返回
true for POD value types.

◆ is_stream_type()

template<typename T >
constexpr bool vlink::Serializer::is_stream_type ( )
inlineconstexprnoexcept

Reports whether T supports bidirectional std::stringstream streaming.

Detected via Traits::Operatorable<std::stringstream, T>(); the check requires both ss << t and ss >> t to be well-formed. Higher-priority codecs are checked first in get_type_of(), so this function is only reached for types that fail every earlier trait.

模板参数
TType to test.
返回
true for stream-serialisable types.

◆ is_string_type()

template<typename T >
constexpr bool vlink::Serializer::is_string_type ( )
inlineconstexprnoexcept

Reports whether T is std::string after unwrapping shared_ptr.

模板参数
TType to test.
返回
true for std::string and std::shared_ptr<std::string>.

◆ is_supported()

static constexpr bool vlink::Serializer::is_supported ( Type  type)
inlineconstexprnoexcept

Reports whether type identifies a usable codec.

kUnknownType is the only unsupported value. This function is invoked from the static_assert in every primitive constructor so unsupported message types fail at compile time with a clear diagnostic.

参数
typeCodec enumerator.
返回
false only for kUnknownType.

◆ serialize() [1/2]

template<typename T >
bool vlink::Serializer::serialize ( const T &  src,
Bytes des 
)
inline

Serialises src into des (codec and transport auto-detected).

模板参数
TC++ message type.
参数
srcSource value.
desDestination Bytes buffer.
返回
true on success.

◆ serialize() [2/2]

template<Type TypeT, typename T >
bool vlink::Serializer::serialize ( const T &  src,
Bytes des,
[[maybe_unused] ] TransportType  transport,
[[maybe_unused] ] uint8_t  offset 
)
inline
函数调用图:
这是这个函数的调用关系图: