rename rpc codec

This commit is contained in:
Asim Aslam 2018-11-23 20:05:31 +00:00
parent 4dc593eca3
commit 34ed5235a3
3 changed files with 9 additions and 9 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
type rpcPlusCodec struct { type rpcCodec struct {
socket transport.Socket socket transport.Socket
codec codec.Codec codec codec.Codec
@ -47,12 +47,12 @@ func (rwc *readWriteCloser) Close() error {
return nil return nil
} }
func newRpcPlusCodec(req *transport.Message, socket transport.Socket, c codec.NewCodec) serverCodec { func newRpcCodec(req *transport.Message, socket transport.Socket, c codec.NewCodec) serverCodec {
rwc := &readWriteCloser{ rwc := &readWriteCloser{
rbuf: bytes.NewBuffer(req.Body), rbuf: bytes.NewBuffer(req.Body),
wbuf: bytes.NewBuffer(nil), wbuf: bytes.NewBuffer(nil),
} }
r := &rpcPlusCodec{ r := &rpcCodec{
buf: rwc, buf: rwc,
codec: c(rwc), codec: c(rwc),
req: req, req: req,
@ -61,7 +61,7 @@ func newRpcPlusCodec(req *transport.Message, socket transport.Socket, c codec.Ne
return r return r
} }
func (c *rpcPlusCodec) ReadRequestHeader(r *request, first bool) error { func (c *rpcCodec) ReadRequestHeader(r *request, first bool) error {
m := codec.Message{Header: c.req.Header} m := codec.Message{Header: c.req.Header}
if !first { if !first {
@ -83,11 +83,11 @@ func (c *rpcPlusCodec) ReadRequestHeader(r *request, first bool) error {
return err return err
} }
func (c *rpcPlusCodec) ReadRequestBody(b interface{}) error { func (c *rpcCodec) ReadRequestBody(b interface{}) error {
return c.codec.ReadBody(b) return c.codec.ReadBody(b)
} }
func (c *rpcPlusCodec) WriteResponse(r *response, body interface{}, last bool) error { func (c *rpcCodec) WriteResponse(r *response, body interface{}, last bool) error {
c.buf.wbuf.Reset() c.buf.wbuf.Reset()
m := &codec.Message{ m := &codec.Message{
Method: r.ServiceMethod, Method: r.ServiceMethod,
@ -111,7 +111,7 @@ func (c *rpcPlusCodec) WriteResponse(r *response, body interface{}, last bool) e
}) })
} }
func (c *rpcPlusCodec) Close() error { func (c *rpcCodec) Close() error {
c.buf.Close() c.buf.Close()
c.codec.Close() c.codec.Close()
return c.socket.Close() return c.socket.Close()

View File

@ -38,7 +38,7 @@ func TestCodecWriteError(t *testing.T) {
wbuf: new(bytes.Buffer), wbuf: new(bytes.Buffer),
} }
c := rpcPlusCodec{ c := rpcCodec{
buf: &rwc, buf: &rwc,
codec: &testCodec{ codec: &testCodec{
buf: rwc.wbuf, buf: rwc.wbuf,

View File

@ -87,7 +87,7 @@ func (s *rpcServer) accept(sock transport.Socket) {
return return
} }
codec := newRpcPlusCodec(&msg, sock, cf) codec := newRpcCodec(&msg, sock, cf)
// strip our headers // strip our headers
hdr := make(map[string]string) hdr := make(map[string]string)