VLink  2.0.0
A high-performance communication middleware
vlink::DynamicData Class Referencefinal

Type-erased wrapper that pairs an inline type name with a serialised payload. More...

#include <dynamic_data.h>

Collaboration diagram for vlink::DynamicData:

Public Member Functions

 DynamicData ()
 Builds an empty container with no buffer and no type tag. More...
 
 DynamicData (const DynamicData &target)
 Copies the buffer and rebinds the local type view to point into the new buffer. More...
 
 DynamicData (DynamicData &&target) noexcept
 Adopts the source buffer and rebinds the type view to point at this object's storage. More...
 
DynamicDataoperator= (const DynamicData &target)
 Copy-assignment that rebinds the local type view to point into the new buffer. More...
 
DynamicDataoperator= (DynamicData &&target) noexcept
 Move-assignment that rebinds the local type view and empties the source. More...
 
template<uint8_t SizeT, typename T >
DynamicDataload (const char(&type)[SizeT], const T &t)
 Serialises t under the type tag type into the internal buffer. More...
 
template<typename T >
bool convert (T &t) const
 Deserialises the stored payload into t. More...
 
template<typename T >
as () const
 Default-constructs a T (or shared_ptr<T>) and decodes the payload into it. More...
 
const Bytesget_data () const
 Returns the underlying Bytes buffer, including the embedded type name. More...
 
const std::string_view & get_type () const
 Returns the embedded type name as a view into the internal buffer. More...
 
bool is_empty () const
 Returns whether the internal buffer is empty. More...
 
bool operator== (const DynamicData &target) const
 Byte-equality comparison. More...
 
bool operator!= (const DynamicData &target) const
 Byte-inequality comparison. More...
 
bool operator<< (const Bytes &bytes) noexcept
 Reconstructs the container from a wire-format Bytes blob. More...
 
bool operator>> (Bytes &bytes) const noexcept
 Emits the container as a wire-format Bytes blob. More...
 

Static Public Member Functions

static constexpr bool is_vlink_dynamic_data ()
 Compile-time trait used by Serializer to detect DynamicData specialisations. More...
 
static constexpr uint8_t get_offset ()
 Returns the byte offset at which the serialised payload begins (= kOffset). More...
 

Detailed Description

Type-erased wrapper that pairs an inline type name with a serialised payload.

Stores its payload in an internal Bytes buffer; the first kOffset bytes are reserved for the type name and exposed through get_type() as a string_view. Copy and move operations rebind the view to the local buffer to avoid dangling.

Constructor & Destructor Documentation

◆ DynamicData() [1/3]

vlink::DynamicData::DynamicData ( )

Builds an empty container with no buffer and no type tag.

◆ DynamicData() [2/3]

vlink::DynamicData::DynamicData ( const DynamicData target)

Copies the buffer and rebinds the local type view to point into the new buffer.

◆ DynamicData() [3/3]

vlink::DynamicData::DynamicData ( DynamicData &&  target)
noexcept

Adopts the source buffer and rebinds the type view to point at this object's storage.

The moved-from object is left in an empty state with no payload and no type tag.

Member Function Documentation

◆ as()

template<typename T >
T vlink::DynamicData::as
inline

Default-constructs a T (or shared_ptr<T>) and decodes the payload into it.

Template Parameters
TDestination type; specialised for std::shared_ptr to allocate the inner object.
Returns
Decoded instance, or a default-constructed T when decoding fails.
Here is the call graph for this function:

◆ convert()

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

Deserialises the stored payload into t.

Fails when the container is empty or the Serializer cannot decode the buffer (for example because T is incompatible with the embedded payload).

Template Parameters
TDestination type.
Parameters
tOutput reference populated on success.
Returns
true on success; 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

Returns the underlying Bytes buffer, including the embedded type name.

◆ get_offset()

constexpr uint8_t vlink::DynamicData::get_offset ( )
inlinestaticconstexpr

Returns the byte offset at which the serialised payload begins (= kOffset).

Here is the caller graph for this function:

◆ get_type()

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

Returns the embedded type name as a view into the internal buffer.

Only valid for the lifetime of this DynamicData instance.

◆ is_empty()

bool vlink::DynamicData::is_empty ( ) const

Returns whether the internal buffer is empty.

◆ is_vlink_dynamic_data()

constexpr bool vlink::DynamicData::is_vlink_dynamic_data ( )
inlinestaticconstexpr

Compile-time trait used by Serializer to detect DynamicData specialisations.

Returns
Always true.

◆ load()

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

Serialises t under the type tag type into the internal buffer.

Details.

The type literal (including its trailing NUL) must be shorter than kOffset, which is checked at compile time. On serialiser failure the container is reset to empty and an error is logged.

Template Parameters
SizeTLength of the type-name string literal including the NUL terminator.
TSource message type (must be supported by Serializer).
Parameters
typeString literal containing the type-name tag.
tMessage instance to serialise.
Returns
Reference to *this for chaining.
Here is the call graph for this function:

◆ operator!=()

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

Byte-inequality comparison.

◆ operator<<()

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

Reconstructs the container from a wire-format Bytes blob.

Parameters
bytesWire blob previously produced by operator>>.
Returns
true on success.

◆ operator=() [1/2]

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

Copy-assignment that rebinds the local type view to point into the new buffer.

◆ operator=() [2/2]

DynamicData& vlink::DynamicData::operator= ( DynamicData &&  target)
noexcept

Move-assignment that rebinds the local type view and empties the source.

◆ operator==()

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

Byte-equality comparison.

Returns
true when both buffers hold identical bytes.

◆ operator>>()

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

Emits the container as a wire-format Bytes blob.

Parameters
bytesDestination buffer.
Returns
true on success; false when the internal buffer is empty, non-owning, or does not carry the reserved prefix.

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