87 #include <string_view>
90 #include "../serializer.h"
147 template <u
int8_t SizeT,
typename T>
148 DynamicData& load(
const char (&type)[SizeT],
const T& t);
161 template <
typename T>
170 template <
typename T>
171 [[nodiscard]] T as()
const;
184 [[nodiscard]]
const std::string_view&
get_type()
const;
208 [[nodiscard]]
static constexpr
bool is_vlink_dynamic_data();
213 [[nodiscard]]
static constexpr uint8_t get_offset();
233 void refresh_type_view(
size_t type_size) noexcept;
235 static constexpr uint8_t kOffset{20};
237 std::string_view type_;
244 template <u
int8_t SizeT,
typename T>
248 static_assert(SizeT <
get_offset(),
"DynamicData name out of size.");
249 static_assert(!Serializer::is_dynamic_type<T>(),
"DynamicData can not serialize self.");
250 static_assert(!Serializer::is_cdr_type<T>(),
"DynamicData can not serialize cdr data.");
252 "DynamicData can not serialize non-owning pointer views.");
259 type_ = std::string_view();
260 VLOG_F(
"DynamicData serialize failed.");
264 data_ = std::move(next_data);
266 if constexpr (SizeT > 0) {
267 std::memcpy(data_.
real_data(), type, SizeT);
269 if constexpr (SizeT < kOffset) {
270 std::memset(data_.
real_data() + SizeT, 0, kOffset - SizeT);
273 size_t name_len = SizeT;
275 if (name_len > 0 && type[SizeT - 1] ==
'\0') {
279 type_ = std::string_view(
reinterpret_cast<const char*
>(data_.
real_data()), name_len);
281 std::memset(data_.
real_data(), 0, kOffset);
282 type_ = std::string_view();
288 template <
typename T>
290 static_assert(!Serializer::is_dynamic_type<T>(),
"DynamicData can not deserialize self.");
291 static_assert(!Serializer::is_cdr_type<T>(),
"DynamicData can not deserialize cdr data.");
300 template <
typename T>
305 t = std::make_shared<typename T::element_type>();
309 VLOG_F(
"DynamicData deserialize failed.");
Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs.
Definition: bytes.h:120
bool empty() const noexcept
Reports whether the buffer is logically empty.
Definition: bytes.h:871
uint8_t * real_data() noexcept
Returns a mutable pointer to the very beginning of the backing buffer.
Definition: bytes.h:855
Type-erased wrapper that pairs an inline type name with a serialised payload.
Definition: dynamic_data.h:103
bool operator>>(Bytes &bytes) const noexcept
Emits the container as a wire-format Bytes blob.
bool operator==(const DynamicData &target) const
Byte-equality comparison.
static constexpr uint8_t get_offset()
Returns the byte offset at which the serialised payload begins (= kOffset).
Definition: dynamic_data.h:318
bool operator!=(const DynamicData &target) const
Byte-inequality comparison.
T as() const
Default-constructs a T (or shared_ptr<T>) and decodes the payload into it.
Definition: dynamic_data.h:301
DynamicData & operator=(const DynamicData &target)
Copy-assignment that 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=(DynamicData &&target) noexcept
Move-assignment that rebinds the local type view and empties the source.
bool is_empty() const
Returns whether the internal buffer is empty.
DynamicData(const DynamicData &target)
Copies the buffer and rebinds the local type view to point into the new buffer.
DynamicData & load(const char(&type)[SizeT], const T &t)
Serialises t under the type tag type into the internal buffer.
Definition: dynamic_data.h:245
bool convert(T &t) const
Deserialises the stored payload into t.
Definition: dynamic_data.h:289
DynamicData()
Builds an empty container with no buffer and no type tag.
bool operator<<(const Bytes &bytes) noexcept
Reconstructs the container from a wire-format Bytes blob.
static constexpr bool is_vlink_dynamic_data()
Compile-time trait used by Serializer to detect DynamicData specialisations.
Definition: dynamic_data.h:316
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.
#define VLOG_F(...)
Definition: logger.h:906
#define VUNLIKELY(...)
Short alias for VLINK_UNLIKELY.
Definition: macros.h:292
#define VLINK_EXPORT
Definition: macros.h:81
Type
Identifies the codec to use for a given C++ message type.
Definition: serializer.h:156
@ kStandardPtrType
Pointer to trivial standard-layout struct (POD pointer).
Definition: serializer.h:172
@ kFlatPtrType
Pointer to flatbuffers::Table (zero-copy view).
Definition: serializer.h:166
bool convert(const SrcT &src, DesT &des)
Converts between two types where at least one side is Bytes.
Definition: serializer-inl.h:824
@ kUnknown
Unknown or unsupported transport.
Detects whether T is (or derives from) a std::shared_ptr specialisation.
Definition: traits.h:203