From 4904cad8efdaf8cee6fc49af303821190eb3e7de Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 21 Mar 2022 15:23:41 +0300 Subject: [PATCH] server: remove unparsed body from request and message Signed-off-by: Vasiliy Tolstov --- server/request.go | 6 +----- server/server.go | 4 +--- server/subscriber.go | 7 +++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/server/request.go b/server/request.go index 09271c74..6b20e988 100644 --- a/server/request.go +++ b/server/request.go @@ -22,7 +22,7 @@ func (r *rpcMessage) Topic() string { return r.topic } -func (r *rpcMessage) Payload() interface{} { +func (r *rpcMessage) Body() interface{} { return r.payload } @@ -30,10 +30,6 @@ func (r *rpcMessage) Header() metadata.Metadata { return r.header } -func (r *rpcMessage) Body() []byte { - return r.body -} - func (r *rpcMessage) Codec() codec.Codec { return r.codec } diff --git a/server/server.go b/server/server.go index 5e9cde3f..9dfa9b58 100644 --- a/server/server.go +++ b/server/server.go @@ -75,13 +75,11 @@ type Message interface { // Topic of the message Topic() string // The decoded payload value - Payload() interface{} + Body() interface{} // The content type of the payload ContentType() string // The raw headers of the message Header() metadata.Metadata - // The raw body of the message - Body() []byte // Codec used to decode the message Codec() codec.Codec } diff --git a/server/subscriber.go b/server/subscriber.go index 2d472251..765a61ee 100644 --- a/server/subscriber.go +++ b/server/subscriber.go @@ -252,7 +252,7 @@ func (n *noopServer) newBatchSubHandler(sb *subscriber, opts Options) broker.Bat return err } rb := reflect.New(req.Type().Elem()) - if err = cf.ReadBody(bytes.NewReader(msg.Body()), rb.Interface()); err != nil { + if err = cf.ReadBody(bytes.NewReader(msg.(*rpcMessage).body), rb.Interface()); err != nil { return err } msg.(*rpcMessage).codec = cf @@ -269,7 +269,7 @@ func (n *noopServer) newBatchSubHandler(sb *subscriber, opts Options) broker.Bat } payloads := reflect.MakeSlice(reqType, 0, len(ms)) for _, m := range ms { - payloads = reflect.Append(payloads, reflect.ValueOf(m.Payload())) + payloads = reflect.Append(payloads, reflect.ValueOf(m.Body())) } vals = append(vals, payloads) @@ -381,7 +381,7 @@ func (n *noopServer) newSubHandler(sb *subscriber, opts Options) broker.Handler vals = append(vals, reflect.ValueOf(ctx)) } - vals = append(vals, reflect.ValueOf(msg.Payload())) + vals = append(vals, reflect.ValueOf(msg.Body())) returnValues := handler.method.Call(vals) if rerr := returnValues[0].Interface(); rerr != nil { @@ -406,7 +406,6 @@ func (n *noopServer) newSubHandler(sb *subscriber, opts Options) broker.Handler contentType: ct, payload: req.Interface(), header: msg.Header, - body: msg.Body, }) results <- cerr }() -- 2.45.2