diff --git a/codec/grpc/grpc_codec.go b/codec/grpc/grpc_codec.go index 9b72fcd..3e7951c 100644 --- a/codec/grpc/grpc_codec.go +++ b/codec/grpc/grpc_codec.go @@ -1,6 +1,8 @@ package grpc -import "fmt" +import ( + "fmt" +) // Name is the name registered for the proto compressor. const Name = "proto" @@ -12,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 { @@ -25,6 +31,12 @@ func (Codec) Unmarshal(data []byte, v interface{}) error { if !ok { return fmt.Errorf("failed to unmarshal, message is %T (missing vtprotobuf helpers)", v) } + //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: can't reset. Message type %T don't implement Reset()", vv) + } + vv.Reset() return vt.UnmarshalVT(data) }