Skip to content

Commit

Permalink
refactor: enhance error handling in GetInt64Array method of RealDecoder
Browse files Browse the repository at this point in the history
- Replaced direct byte manipulation with a call to GetInt64 for improved abstraction.
- Added context to decoding errors to aid in debugging.
- Improved overall readability and maintainability of the GetInt64Array function.
  • Loading branch information
ryan-gang committed Jan 9, 2025
1 parent 60028f5 commit f36c78a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions protocol/decoder/real_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,14 @@ func (rd *RealDecoder) GetInt64Array() ([]int64, error) {

ret := make([]int64, n)
for i := range ret {
ret[i] = int64(binary.BigEndian.Uint64(rd.raw[rd.off:]))
rd.off += 8
entry, err := rd.GetInt64()
if err != nil {
if decodingErr, ok := err.(*errors.PacketDecodingError); ok {
return nil, decodingErr.WithAddedContext("COMPACT_INT32_ARRAY")
}
return nil, err
}
ret[i] = entry
}
return ret, nil
}
Expand Down

0 comments on commit f36c78a

Please sign in to comment.