Skip to content

Commit 4341d9b

Browse files
committed
correct capitalization
1 parent 1e39e03 commit 4341d9b

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

server/util/proto/proto.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var Bool = gproto.Bool
2020
type Message = gproto.Message
2121
type MarshalOptions = gproto.MarshalOptions
2222

23-
type VtprotoMessage interface {
23+
type VTProtoMessage interface {
2424
MarshalVT() ([]byte, error)
2525
UnmarshalVT([]byte) error
2626
CloneMessageVT() Message
@@ -31,15 +31,15 @@ type VtprotoMessage interface {
3131
}
3232

3333
func Marshal(v Message) ([]byte, error) {
34-
vt, ok := v.(VtprotoMessage)
34+
vt, ok := v.(VTProtoMessage)
3535
if ok {
3636
return vt.MarshalVT()
3737
}
3838
return MarshalOld(v)
3939
}
4040

4141
func Unmarshal(b []byte, v Message) error {
42-
vt, ok := v.(VtprotoMessage)
42+
vt, ok := v.(VTProtoMessage)
4343
if ok {
4444
return vt.UnmarshalVT(b)
4545
}
@@ -48,7 +48,7 @@ func Unmarshal(b []byte, v Message) error {
4848
}
4949

5050
func Clone(v Message) Message {
51-
vt, ok := v.(VtprotoMessage)
51+
vt, ok := v.(VTProtoMessage)
5252
if ok {
5353
return vt.CloneMessageVT()
5454
}

server/util/vtprotocodec/vtprotocodec.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,48 @@ import (
1111

1212
const Name = "proto"
1313

14-
// vtprotoCodecV2 implements encoding.CodecV2 and uses vtproto and default buffer pool
14+
// CodecV2 implements encoding.CodecV2 and uses vtproto and default buffer pool
1515
// to encode/decode proto messages. The implementation is heavily inspired by
1616
// https://github.com/planetscale/vtprotobuf/pull/138
1717
// and https://github.com/vitessio/vitess/pull/16790.
18-
type vtprotoCodecV2 struct {
18+
type CodecV2 struct {
1919
fallback encoding.CodecV2
2020
}
2121

22-
func (vtprotoCodecV2) Name() string {
22+
func (CodecV2) Name() string {
2323
return Name
2424
}
2525

26-
func (c *vtprotoCodecV2) Marshal(v any) (mem.BufferSlice, error) {
27-
m, ok := v.(proto.VtprotoMessage)
26+
func (c *CodecV2) Marshal(v any) (mem.BufferSlice, error) {
27+
m, ok := v.(proto.VTProtoMessage)
2828
if !ok {
2929
return c.fallback.Marshal(v)
3030
}
31-
3231
size := m.SizeVT()
3332
if mem.IsBelowBufferPoolingThreshold(size) {
34-
buf := make([]byte, 0, size)
35-
if _, err := m.MarshalToSizedBufferVT(buf[:size]); err != nil {
33+
buf := make([]byte, size)
34+
n, err := m.MarshalToSizedBufferVT(buf)
35+
if err != nil {
3636
return nil, err
3737
}
38-
return mem.BufferSlice{mem.SliceBuffer(buf)}, nil
38+
return mem.BufferSlice{mem.SliceBuffer(buf[:n])}, nil
3939
}
40-
4140
pool := mem.DefaultBufferPool()
4241
buf := pool.Get(size)
43-
if _, err := m.MarshalToSizedBufferVT((*buf)[:size]); err != nil {
42+
n, err := m.MarshalToSizedBufferVT(*buf)
43+
if err != nil {
4444
pool.Put(buf)
4545
return nil, err
4646
}
47+
*buf = (*buf)[:n]
4748
return mem.BufferSlice{mem.NewBuffer(buf, pool)}, nil
4849
}
4950

50-
func (c *vtprotoCodecV2) Unmarshal(data mem.BufferSlice, v any) error {
51-
m, ok := v.(proto.VtprotoMessage)
51+
func (c *CodecV2) Unmarshal(data mem.BufferSlice, v any) error {
52+
m, ok := v.(proto.VTProtoMessage)
5253
if !ok {
5354
return c.fallback.Unmarshal(data, v)
5455
}
55-
5656
buf := data.MaterializeToBuffer(mem.DefaultBufferPool())
5757
defer buf.Free()
5858
return m.UnmarshalVT(buf.ReadOnlyData())
@@ -61,7 +61,8 @@ func (c *vtprotoCodecV2) Unmarshal(data mem.BufferSlice, v any) error {
6161
// RegisterCodec registers the vtprotoCodec to encode/decode proto messages with
6262
// all gRPC clients and servers.
6363
func Register() {
64-
encoding.RegisterCodecV2(&vtprotoCodecV2{
64+
encoding.RegisterCodecV2(&CodecV2{
65+
// the default codecv2 implemented in @org_golang_google_grpc//encoding/proto.
6566
fallback: encoding.GetCodecV2("proto"),
6667
})
6768
}

0 commit comments

Comments
 (0)