Skip to content

Commit

Permalink
Avoid redundant ByteSizeLong() call.
Browse files Browse the repository at this point in the history
Given we have called ByteSizeLog() at line 52, we can use WithCachedSizes here.

PiperOrigin-RevId: 656534835
  • Loading branch information
ckennelly authored and copybara-github committed Jul 26, 2024
1 parent 7e089a2 commit 164d4c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/grpcpp/impl/codegen/config_protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion include/grpcpp/impl/proto_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 164d4c6

Please sign in to comment.