Type-erased wrapper that pairs an inline type name with a serialised payload.
More...
#include <dynamic_data.h>
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.
◆ 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.
◆ as()
Default-constructs a T (or shared_ptr<T>) and decodes the payload into it.
- Template Parameters
-
| T | Destination type; specialised for std::shared_ptr to allocate the inner object. |
- Returns
- Decoded instance, or a default-constructed
T when decoding fails.
◆ 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
-
- Parameters
-
| t | Output reference populated on success. |
- Returns
true on success; false otherwise.
◆ 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).
◆ 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 |
◆ 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
-
| SizeT | Length of the type-name string literal including the NUL terminator. |
| T | Source message type (must be supported by Serializer). |
- Parameters
-
| type | String literal containing the type-name tag. |
| t | Message instance to serialise. |
- Returns
- Reference to
*this for chaining.
◆ 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
-
| bytes | Wire blob previously produced by operator>>. |
- Returns
true on success.
◆ operator=() [1/2]
Copy-assignment that rebinds the local type view to point into the new buffer.
◆ operator=() [2/2]
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
-
- 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: