fix: add gRPC nil/zero check in query (#13352)

This commit is contained in:
yihuang
2022-09-29 01:20:03 +00:00
committed by GitHub
parent 3d0e214446
commit a9f02d9cb7
4 changed files with 39 additions and 6 deletions
+5
View File
@@ -43,6 +43,11 @@ func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec {
// NOTE: this function must be used with a concrete type which
// implements proto.Message. For interface please use the codec.MarshalInterface
func (pc *ProtoCodec) Marshal(o ProtoMarshaler) ([]byte, error) {
// Size() check can catch the typed nil value.
if o == nil || o.Size() == 0 {
// return empty bytes instead of nil, because nil has special meaning in places like store.Set
return []byte{}, nil
}
return o.Marshal()
}