VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::DynamicData Class Referencefinal

Runtime-typed container that serializes any VLink-compatible message type. More...

#include <dynamic_data.h>

Collaboration diagram for vlink::DynamicData:

Public Member Functions

 DynamicData ()
 Constructs an empty DynamicData with no payload.
template<uint8_t SizeT, typename T>
DynamicDataload (const char(&type)[SizeT], const T &t)
 Serializes t with a type-name tag into the internal buffer.
template<typename T>
bool convert (T &t) const
 Deserializes the internal buffer into t.
template<typename T>
as () const
 Deserializes the internal buffer and returns the result by value.
const Bytesget_data () const
 Returns a const reference to the raw serialized bytes (including type tag).
const std::string_view & get_type () const
 Returns the type name string embedded in the buffer.
bool is_empty () const
 Returns true if no payload has been loaded.
bool operator== (const DynamicData &target) const
 Returns true if both DynamicData objects have identical buffers.
bool operator!= (const DynamicData &target) const
 Returns true if the objects differ.
bool operator<< (const Bytes &bytes) noexcept
 Deserializes a wire-format Bytes blob into this DynamicData.
bool operator>> (Bytes &bytes) const noexcept
 Serializes this DynamicData to a wire-format Bytes blob.

Static Public Member Functions

static constexpr bool is_vlink_dynamic_data ()
 Compile-time trait marker – returns true to identify this as a DynamicData type.
static constexpr uint8_t get_offset ()
 Returns the byte offset where the serialized payload begins.

Detailed Description

Runtime-typed container that serializes any VLink-compatible message type.

Uses Serializer to pack the message into internal Bytes storage. The type tag is embedded in the first kOffset bytes of the buffer.

Constructor & Destructor Documentation

◆ DynamicData()

vlink::DynamicData::DynamicData ( )

Constructs an empty DynamicData with no payload.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ as()

template<typename T>
T vlink::DynamicData::as ( ) const
inlinenodiscard

Deserializes the internal buffer and returns the result by value.

Constructs a default T (or shared_ptr<T> for pointer types) and calls convert(). Returns a default-constructed T on failure.

Template Parameters
TMessage type to deserialize.
Returns
Deserialized instance, or default-constructed value on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert()

template<typename T>
bool vlink::DynamicData::convert ( T & t) const
inline

Deserializes the internal buffer into t.

Uses Serializer to populate t from the payload bytes. Returns false if the buffer is empty or deserialisation fails.

Template Parameters
TMessage type to deserialize into.
Parameters
tOutput parameter populated on success.
Returns
true if deserialization succeeded; false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_data()

const Bytes & vlink::DynamicData::get_data ( ) const
nodiscard

Returns a const reference to the raw serialized bytes (including type tag).

Returns
Internal Bytes buffer.

◆ get_offset()

uint8_t vlink::DynamicData::get_offset ( )
inlinestaticnodiscardconstexpr

Returns the byte offset where the serialized payload begins.

Equal to kOffset (20). The first kOffset bytes are reserved for the type name.

Returns
Offset value (20).
Here is the caller graph for this function:

◆ get_type()

const std::string_view & vlink::DynamicData::get_type ( ) const
nodiscard

Returns the type name string embedded in the buffer.

Points into the first kOffset bytes of the internal Bytes buffer. The view is only valid for the lifetime of this DynamicData instance.

Returns
string_view of the type name.

◆ is_empty()

bool vlink::DynamicData::is_empty ( ) const
nodiscard

Returns true if no payload has been loaded.

Returns
true if the internal Bytes buffer is empty.

◆ is_vlink_dynamic_data()

bool vlink::DynamicData::is_vlink_dynamic_data ( )
inlinestaticnodiscardconstexpr

Compile-time trait marker – returns true to identify this as a DynamicData type.

Used internally by Serializer via template specialisation detection.

Returns
Always true.
Here is the caller graph for this function:

◆ load()

template<uint8_t SizeT, typename T>
DynamicData & vlink::DynamicData::load ( const char(&) type[SizeT],
const T & t )
inline

Serializes t with a type-name tag into the internal buffer.

Details.

The type name is stored in the first kOffset bytes of the underlying Bytes buffer. A static_assert enforces that SizeT < kOffset (20).

Template Parameters
SizeTLength of the type-name string literal including NUL.
TMessage type to serialize (must be supported by Serializer).
Parameters
typeType name string literal, e.g., "MyProtoMsg".
tMessage instance to serialize.
Returns
Reference to *this for chaining.
Note
Logs a failure if serialisation returns false.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool vlink::DynamicData::operator!= ( const DynamicData & target) const
nodiscard

Returns true if the objects differ.

Parameters
targetRight-hand side.
Returns
true if the raw bytes differ.
Here is the call graph for this function:

◆ operator<<()

bool vlink::DynamicData::operator<< ( const Bytes & bytes)
noexcept

Deserializes a wire-format Bytes blob into this DynamicData.

Parameters
bytesWire-format bytes produced by operator>>.
Returns
true on success; false if parsing failed.

◆ operator==()

bool vlink::DynamicData::operator== ( const DynamicData & target) const
nodiscard

Returns true if both DynamicData objects have identical buffers.

Parameters
targetRight-hand side.
Returns
true if the raw bytes are equal.
Here is the call graph for this function:

◆ operator>>()

bool vlink::DynamicData::operator>> ( Bytes & bytes) const
noexcept

Serializes this DynamicData to a wire-format Bytes blob.

Parameters
bytesOutput buffer.
Returns
true on success; false if the internal buffer is empty.

The documentation for this class was generated from the following file: