Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/json2pb/json_to_pb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ bool ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json,
google::protobuf::Message* message,
const ProtoJson2PbOptions& options,
std::string* error) {
#if GOOGLE_PROTOBUF_VERSION >= 6031000
auto st = google::protobuf::json::JsonStreamToMessage(json, message, options);
bool ok = st.ok();
if (!ok && NULL != error) {
*error = st.ToString();
}
return ok;
#else
TypeResolverUniqueptr type_resolver = GetTypeResolver(*message);
std::string type_url = GetTypeUrl(*message);
butil::IOBuf buf;
Expand All @@ -753,6 +761,7 @@ bool ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json,
*error = "Fail to ParseFromCodedStream";
}
return ok;
#endif // GOOGLE_PROTOBUF_VERSION >= 6031000
}

bool ProtoJsonToProtoMessage(const std::string& json, google::protobuf::Message* message,
Expand Down
9 changes: 9 additions & 0 deletions src/json2pb/pb_to_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ bool ProtoMessageToProtoJson(const google::protobuf::Message& message,
}
return false;
}
#if GOOGLE_PROTOBUF_VERSION >= 6031000
auto st = google::protobuf::json::MessageToJsonStream(message, json, options);
bool ok = st.ok();
if (!ok && NULL != error) {
*error = st.ToString();
}
return ok;
#else
butil::IOBuf buf;
butil::IOBufAsZeroCopyOutputStream output_stream(&buf);
if (!message.SerializeToZeroCopyStream(&output_stream)) {
Expand All @@ -432,6 +440,7 @@ bool ProtoMessageToProtoJson(const google::protobuf::Message& message,
*error = st.ToString();
}
return ok;
#endif // GOOGLE_PROTOBUF_VERSION >= 6031000
}

bool ProtoMessageToProtoJson(const google::protobuf::Message& message, std::string* json,
Expand Down
2 changes: 2 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,15 @@ generate_unittests(
# real-time waits exceed Bazel's default per-test 300s (size=medium) limit
# on contended CI runners, causing TIMEOUT failures. Raise its limit to
# size=large (900s).
# brpc_load_balancer_unittest.cpp also has the same problem.
#
# NB: do NOT shard this binary. Its TEST_F share fixed loopback endpoints
# and global state; running shards as parallel processes makes a
# "connection should be refused" test observe another shard's live server
# on the same port and fail. size=large is the only safe lever here.
per_test_size = {
"brpc_channel_unittest.cpp": "large",
"brpc_load_balancer_unittest.cpp": "large",
},
)

Expand Down
Loading