VLink  2.3.0
A high-performance communication middleware
vlink::Serializer Namespace Reference

Enumerations

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

Functions

constexpr bool is_supported (Type type) noexcept
 Reports whether type identifies a usable codec. More...
 
template<typename T >
constexpr Type get_type_of () noexcept
 Resolves the codec Type for T at compile time. More...
 
template<Type TypeT, typename T >
std::string get_serialized_type () noexcept
 Returns the serialised type-name string for T with explicit codec tag. More...
 
template<typename T >
std::string get_serialized_type () noexcept
 Returns the serialised type-name string for T with explicit codec tag. More...
 
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. More...
 
template<typename T >
size_t get_serialized_size (const T &src) noexcept
 Returns a serialised-size hint for src with explicit codec tag. More...
 
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). More...
 
template<Type TypeT, typename T , typename LoanCallbackT >
bool serialize_to_transport (const T &src, Bytes &des, TransportType transport, bool use_loan, LoanCallbackT &&loan)
 Serialises into transport-provided storage when available. More...
 
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). More...
 
template<typename SrcT , typename DesT >
bool convert (const SrcT &src, DesT &des)
 Converts between two types where at least one side is Bytes. More...
 
template<typename T >
constexpr auto & deref (const T &t) noexcept
 Dereferences a value, unwrapping std::shared_ptr when present. More...
 
template<typename T >
constexpr bool is_bytes_type () noexcept
 Reports whether T is exactly Bytes. More...
 
template<typename T >
constexpr bool is_dynamic_type () noexcept
 Reports whether T is a VLink dynamic data type. More...
 
template<typename T >
constexpr bool is_cdr_type () noexcept
 Reports whether T is a FastDDS CDR-serialisable type. More...
 
template<typename T >
constexpr bool is_proto_type () noexcept
 Reports whether T is a Protobuf-like message value type. More...
 
template<typename T >
constexpr bool is_proto_ptr_type () noexcept
 Reports whether T is a raw pointer to a Protobuf-like message. More...
 
template<typename T >
constexpr bool is_flat_table_type () noexcept
 Reports whether T is a FlatBuffers NativeTable type. More...
 
template<typename T >
constexpr bool is_flat_builder_type () noexcept
 Reports whether T is a FlatBuffers builder type. More...
 
template<typename T >
constexpr bool is_flat_ptr_type () noexcept
 Reports whether T is a raw pointer to a flatbuffers::Table. More...
 
template<typename T >
constexpr bool is_someip_type () noexcept
 Reports whether T is a macro-declared SOME/IP structure. More...
 
template<typename T >
constexpr bool is_custom_type () noexcept
 Reports whether T provides a custom operator>>/<< codec. More...
 
template<typename T >
constexpr bool is_string_type () noexcept
 Reports whether T is std::string after unwrapping shared_ptr. More...
 
template<typename T >
constexpr bool is_chars_type () noexcept
 Reports whether T is a pointer or array of non-volatile char. More...
 
template<typename T >
constexpr bool is_stream_type () noexcept
 Reports whether T supports bidirectional std::stringstream streaming. More...
 
template<typename T >
constexpr bool is_standard_type () noexcept
 Reports whether T is a trivial standard-layout value (POD). More...
 
template<typename T >
constexpr bool is_standard_ptr_type () noexcept
 Reports whether T is a pointer to a trivial standard-layout type. More...
 

Enumeration Type Documentation

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

Enumerator
kUnknownType 

Unsupported type; is_supported() returns false.

kBytesType 

Bytes – raw byte pass-through.

kDynamicType 

VLink dynamic typed data.

kCustomType 

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

kSomeipType 

Macro-declared SOME/IP structure 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 payload bytes; no text-encoding validation.

kCharsType 

C string serialisation; deserialise as std::string.

kStreamType 

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

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

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

Template Parameters
TInput type (value or shared_ptr).
Parameters
tInput value.
Returns
Reference to the underlying value.
Here is the call graph for this function:
Here is the caller graph for this function:

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

When T is inferred as kSomeipType, source storage must not overlap any storage reachable from des. Exceptions raised by inferred Dynamic or Custom decoding operators retain the operator's own exception contract.

Template Parameters
TC++ message type.
Parameters
srcSource Bytes buffer.
desDestination value.
Returns
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
Here is the call graph for this function:
Here is the caller graph for this function:

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

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

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

Template Parameters
TypeTCodec kind.
TC++ message type.
Parameters
srcSource value to measure.
Returns
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).

Template Parameters
TypeTExplicit codec kind.
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<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).

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

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

Template Parameters
TC++ message type to classify.
Returns
Resolved Type enumerator.

◆ is_bytes_type()

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

Reports whether T is exactly Bytes.

Template Parameters
TType to test.
Returns
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 VLINK_HAS_CDR, plus either both serialize(Cdr&) and deserialize(Cdr&) methods, or a type name carrying the VLINK_DDS_IDL_PREFIX prefix. When VLINK_HAS_ROS2 is defined, ROS2 message traits are also recognised.

Template Parameters
TType to test.
Returns
true for supported CDR types.
Here is the call graph for this function:

◆ is_chars_type()

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

Reports whether T is a pointer or array of non-volatile char.

Matches char*, const char*, and string literal source types for serialisation. Deserialisation into a raw character pointer is rejected because the pointer cannot own the decoded storage; use std::string as the destination. The trait deliberately excludes other string-like types such as std::string_view because the chars codec requires a null-terminated source when serialising. Arrays must contain a null terminator within their extent; pointer callers must guarantee that a terminator is reachable. Bytes after the first terminator are ignored.

Template Parameters
TType to test.
Returns
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&).

Template Parameters
TType to test.
Returns
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.

Template Parameters
TType to test.
Returns
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.

Template Parameters
TType to test.
Returns
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.

Template Parameters
TPointer type to test.
Returns
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.

Template Parameters
TType to test.
Returns
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.

Template Parameters
TPointer type to test.
Returns
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.

Template Parameters
TType to test.
Returns
true for Protobuf-compatible value types.

◆ is_someip_type()

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

Reports whether T is a macro-declared SOME/IP structure.

Detects the static is_vlink_someip_type() marker generated by VLINK_SOMEIP_FIELDS after unwrapping std::shared_ptr.

Template Parameters
TType to test.
Returns
true for macro-declared SOME/IP structures.

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

Template Parameters
TPointer type to test.
Returns
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.

Template Parameters
TType to test.
Returns
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.

Template Parameters
TType to test.
Returns
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.

Template Parameters
TType to test.
Returns
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. Support may be directional: kCharsType supports C-string serialisation but requires std::string on the deserialisation side. This function is invoked from the static_assert in every primitive constructor so unknown message types fail at compile time with a clear diagnostic.

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

When T is inferred as kSomeipType, destination storage must not overlap any storage reachable from src.

Template Parameters
TC++ message type.
Parameters
srcSource value.
desDestination Bytes buffer.
Returns
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ serialize_to_transport()

template<Type TypeT, typename T , typename LoanCallbackT >
bool vlink::Serializer::serialize_to_transport ( const T &  src,
Bytes &  des,
TransportType  transport,
bool  use_loan,
LoanCallbackT &&  loan 
)
inline

Serialises into transport-provided storage when available.

When use_loan is true and a non-zero size hint is available, loan is called and may return either loaned or owning storage. A zero hint falls back to normal owning serialisation. FlatBuilder sources are finished before requesting their exact-size destination, including when that request subsequently fails. Other codecs use get_serialized_size() followed by the normal serialize() path. A non-zero size hint requires storage of exactly that size. A codec must not replace transport-loaned storage. For kSomeipType, storage returned by loan must not overlap any storage reachable from src.

Template Parameters
TypeTCodec kind.
TC++ message type.
LoanCallbackTCallable compatible with Bytes(size_t).
Parameters
srcSource value to serialise.
desDestination populated on success; it may be modified on failure.
transportActive transport back-end.
use_loanWhether to request transport-provided storage.
loanDestination provider called at most once.
Returns
true on success; false on allocation, size, or codec failure.
Here is the call graph for this function: