Skip to content

Commit

Permalink
read ErrUnexpectedEOF
Browse files Browse the repository at this point in the history
  • Loading branch information
brianshih1 committed Apr 22, 2024
1 parent 3c9f29c commit 20c4c65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestDecoder_DecodeNilPtr(t *testing.T) {
assert.Error(t, err)
}

func TestDecoder_DecodeEOFDoesntReturnError(t *testing.T) {
func TestDecoder_DecodeEOF(t *testing.T) {
defer ConfigTeardown()

data := []byte{0xE2}
Expand All @@ -78,7 +78,7 @@ func TestDecoder_DecodeEOFDoesntReturnError(t *testing.T) {
var i int
err := dec.Decode(&i)

assert.NoError(t, err)
assert.Error(t, err)
}

func TestUnmarshal(t *testing.T) {
Expand All @@ -87,7 +87,7 @@ func TestUnmarshal(t *testing.T) {
schema := avro.MustParse("int")

var i int
err := avro.Unmarshal(schema, []byte{0xE2}, &i)
err := avro.Unmarshal(schema, []byte{0x13}, &i)

assert.NoError(t, err)
}
Expand Down
7 changes: 4 additions & 3 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (r *Reader) Read(b []byte) {
for read < size {
if r.head == r.tail {
if !r.loadMore() {
r.Error = io.ErrUnexpectedEOF
return
}
}
Expand Down Expand Up @@ -174,6 +175,7 @@ func (r *Reader) ReadInt() int32 {
// We ran out of buffer and are not at the end of the int,
// Read more into the buffer.
if !r.loadMore() {
r.Error = io.ErrUnexpectedEOF
return 0
}
}
Expand Down Expand Up @@ -216,6 +218,7 @@ func (r *Reader) ReadLong() int64 {
// We ran out of buffer and are not at the end of the long,
// Read more into the buffer.
if !r.loadMore() {
r.Error = io.ErrUnexpectedEOF
return 0
}
}
Expand Down Expand Up @@ -247,9 +250,6 @@ func (r *Reader) ReadBytes() []byte {
// ReadString reads a String from the Reader.
func (r *Reader) ReadString() string {
b := r.readBytes("string")
if r.Error != nil {
r.Error = fmt.Errorf("reading string: %w", r.Error)
}

if len(b) == 0 {
return ""
Expand Down Expand Up @@ -288,6 +288,7 @@ func (r *Reader) readBytes(op string) []byte {
}

buf := make([]byte, size)

r.Read(buf)
return buf
}
Expand Down

0 comments on commit 20c4c65

Please sign in to comment.