proto_utils.h#

General-purpose protobuf utility templates covering debug string formatting (onnx::ProtoDebugString()), byte-buffer deserialization (onnx::ParseProtoFromBytes()), and typed attribute-value extraction (onnx::RetrieveValues()).

General-purpose protobuf utility templates: debug formatting, byte-buffer parsing, and attribute-value extraction.

namespace ONNX_LIGHT_NAMESPACE

Functions

template<typename Proto>
inline std::string ProtoDebugString(const Proto &proto)#

Returns a human-readable debug representation of a protobuf message.

Calls PrintToVectorString() on proto with default print options and joins the resulting lines with newline characters.

Template Parameters:

Proto – A protobuf-like message type that exposes a PrintToVectorString(utils::PrintOptions&) method.

Parameters:

proto – The message to format.

Returns:

A multi-line string representation of proto.

template<typename Proto>
inline bool ParseProtoFromBytes(Proto *proto, const char *buffer, size_t length)#

Parses a protobuf message from a raw byte buffer.

Constructs a StringStream over the supplied buffer and calls ParseFromStream() on proto. Returns false without modifying proto when proto is null, when buffer is null but length is positive, when parsing raises a std::runtime_error, or when bytes remain unconsumed after parsing completes.

Template Parameters:

Proto – A protobuf-like message type that exposes a ParseFromStream(utils::StringStream&, ParseOptions&) method.

Parameters:
  • proto – Destination message that receives the parsed content. Must not be nullptr.

  • buffer – Pointer to the serialized byte data. May be nullptr only when length is 0.

  • length – Number of bytes in buffer.

Returns:

true if the entire buffer was consumed and parsed successfully; false otherwise.

template<typename T>
inline std::vector<T> RetrieveValues(const AttributeProto &attr)#

Extracts a typed list of values from an AttributeProto.

The primary template is declared but not defined; callers must use one of the explicit specializations for int64_t, std::string, or float.

Template Parameters:

T – Element type to retrieve. Must be int64_t, std::string, or float.

Parameters:

attr – Source attribute whose repeated field is extracted.

Returns:

A std::vector<T> containing the attribute values.

template<>
inline std::vector<int64_t> RetrieveValues(const AttributeProto &attr)#

Extracts a list of int64_t values from an AttributeProto.

Parameters:

attr – Source attribute (must have type INT or INTS).

Returns:

A std::vector<int64_t> copied from the ints repeated field.

template<>
inline std::vector<std::string> RetrieveValues(const AttributeProto &attr)#

Extracts a list of std::string values from an AttributeProto.

Parameters:

attr – Source attribute (must have type STRING or STRINGS).

Returns:

A std::vector<std::string> copied from the strings repeated field.

template<>
inline std::vector<float> RetrieveValues(const AttributeProto &attr)#

Extracts a list of float values from an AttributeProto.

Parameters:

attr – Source attribute (must have type FLOAT or FLOATS).

Returns:

A std::vector<float> copied from the floats repeated field.