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

函数

constexpr bool is_supported (Type type) noexcept
 Returns true when type identifies a supported serializer.
template<typename T>
constexpr Type get_type_of () noexcept
 Deduces the Type enumerator for T at compile time.
template<Type TypeT, typename T>
std::string get_serialized_type () noexcept
 Returns the serialisation type name string for T with explicit TypeT.
template<typename T>
std::string get_serialized_type () noexcept
 Returns the serialisation type name string for T (type auto-detected).
template<Type TypeT, typename T>
size_t get_serialized_size (const T &src) noexcept
 Returns the exact serialised byte size for a given src value.
template<typename T>
size_t get_serialized_size (const T &src) noexcept
 Returns the serialized byte size (type auto-detected).
template<Type TypeT, typename T>
bool serialize (const T &src, Bytes &des, TransportType transport, uint8_t offset)
 Serializes src into des with explicit type and transport hints.
template<typename T>
bool serialize (const T &src, Bytes &des)
 Serializes src into des (type and transport auto-detected).
template<Type TypeT, typename T>
bool deserialize (const Bytes &src, T &des, TransportType transport)
 Deserializes src bytes into des with explicit type and transport hints.
template<typename T>
bool deserialize (const Bytes &src, T &des)
 Deserializes src bytes into des (type and transport auto-detected).
template<typename SrcT, typename DesT>
bool convert (const SrcT &src, DesT &des)
 Converts between two types where at least one is Bytes.
template<typename T>
constexpr auto & deref (const T &t) noexcept
 Dereferences a value, unwrapping shared_ptr if necessary.
template<typename T>
constexpr bool is_bytes_type () noexcept
 Returns true if T is exactly Bytes.
template<typename T>
constexpr bool is_dynamic_type () noexcept
 Returns true if T is a VLink dynamic data type.
template<typename T>
constexpr bool is_cdr_type () noexcept
 Returns true if T is a FastDDS CDR-serialisable type.
template<typename T>
constexpr bool is_proto_type () noexcept
 Returns true if T is a Protobuf message value type.
template<typename T>
constexpr bool is_proto_ptr_type () noexcept
 Returns true if T is a raw pointer to a Protobuf message.
template<typename T>
constexpr bool is_flat_table_type () noexcept
 Returns true if T is a FlatBuffers NativeTable type.
template<typename T>
constexpr bool is_flat_builder_type () noexcept
 Returns true if T is a FlatBuffers builder type.
template<typename T>
constexpr bool is_flat_ptr_type () noexcept
 Returns true if T is a raw pointer to a flatbuffers::Table.
template<typename T>
constexpr bool is_custom_type () noexcept
 Returns true if T provides custom operator>> / operator<<.
template<typename T>
constexpr bool is_string_type () noexcept
 Returns true if T is std::string.
template<typename T>
constexpr bool is_chars_type () noexcept
 Returns true if T is constructible from std::string (but is not std::string).
template<typename T>
constexpr bool is_stream_type () noexcept
 Returns true if T supports both operator<< and operator>> with std::stringstream.
template<typename T>
constexpr bool is_standard_type () noexcept
 Returns true if T is a trivial standard-layout value type (POD).
template<typename T>
constexpr bool is_standard_ptr_type () noexcept
 Returns true if T is a pointer to a trivial standard-layout type.

枚举类型说明

◆ Type

enum vlink::Serializer::Type : uint8_t

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

Resolved at compile time by get_type_of<T>(). The value is stored in the Publisher / Subscriber etc. as a constexpr member so that all codec dispatch is zero-cost at runtime.

枚举值
kUnknownType 

Unsupported type – is_supported() returns false.

kBytesType 

Bytes – raw byte pass-through.

kDynamicType 

Dynamic typed data via is_vlink_dynamic_data().

kCustomType 

User-defined via operator>>(Bytes&) / operator<<(const Bytes&).

kCdrType 

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

kProtoType 

Protobuf value (MessageLite derived).

kProtoPtrType 

Protobuf raw pointer (Arena-managed).

kFlatTableType 

FlatBuffers NativeTable (object API).

kFlatPtrType 

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

kFlatBuilderType 

FlatBuffers builder (fbb_ + Finish()).

kStringType 

std::string – UTF-8 text.

kCharsType 

char* / string literal.

kStreamType 

Stream-serialisable via operator<<(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 is Bytes.

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

  • Both Bytes: shallow-copies src to des.
  • DesT == Bytes: calls serialize(src, des).
  • SrcT == Bytes: calls deserialize(src, des).
模板参数
SrcTSource type.
DesTDestination type.
参数
srcSource value.
desDestination value.
返回
true on success.
函数调用图:

◆ deref()

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

Dereferences a value, unwrapping shared_ptr if necessary.

If T is a shared_ptr, returns *t; otherwise returns t. Used internally so serialisation code handles both value and shared-ptr message types uniformly.

模板参数
TThe input 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

Deserializes src bytes into des (type 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,
TransportType transport = TransportType::kUnknown )
inline

Deserializes src bytes into des with explicit type and transport hints.

The transport activates transport-specific fast paths (e.g. kDds dereferences a CDR pointer stored in src instead of copying bytes).

模板参数
TypeTSerializer type.
TC++ message type.
参数
srcSource Bytes buffer.
desDestination value to fill.
transportActive transport backend.
返回
true on success; false on parse failure.
函数调用图:
这是这个函数的调用关系图:

◆ get_serialized_size() [1/2]

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

Returns the serialized byte size (type auto-detected).

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

◆ get_serialized_size() [2/2]

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

Returns the exact serialised byte size for a given src value.

Used to pre-allocate loaned buffers before serializing. Returns 0 for types whose serialized size is not known ahead of time (e.g. kBytesType, kStringType, kFlatTableType). For kStandardType returns sizeof(T).

模板参数
TypeTSerializer type.
TC++ message type.
参数
srcSource value to measure.
返回
Byte count needed to serialise src; 0 if unknown.
函数调用图:
这是这个函数的调用关系图:

◆ get_serialized_type() [1/2]

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

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

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

◆ get_serialized_type() [2/2]

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

Returns the serialisation type name string for T with explicit TypeT.

Returns a human-readable type identifier used by the framework for type-matching between publisher and subscriber (e.g. DDS topic type name, Protobuf fully-qualified name, FlatBuffers table name). Returns an empty string for types that have no meaningful type name (e.g. kBytesType).

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

◆ get_type_of()

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

Deduces the Type enumerator for T at compile time.

Evaluates a compile-time if constexpr chain that tests each codec's trait (e.g. is_proto_type<T>()) and returns the first matching Type. Returns kUnknownType if no codec matches.

The detection order is: Bytes, Dynamic, CDR, Proto, ProtoPtr, FlatTable, FlatPtr, FlatBuilder, Custom, String, Chars, Standard, StandardPtr, Stream.

模板参数
TThe C++ message type to classify.
返回
Type enumerator identifying the codec for T.
函数调用图:
这是这个函数的调用关系图:

◆ is_bytes_type()

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

Returns true if T is exactly Bytes.

模板参数
TType to test.
返回
true for Bytes.
这是这个函数的调用关系图:

◆ is_cdr_type()

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

Returns true if T is a FastDDS CDR-serialisable type.

Requires fastcdr to be present and the type to have both serialize(Cdr&) and deserialize(Cdr&) methods, or its name to contain the VLINK_FASTDDS_IDL_PREFIX prefix.

模板参数
TType to test.
返回
true for CDR types when fastcdr is available.
函数调用图:
这是这个函数的调用关系图:

◆ is_chars_type()

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

Returns true if T is constructible from std::string (but is not std::string).

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

模板参数
TType to test.
返回
true for C-string types.
这是这个函数的调用关系图:

◆ is_custom_type()

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

Returns true if T provides custom operator>> / operator<<.

Checks via Traits::Operatorable whether T supports operator>>(Bytes&) and operator<<(const Bytes&).

模板参数
TType to test.
返回
true for custom-codec types.
这是这个函数的调用关系图:

◆ is_dynamic_type()

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

Returns true if T is a VLink dynamic data type.

Dynamic types have an is_vlink_dynamic_data() member.

模板参数
TType to test.
返回
true for dynamic data types.
这是这个函数的调用关系图:

◆ is_flat_builder_type()

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

Returns true if T is a FlatBuffers builder type.

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

模板参数
TType to test.
返回
true for FlatBuffers builder types.
这是这个函数的调用关系图:

◆ is_flat_ptr_type()

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

Returns true if T is a raw pointer to a flatbuffers::Table.

模板参数
TType to test (expected to be MyTable*).
返回
true for FlatBuffers Table pointer types.
这是这个函数的调用关系图:

◆ is_flat_table_type()

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

Returns true if T is a FlatBuffers NativeTable type.

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

模板参数
TType to test.
返回
true for FlatBuffers NativeTable types.
这是这个函数的调用关系图:

◆ is_proto_ptr_type()

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

Returns true if T is a raw pointer to a Protobuf message.

模板参数
TType to test (expected to be MyProto*).
返回
true for Protobuf pointer types.
这是这个函数的调用关系图:

◆ is_proto_type()

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

Returns true if T is a Protobuf message value type.

Requires protobuf to be present and the type to have both SerializeToArray() and ParseFromArray() methods.

模板参数
TType to test.
返回
true for Protobuf value types.
这是这个函数的调用关系图:

◆ is_standard_ptr_type()

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

Returns true if T is a pointer to a trivial standard-layout type.

Matches T* where std::is_trivial_v<T> && std::is_standard_layout_v<T>. The pointer is reinterpreted (not dereferenced and copied) for zero-copy usage.

模板参数
TPointer type to test.
返回
true for POD pointer types.
这是这个函数的调用关系图:

◆ is_standard_type()

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

Returns true if T is a trivial standard-layout value type (POD).

Matches types where std::is_trivial_v and std::is_standard_layout_v are both true and the type is not a pointer. Such types are byte-copied directly into/from a Bytes buffer of exactly sizeof(T) bytes.

模板参数
TType to test.
返回
true for POD value types.
这是这个函数的调用关系图:

◆ is_stream_type()

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

Returns true if T supports both operator<< and operator>> with std::stringstream.

Detected via Traits::Operatorable<std::stringstream, T>(), which requires both ss << t and ss >> t to be well-formed. Non-pointer types that support bidirectional streaming via std::stringstream (e.g. arithmetic types or types with custom stream operator overloads) match. Note that higher-priority codecs (e.g. Proto, CDR) are checked first in get_type_of(), so this function is only reached for types that do not match any earlier codec.

模板参数
TType to test.
返回
true for stream-serialisable types.
这是这个函数的调用关系图:

◆ is_string_type()

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

Returns true if T is std::string.

模板参数
TType to test.
返回
true only for std::string.
这是这个函数的调用关系图:

◆ is_supported()

constexpr bool vlink::Serializer::is_supported ( Type type)
inlinenodiscardconstexprnoexcept

Returns true when type identifies a supported serializer.

kUnknownType is the only unsupported value. This function is called by the static_assert in every node constructor to catch unsupported message types at compile time.

参数
typeSerializer type enumerator.
返回
false only for kUnknownType.

◆ serialize() [1/2]

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

Serializes src into des (type and transport auto-detected).

模板参数
TC++ message type.
参数
srcSource value.
desDestination Bytes.
返回
true on success.
函数调用图:

◆ serialize() [2/2]

template<Type TypeT, typename T>
bool vlink::Serializer::serialize ( const T & src,
Bytes & des,
TransportType transport = TransportType::kUnknown,
uint8_t offset = 0 )
inline

Serializes src into des with explicit type and transport hints.

The transport parameter activates transport-specific fast paths (e.g. CDR pointer passing for kDds). Pass TransportType::kUnknown for the default copy-based path. The offset parameter prepends offset zero bytes before the payload (used internally for some transports).

模板参数
TypeTSerializer type.
TC++ message type.
参数
srcSource value to serialise.
desDestination Bytes buffer (may be pre-allocated or loaned).
transportActive transport backend for fast-path selection.
offsetNumber of header bytes to prepend (default 0).
返回
true on success; false on serialisation failure.
函数调用图:
这是这个函数的调用关系图: