Avoid redundant ByteSizeLong() call.

Given we have called ByteSizeLog() at line 52, we can use WithCachedSizes here.

PiperOrigin-RevId: 656534835
pull/37252/head
Chris Kennelly 4 months ago committed by Copybara-Service
parent 7e089a22d7
commit 164d4c63c8
  1. 2
      include/grpcpp/impl/codegen/config_protobuf.h
  2. 4
      include/grpcpp/impl/proto_utils.h

@ -71,6 +71,7 @@
#define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM \
::google::protobuf::io::ZeroCopyInputStream
#define GRPC_CUSTOM_CODEDINPUTSTREAM ::google::protobuf::io::CodedInputStream
#define GRPC_CUSTOM_CODEDOUTPUTSTREAM ::google::protobuf::io::CodedOutputStream
#endif
#ifndef GRPC_CUSTOM_JSONUTIL
@ -113,6 +114,7 @@ namespace io {
typedef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ZeroCopyOutputStream;
typedef GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ZeroCopyInputStream;
typedef GRPC_CUSTOM_CODEDINPUTSTREAM CodedInputStream;
typedef GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream;
} // namespace io
} // namespace protobuf

@ -61,7 +61,9 @@ Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb,
return grpc::Status::OK;
}
ProtoBufferWriter writer(bb, kProtoBufferWriterMaxBufferLength, byte_size);
return msg.SerializeToZeroCopyStream(&writer)
protobuf::io::CodedOutputStream cs(&writer);
msg.SerializeWithCachedSizes(&cs);
return !cs.HadError()
? grpc::Status::OK
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}

Loading…
Cancel
Save