mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-09-10 08:39:37 +00:00
cleanup function layout for decoders
This commit is contained in:
@@ -4,25 +4,6 @@ type InfoTrackerListChunkData struct {
|
||||
Trackers []InfoTrackerChunk
|
||||
}
|
||||
|
||||
func decodeInfoTrackerListChunkData(infoTrackerListChunk Chunk) InfoTrackerListChunkData {
|
||||
var trackers []InfoTrackerChunk
|
||||
if infoTrackerListChunk.Header.HasSubchunks && infoTrackerListChunk.Header.DataLen > 0 {
|
||||
offset := 0
|
||||
for offset < int(infoTrackerListChunk.Header.DataLen) {
|
||||
trackerChunk := DecodeInfoTrackerChunk(infoTrackerListChunk.ChunkData[offset:])
|
||||
offset += 4
|
||||
if trackerChunk.Chunk.Header.DataLen > 0 {
|
||||
offset += int(trackerChunk.Chunk.Header.DataLen)
|
||||
}
|
||||
trackers = append(trackers, trackerChunk)
|
||||
}
|
||||
}
|
||||
|
||||
return InfoTrackerListChunkData{
|
||||
Trackers: trackers,
|
||||
}
|
||||
}
|
||||
|
||||
type InfoTrackerListChunk struct {
|
||||
Chunk Chunk
|
||||
Data InfoTrackerListChunkData
|
||||
@@ -30,7 +11,23 @@ type InfoTrackerListChunk struct {
|
||||
|
||||
func DecodeInfoTrackerListChunk(bytes []byte) InfoTrackerListChunk {
|
||||
chunk := DecodeChunk(bytes)
|
||||
data := decodeInfoTrackerListChunkData(chunk)
|
||||
|
||||
trackers := []InfoTrackerChunk{}
|
||||
if chunk.Header.HasSubchunks && chunk.Header.DataLen > 0 {
|
||||
offset := 0
|
||||
for offset < int(chunk.Header.DataLen) {
|
||||
trackerChunk := DecodeInfoTrackerChunk(chunk.ChunkData[offset:])
|
||||
offset += 4
|
||||
if trackerChunk.Chunk.Header.DataLen > 0 {
|
||||
offset += int(trackerChunk.Chunk.Header.DataLen)
|
||||
}
|
||||
trackers = append(trackers, trackerChunk)
|
||||
}
|
||||
}
|
||||
|
||||
data := InfoTrackerListChunkData{
|
||||
Trackers: trackers,
|
||||
}
|
||||
|
||||
return InfoTrackerListChunk{
|
||||
Chunk: chunk,
|
||||
|
||||
Reference in New Issue
Block a user