Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix empty biz body unwrapBinary EOF error #70

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
AsterDY marked this conversation as resolved.
Show resolved Hide resolved
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)

}
Loading