From f60b239b6777d8f84b0e1d78973882cb6d386cef Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 4 Jul 2019 14:06:29 +0300 Subject: [PATCH] codec grpc: fix extra allocations on message unmarshal Signed-off-by: Vasiliy Tolstov --- codec.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/codec.go b/codec.go index 7562a04..7362f49 100644 --- a/codec.go +++ b/codec.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + b "bytes" + "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" "github.com/micro/go-micro/codec" @@ -81,7 +83,7 @@ func (jsonCodec) Marshal(v interface{}) ([]byte, error) { func (jsonCodec) Unmarshal(data []byte, v interface{}) error { if pb, ok := v.(proto.Message); ok { - return jsonpb.UnmarshalString(string(data), pb) + return jsonpb.Unmarshal(b.NewReader(data), pb) } return json.Unmarshal(data, v)