Commit b79f0126 authored by AlexStocks's avatar AlexStocks

Fix: do not encode nil body

parent e3cfbea1
......@@ -426,14 +426,20 @@ func (resp *GettyRPCResponse) Marshal(sz CodecType, buf *bytes.Buffer) (int, err
if codec == nil {
return 0, jerrors.Errorf("can not find codec for %d", sz)
}
headerData, err := codec.Encode(&resp.header)
var err error
var headerData, bodyData []byte
headerData, err = codec.Encode(&resp.header)
if err != nil {
return 0, jerrors.Trace(err)
}
bodyData, err := codec.Encode(resp.body)
if err != nil {
return 0, jerrors.Trace(err)
if resp.body != nil {
bodyData, err = codec.Encode(resp.body)
if err != nil {
return 0, jerrors.Trace(err)
}
}
err = binary.Write(buf, binary.LittleEndian, uint16(len(headerData)))
......
......@@ -7,7 +7,6 @@ import (
import (
"github.com/AlexStocks/getty"
"github.com/AlexStocks/goext/log"
log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
)
......@@ -48,7 +47,6 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface
return req, length, nil
}
// get service & method
gxlog.CError("req service:%s, service map:%#v", req.header.Service, p.server.serviceMap)
req.service = p.server.serviceMap[req.header.Service]
if req.service != nil {
req.methodType = req.service.method[req.header.Method]
......@@ -144,7 +142,7 @@ func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) error
buf, err := req.Marshal()
if err != nil {
log.Warn("binary.Write(req{%#v}) = err{%#v}", req, err)
log.Warn("binary.Write(req{%#v}) = err{%#v}", req, jerrors.ErrorStack(err))
return jerrors.Trace(err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment