Skip to content

Commit 19a8cef

Browse files
committed
proto: enable use cached size option
1 parent e60a04b commit 19a8cef

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

encoding/proto/proto.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ package proto
2323
import (
2424
"fmt"
2525

26-
"google.golang.org/grpc/encoding"
27-
"google.golang.org/grpc/mem"
2826
"google.golang.org/protobuf/proto"
2927
"google.golang.org/protobuf/protoadapt"
28+
29+
"google.golang.org/grpc/encoding"
30+
"google.golang.org/grpc/mem"
3031
)
3132

3233
// Name is the name registered for the proto compressor.
@@ -48,15 +49,15 @@ func (c *codecV2) Marshal(v any) (data mem.BufferSlice, err error) {
4849

4950
size := proto.Size(vv)
5051
if mem.IsBelowBufferPoolingThreshold(size) {
51-
buf, err := proto.Marshal(vv)
52+
buf, err := proto.MarshalOptions{UseCachedSize: true}.Marshal(vv)
5253
if err != nil {
5354
return nil, err
5455
}
5556
data = append(data, mem.SliceBuffer(buf))
5657
} else {
5758
pool := mem.DefaultBufferPool()
5859
buf := pool.Get(size)
59-
if _, err := (proto.MarshalOptions{}).MarshalAppend((*buf)[:0], vv); err != nil {
60+
if _, err := (proto.MarshalOptions{UseCachedSize: true}).MarshalAppend((*buf)[:0], vv); err != nil {
6061
pool.Put(buf)
6162
return nil, err
6263
}

0 commit comments

Comments
 (0)