mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-08-22 15:39:15 +00:00
add most basic error handling on the decode side
This commit is contained in:
@@ -8,14 +8,21 @@ type DataTrackerListChunk struct {
|
||||
Data DataTrackerListChunkData
|
||||
}
|
||||
|
||||
func DecodeDataTrackerListChunk(bytes []byte) DataTrackerListChunk {
|
||||
chunk := DecodeChunk(bytes)
|
||||
func DecodeDataTrackerListChunk(bytes []byte) (DataTrackerListChunk, error) {
|
||||
chunk, err := DecodeChunk(bytes)
|
||||
|
||||
if err != nil {
|
||||
return DataTrackerListChunk{}, err
|
||||
}
|
||||
|
||||
trackers := []DataTrackerChunk{}
|
||||
if chunk.Header.HasSubchunks && chunk.Header.DataLen > 0 {
|
||||
offset := 0
|
||||
for offset < int(chunk.Header.DataLen) {
|
||||
trackerChunk := DecodeDataTrackerChunk(chunk.ChunkData[offset:])
|
||||
trackerChunk, err := DecodeDataTrackerChunk(chunk.ChunkData[offset:])
|
||||
if err != nil {
|
||||
return DataTrackerListChunk{}, err
|
||||
}
|
||||
offset += 4
|
||||
if trackerChunk.Chunk.Header.DataLen > 0 {
|
||||
offset += int(trackerChunk.Chunk.Header.DataLen)
|
||||
@@ -29,7 +36,8 @@ func DecodeDataTrackerListChunk(bytes []byte) DataTrackerListChunk {
|
||||
}
|
||||
|
||||
return DataTrackerListChunk{
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
},
|
||||
nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user