1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-08-10 21:52:01 +02:00

Allow bytes.Frame to be set to sent just bytes

This commit is contained in:
Asim Aslam
2019-01-16 15:27:57 +00:00
parent a9c0b95603
commit 784a89b488
3 changed files with 32 additions and 13 deletions

View File

@@ -127,6 +127,12 @@ func (c *rpcCodec) ReadBody(b interface{}) error {
if len(c.req.Body) == 0 {
return nil
}
// read raw data
if v, ok := b.(*raw.Frame); ok {
v.Data = c.req.Body
return nil
}
// decode the usual way
return c.codec.ReadBody(b)
}
@@ -168,8 +174,11 @@ func (c *rpcCodec) Write(r *codec.Message, b interface{}) error {
// the body being sent
var body []byte
// if we have encoded data just send it
if len(r.Body) > 0 {
// is it a raw frame?
if v, ok := b.(*raw.Frame); ok {
body = v.Data
// if we have encoded data just send it
} else if len(r.Body) > 0 {
body = r.Body
// write the body to codec
} else if err := c.codec.Write(m, b); err != nil {
@@ -182,7 +191,6 @@ func (c *rpcCodec) Write(r *codec.Message, b interface{}) error {
if err := c.codec.Write(m, nil); err != nil {
return err
}
// write the body
} else {
// set the body
body = c.buf.wbuf.Bytes()