VLink  2.3.0
A high-performance communication middleware
serializer.h
浏览该文件的文档.
1 /*
2  * Copyright (C) 2026 by Thun Lu. All rights reserved.
3  * Author: Thun Lu <thun.lu@zohomail.cn>
4  * Repo: https://github.com/thun-res/vlink
5  * _ __ __ _ __
6  * | | / / / / (_) ____ / /__
7  * | | / / / / / / / __ \ / //_/
8  * | |/ / / /___ / / / / / / / ,<
9  * |___/ /_____/ /_/ /_/ /_/ /_/|_|
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 
24 /**
25  * @file serializer.h
26  * @brief Compile-time codec dispatch for VLink message payloads.
27  *
28  * @details
29  * The @c Serializer namespace is the codec router used by every VLink
30  * primitive. Given a C++ type @c T it determines, at compile time, which
31  * encoding family applies (raw bytes, Protobuf, FlatBuffers, FastDDS CDR,
32  * standard-layout POD, etc.) and dispatches @c serialize() / @c deserialize()
33  * to the appropriate code path with zero runtime cost.
34  *
35  * Application code rarely calls these helpers directly; @c Publisher,
36  * @c Subscriber, @c Client, @c Server, @c Setter, and @c Getter call them
37  * internally as part of their @c publish() / @c listen() / @c invoke() /
38  * @c set() / @c get() implementations.
39  *
40  * @par Codec Table -- @c Serializer::Type Enum
41  * | Constant | C++ criterion | Trait | Notes |
42  * | -------------------- | -------------------------------- | ----------------------- | ------------------ |
43  * | @c kBytesType | @c T is @c Bytes | @c is_bytes_type | Pass-through. |
44  * | @c kDynamicType | Has @c is_vlink_dynamic_data() | @c is_dynamic_type | Dynamic data. |
45  * | @c kCustomType | Has @c operator>>/<<(Bytes&) | @c is_custom_type | Custom codec. |
46  * | @c kSomeipType | Has @c is_vlink_someip_type() | @c is_someip_type | SOME/IP codec. |
47  * | @c kCdrType | FastDDS IDL or ROS 2 type | @c is_cdr_type | CDR bytes. |
48  * | @c kProtoType | Protobuf-like value | @c is_proto_type | Protobuf value. |
49  * | @c kProtoPtrType | Protobuf-like pointer | @c is_proto_ptr_type | Caller-owned. |
50  * | @c kFlatTableType | FlatBuffers NativeTable | @c is_flat_table_type | Object API. |
51  * | @c kFlatPtrType | Pointer to @c flatbuffers::Table | @c is_flat_ptr_type | Zero-copy view. |
52  * | @c kFlatBuilderType | Has @c fbb_ and @c Finish() | @c is_flat_builder_type | Builder. |
53  * | @c kStringType | @c T is @c std::string | @c is_string_type | Byte string. |
54  * | @c kCharsType | Character pointer or array | @c is_chars_type | Serialise only. |
55  * | @c kStreamType | Supports @c std::stringstream | @c is_stream_type | Fallback. |
56  * | @c kStandardType | Trivial standard-layout value | @c is_standard_type | Byte copy. |
57  * | @c kStandardPtrType | Pointer to trivial standard type | @c is_standard_ptr_type | Zero-copy pointer. |
58  *
59  * Most value-like detectors unwrap @c std::shared_ptr<T> before matching
60  * (e.g. Protobuf values, CDR values, FlatBuffers native tables, custom
61  * codecs, strings, stream types, and standard-layout values).
62  * @par Detection Precedence Flow
63  * @verbatim
64  * get_type_of<T>() probes traits in this fixed order; first match wins:
65  *
66  * Bytes --(no)--> Dynamic --(no)--> SOME/IP --(no)--> CDR
67  * |
68  * v (no)
69  * FlatTable <--(no)-- ProtoPtr <--(no)-- Proto <----(no)--+
70  * |
71  * v (no)
72  * FlatPtr --(no)--> FlatBuilder --(no)--> Custom --(no)--> String
73  * |
74  * v (no)
75  * Stream <--(no)-- StandardPtr <--(no)-- Standard <--(no)-- Chars
76  * |
77  * v (no)
78  * kUnknownType
79  * @endverbatim
80  *
81  * @par Type Detection Example
82  * @code
83  * constexpr auto t = vlink::Serializer::get_type_of<MyProto>(); // -> kProtoType
84  * static_assert(vlink::Serializer::is_supported(t));
85  *
86  * constexpr auto u = vlink::Serializer::get_type_of<int>(); // -> kStandardType (POD)
87  * constexpr auto v = vlink::Serializer::get_type_of<std::string>(); // -> kStringType
88  * constexpr auto w = vlink::Serializer::get_type_of<const char*>(); // -> kCharsType
89  * @endcode
90  *
91  * @par Serialise and Deserialise
92  * @code
93  * MyProto msg;
94  * vlink::Bytes bytes;
95  * vlink::Serializer::serialize(msg, bytes);
96  *
97  * MyProto out;
98  * vlink::Serializer::deserialize(bytes, out);
99  * @endcode
100  *
101  * @par Custom Codec
102  * @code
103  * struct MyCustomMsg {
104  * int x;
105  * void operator>>(vlink::Bytes& out) const { ... } // serialise
106  * void operator<<(const vlink::Bytes& in) { ... } // deserialise
107  * };
108  * // vlink::Serializer::get_type_of<MyCustomMsg>() == vlink::Serializer::kCustomType
109  * @endcode
110  *
111  * @par Explicit Codec Selection
112  * CDR serialization produces a byte stream containing the 4-byte DDS
113  * encapsulation header. Use the explicit overload when the codec cannot be
114  * inferred from @c T:
115  * @code
116  * vlink::Serializer::serialize<vlink::Serializer::kCdrType>(msg, bytes, vlink::TransportType::kDds);
117  * @endcode
118  *
119  * @note Most entry points are header-defined templates; a few non-template
120  * overloads are declared @c static or @c inline where appropriate.
121  *
122  * @see base/bytes.h, impl/types.h
123  */
124 
125 #pragma once
126 
127 #include <cstddef>
128 #include <string>
129 
130 #include "./base/bytes.h"
131 #include "./impl/types.h"
132 
133 namespace vlink {
134 
135 /**
136  * @namespace Serializer
137  * @brief Compile-time codec detection and dispatch for VLink message payloads.
138  *
139  * @details
140  * Header-defined helper namespace. Most entry points are templates so the
141  * full codec chain is resolved at compile time. Application code rarely
142  * uses this namespace directly; the framework invokes it internally inside
143  * @c publish() / @c listen() / @c invoke() / @c set() / @c get().
144  */
145 namespace Serializer { // NOLINT(readability-identifier-naming)
146 
147 /**
148  * @enum Type
149  * @brief Identifies the codec to use for a given C++ message type.
150  *
151  * @details
152  * Resolved at compile time by @c get_type_of<T>() and stored as a
153  * @c constexpr member on every primitive class, so all codec dispatch is
154  * zero-cost at runtime.
155  */
156 enum Type : uint8_t {
157  kUnknownType = 0, ///< Unsupported type; @c is_supported() returns @c false.
158  kBytesType = 1, ///< @c Bytes -- raw byte pass-through.
159  kDynamicType = 2, ///< VLink dynamic typed data.
160  kCustomType = 3, ///< User-defined codec via @c operator>>/<<.
161  kSomeipType = 4, ///< Macro-declared SOME/IP structure via @c operator>>/<<.
162  kCdrType = 5, ///< FastDDS CDR via @c serialize(Cdr&) / @c deserialize(Cdr&).
163  kProtoType = 6, ///< Protobuf-like value.
164  kProtoPtrType = 7, ///< Protobuf-like raw pointer; caller-owned.
165  kFlatTableType = 8, ///< FlatBuffers NativeTable (object API).
166  kFlatPtrType = 9, ///< Pointer to @c flatbuffers::Table (zero-copy view).
167  kFlatBuilderType = 10, ///< FlatBuffers builder (@c fbb_ + @c Finish()).
168  kStringType = 11, ///< @c std::string payload bytes; no text-encoding validation.
169  kCharsType = 12, ///< C string serialisation; deserialise as @c std::string.
170  kStreamType = 13, ///< Stream-serialisable via @c std::stringstream.
171  kStandardType = 14, ///< Trivial standard-layout struct (POD value).
172  kStandardPtrType = 15, ///< Pointer to trivial standard-layout struct (POD pointer).
173 };
174 
175 /**
176  * @brief Reports whether @p type identifies a usable codec.
177  *
178  * @details
179  * @c kUnknownType is the only unsupported value. Support may be directional:
180  * @c kCharsType supports C-string serialisation but requires @c std::string on
181  * the deserialisation side. This function is invoked from the @c static_assert
182  * in every primitive constructor so unknown message types fail at compile time
183  * with a clear diagnostic.
184  *
185  * @param type Codec enumerator.
186  * @return @c false only for @c kUnknownType.
187  */
188 [[maybe_unused]] [[nodiscard]] static constexpr bool is_supported(Type type) noexcept;
189 
190 /**
191  * @brief Resolves the codec @c Type for @c T at compile time.
192  *
193  * @details
194  * Evaluates the @c if-constexpr chain documented above and returns the
195  * first matching enumerator. Returns @c kUnknownType if no codec matches.
196  *
197  * @tparam T C++ message type to classify.
198  * @return Resolved @c Type enumerator.
199  */
200 template <typename T>
201 [[nodiscard]] static constexpr Type get_type_of() noexcept;
202 
203 /**
204  * @brief Returns the coarse schema family for @c T with an explicit codec tag.
205  *
206  * @tparam TypeT Explicit VLink codec kind.
207  * @tparam T C++ message type to classify.
208  * @return @c SchemaType::kProtobuf, @c kFlatbuffers, @c kZeroCopy, @c kCdr, or @c kRaw.
209  */
210 template <Type TypeT, typename T>
211 [[nodiscard]] static constexpr SchemaType get_schema_type() noexcept;
212 
213 /**
214  * @brief Returns the coarse schema family inferred from @c T alone.
215  *
216  * @tparam T C++ message type to classify.
217  * @return @c SchemaType::kProtobuf, @c kFlatbuffers, @c kZeroCopy, @c kCdr, or @c kRaw.
218  */
219 template <typename T>
220 [[nodiscard]] static constexpr SchemaType get_schema_type() noexcept;
221 
222 /**
223  * @brief Returns the serialised type-name string for @c T with explicit codec tag.
224  *
225  * @details
226  * Used by the framework for cross-peer type matching (DDS topic type name,
227  * Protobuf fully-qualified name, FlatBuffers table name, etc.). Returns an
228  * empty string for codecs with no meaningful type name (e.g. @c kBytesType).
229  *
230  * @tparam TypeT Explicit codec kind.
231  * @tparam T C++ message type.
232  * @return Type-name string; empty if not applicable.
233  */
234 template <Type TypeT, typename T>
235 [[nodiscard]] static std::string get_serialized_type() noexcept;
236 
237 /**
238  * @brief Returns the serialised type-name string for @c T (codec auto-detected).
239  *
240  * @tparam T C++ message type.
241  * @return Type-name string; empty if not applicable.
242  */
243 template <typename T>
244 [[nodiscard]] static std::string get_serialized_type() noexcept;
245 
246 /**
247  * @brief Returns a serialised-size hint for @p src with explicit codec tag.
248  *
249  * @details
250  * Used to size loaned buffers ahead of serialisation. The returned value is
251  * an exact byte count only for codecs that can produce one cheaply; it is
252  * @c 0 for codecs that cannot report an upfront size (e.g. @c kBytesType,
253  * @c kStringType, @c kFlatTableType, @c kStandardType).
254  *
255  * @tparam TypeT Codec kind.
256  * @tparam T C++ message type.
257  * @param src Source value to measure.
258  * @return Byte-count hint; @c 0 if unknown.
259  */
260 template <Type TypeT, typename T>
261 [[nodiscard]] static size_t get_serialized_size(const T& src) noexcept;
262 
263 /**
264  * @brief Returns a serialised-size hint for @p src (codec auto-detected).
265  *
266  * @tparam T C++ message type.
267  * @param src Source value to measure.
268  * @return Byte-count hint; @c 0 if unknown.
269  */
270 template <typename T>
271 [[nodiscard]] static size_t get_serialized_size(const T& src) noexcept;
272 
273 /**
274  * @brief Serialises @p src into @p des with explicit codec and transport tags.
275  *
276  * @details
277  * @p transport identifies the active transport. CDR output is the same
278  * encapsulated byte representation for every transport. @p offset reserves
279  * that many bytes before the payload for transport framing; their initial
280  * contents are unspecified.
281  *
282  * For @c kFlatBuilderType, serialisation calls the builder's @c Finish()
283  * path so @p src may be mutated. Because the final size is unavailable
284  * before @c Finish(), its size hint is @c 0 and a loaned destination is
285  * rejected without changing either the loan or the builder. Successful
286  * serialisation returns an owning copy.
287  *
288  * When @c TypeT is @c kSomeipType, destination storage must not overlap
289  * any storage reachable from @p src.
290  *
291  * @tparam TypeT Codec kind.
292  * @tparam T C++ message type.
293  * @param src Source value to serialise.
294  * @param des Destination @c Bytes buffer (may be loaned).
295  * @param transport Active transport back-end.
296  * @param offset Number of header bytes to prepend (default @c 0).
297  * @return @c true on success; @c false on codec failure.
298  */
299 template <Type TypeT, typename T>
300 static bool serialize(const T& src, Bytes& des, TransportType transport = TransportType::kUnknown, uint8_t offset = 0);
301 
302 /**
303  * @brief Serialises @p src into @p des (codec and transport auto-detected).
304  *
305  * @details
306  * When @c T is inferred as @c kSomeipType, destination storage must not
307  * overlap any storage reachable from @p src.
308  *
309  * @tparam T C++ message type.
310  * @param src Source value.
311  * @param des Destination @c Bytes buffer.
312  * @return @c true on success.
313  */
314 template <typename T>
315 static bool serialize(const T& src, Bytes& des);
316 
317 /**
318  * @brief Serialises into transport-provided storage when available.
319  *
320  * @details
321  * When @p use_loan is true and a non-zero size hint is available, @p loan is
322  * called and may return either loaned or owning storage. A zero hint falls
323  * back to normal owning serialisation. FlatBuilder sources are finished
324  * before requesting their exact-size destination, including when that request
325  * subsequently fails. Other codecs use @c get_serialized_size() followed by
326  * the normal @c serialize() path. A non-zero size hint requires storage of
327  * exactly that size. A codec must not replace transport-loaned storage.
328  * For @c kSomeipType, storage returned by @p loan must not overlap any
329  * storage reachable from @p src.
330  *
331  * @tparam TypeT Codec kind.
332  * @tparam T C++ message type.
333  * @tparam LoanCallbackT Callable compatible with @c Bytes(size_t).
334  * @param src Source value to serialise.
335  * @param des Destination populated on success; it may be modified on failure.
336  * @param transport Active transport back-end.
337  * @param use_loan Whether to request transport-provided storage.
338  * @param loan Destination provider called at most once.
339  * @return @c true on success; @c false on allocation, size, or codec failure.
340  */
341 template <Type TypeT, typename T, typename LoanCallbackT>
342 static bool serialize_to_transport(const T& src, Bytes& des, TransportType transport, bool use_loan,
343  LoanCallbackT&& loan);
344 
345 /**
346  * @brief Deserialises @p src into @p des with explicit codec and transport tags.
347  *
348  * @details
349  * CDR input must contain its DDS encapsulation header and is decoded
350  * identically for every transport. @c kCharsType destinations are rejected
351  * because a raw pointer cannot carry ownership of the required null-terminated
352  * storage. Use @c std::string for deserialisation. When @c TypeT is
353  * @c kSomeipType, source storage must not overlap any storage reachable from
354  * @p des. Exceptions raised by Dynamic or Custom decoding operators retain
355  * the operator's own exception contract.
356  *
357  * @tparam TypeT Codec kind.
358  * @tparam T C++ message type.
359  * @param src Source @c Bytes buffer.
360  * @param des Destination value to fill.
361  * @param transport Active transport back-end.
362  * @return @c true on success; @c false on parse failure.
363  */
364 template <Type TypeT, typename T>
365 static bool deserialize(const Bytes& src, T& des, TransportType transport = TransportType::kUnknown);
366 
367 /**
368  * @brief Deserialises @p src into @p des (codec and transport auto-detected).
369  *
370  * @details
371  * When @c T is inferred as @c kSomeipType, source storage must not overlap
372  * any storage reachable from @p des. Exceptions raised by inferred Dynamic
373  * or Custom decoding operators retain the operator's own exception contract.
374  *
375  * @tparam T C++ message type.
376  * @param src Source @c Bytes buffer.
377  * @param des Destination value.
378  * @return @c true on success.
379  */
380 template <typename T>
381 static bool deserialize(const Bytes& src, T& des);
382 
383 /**
384  * @brief Converts between two types where at least one side is @c Bytes.
385  *
386  * @details
387  * A compile-time @c static_assert enforces that @c SrcT or @c DesT (or both)
388  * is @c Bytes. The three cases are:
389  * - Both @c Bytes: shallow-copies @p src to @p des.
390  * - @c DesT == @c Bytes: dispatches to @c serialize().
391  * - @c SrcT == @c Bytes: dispatches to @c deserialize().
392  *
393  * @tparam SrcT Source type.
394  * @tparam DesT Destination type.
395  * @param src Source value.
396  * @param des Destination value.
397  * @return @c true on success.
398  */
399 template <typename SrcT, typename DesT>
400 static bool convert(const SrcT& src, DesT& des);
401 
402 /**
403  * @brief Dereferences a value, unwrapping @c std::shared_ptr when present.
404  *
405  * @details
406  * If @c T is @c std::shared_ptr<U>, returns @c *t; otherwise returns @c t.
407  * Internal helper so codec code can treat both value and shared-pointer
408  * inputs uniformly.
409  *
410  * @tparam T Input type (value or @c shared_ptr).
411  * @param t Input value.
412  * @return Reference to the underlying value.
413  */
414 template <typename T>
415 [[nodiscard]] static constexpr auto& deref(const T& t) noexcept;
416 
417 /**
418  * @brief Reports whether @c T is exactly @c Bytes.
419  *
420  * @tparam T Type to test.
421  * @return @c true for @c Bytes.
422  */
423 template <typename T>
424 [[nodiscard]] static constexpr bool is_bytes_type() noexcept;
425 
426 /**
427  * @brief Reports whether @c T is a VLink dynamic data type.
428  *
429  * @details
430  * Dynamic types expose an @c is_vlink_dynamic_data() member.
431  *
432  * @tparam T Type to test.
433  * @return @c true for dynamic data types.
434  */
435 template <typename T>
436 [[nodiscard]] static constexpr bool is_dynamic_type() noexcept;
437 
438 /**
439  * @brief Reports whether @c T is a FastDDS CDR-serialisable type.
440  *
441  * @details
442  * Requires @c VLINK_HAS_CDR, plus either both
443  * @c serialize(Cdr&) and @c deserialize(Cdr&) methods, or a type name
444  * carrying the @c VLINK_DDS_IDL_PREFIX prefix. When @c VLINK_HAS_ROS2 is
445  * defined, ROS2 message traits are also recognised.
446  *
447  * @tparam T Type to test.
448  * @return @c true for supported CDR types.
449  */
450 template <typename T>
451 [[nodiscard]] static constexpr bool is_cdr_type() noexcept;
452 
453 /**
454  * @brief Reports whether @c T is a Protobuf-like message value type.
455  *
456  * @details
457  * Requires Protobuf to be available and the type to expose
458  * @c SerializeToArray() and @c ParseFromArray() methods.
459  *
460  * @tparam T Type to test.
461  * @return @c true for Protobuf-compatible value types.
462  */
463 template <typename T>
464 [[nodiscard]] static constexpr bool is_proto_type() noexcept;
465 
466 /**
467  * @brief Reports whether @c T is a raw pointer to a Protobuf-like message.
468  *
469  * @details
470  * The pointee is not owned by the serialiser and must be non-null whenever
471  * the codec path dereferences it.
472  *
473  * @tparam T Pointer type to test.
474  * @return @c true for Protobuf-compatible pointer types.
475  */
476 template <typename T>
477 [[nodiscard]] static constexpr bool is_proto_ptr_type() noexcept;
478 
479 /**
480  * @brief Reports whether @c T is a FlatBuffers NativeTable type.
481  *
482  * @details
483  * Requires @c flatbuffers and the type (or its @c shared_ptr element type)
484  * to derive from @c flatbuffers::NativeTable.
485  *
486  * @tparam T Type to test.
487  * @return @c true for FlatBuffers NativeTable types.
488  */
489 template <typename T>
490 [[nodiscard]] static constexpr bool is_flat_table_type() noexcept;
491 
492 /**
493  * @brief Reports whether @c T is a FlatBuffers builder type.
494  *
495  * @details
496  * Requires @c flatbuffers and the type to expose both an @c fbb_ member
497  * and a @c Finish() method.
498  *
499  * @tparam T Type to test.
500  * @return @c true for FlatBuffers builder types.
501  */
502 template <typename T>
503 [[nodiscard]] static constexpr bool is_flat_builder_type() noexcept;
504 
505 /**
506  * @brief Reports whether @c T is a raw pointer to a @c flatbuffers::Table.
507  *
508  * @tparam T Pointer type to test.
509  * @return @c true for FlatBuffers Table pointer types.
510  */
511 template <typename T>
512 [[nodiscard]] static constexpr bool is_flat_ptr_type() noexcept;
513 
514 /**
515  * @brief Reports whether @c T is a macro-declared SOME/IP structure.
516  *
517  * @details
518  * Detects the static @c is_vlink_someip_type() marker generated by
519  * @c VLINK_SOMEIP_FIELDS after unwrapping @c std::shared_ptr.
520  *
521  * @tparam T Type to test.
522  * @return @c true for macro-declared SOME/IP structures.
523  */
524 template <typename T>
525 [[nodiscard]] static constexpr bool is_someip_type() noexcept;
526 
527 /**
528  * @brief Reports whether @c T provides a custom @c operator>>/<< codec.
529  *
530  * @details
531  * Checked via @c Traits::Operatorable for @c operator>>(Bytes&) and
532  * @c operator<<(const Bytes&).
533  *
534  * @tparam T Type to test.
535  * @return @c true for custom-codec types.
536  */
537 template <typename T>
538 [[nodiscard]] static constexpr bool is_custom_type() noexcept;
539 
540 /**
541  * @brief Reports whether @c T is @c std::string after unwrapping @c shared_ptr.
542  *
543  * @tparam T Type to test.
544  * @return @c true for @c std::string and @c std::shared_ptr<std::string>.
545  */
546 template <typename T>
547 [[nodiscard]] static constexpr bool is_string_type() noexcept;
548 
549 /**
550  * @brief Reports whether @c T is a pointer or array of non-volatile @c char.
551  *
552  * @details
553  * Matches @c char*, @c const char*, and string literal source types for
554  * serialisation. Deserialisation into a raw character pointer is rejected
555  * because the pointer cannot own the decoded storage; use @c std::string as
556  * the destination. The trait deliberately excludes other string-like types
557  * such as @c std::string_view because the chars codec requires a null-terminated
558  * source when serialising. Arrays must contain a null terminator within their
559  * extent; pointer callers must guarantee that a terminator is reachable. Bytes
560  * after the first terminator are ignored.
561  *
562  * @tparam T Type to test.
563  * @return @c true for C-string-compatible types.
564  */
565 template <typename T>
566 [[nodiscard]] static constexpr bool is_chars_type() noexcept;
567 
568 /**
569  * @brief Reports whether @c T supports bidirectional @c std::stringstream streaming.
570  *
571  * @details
572  * Detected via @c Traits::Operatorable<std::stringstream, T>(); the check
573  * requires both @c ss << t and @c ss >> t to be well-formed. Higher-priority
574  * codecs are checked first in @c get_type_of(), so this function is only
575  * reached for types that fail every earlier trait.
576  *
577  * @tparam T Type to test.
578  * @return @c true for stream-serialisable types.
579  */
580 template <typename T>
581 [[nodiscard]] static constexpr bool is_stream_type() noexcept;
582 
583 /**
584  * @brief Reports whether @c T is a trivial standard-layout value (POD).
585  *
586  * @details
587  * Matches non-pointer types where both @c std::is_trivial_v and
588  * @c std::is_standard_layout_v hold. Such types are byte-copied into and
589  * out of a @c Bytes buffer of @c sizeof(T) bytes.
590  *
591  * @tparam T Type to test.
592  * @return @c true for POD value types.
593  */
594 template <typename T>
595 [[nodiscard]] static constexpr bool is_standard_type() noexcept;
596 
597 /**
598  * @brief Reports whether @c T is a pointer to a trivial standard-layout type.
599  *
600  * @details
601  * Matches @c U* where @c std::is_trivial_v<U> && @c std::is_standard_layout_v<U>.
602  * The pointer is reinterpreted (not copied through) for zero-copy use.
603  *
604  * @tparam T Pointer type to test.
605  * @return @c true for POD-pointer types.
606  */
607 template <typename T>
608 [[nodiscard]] static constexpr bool is_standard_ptr_type() noexcept;
609 
610 } // namespace Serializer
611 
612 } // namespace vlink
613 
614 #include "./internal/serializer-inl.h"
Canonical 128-byte binary payload carrier with inline storage, multi-mode ownership and LZAV compress...
Compile-time codec detection and dispatch for VLink message payloads.
Core enumerations and small value types shared by the entire VLink implementation layer.