aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/util/json_util.h
diff options
context:
space:
mode:
authorFeng Xiao <xfxyjwf@gmail.com>2016-07-13 13:47:51 -0700
committerFeng Xiao <xfxyjwf@gmail.com>2016-07-13 13:48:40 -0700
commit9086d9643903c608ab015b0b7d903547a4e7b6f3 (patch)
treeb47053ab6f6bde20b55c4fff4019c68a7c45545c /src/google/protobuf/util/json_util.h
parent70c1ac756d3cd8fa04725f82f0ad1a30404c3bb3 (diff)
downloadprotobuf-9086d9643903c608ab015b0b7d903547a4e7b6f3.tar.gz
protobuf-9086d9643903c608ab015b0b7d903547a4e7b6f3.tar.bz2
protobuf-9086d9643903c608ab015b0b7d903547a4e7b6f3.zip
Integrate from internal code base.
Diffstat (limited to 'src/google/protobuf/util/json_util.h')
-rw-r--r--src/google/protobuf/util/json_util.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h
index b4c2579b..170ae91b 100644
--- a/src/google/protobuf/util/json_util.h
+++ b/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>
@@ -69,6 +70,30 @@ struct JsonPrintOptions {
// 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.
+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.
+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.