VLink  2.1.0
A high-performance communication middleware
vlink::zerocopy::MessageParser类 参考final

Unified parser and field reader for built-in zero-copy messages. 更多...

#include <message_parser.h>

vlink::zerocopy::MessageParser 的协作图:

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. 更多...
 
MessageParseroperator= (const MessageParser &)=delete
 
 MessageParser (MessageParser &&) noexcept=default
 Move-constructs or move-assigns the retained parser state. 更多...
 
MessageParseroperator= (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< Fieldfields () const
 Enumerates root fields available for the parsed type. 更多...
 
std::vector< Fieldelement_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.

成员类型定义说明

◆ Value

Exact schema-neutral field value without implicit integer-to-double conversion.

成员枚举类型说明

◆ EnumKind

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.

枚举值
kEnumNone 

Plain numeric field with no symbolic enumeration.

kEnumCameraFormat 

CameraFrame::Format image or codec format.

kEnumCameraStream 

CameraFrame::Stream stream role.

kEnumGridCellType 

OccupancyGrid::CellType cell storage type.

kEnumTensorDataType 

Tensor::DataType element data type.

kEnumTensorDevice 

Tensor::Device residency device.

kEnumAudioFormat 

AudioFrame::Format sample format.

kEnumAudioLayout 

AudioFrame::Layout channel layout.

◆ Type

Built-in zero-copy wire type retained by the parser.

枚举值
kUnknown 

No message is parsed, or the serialized type is unsupported.

kRawData 

Opaque bytes with a common zero-copy header.

kCameraFrame 

Image or encoded video frame.

kPointCloud 

Dynamically described packed point records.

kProxyData 

Proxy routing envelope and nested raw payload.

kOccupancyGrid 

Typed two-dimensional occupancy or cost cells.

kTensor 

Typed multidimensional tensor payload.

kObjectArray 

Detection or tracking object records.

kAudioFrame 

PCM or encoded audio frame.

◆ ValueType

Exact C++ alternative stored by Value for a field.

枚举值
kValueUnknown 

Field has no supported value representation.

kInt64 

Signed integral value retained as int64_t.

kUInt64 

Unsigned integral value retained as uint64_t.

kDouble 

Floating-point value represented as double.

kString 

UTF-8 or protocol text represented as std::string.

kBytes 

Opaque payload returned as a borrowed Bytes view.

构造及析构函数说明

◆ MessageParser() [1/3]

vlink::zerocopy::MessageParser::MessageParser ( )
default

Constructs an invalid parser with no retained message.

◆ ~MessageParser()

vlink::zerocopy::MessageParser::~MessageParser ( )
default

Releases the retained typed message.

◆ MessageParser() [2/3]

vlink::zerocopy::MessageParser::MessageParser ( const MessageParser )
delete

Parsers are non-copyable because decoded containers may borrow wire storage.

参数
targetParser whose borrowed state would otherwise be copied.

◆ MessageParser() [3/3]

vlink::zerocopy::MessageParser::MessageParser ( MessageParser &&  )
defaultnoexcept

Move-constructs or move-assigns the retained parser state.

参数
targetParser whose retained state is transferred.

成员函数说明

◆ clear()

void vlink::zerocopy::MessageParser::clear ( )
noexcept

Releases the current decoded message and returns to the invalid state.

◆ collection_size()

size_t vlink::zerocopy::MessageParser::collection_size ( std::string_view  collection) const
noexcept

Returns the validated accessible element count of collection.

参数
collectionCanonical collection or supported alias.
返回
Number of elements safe to read from the decoded payload.

◆ copy_to()

template<typename T >
bool vlink::zerocopy::MessageParser::copy_to ( T &  out) const
inline

Deep-copies the retained message into a matching typed container.

模板参数
TOne of the built-in zero-copy container types.
参数
outDestination container replaced only when T matches the parsed type.
返回
true when a matching retained message was copied.
注解
This compatibility operation is intended for typed container APIs. Dynamic readers should use value(), fields(), and collection access instead.

◆ detect_type()

static Type vlink::zerocopy::MessageParser::detect_type ( std::string_view  serialized_type)
staticnoexcept

Detects a built-in type using an exact name or namespace-delimited suffix.

参数
serialized_typeSerialized type name supplied by schema metadata.
返回
Detected built-in type, or kUnknown when no exact suffix matches.

◆ element_fields()

std::vector<Field> vlink::zerocopy::MessageParser::element_fields ( std::string_view  collection) const

Enumerates fields of one element in collection.

参数
collectionCanonical collection or supported alias.
返回
Stable element field descriptors, or an empty vector for an unknown collection.

◆ fields()

std::vector<Field> vlink::zerocopy::MessageParser::fields ( ) const

Enumerates root fields available for the parsed type.

返回
Stable declaration-order descriptors; empty when the parser is invalid.

◆ numeric() [1/3]

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.

◆ numeric() [2/3]

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.

参数
collectionCanonical collection or supported alias.
indexZero-based element index.
fieldElement field name, or value for scalar collections.
outNumeric value converted to double.
precision_lossOptional flag set when integer conversion is inexact.
返回
true when the selected element resolves to a numeric value.

◆ numeric() [3/3]

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.

参数
pathRoot or indexed numeric field path.
outNumeric value converted to double.
precision_lossOptional flag set when an integer exceeds the exact IEEE-754 range.
返回
true when path resolves to a numeric value.

◆ operator=() [1/2]

MessageParser& vlink::zerocopy::MessageParser::operator= ( const MessageParser )
delete

◆ operator=() [2/2]

MessageParser& vlink::zerocopy::MessageParser::operator= ( MessageParser &&  )
defaultnoexcept

◆ parse() [1/2]

bool vlink::zerocopy::MessageParser::parse ( std::string_view  serialized_type,
const Bytes bytes 
)

Detects serialized_type and parses bytes; failure clears the parser.

参数
serialized_typeExact type name or namespace-delimited built-in type suffix.
bytesZero-copy wire envelope to decode; its storage must outlive this parser.
返回
true on successful type detection and deserialization.

◆ parse() [2/2]

bool vlink::zerocopy::MessageParser::parse ( Type  type,
const Bytes bytes 
)

Parses bytes as the explicitly selected type; failure clears the parser.

参数
typeBuilt-in zero-copy type expected in bytes.
bytesZero-copy wire envelope to decode; its storage must outlive this parser.
返回
true when the envelope is valid for type.

◆ text() [1/2]

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.

参数
collectionCanonical collection or supported alias.
indexZero-based element index.
fieldString field name.
outString copied from the decoded field on success.
返回
true when the selected element resolves to a string value.

◆ text() [2/2]

bool vlink::zerocopy::MessageParser::text ( std::string_view  path,
std::string &  out 
) const

Reads a string-valued path.

参数
pathRoot or indexed string field path.
outString copied from the decoded field on success.
返回
true when path resolves to a string value.

◆ type()

MessageParser::Type vlink::zerocopy::MessageParser::type ( ) const
inlinenoexcept

Returns the retained built-in type, or kUnknown when invalid.

Details

◆ type_name()

static std::string_view vlink::zerocopy::MessageParser::type_name ( Type  type)
staticnoexcept

Returns the canonical unqualified serialized name for type.

参数
typeBuilt-in parser type.
返回
Stable unqualified name, or an empty view for kUnknown.

◆ valid()

bool vlink::zerocopy::MessageParser::valid ( ) const
inlinenoexcept

Returns whether the parser currently retains a successfully decoded message.

◆ value() [1/3]

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.

◆ value() [2/3]

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.

参数
collectionCanonical collection or supported alias.
indexZero-based element index.
fieldElement field name, or value for scalar collections.
outExact field value written on success.
返回
false for an unknown collection, field, or out-of-range index.

◆ value() [3/3]

bool vlink::zerocopy::MessageParser::value ( std::string_view  path,
Value out 
) const

Reads a root or indexed field without losing its integer representation.

参数
pathRoot path or indexed path such as data[3].x.
outExact field value written only when the path resolves.
返回
true when path exists and is readable.

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