Skip to content
Snippets Groups Projects
Commit cc5dc5bb authored by Craig Tiller's avatar Craig Tiller
Browse files

Fast path for proto serialization for small protos

parent fc193e1f
No related branches found
No related tags found
No related merge requests found
...@@ -158,11 +158,20 @@ namespace grpc { ...@@ -158,11 +158,20 @@ namespace grpc {
Status SerializeProto(const grpc::protobuf::Message& msg, Status SerializeProto(const grpc::protobuf::Message& msg,
grpc_byte_buffer** bp) { grpc_byte_buffer** bp) {
int byte_size = msg.ByteSize();
if (byte_size <= kMaxBufferLength) {
gpr_slice slice = gpr_slice_malloc(byte_size);
GPR_ASSERT(GPR_SLICE_END_PTR(slice) == msg.SerializeWithCachedSizesToArray(GPR_SLICE_START_PTR(slice)));
*bp = grpc_raw_byte_buffer_create(&slice, 1);
gpr_slice_unref(slice);
return Status::OK;
} else {
GrpcBufferWriter writer(bp); GrpcBufferWriter writer(bp);
return msg.SerializeToZeroCopyStream(&writer) return msg.SerializeToZeroCopyStream(&writer)
? Status::OK ? Status::OK
: Status(StatusCode::INTERNAL, "Failed to serialize message"); : Status(StatusCode::INTERNAL, "Failed to serialize message");
} }
}
Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,
int max_message_size) { int max_message_size) {
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment