VLink  2.0.0
A high-performance communication middleware
serializer.h File Reference

Compile-time codec dispatch for VLink message payloads. More...

#include <string>
#include "./base/bytes.h"
#include "./impl/types.h"
#include "./internal/serializer-inl.h"
Include dependency graph for serializer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

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

Enumerations

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

Functions

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

Detailed Description

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++ Type Criterion Trait check Notes
kBytesType T == Bytes is_bytes_type Pass-through, no codec.
kDynamicType Has is_vlink_dynamic_data() is_dynamic_type Dynamic typed data.
kCdrType Has serialize/deserialize(Cdr&) is_cdr_type FastDDS CDR fast path.
kProtoType Has SerializeToArray/ParseFromArray is_proto_type Protobuf-like value.
kProtoPtrType Pointer with proto serialize/parse is_proto_ptr_type Caller owns the pointee.
kFlatTableType Derives from FB NativeTable is_flat_table_type FlatBuffers object API.
kFlatPtrType Pointer to flatbuffers::Table is_flat_ptr_type Zero-copy FlatBuffers view.
kFlatBuilderType Has fbb_ member and Finish() is_flat_builder_type FlatBuffers builder.
kCustomType Has operator>>/<<(Bytes&) is_custom_type User-supplied codec.
kStringType T == std::string is_string_type UTF-8 string.
kCharsType String-constructible (not string) is_chars_type C string / char*.
kStreamType Streamable via std::stringstream is_stream_type Reached only as fallback.
kStandardType Trivial standard-layout value (POD) is_standard_type sizeof(T) byte copy.
kStandardPtrType Pointer to trivial standard-layout is_standard_ptr_type Zero-copy POD 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
Transport-aware Fast Path
Some transports (e.g. dds://) use pointer passing for CDR types. Use the explicit overloads to opt into the transport-specific path:
vlink::Serializer::serialize<vlink::Serializer::kCdrType>(msg, bytes, vlink::TransportType::kDds);
Note
Most entry points are header-defined templates; a few non-template overloads are declared static or inline where appropriate.
See also
base/bytes.h, impl/types.h