Skip to content

Commit

Permalink
return EOF early
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Mar 30, 2024
1 parent 8be3880 commit a9e11df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions decode_stream.go
Expand Up @@ -60,9 +60,9 @@ func (d *JSONStreamCommandDecoder) Decode() (*Command, int, error) {
if err != nil {
if err == io.EOF && len(cmdBytes) > 0 {
var c Command
_, err = json.Parse(cmdBytes, &c, 0)
if err != nil {
return nil, 0, err
_, parseErr := json.Parse(cmdBytes, &c, 0)
if parseErr != nil {
return nil, 0, parseErr
}
return &c, len(cmdBytes), err
}
Expand Down
10 changes: 7 additions & 3 deletions decode_stream_test.go
Expand Up @@ -89,13 +89,17 @@ func testDecodingFrame(tb testing.TB, frame []byte, protoType Type) {
require.Equal(tb, 10037, size)
}
_, size, err = dec.Decode()
require.NoError(tb, err)
if protoType == TypeProtobuf {
require.Equal(tb, 10018, size)
} else {
require.Equal(tb, 10036, size)
}
_, _, err = dec.Decode()
require.ErrorIs(tb, err, io.EOF)
if err != nil {
require.ErrorIs(tb, err, io.EOF)
} else {
_, _, err = dec.Decode()
require.ErrorIs(tb, err, io.EOF)
}

PutStreamCommandDecoder(protoType, dec)
}

0 comments on commit a9e11df

Please sign in to comment.