VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::Serializer Namespace Reference

Enumerations

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. More...

Functions

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.

Enumeration Type Documentation

◆ 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.

Enumerator
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).

Function Documentation

◆ 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).
Template Parameters
SrcTSource type.
DesTDestination type.
Parameters
srcSource value.
desDestination value.
Returns
true on success.
Here is the call graph for this function:

◆ 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.

Template Parameters
TThe input type (value or shared_ptr).
Parameters
tInput value.
Returns
Reference to the underlying value.

Here is the caller graph for this function:

◆ 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).

Template Parameters
TC++ message type.
Parameters
srcSource Bytes buffer.
desDestination value.
Returns
true on success.
Here is the call graph for this function:

◆ 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).

Template Parameters
TypeTSerializer type.
TC++ message type.
Parameters
srcSource Bytes buffer.
desDestination value to fill.
transportActive transport backend.
Returns
true on success; false on parse failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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).

Template Parameters
TC++ message type.
Parameters
srcSource value to measure.
Returns
Byte count; 0 if unknown.
Here is the call graph for this function:

◆ 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).

Template Parameters
TypeTSerializer type.
TC++ message type.
Parameters
srcSource value to measure.
Returns
Byte count needed to serialise src; 0 if unknown.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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).

Template Parameters
TC++ message type.
Returns
Type name string; empty if not applicable.
Here is the call graph for this function:

◆ 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).

Template Parameters
TypeTExplicit serializer type.
TC++ message type.
Returns
Type name string; empty if not applicable.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Template Parameters
TThe C++ message type to classify.
Returns
Type enumerator identifying the codec for T.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_bytes_type()

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

Returns true if T is exactly Bytes.

Template Parameters
TType to test.
Returns
true for Bytes.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for CDR types when fastcdr is available.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for C-string types.
Here is the caller graph for this function:

◆ 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&).

Template Parameters
TType to test.
Returns
true for custom-codec types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for dynamic data types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for FlatBuffers builder types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test (expected to be MyTable*).
Returns
true for FlatBuffers Table pointer types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for FlatBuffers NativeTable types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test (expected to be MyProto*).
Returns
true for Protobuf pointer types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for Protobuf value types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TPointer type to test.
Returns
true for POD pointer types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for POD value types.
Here is the caller graph for this function:

◆ 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.

Template Parameters
TType to test.
Returns
true for stream-serialisable types.
Here is the caller graph for this function:

◆ is_string_type()

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

Returns true if T is std::string.

Template Parameters
TType to test.
Returns
true only for std::string.
Here is the caller graph for this function:

◆ 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.

Parameters
typeSerializer type enumerator.
Returns
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).

Template Parameters
TC++ message type.
Parameters
srcSource value.
desDestination Bytes.
Returns
true on success.
Here is the call graph for this function:

◆ 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).

Template Parameters
TypeTSerializer type.
TC++ message type.
Parameters
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).
Returns
true on success; false on serialisation failure.
Here is the call graph for this function:
Here is the caller graph for this function: