Top namespace for the protobuf JSON utilities.
Classes | |
| class | ConversionError |
| JSON/protobuf conversion error. More... | |
| class | ConversionErrorBase |
| Base exception type for JSON/protobuf conversion errors. More... | |
| class | ConversionErrorInfo |
| JSON/protobuf conversion error information. More... | |
| class | JsonError |
| Base exception type for JSON utilities. More... | |
| struct | ParseOptions |
| Options which affect how JSON Value is converted to a protobuf message. More... | |
| struct | PrintOptions |
| Options which affect how protobuf message is converted to a JSON ValueBuilder/Value. More... | |
Typedefs | |
| using | ParseErrorInfo = ConversionErrorInfo<ParseErrorCode> |
| JSON Value to protobuf message conversion error information. | |
| using | PrintErrorInfo = ConversionErrorInfo<PrintErrorCode> |
| Protobuf message to JSON Value conversion error information. | |
| using | ParseError = ConversionError<ParseErrorCode> |
| JSON Value to protobuf message conversion error. | |
| using | PrintError = ConversionError<PrintErrorCode> |
| Protobuf message to JSON Value conversion error. | |
Enumerations | |
| enum class | ParseErrorCode { kUnknownField = 1 , kUnknownEnum = 2 , kMultipleOneofFields = 3 , kInvalidType = 4 , kInvalidValue = 5 } |
| JSON Value to protobuf message conversion error code. More... | |
| enum class | PrintErrorCode { kInvalidValue = 1 } |
| Protobuf message to JSON Value conversion error code. More... | |
Functions | |
| formats::json::ValueBuilder | MessageToJsonBuilder (const ::google::protobuf::Message &message, const PrintOptions &options) |
| Converts protobuf message to JSON ValueBuilder. | |
| formats::json::Value | MessageToJson (const ::google::protobuf::Message &message, const PrintOptions &options) |
| Converts protobuf message to JSON Value. | |
| void | JsonToMessage (const formats::json::Value &json, ::google::protobuf::Message &message, const ParseOptions &options={}) |
| Converts json to protobuf message . | |
| template<typename T> requires (std::is_base_of_v<::google::protobuf::Message, T> || !std::is_same_v<::google::protobuf::Message, T>) | |
| T | JsonToMessage (const formats::json::Value &json, const ParseOptions &options={}) |
| Converts json to protobuf message of type T. | |
| std::string | MessageToJsonString (const ::google::protobuf::Message &message, const PrintOptions &options) |
| Serializes protobuf message to a JSON string. | |
| std::string | MessageToDebugString (const ::google::protobuf::Message &message, std::size_t limit) |
| Serializes protobuf message to a JSON string for debugging/logging, stopping early once limit bytes have been produced. | |
JSON Value to protobuf message conversion error.
Definition at line 123 of file exceptions.hpp.
JSON Value to protobuf message conversion error information.
Definition at line 80 of file exceptions.hpp.
Protobuf message to JSON Value conversion error.
Definition at line 126 of file exceptions.hpp.
Protobuf message to JSON Value conversion error information.
Definition at line 83 of file exceptions.hpp.
|
strong |
JSON Value to protobuf message conversion error code.
Definition at line 17 of file exceptions.hpp.
|
strong |
Protobuf message to JSON Value conversion error code.
| Enumerator | |
|---|---|
| kInvalidValue | Protobuf message field has invalid value. This code can be set when converting well-known message which may have more strict constraints than the types of their fields (see here for example). |
Definition at line 35 of file exceptions.hpp.
| void protobuf::json::JsonToMessage | ( | const formats::json::Value & | json, |
| ::google::protobuf::Message & | message, | ||
| const ParseOptions & | options = {} ) |
Converts json to protobuf message .
| ParseError | if conversion has failed |
| MemberMissingException | is json holds nothing The conversion is performed according to ProtoJSON specification. |
Definition at line 19 of file convert.cpp.
|
nodiscard |
Converts json to protobuf message of type T.
| T | protobuf message type |
| ParseError | if conversion has failed |
| MemberMissingException | is json holds nothing The conversion is performed according to ProtoJSON specification. |
Definition at line 80 of file convert.hpp.
| std::string protobuf::json::MessageToDebugString | ( | const ::google::protobuf::Message & | message, |
| std::size_t | limit ) |
Serializes protobuf message to a JSON string for debugging/logging, stopping early once limit bytes have been produced.
Unlike MessageToJson / MessageToJsonBuilder / MessageToJsonString, this is a debug serializer:
| message | The protobuf message to convert. |
| limit | Maximum size of the resulting string. The output may exceed it by at most one scalar value, since the traversal is interrupted at container-element granularity. This function does not append any truncation marker itself; callers that need one (e.g. for logging) should detect truncation by checking whether the result size exceeds limit. |
| PrintError | if conversion has failed |
Definition at line 31 of file convert.cpp.
|
inlinenodiscard |
Converts protobuf message to JSON Value.
| PrintError | if conversion has failed The conversion is performed according to ProtoJSON specification. |
Definition at line 47 of file convert.hpp.
|
nodiscard |
Converts protobuf message to JSON ValueBuilder.
| PrintError | if conversion has failed The conversion is performed according to ProtoJSON specification. |
Definition at line 12 of file convert.cpp.
| std::string protobuf::json::MessageToJsonString | ( | const ::google::protobuf::Message & | message, |
| const PrintOptions & | options ) |
Serializes protobuf message to a JSON string.
Honors PrintOptions in exactly the same way as MessageToJson / MessageToJsonBuilder do (including nonportable_raw_any, which controls whether google.protobuf.Any is expanded or emitted raw). In particular, [debug_redact = true] fields are not redacted here either, same as in MessageToJson / MessageToJsonBuilder.
| message | The protobuf message to convert. |
| options | Same conversion options as for MessageToJson / MessageToJsonBuilder. |
| PrintError | if conversion has failed |
Definition at line 27 of file convert.cpp.