|
VLink
2.0.0
A high-performance communication middleware
|
Type-erased wrapper that pairs an inline type name with a serialised payload. 更多...
#include <dynamic_data.h>
Public 成员函数 | |
| DynamicData () | |
| Builds an empty container with no buffer and no type tag. 更多... | |
| DynamicData (const DynamicData &target) | |
| Copies the buffer and rebinds the local type view to point into the new buffer. 更多... | |
| DynamicData (DynamicData &&target) noexcept | |
| Adopts the source buffer and rebinds the type view to point at this object's storage. 更多... | |
| DynamicData & | operator= (const DynamicData &target) |
| Copy-assignment that rebinds the local type view to point into the new buffer. 更多... | |
| DynamicData & | operator= (DynamicData &&target) noexcept |
| Move-assignment that rebinds the local type view and empties the source. 更多... | |
| template<uint8_t SizeT, typename T > | |
| DynamicData & | load (const char(&type)[SizeT], const T &t) |
Serialises t under the type tag type into the internal buffer. 更多... | |
| template<typename T > | |
| bool | convert (T &t) const |
Deserialises the stored payload into t. 更多... | |
| template<typename T > | |
| T | as () const |
Default-constructs a T (or shared_ptr<T>) and decodes the payload into it. 更多... | |
| const Bytes & | get_data () const |
Returns the underlying Bytes buffer, including the embedded type name. 更多... | |
| const std::string_view & | get_type () const |
| Returns the embedded type name as a view into the internal buffer. 更多... | |
| bool | is_empty () const |
| Returns whether the internal buffer is empty. 更多... | |
| bool | operator== (const DynamicData &target) const |
| Byte-equality comparison. 更多... | |
| bool | operator!= (const DynamicData &target) const |
| Byte-inequality comparison. 更多... | |
| bool | operator<< (const Bytes &bytes) noexcept |
Reconstructs the container from a wire-format Bytes blob. 更多... | |
| bool | operator>> (Bytes &bytes) const noexcept |
Emits the container as a wire-format Bytes blob. 更多... | |
静态 Public 成员函数 | |
| static constexpr bool | is_vlink_dynamic_data () |
Compile-time trait used by Serializer to detect DynamicData specialisations. 更多... | |
| static constexpr uint8_t | get_offset () |
Returns the byte offset at which the serialised payload begins (= kOffset). 更多... | |
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.
| vlink::DynamicData::DynamicData | ( | ) |
Builds an empty container with no buffer and no type tag.
| vlink::DynamicData::DynamicData | ( | const DynamicData & | target | ) |
Copies the buffer and rebinds the local type view to point into the new buffer.
|
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.
|
inline |
Default-constructs a T (or shared_ptr<T>) and decodes the payload into it.
| T | Destination type; specialised for std::shared_ptr to allocate the inner object. |
T when decoding fails.
|
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).
| T | Destination type. |
| t | Output reference populated on success. |
true on success; false otherwise. | const Bytes& vlink::DynamicData::get_data | ( | ) | const |
Returns the underlying Bytes buffer, including the embedded type name.
|
inlinestaticconstexpr |
Returns the byte offset at which the serialised payload begins (= kOffset).
| 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.
| bool vlink::DynamicData::is_empty | ( | ) | const |
Returns whether the internal buffer is empty.
|
inlinestaticconstexpr |
Compile-time trait used by Serializer to detect DynamicData specialisations.
true.
|
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.
| SizeT | Length of the type-name string literal including the NUL terminator. |
| T | Source message type (must be supported by Serializer). |
| type | String literal containing the type-name tag. |
| t | Message instance to serialise. |
*this for chaining. | bool vlink::DynamicData::operator!= | ( | const DynamicData & | target | ) | const |
Byte-inequality comparison.
|
noexcept |
Reconstructs the container from a wire-format Bytes blob.
| bytes | Wire blob previously produced by operator>>. |
true on success. | DynamicData& vlink::DynamicData::operator= | ( | const DynamicData & | target | ) |
Copy-assignment that rebinds the local type view to point into the new buffer.
|
noexcept |
Move-assignment that rebinds the local type view and empties the source.
| bool vlink::DynamicData::operator== | ( | const DynamicData & | target | ) | const |
Byte-equality comparison.
true when both buffers hold identical bytes.
|
noexcept |
Emits the container as a wire-format Bytes blob.
| bytes | Destination buffer. |
true on success; false when the internal buffer is empty, non-owning, or does not carry the reserved prefix.