Skip to content
Snippets Groups Projects
Commit f99c0906 authored by yang-g's avatar yang-g
Browse files

return StatusCode::INTERNAL for proto parsing error

parent 826f07eb
No related branches found
No related tags found
No related merge requests found
......@@ -158,14 +158,13 @@ Status SerializeProto(const grpc::protobuf::Message& msg, grpc_byte_buffer** bp)
GrpcBufferWriter writer(bp);
return msg.SerializeToZeroCopyStream(&writer)
? Status::OK
: Status(StatusCode::INVALID_ARGUMENT,
"Failed to serialize message");
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}
Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,
int max_message_size) {
if (!buffer) {
return Status(StatusCode::INVALID_ARGUMENT, "No payload");
return Status(StatusCode::INTERNAL, "No payload");
}
GrpcBufferReader reader(buffer);
::grpc::protobuf::io::CodedInputStream decoder(&reader);
......@@ -173,11 +172,11 @@ Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,
decoder.SetTotalBytesLimit(max_message_size, max_message_size);
}
if (!msg->ParseFromCodedStream(&decoder)) {
return Status(StatusCode::INVALID_ARGUMENT,
return Status(StatusCode::INTERNAL,
msg->InitializationErrorString());
}
if (!decoder.ConsumedEntireMessage()) {
return Status(StatusCode::INVALID_ARGUMENT, "Did not read entire message");
return Status(StatusCode::INTERNAL, "Did not read entire message");
}
return Status::OK;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment