VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
serializer.h File Reference

Compile-time type-detection and serialisation utilities for VLink messages. 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

namespace  Serializer
 Compile-time type detection and codec dispatch for VLink messages.

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

Functions

constexpr bool vlink::Serializer::is_supported (Type type) noexcept
 Returns true when type identifies a supported serializer.

Detailed Description

Compile-time type-detection and serialisation utilities for VLink messages.

The Serializer namespace provides a unified serialisation and deserialisation interface that automatically selects the correct codec based on the C++ type of the message via constexpr if chains.

Supported Serializer Types
Type constant C++ Type Criteria Notes
kBytesType T == Bytes Pass-through, no-copy.
kDynamicType Has is_vlink_dynamic_data() member Dynamic type via operator>>/<<
kCdrType Has serialize(Cdr&) and deserialize(Cdr&) FastDDS CDR codec.
kProtoType Has SerializeToArray() and ParseFromArray() Protobuf by value.
kProtoPtrType Pointer with SerializeToArray / ParseFromArray Arena-managed proto pointer.
kFlatTableType Inherits flatbuffers::NativeTable FlatBuffers native table.
kFlatPtrType Pointer to flatbuffers::Table subclass Zero-copy FlatBuffers read.
kFlatBuilderType Has fbb_ member and Finish() FlatBuffers builder.
kCustomType Has operator>>(Bytes&) and operator<<(const Bytes&) User-defined codec.
kStringType T == std::string UTF-8 string.
kCharsType Constructible as std::string but not std::string C string literal / char*.
kStreamType Has operator<< and operator>> with stringstream Stream-based text encoding.
kStandardType Trivial standard-layout value (POD) Byte-copied directly.
kStandardPtrType Pointer to trivial standard-layout type Zero-copy POD pointer.
Type Detection
// At compile time, get the Type enumerator for any message type:
constexpr auto t = Serializer::get_type_of<MyMsg>(); // e.g. kProtoType
static_assert(Serializer::is_supported(t), "");
Serialize and Deserialize
MyProto msg;
Bytes bytes;
Serializer::serialize(msg, bytes); // MyProto -> Bytes
MyProto out;
Serializer::deserialize(bytes, out); // Bytes -> MyProto
Custom Type
Implement operator>> and operator<< on your type:
struct MyCustomMsg {
int x;
void operator>>(vlink::Bytes& out) const { ... } // serialize
void operator<<(const vlink::Bytes& in) { ... } // deserialize
};
// Now Serializer::get_type_of<MyCustomMsg>() == kCustomType
Transport-aware Serialization
Some transports (e.g. dds://) use a special fast-path for CDR types (pointer passing instead of byte-copy). Pass the TransportType to the explicit overloads to activate the transport-specific path:
Serializer::serialize<kCdrType>(msg, bytes, TransportType::kDds);
Note
All functions in this namespace are static and inline. The namespace name starts with a capital letter by convention (matches VLink style). Direct use by application code is rarely needed; the framework calls these functions automatically inside publish(), listen(), invoke(), etc.