Skip to content

Commit

Permalink
Return the correct number of bytes read from DecodeStructSliceWithLim…
Browse files Browse the repository at this point in the history
…it (#55)
  • Loading branch information
fasmat authored Apr 17, 2023
1 parent f6adb7a commit 8e485e9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,20 @@ func DecodeStructSlice[V any, H DecodablePtr[V]](d *Decoder) ([]V, int, error) {
func DecodeStructSliceWithLimit[V any, H DecodablePtr[V]](d *Decoder, limit uint32) ([]V, int, error) {
lth, total, err := DecodeLen(d, limit)
if err != nil {
return nil, 0, err
return nil, total, err
}
if lth == 0 {
return nil, 0, nil
return nil, total, nil
}

value := make([]V, 0, lth)

for i := uint32(0); i < lth; i++ {
val, n, err := DecodeStruct[V, H](d)
total += n
if err != nil {
return nil, 0, err
return nil, total, err
}
value = append(value, val)
total += n
}
return value, total, nil
}
Expand Down

0 comments on commit 8e485e9

Please sign in to comment.