Skip to content

Commit

Permalink
delete CallError
Browse files Browse the repository at this point in the history
  • Loading branch information
hslam committed Dec 2, 2020
1 parent b140760 commit 10a25a7
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 74 deletions.
12 changes: 3 additions & 9 deletions codec.code.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,15 @@ func (req *request) Unmarshal(data []byte) (uint64, error) {
}

type response struct {
Seq uint64
CallError bool
Error string
Reply []byte
Seq uint64
Error string
Reply []byte
}

//Marshal marshals the Response into buf and returns the bytes.
func (res *response) Marshal(buf []byte) ([]byte, error) {
var size uint64
size += 10
size++
size += 10 + uint64(len(res.Error))
size += 10 + uint64(len(res.Reply))
if uint64(cap(buf)) >= size {
Expand All @@ -181,8 +179,6 @@ func (res *response) Marshal(buf []byte) ([]byte, error) {
n = size
}
offset += n
n = code.EncodeBool(buf[offset:], res.CallError)
offset += n
//n = code.EncodeString(buf[offset:], res.Error)
if len(res.Error) > 127 {
var length = uint64(len(res.Error))
Expand Down Expand Up @@ -238,8 +234,6 @@ func (res *response) Unmarshal(data []byte) (uint64, error) {
var n uint64
n = code.DecodeVarint(data[offset:], &res.Seq)
offset += n
n = code.DecodeBool(data[offset:], &res.CallError)
offset += n
if data[offset] > 0 {
n = code.DecodeString(data[offset:], &res.Error)
} else {
Expand Down
1 change: 0 additions & 1 deletion codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Context struct {
Seq uint64
Upgrade []byte
ServiceMethod string
CallError bool
Error string
upgrade *upgrade
keepReading bool
Expand Down
7 changes: 3 additions & 4 deletions codec.json.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ type jsonRequest struct {
}

type jsonResponse struct {
Seq uint64 `json:"i"`
CallError bool `json:"c"`
Error string `json:"e"`
Reply []byte `json:"r"`
Seq uint64 `json:"i"`
Error string `json:"e"`
Reply []byte `json:"r"`
}
26 changes: 6 additions & 20 deletions codec.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,15 @@ func (req *pbRequest) Unmarshal(data []byte) error {
}

type pbResponse struct {
Seq uint64
CallError bool
Error string
Reply []byte
Seq uint64
Error string
Reply []byte
}

// Size return the buf size.
func (res *pbResponse) Size() (n int) {
var size uint64
size += 11
size += 11
size += 11 + uint64(len(res.Error))
size += 11 + uint64(len(res.Reply))
return int(size)
Expand Down Expand Up @@ -223,14 +221,8 @@ func (res *pbResponse) MarshalTo(buf []byte) (int, error) {
}
offset += n
}
if res.CallError {
buf[offset] = 2<<3 | 0
offset++
n = code.EncodeBool(buf[offset:], res.CallError)
offset += n
}
if len(res.Error) > 0 {
buf[offset] = 3<<3 | 2
buf[offset] = 2<<3 | 2
offset++
//n = code.EncodeString(buf[offset:], res.Error)
{
Expand All @@ -249,7 +241,7 @@ func (res *pbResponse) MarshalTo(buf []byte) (int, error) {
offset += n
}
if len(res.Reply) > 0 {
buf[offset] = 4<<3 | 2
buf[offset] = 3<<3 | 2
offset++
//n = code.EncodeBytes(buf[offset:], res.Reply)
{
Expand Down Expand Up @@ -295,18 +287,12 @@ func (res *pbResponse) Unmarshal(data []byte) error {
n = code.DecodeVarint(data[offset:], &res.Seq)
offset += n
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Seq", wireType)
}
n = code.DecodeBool(data[offset:], &res.CallError)
offset += n
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType)
}
n = code.DecodeString(data[offset:], &res.Error)
offset += n
case 4:
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Reply", wireType)
}
Expand Down
2 changes: 0 additions & 2 deletions codec_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (c *clientCodec) ReadResponseHeader(ctx *Context) error {
ctx.Error = ""
ctx.Seq = c.headerEncoder.Response.GetSeq()
if c.headerEncoder.Response.GetError() != "" || len(c.headerEncoder.Response.GetReply()) == 0 {
ctx.CallError = c.headerEncoder.Response.GetCallError()
ctx.Error = c.headerEncoder.Response.GetError()
} else if len(c.headerEncoder.Response.GetReply()) > 0 {
ctx.value = c.headerEncoder.Response.GetReply()
Expand All @@ -125,7 +124,6 @@ func (c *clientCodec) ReadResponseHeader(ctx *Context) error {
ctx.Error = ""
ctx.Seq = c.res.GetSeq()
if c.res.GetError() != "" || len(c.res.GetReply()) == 0 {
ctx.CallError = c.res.GetCallError()
ctx.Error = c.res.GetError()
} else if len(c.res.GetReply()) > 0 {
ctx.value = c.res.GetReply()
Expand Down
2 changes: 0 additions & 2 deletions codec_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func (c *serverCodec) WriteResponse(ctx *Context, x interface{}) error {
}
if c.headerEncoder != nil {
c.headerEncoder.Response.SetSeq(reqSeq)
c.headerEncoder.Response.SetCallError(ctx.CallError)
c.headerEncoder.Response.SetError(ctx.Error)
c.headerEncoder.Response.SetReply(reply)
data, err = c.headerEncoder.Codec.Marshal(c.responseBuffer, c.headerEncoder.Response)
Expand All @@ -123,7 +122,6 @@ func (c *serverCodec) WriteResponse(ctx *Context, x interface{}) error {
}
} else {
c.res.SetSeq(reqSeq)
c.res.SetCallError(ctx.CallError)
c.res.SetError(ctx.Error)
c.res.SetReply(reply)
data, err = c.res.Marshal(c.responseBuffer)
Expand Down
6 changes: 3 additions & 3 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCodecCODE(t *testing.T) {
var req = request{Seq: 1024, Upgrade: make([]byte, 512), ServiceMethod: strings.Repeat("a", 512), Args: make([]byte, 512)}
var res = response{Seq: 1024, CallError: true, Error: strings.Repeat("e", 512), Reply: make([]byte, 512)}
var res = response{Seq: 1024, Error: strings.Repeat("e", 512), Reply: make([]byte, 512)}
var c = codec.CODECodec{}
var data []byte
{
Expand Down Expand Up @@ -57,7 +57,7 @@ func BenchmarkRoundtripCODE(t *testing.B) {

func TestCodecPB(t *testing.T) {
var req = pbRequest{Seq: 1024, Upgrade: make([]byte, 512), ServiceMethod: strings.Repeat("a", 512), Args: make([]byte, 512)}
var res = pbResponse{Seq: 1024, CallError: true, Error: strings.Repeat("e", 512), Reply: make([]byte, 512)}
var res = pbResponse{Seq: 1024, Error: strings.Repeat("e", 512), Reply: make([]byte, 512)}
var c = codec.GOGOPBCodec{}
var data []byte
{
Expand Down Expand Up @@ -111,7 +111,7 @@ func BenchmarkRoundtripPB(t *testing.B) {

func TestCodecJSON(t *testing.T) {
var req = jsonRequest{Seq: 1024, Upgrade: make([]byte, 512), ServiceMethod: strings.Repeat("a", 512), Args: make([]byte, 512)}
var res = jsonResponse{Seq: 1024, CallError: true, Error: strings.Repeat("e", 512), Reply: make([]byte, 512)}
var res = jsonResponse{Seq: 1024, Error: strings.Repeat("e", 512), Reply: make([]byte, 512)}
var c = codec.JSONCodec{}
var bufq = make([]byte, 10240)
var bufs = make([]byte, 10240)
Expand Down
10 changes: 0 additions & 10 deletions encoder.code.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ func (res *response) GetSeq() uint64 {
return res.Seq
}

// SetCallError sets the value of CallError.
func (res *response) SetCallError(callError bool) {
res.CallError = callError
}

// GetCallError returns the value of CallError.
func (res *response) GetCallError() bool {
return res.CallError
}

//SetError sets the value of Error.
func (res *response) SetError(errorMsg string) {
res.Error = errorMsg
Expand Down
2 changes: 0 additions & 2 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ type Request interface {
type Response interface {
SetSeq(uint64)
GetSeq() uint64
SetCallError(bool)
GetCallError() bool
SetError(string)
GetError() string
SetReply([]byte)
Expand Down
10 changes: 0 additions & 10 deletions encoder.json.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ func (res *jsonResponse) GetSeq() uint64 {
return res.Seq
}

// SetCallError sets the value of CallError.
func (res *jsonResponse) SetCallError(callError bool) {
res.CallError = callError
}

// GetCallError returns the value of CallError.
func (res *jsonResponse) GetCallError() bool {
return res.CallError
}

// SetError sets the value of Error.
func (res *jsonResponse) SetError(errorMsg string) {
res.Error = errorMsg
Expand Down
10 changes: 0 additions & 10 deletions encoder.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ func (res *pbResponse) GetSeq() uint64 {
return res.Seq
}

// SetCallError sets the value of CallError.
func (res *pbResponse) SetCallError(callError bool) {
res.CallError = callError
}

// GetCallError returns the value of CallError.
func (res *pbResponse) GetCallError() bool {
return res.CallError
}

// SetError sets the value of Error.
func (res *pbResponse) SetError(errorMsg string) {
res.Error = errorMsg
Expand Down
1 change: 0 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ func (server *Server) callService(wg *sync.WaitGroup, ctx *Context) {
return
}
if err := ctx.f.ValueCall(ctx.args, ctx.reply); err != nil {
ctx.CallError = true
ctx.Error = err.Error()
}
server.sendResponse(ctx)
Expand Down

0 comments on commit 10a25a7

Please sign in to comment.