|
VLink
2.1.0
A high-performance communication middleware
|
Unified parser and field reader for built-in zero-copy messages. 更多...
#include <message_parser.h>
类 | |
| struct | Field |
| Schema-neutral field descriptor returned by field enumeration. 更多... | |
Public 类型 | |
| enum | Type : uint8_t { kUnknown = 0 , kRawData = 1 , kCameraFrame = 2 , kPointCloud = 3 , kProxyData = 4 , kOccupancyGrid = 5 , kTensor = 6 , kObjectArray = 7 , kAudioFrame = 8 } |
| Built-in zero-copy wire type retained by the parser. 更多... | |
| enum | ValueType : uint8_t { kValueUnknown = 0 , kInt64 = 1 , kUInt64 = 2 , kDouble = 3 , kString = 4 , kBytes = 5 } |
Exact C++ alternative stored by Value for a field. 更多... | |
| enum | EnumKind : uint8_t { kEnumNone = 0 , kEnumCameraFormat = 1 , kEnumCameraStream = 2 , kEnumGridCellType = 3 , kEnumTensorDataType = 4 , kEnumTensorDevice = 5 , kEnumAudioFormat = 6 , kEnumAudioLayout = 7 } |
| Built-in enumeration a scalar field maps to, for symbolic-name rendering. 更多... | |
| using | Value = std::variant< int64_t, uint64_t, double, std::string, Bytes > |
| Exact schema-neutral field value without implicit integer-to-double conversion. 更多... | |
Public 成员函数 | |
| MessageParser ()=default | |
| Constructs an invalid parser with no retained message. 更多... | |
| ~MessageParser ()=default | |
| Releases the retained typed message. 更多... | |
| MessageParser (const MessageParser &)=delete | |
| Parsers are non-copyable because decoded containers may borrow wire storage. 更多... | |
| MessageParser & | operator= (const MessageParser &)=delete |
| MessageParser (MessageParser &&) noexcept=default | |
| Move-constructs or move-assigns the retained parser state. 更多... | |
| MessageParser & | operator= (MessageParser &&) noexcept=default |
| bool | parse (std::string_view serialized_type, const Bytes &bytes) |
Detects serialized_type and parses bytes; failure clears the parser. 更多... | |
| bool | parse (Type type, const Bytes &bytes) |
Parses bytes as the explicitly selected type; failure clears the parser. 更多... | |
| void | clear () noexcept |
| Releases the current decoded message and returns to the invalid state. 更多... | |
| Type | type () const noexcept |
Returns the retained built-in type, or kUnknown when invalid. 更多... | |
| bool | valid () const noexcept |
| Returns whether the parser currently retains a successfully decoded message. 更多... | |
| bool | value (std::string_view path, Value &out) const |
| Reads a root or indexed field without losing its integer representation. 更多... | |
| bool | value (std::string_view collection, size_t index, std::string_view field, Value &out) const |
Reads field from element index of a named collection. 更多... | |
| bool | value (std::string_view collection, size_t index, const Field &field, Value &out) const |
Reads a collection element through a descriptor returned by element_fields(). 更多... | |
| bool | numeric (std::string_view path, double &out, bool *precision_loss=nullptr) const |
| Reads a numeric path and optionally reports integer-to-double precision loss. 更多... | |
| bool | numeric (std::string_view collection, size_t index, std::string_view field, double &out, bool *precision_loss=nullptr) const |
| Reads a numeric collection element and optionally reports precision loss. 更多... | |
| bool | numeric (std::string_view collection, size_t index, const Field &field, double &out, bool *precision_loss=nullptr) const |
| Reads a numeric collection element through a pre-resolved field descriptor. 更多... | |
| bool | text (std::string_view path, std::string &out) const |
| Reads a string-valued path. 更多... | |
| bool | text (std::string_view collection, size_t index, std::string_view field, std::string &out) const |
| Reads a string-valued collection element. 更多... | |
| size_t | collection_size (std::string_view collection) const noexcept |
Returns the validated accessible element count of collection. 更多... | |
| std::vector< Field > | fields () const |
| Enumerates root fields available for the parsed type. 更多... | |
| std::vector< Field > | element_fields (std::string_view collection) const |
Enumerates fields of one element in collection. 更多... | |
| template<typename T > | |
| bool | copy_to (T &out) const |
| Deep-copies the retained message into a matching typed container. 更多... | |
静态 Public 成员函数 | |
| static Type | detect_type (std::string_view serialized_type) noexcept |
| Detects a built-in type using an exact name or namespace-delimited suffix. 更多... | |
| static std::string_view | type_name (Type type) noexcept |
Returns the canonical unqualified serialized name for type. 更多... | |
Unified parser and field reader for built-in zero-copy messages.
A successful parse retains the decoded message and exposes schema-neutral scalar access through value(), numeric(), and text(). Indexed payloads use paths such as data[4].x, shape[1], and objects[2].track_id. Integer values remain exact in Value; callers converting them to double can request a precision loss report. Decoded containers and Bytes values borrow payload storage from the input. The input must outlive the parser and every returned byte view; scalar and string values are copied into Value.
Exact schema-neutral field value without implicit integer-to-double conversion.
| enum vlink::zerocopy::MessageParser::EnumKind : uint8_t |
Built-in enumeration a scalar field maps to, for symbolic-name rendering.
Structural reflection alone cannot recover an integer field's symbolic enumerator name. EnumKind names the concrete built-in enum a field encodes so a presentation layer can resolve its label without re-hardcoding per-type knowledge. kEnumNone marks a plain numeric field.
| enum vlink::zerocopy::MessageParser::Type : uint8_t |
Built-in zero-copy wire type retained by the parser.
| enum vlink::zerocopy::MessageParser::ValueType : uint8_t |
Exact C++ alternative stored by Value for a field.
| 枚举值 | |
|---|---|
| kValueUnknown | Field has no supported value representation. |
| kInt64 | Signed integral value retained as |
| kUInt64 | Unsigned integral value retained as |
| kDouble | Floating-point value represented as |
| kString | UTF-8 or protocol text represented as |
| kBytes | Opaque payload returned as a borrowed |
|
default |
Constructs an invalid parser with no retained message.
|
default |
Releases the retained typed message.
|
delete |
Parsers are non-copyable because decoded containers may borrow wire storage.
| target | Parser whose borrowed state would otherwise be copied. |
|
defaultnoexcept |
Move-constructs or move-assigns the retained parser state.
| target | Parser whose retained state is transferred. |
|
noexcept |
Releases the current decoded message and returns to the invalid state.
|
noexcept |
Returns the validated accessible element count of collection.
| collection | Canonical collection or supported alias. |
|
inline |
Deep-copies the retained message into a matching typed container.
| T | One of the built-in zero-copy container types. |
| out | Destination container replaced only when T matches the parsed type. |
true when a matching retained message was copied.
|
staticnoexcept |
Detects a built-in type using an exact name or namespace-delimited suffix.
| serialized_type | Serialized type name supplied by schema metadata. |
kUnknown when no exact suffix matches. | std::vector<Field> vlink::zerocopy::MessageParser::element_fields | ( | std::string_view | collection | ) | const |
Enumerates fields of one element in collection.
| collection | Canonical collection or supported alias. |
| std::vector<Field> vlink::zerocopy::MessageParser::fields | ( | ) | const |
Enumerates root fields available for the parsed type.
| bool vlink::zerocopy::MessageParser::numeric | ( | std::string_view | collection, |
| size_t | index, | ||
| const Field & | field, | ||
| double & | out, | ||
| bool * | precision_loss = nullptr |
||
| ) | const |
Reads a numeric collection element through a pre-resolved field descriptor.
| bool vlink::zerocopy::MessageParser::numeric | ( | std::string_view | collection, |
| size_t | index, | ||
| std::string_view | field, | ||
| double & | out, | ||
| bool * | precision_loss = nullptr |
||
| ) | const |
Reads a numeric collection element and optionally reports precision loss.
| collection | Canonical collection or supported alias. |
| index | Zero-based element index. |
| field | Element field name, or value for scalar collections. |
| out | Numeric value converted to double. |
| precision_loss | Optional flag set when integer conversion is inexact. |
true when the selected element resolves to a numeric value. | bool vlink::zerocopy::MessageParser::numeric | ( | std::string_view | path, |
| double & | out, | ||
| bool * | precision_loss = nullptr |
||
| ) | const |
Reads a numeric path and optionally reports integer-to-double precision loss.
| path | Root or indexed numeric field path. |
| out | Numeric value converted to double. |
| precision_loss | Optional flag set when an integer exceeds the exact IEEE-754 range. |
true when path resolves to a numeric value.
|
delete |
|
defaultnoexcept |
| bool vlink::zerocopy::MessageParser::parse | ( | std::string_view | serialized_type, |
| const Bytes & | bytes | ||
| ) |
Detects serialized_type and parses bytes; failure clears the parser.
| serialized_type | Exact type name or namespace-delimited built-in type suffix. |
| bytes | Zero-copy wire envelope to decode; its storage must outlive this parser. |
true on successful type detection and deserialization. Parses bytes as the explicitly selected type; failure clears the parser.
| type | Built-in zero-copy type expected in bytes. |
| bytes | Zero-copy wire envelope to decode; its storage must outlive this parser. |
true when the envelope is valid for type. | bool vlink::zerocopy::MessageParser::text | ( | std::string_view | collection, |
| size_t | index, | ||
| std::string_view | field, | ||
| std::string & | out | ||
| ) | const |
Reads a string-valued collection element.
| collection | Canonical collection or supported alias. |
| index | Zero-based element index. |
| field | String field name. |
| out | String copied from the decoded field on success. |
true when the selected element resolves to a string value. | bool vlink::zerocopy::MessageParser::text | ( | std::string_view | path, |
| std::string & | out | ||
| ) | const |
Reads a string-valued path.
| path | Root or indexed string field path. |
| out | String copied from the decoded field on success. |
true when path resolves to a string value.
|
inlinenoexcept |
Returns the retained built-in type, or kUnknown when invalid.
Details
|
staticnoexcept |
Returns the canonical unqualified serialized name for type.
| type | Built-in parser type. |
kUnknown.
|
inlinenoexcept |
Returns whether the parser currently retains a successfully decoded message.
| bool vlink::zerocopy::MessageParser::value | ( | std::string_view | collection, |
| size_t | index, | ||
| const Field & | field, | ||
| Value & | out | ||
| ) | const |
Reads a collection element through a descriptor returned by element_fields().
This overload avoids repeated name resolution in packed-record hot paths. The descriptor is validated against the parser's current schema, so a stale descriptor from an incompatible subsequent parse is rejected.
| bool vlink::zerocopy::MessageParser::value | ( | std::string_view | collection, |
| size_t | index, | ||
| std::string_view | field, | ||
| Value & | out | ||
| ) | const |
Reads field from element index of a named collection.
| collection | Canonical collection or supported alias. |
| index | Zero-based element index. |
| field | Element field name, or value for scalar collections. |
| out | Exact field value written on success. |
false for an unknown collection, field, or out-of-range index. | bool vlink::zerocopy::MessageParser::value | ( | std::string_view | path, |
| Value & | out | ||
| ) | const |
Reads a root or indexed field without losing its integer representation.
| path | Root path or indexed path such as data[3].x. |
| out | Exact field value written only when the path resolves. |
true when path exists and is readable.