Skip to content

Commit

Permalink
feat: optional read supported
Browse files Browse the repository at this point in the history
  • Loading branch information
gnolizuh committed Mar 19, 2024
1 parent b0abbbf commit de8690d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,11 @@ func (d *decodeState) unmarshal(v any, opts decOpts) error {
return &InvalidUnmarshalError{reflect.TypeOf(v)}
}

// Return io.EOF to upper layer if reader has zero length.
if d.reader.Len() == 0 {
return io.EOF
}

// We decode rv not rv.Elem because the Unmarshaler interface
// test must be applied at the top level of the value.
err := d.value(rv, opts)
Expand Down

0 comments on commit de8690d

Please sign in to comment.