Skip to content

Commit

Permalink
Don't depend on github.com/golang/protobuf/proto
Browse files Browse the repository at this point in the history
  • Loading branch information
aureliar8 committed May 18, 2024
1 parent a5301e8 commit db5b5b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions codec/grpc/grpc_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package grpc

import (
"fmt"

"github.com/golang/protobuf/proto" //nolint
)

// Name is the name registered for the proto compressor.
Expand All @@ -16,6 +14,10 @@ type vtprotoMessage interface {
UnmarshalVT([]byte) error
}

type reseter interface{
Reset()
}

func (Codec) Marshal(v interface{}) ([]byte, error) {
vt, ok := v.(vtprotoMessage)
if !ok {
Expand All @@ -29,9 +31,10 @@ func (Codec) Unmarshal(data []byte, v interface{}) error {
if !ok {
return fmt.Errorf("failed to unmarshal, message is %T (missing vtprotobuf helpers)", v)
}
vv, ok := v.(proto.Message)
//All types that implement github.com/golang/protobuf/proto.Message have a Reset method
vv, ok := v.(reseter)
if !ok {
return fmt.Errorf("failed to unmarshal, message is %T (can't reset)", vv)
return fmt.Errorf("failed to unmarshal: can't reset. Message type %T don't implement Reset()", vv)
}
vv.Reset()
return vt.UnmarshalVT(data)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/planetscale/vtprotobuf
go 1.20

require (
github.com/golang/protobuf v1.5.3
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.58.2
google.golang.org/protobuf v1.31.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
Expand Down

0 comments on commit db5b5b4

Please sign in to comment.