Skip to content

Commit

Permalink
fix empty biz body unwrapBinary EOF error (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: xielei.xielei <[email protected]>
  • Loading branch information
wodeqiangne and xielei.xielei authored Aug 10, 2024
1 parent 2326e65 commit 0edfd20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion thrift/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,14 @@ func (p BinaryProtocol) UnwrapBody() (string, TMessageType, int32, FieldID, []by
return name, rTyp, seqID, 0, nil, err
}
// read the success struct
_, _, structID, err := p.ReadFieldBegin()
_, typeId, structID, err := p.ReadFieldBegin()
if err != nil {
return name, rTyp, seqID, structID, nil, err
}
//empty response
if typeId == STOP {
return name, rTyp, seqID, structID, []byte{}, nil
}
// there's alway a struct stop by success struct
if p.Read > len(p.Buf)-1 {
return name, rTyp, seqID, structID, nil, io.EOF
Expand Down
22 changes: 22 additions & 0 deletions thrift/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,25 @@ func TestBinaryProtocol_WriteAny_ReadAny(t *testing.T) {
})
}
}

func TestBinaryUnwrap(t *testing.T) {
b := BinaryProtocol{
Buf: nil,
Read: 0,
}
var i32 int32 = -2147418110
var methodName = "DummyNew"
b.WriteI32(i32)
b.WriteString(methodName)
b.WriteI32(1)
b.WriteByte(byte(STOP))

name, rType, _, _, bs, err := UnwrapBinaryMessage(b.Buf)

require.Equal(t, bs, []byte{})
require.Equal(t, name, methodName)
require.Equal(t, rType, REPLY)
var nilErr error
require.Equal(t, err, nilErr)

}

0 comments on commit 0edfd20

Please sign in to comment.