Skip to content
Closed
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 st.ok();
Comment thread
chenBright marked this conversation as resolved.
#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 st.ok();
Comment thread
chenBright marked this conversation as resolved.
#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
Loading