From 2561a958d3285aad2d9437eb3ef2f8ec92ef8e4f Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 23 Dec 2024 20:44:18 +0300 Subject: [PATCH] add codec.RawMessage support Signed-off-by: Vasiliy Tolstov --- go.mod | 7 ++----- go.sum | 9 ++------- proto.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index a07375e..cf52c95 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,7 @@ go 1.22 require ( go.unistack.org/micro-proto/v3 v3.4.1 go.unistack.org/micro/v3 v3.10.88 - google.golang.org/protobuf v1.34.2 + google.golang.org/protobuf v1.35.2 ) -require ( - github.com/google/go-cmp v0.5.7 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect -) +require github.com/google/go-cmp v0.6.0 // indirect diff --git a/go.sum b/go.sum index 219f567..9a524e8 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,6 @@ -github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q= go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo= go.unistack.org/micro/v3 v3.10.88 h1:MxlzP+77Y6Kphb3lzHxROL4XfE/WdCQMQpnPv4D9Z8U= go.unistack.org/micro/v3 v3.10.88/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= diff --git a/proto.go b/proto.go index 6c2ae1c..7e5cdfa 100644 --- a/proto.go +++ b/proto.go @@ -61,6 +61,10 @@ func (c *protoCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error } } return marshalOptions.Marshal(m) + case codec.RawMessage: + return []byte(m), nil + case *codec.RawMessage: + return []byte(*m), nil default: return nil, codec.ErrInvalidMessage } @@ -97,6 +101,12 @@ func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) er } } return unmarshalOptions.Unmarshal(d, m) + case *codec.RawMessage: + *m = append((*m)[0:0], d...) + return nil + case codec.RawMessage: + copy(m, d) + return nil default: return codec.ErrInvalidMessage }