VLink  2.0.0
A high-performance communication middleware
vlink::DynamicData类 参考final

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

#include <dynamic_data.h>

vlink::DynamicData 的协作图:

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. 更多...
 
DynamicDataoperator= (const DynamicData &target)
 Copy-assignment that rebinds the local type view to point into the new buffer. 更多...
 
DynamicDataoperator= (DynamicData &&target) noexcept
 Move-assignment that rebinds the local type view and empties the source. 更多...
 
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. 更多...
 
template<typename T >
bool convert (T &t) const
 Deserialises the stored payload into t. 更多...
 
template<typename T >
as () const
 Default-constructs a T (or shared_ptr<T>) and decodes the payload into it. 更多...
 
const Bytesget_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.

构造及析构函数说明

◆ 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()

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

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

模板参数
TDestination type; specialised for std::shared_ptr to allocate the inner object.
返回
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).

模板参数
TDestination type.
参数
tOutput reference populated on success.
返回
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

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

返回
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.

模板参数
SizeTLength of the type-name string literal including the NUL terminator.
TSource message type (must be supported by Serializer).
参数
typeString literal containing the type-name tag.
tMessage instance to serialise.
返回
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.

参数
bytesWire blob previously produced by operator>>.
返回
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.

返回
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.

参数
bytesDestination buffer.
返回
true on success; false when the internal buffer is empty, non-owning, or does not carry the reserved prefix.

该类的文档由以下文件生成: