You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ww...@apache.org on 2022/12/05 02:29:11 UTC

[incubator-brpc] branch master updated: only allow to convert root array to single repeated pb

This is an automated email from the ASF dual-hosted git repository.

wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new a0bc7db4 only allow to convert root array to single repeated pb
     new 4f59bc64 Merge pull request #2035 from chenBright/root_single_array
a0bc7db4 is described below

commit a0bc7db47439e0da7597110c918079782508bb3b
Author: chenBright <10...@qq.com>
AuthorDate: Sun Dec 4 22:14:36 2022 +0800

    only allow to convert root array to single repeated pb
---
 src/json2pb/json_to_pb.cpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/json2pb/json_to_pb.cpp b/src/json2pb/json_to_pb.cpp
index fc9a31a0..6a6f46cc 100644
--- a/src/json2pb/json_to_pb.cpp
+++ b/src/json2pb/json_to_pb.cpp
@@ -275,7 +275,9 @@ inline bool convert_uint64_type(const BUTIL_RAPIDJSON_NAMESPACE::Value& item,
 
 bool JsonValueToProtoMessage(const BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
                              google::protobuf::Message* message,
-                             const Json2PbOptions& options, std::string* err);
+                             const Json2PbOptions& options,
+                             std::string* err,
+                             bool root_val = false);
 
 //Json value to protobuf convert rules for type:
 //Json value type                 Protobuf type                convert rules
@@ -516,9 +518,11 @@ bool JsonMapToProtoMap(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
 bool JsonValueToProtoMessage(const BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
                              google::protobuf::Message* message,
                              const Json2PbOptions& options,
-                             std::string* err) {
+                             std::string* err,
+                             bool root_val) {
     const google::protobuf::Descriptor* descriptor = message->GetDescriptor();
-    if (!json_value.IsObject() && !(json_value.IsArray() && options.array_to_single_repeated)) {
+    if (!json_value.IsObject() &&
+        !(json_value.IsArray() && options.array_to_single_repeated && root_val)) {
         J2PERROR_WITH_PB(message, err, "The input is not a json object");
         return false;
     }
@@ -627,7 +631,7 @@ inline bool JsonToProtoMessageInline(const std::string& json_string,
         J2PERROR_WITH_PB(message, error, "Invalid json: %s", BUTIL_RAPIDJSON_NAMESPACE::GetParseError_En(d.GetParseError()));
         return false;
     }
-    return JsonValueToProtoMessage(d, message, options, error);
+    return JsonValueToProtoMessage(d, message, options, error, true);
 }
 
 bool JsonToProtoMessage(const std::string& json_string,
@@ -675,7 +679,7 @@ bool JsonToProtoMessage(ZeroCopyStreamReader* reader,
         J2PERROR_WITH_PB(message, error, "Invalid json: %s", BUTIL_RAPIDJSON_NAMESPACE::GetParseError_En(d.GetParseError()));
         return false;
     }
-    return JsonValueToProtoMessage(d, message, options, error);
+    return JsonValueToProtoMessage(d, message, options, error, true);
 }
 
 bool JsonToProtoMessage(const std::string& json_string, 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org