| Index: third_party/protobuf/src/google/protobuf/util/json_util.h
|
| diff --git a/third_party/protobuf/src/google/protobuf/util/json_util.h b/third_party/protobuf/src/google/protobuf/util/json_util.h
|
| index 1718bfb528119fad916b0d934190ff7f3a89ef1a..6d3cee52818f834ddd72e8c9576919b96f01f205 100644
|
| --- a/third_party/protobuf/src/google/protobuf/util/json_util.h
|
| +++ b/third_party/protobuf/src/google/protobuf/util/json_util.h
|
| @@ -33,6 +33,7 @@
|
| #ifndef GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__
|
| #define GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__
|
|
|
| +#include <google/protobuf/message.h>
|
| #include <google/protobuf/util/type_resolver.h>
|
| #include <google/protobuf/stubs/bytestream.h>
|
|
|
| @@ -44,7 +45,14 @@ class ZeroCopyOutputStream;
|
| } // namespace io
|
| namespace util {
|
|
|
| -struct JsonOptions {
|
| +struct JsonParseOptions {
|
| + // Whether to ignore unknown JSON fields during parsing
|
| + bool ignore_unknown_fields;
|
| +
|
| + JsonParseOptions() : ignore_unknown_fields(false) {}
|
| +};
|
| +
|
| +struct JsonPrintOptions {
|
| // Whether to add spaces, line breaks and indentation to make the JSON output
|
| // easy to read.
|
| bool add_whitespace;
|
| @@ -54,30 +62,57 @@ struct JsonOptions {
|
| // behavior and print primitive fields regardless of their values.
|
| bool always_print_primitive_fields;
|
|
|
| - JsonOptions() : add_whitespace(false),
|
| - always_print_primitive_fields(false) {
|
| + JsonPrintOptions() : add_whitespace(false),
|
| + always_print_primitive_fields(false) {
|
| }
|
| };
|
|
|
| +// DEPRECATED. Use JsonPrintOptions instead.
|
| +typedef JsonPrintOptions JsonOptions;
|
| +
|
| +// Converts from protobuf message to JSON. This is a simple wrapper of
|
| +// BinaryToJsonString(). It will use the DescriptorPool of the passed-in
|
| +// message to resolve Any types.
|
| +LIBPROTOBUF_EXPORT util::Status MessageToJsonString(const Message& message,
|
| + string* output,
|
| + const JsonOptions& options);
|
| +
|
| +inline util::Status MessageToJsonString(const Message& message,
|
| + string* output) {
|
| + return MessageToJsonString(message, output, JsonOptions());
|
| +}
|
| +
|
| +// Converts from JSON to protobuf message. This is a simple wrapper of
|
| +// JsonStringToBinary(). It will use the DescriptorPool of the passed-in
|
| +// message to resolve Any types.
|
| +LIBPROTOBUF_EXPORT util::Status JsonStringToMessage(const string& input,
|
| + Message* message,
|
| + const JsonParseOptions& options);
|
| +
|
| +inline util::Status JsonStringToMessage(const string& input,
|
| + Message* message) {
|
| + return JsonStringToMessage(input, message, JsonParseOptions());
|
| +}
|
| +
|
| // Converts protobuf binary data to JSON.
|
| // The conversion will fail if:
|
| // 1. TypeResolver fails to resolve a type.
|
| // 2. input is not valid protobuf wire format, or conflicts with the type
|
| // information returned by TypeResolver.
|
| // Note that unknown fields will be discarded silently.
|
| -util::Status BinaryToJsonStream(
|
| +LIBPROTOBUF_EXPORT util::Status BinaryToJsonStream(
|
| TypeResolver* resolver,
|
| const string& type_url,
|
| io::ZeroCopyInputStream* binary_input,
|
| io::ZeroCopyOutputStream* json_output,
|
| - const JsonOptions& options);
|
| + const JsonPrintOptions& options);
|
|
|
| inline util::Status BinaryToJsonStream(
|
| TypeResolver* resolver, const string& type_url,
|
| io::ZeroCopyInputStream* binary_input,
|
| io::ZeroCopyOutputStream* json_output) {
|
| return BinaryToJsonStream(resolver, type_url, binary_input, json_output,
|
| - JsonOptions());
|
| + JsonPrintOptions());
|
| }
|
|
|
| LIBPROTOBUF_EXPORT util::Status BinaryToJsonString(
|
| @@ -85,14 +120,14 @@ LIBPROTOBUF_EXPORT util::Status BinaryToJsonString(
|
| const string& type_url,
|
| const string& binary_input,
|
| string* json_output,
|
| - const JsonOptions& options);
|
| + const JsonPrintOptions& options);
|
|
|
| inline util::Status BinaryToJsonString(TypeResolver* resolver,
|
| const string& type_url,
|
| const string& binary_input,
|
| string* json_output) {
|
| return BinaryToJsonString(resolver, type_url, binary_input, json_output,
|
| - JsonOptions());
|
| + JsonPrintOptions());
|
| }
|
|
|
| // Converts JSON data to protobuf binary format.
|
| @@ -100,18 +135,37 @@ inline util::Status BinaryToJsonString(TypeResolver* resolver,
|
| // 1. TypeResolver fails to resolve a type.
|
| // 2. input is not valid JSON format, or conflicts with the type
|
| // information returned by TypeResolver.
|
| -// 3. input has unknown fields.
|
| -util::Status JsonToBinaryStream(
|
| +LIBPROTOBUF_EXPORT util::Status JsonToBinaryStream(
|
| TypeResolver* resolver,
|
| const string& type_url,
|
| io::ZeroCopyInputStream* json_input,
|
| - io::ZeroCopyOutputStream* binary_output);
|
| + io::ZeroCopyOutputStream* binary_output,
|
| + const JsonParseOptions& options);
|
| +
|
| +inline util::Status JsonToBinaryStream(
|
| + TypeResolver* resolver,
|
| + const string& type_url,
|
| + io::ZeroCopyInputStream* json_input,
|
| + io::ZeroCopyOutputStream* binary_output) {
|
| + return JsonToBinaryStream(resolver, type_url, json_input, binary_output,
|
| + JsonParseOptions());
|
| +}
|
|
|
| LIBPROTOBUF_EXPORT util::Status JsonToBinaryString(
|
| TypeResolver* resolver,
|
| const string& type_url,
|
| const string& json_input,
|
| - string* binary_output);
|
| + string* binary_output,
|
| + const JsonParseOptions& options);
|
| +
|
| +inline util::Status JsonToBinaryString(
|
| + TypeResolver* resolver,
|
| + const string& type_url,
|
| + const string& json_input,
|
| + string* binary_output) {
|
| + return JsonToBinaryString(resolver, type_url, json_input, binary_output,
|
| + JsonParseOptions());
|
| +}
|
|
|
| namespace internal {
|
| // Internal helper class. Put in the header so we can write unit-tests for it.
|
|
|