Skip to content

Commit 864001d

Browse files
anandoleecopybara-github
authored andcommitted
Change back to CodedOutputStream with SetSerializationDeterministic() and Trim() in proto_api.
PiperOrigin-RevId: 732268005
1 parent 19d97d3 commit 864001d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

python/google/protobuf/proto_api.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,18 @@ bool PythonConstMessagePointer::NotChanged() {
101101
std::unique_ptr<google::protobuf::Message> parsed_msg(owned_msg_->New());
102102
parsed_msg->ParseFromArray(data, static_cast<int>(len));
103103
std::string wire_other;
104-
parsed_msg->SerializeToString(&wire_other);
104+
google::protobuf::io::StringOutputStream stream_other(&wire_other);
105+
google::protobuf::io::CodedOutputStream output_other(&stream_other);
106+
output_other.SetSerializationDeterministic(true);
107+
parsed_msg->SerializeToCodedStream(&output_other);
108+
output_other.Trim();
105109

106110
std::string wire;
107-
owned_msg_->SerializeToString(&wire);
111+
google::protobuf::io::StringOutputStream stream(&wire);
112+
google::protobuf::io::CodedOutputStream output(&stream);
113+
output.SetSerializationDeterministic(true);
114+
owned_msg_->SerializeToCodedStream(&output);
115+
output.Trim();
108116

109117
if (wire == wire_other) {
110118
Py_DECREF(py_serialized_pb);

0 commit comments

Comments
 (0)