A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/protocolbuffers/protobuf/commit/f63ed55d4b85ad3cd558057e178c035e70c02c77 below:

Fix python proto_api to work with messages that required fields are n… · protocolbuffers/protobuf@f63ed55 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+17

-10

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+17

-10

lines changed Original file line number Diff line number Diff line change

@@ -2,6 +2,7 @@

2 2 3 3

#include <Python.h>

4 4 5 +

#include <climits>

5 6

#include <memory>

6 7

#include <string>

7 8

@@ -38,7 +39,7 @@ PythonMessageMutator::~PythonMessageMutator() {

38 39

// check.

39 40

if (!PyErr_Occurred() && owned_msg_ != nullptr) {

40 41

std::string wire;

41 -

message_->SerializeToString(&wire);

42 +

message_->SerializePartialToString(&wire);

42 43

PyObject* py_wire = PyBytes_FromStringAndSize(

43 44

wire.data(), static_cast<Py_ssize_t>(wire.size()));

44 45

PyObject* parse =

@@ -81,8 +82,14 @@ bool PythonConstMessagePointer::NotChanged() {

81 82

return false;

82 83

}

83 84 85 +

// Skip the check if too large. Parse won't work

86 +

// for messages larger than 2 GB.

87 +

if (message_->ByteSizeLong() > INT_MAX) {

88 +

return true;

89 +

}

90 + 84 91

PyObject* py_serialized_pb(

85 -

PyObject_CallMethod(py_msg_, "SerializeToString", nullptr));

92 +

PyObject_CallMethod(py_msg_, "SerializePartialToString", nullptr));

86 93

if (py_serialized_pb == nullptr) {

87 94

PyErr_Format(PyExc_ValueError, "Fail to serialize py_msg");

88 95

return false;

@@ -99,19 +106,19 @@ bool PythonConstMessagePointer::NotChanged() {

99 106

// serialize result may still diff between languages. So parse to

100 107

// another c++ message for compare.

101 108

std::unique_ptr<google::protobuf::Message> parsed_msg(owned_msg_->New());

102 -

parsed_msg->ParseFromArray(data, static_cast<int>(len));

109 +

parsed_msg->ParsePartialFromArray(data, static_cast<int>(len));

103 110

std::string wire_other;

104 111

google::protobuf::io::StringOutputStream stream_other(&wire_other);

105 112

google::protobuf::io::CodedOutputStream output_other(&stream_other);

106 113

output_other.SetSerializationDeterministic(true);

107 -

parsed_msg->SerializeToCodedStream(&output_other);

114 +

parsed_msg->SerializePartialToCodedStream(&output_other);

108 115

output_other.Trim();

109 116 110 117

std::string wire;

111 118

google::protobuf::io::StringOutputStream stream(&wire);

112 119

google::protobuf::io::CodedOutputStream output(&stream);

113 120

output.SetSerializationDeterministic(true);

114 -

owned_msg_->SerializeToCodedStream(&output);

121 +

owned_msg_->SerializePartialToCodedStream(&output);

115 122

output.Trim();

116 123 117 124

if (wire == wire_other) {

Original file line number Diff line number Diff line change

@@ -85,7 +85,7 @@ class ProtoAPIDescriptorDatabase : public google::protobuf::DescriptorDatabase {

85 85

return false;

86 86

}

87 87 88 -

bool ok = output->ParseFromArray(

88 +

bool ok = output->ParsePartialFromArray(

89 89

reinterpret_cast<uint8_t*>(PyBytes_AS_STRING(pyfile_serialized)),

90 90

PyBytes_GET_SIZE(pyfile_serialized));

91 91

if (!ok) {

@@ -207,8 +207,8 @@ absl::StatusOr<google::protobuf::Message*> CreateNewMessage(PyObject* py_msg) {

207 207

bool CopyToOwnedMsg(google::protobuf::Message** copy, const google::protobuf::Message& message) {

208 208

*copy = message.New();

209 209

std::string wire;

210 -

message.SerializeToString(&wire);

211 -

(*copy)->ParseFromArray(wire.data(), wire.size());

210 +

message.SerializePartialToString(&wire);

211 +

(*copy)->ParsePartialFromArray(wire.data(), wire.size());

212 212

return true;

213 213

}

214 214

@@ -245,7 +245,7 @@ struct ApiImplementation : google::protobuf::python::PyProto_API {

245 245

auto msg = CreateNewMessage(py_msg);

246 246

RETURN_IF_ERROR(msg.status());

247 247

PyObject* serialized_pb(

248 -

PyObject_CallMethod(py_msg, "SerializeToString", nullptr));

248 +

PyObject_CallMethod(py_msg, "SerializePartialToString", nullptr));

249 249

if (serialized_pb == nullptr) {

250 250

return absl::InternalError("Fail to serialize py_msg");

251 251

}

@@ -256,7 +256,7 @@ struct ApiImplementation : google::protobuf::python::PyProto_API {

256 256

return absl::InternalError(

257 257

"Fail to get bytes from py_msg serialized data");

258 258

}

259 -

if (!(*msg)->ParseFromArray(data, len)) {

259 +

if (!(*msg)->ParsePartialFromArray(data, len)) {

260 260

Py_DECREF(serialized_pb);

261 261

return absl::InternalError(

262 262

"Couldn't parse py_message to google::protobuf::Message*!");

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4