mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-09-07 07:19:20 +00:00
add decode functions for info and data packets
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package decoders
|
||||
|
||||
type DataTrackerListChunkData struct {
|
||||
Trackers []DataTrackerChunk
|
||||
}
|
||||
|
||||
func decodeDataTrackerListChunkData(dataTrackerListChunk Chunk) DataTrackerListChunkData {
|
||||
var trackers []DataTrackerChunk
|
||||
if dataTrackerListChunk.Header.HasSubchunks && dataTrackerListChunk.Header.DataLen > 0 {
|
||||
offset := 0
|
||||
for offset < int(dataTrackerListChunk.Header.DataLen) {
|
||||
trackerChunk := DecodeDataTrackerChunk(dataTrackerListChunk.ChunkData[offset:])
|
||||
offset += CHUNK_HEADER_SIZE
|
||||
if trackerChunk.Chunk.Header.DataLen > 0 {
|
||||
offset += int(trackerChunk.Chunk.Header.DataLen)
|
||||
}
|
||||
trackers = append(trackers, trackerChunk)
|
||||
}
|
||||
}
|
||||
|
||||
return DataTrackerListChunkData{
|
||||
Trackers: trackers,
|
||||
}
|
||||
}
|
||||
|
||||
type DataTrackerListChunk struct {
|
||||
Chunk Chunk
|
||||
Data DataTrackerListChunkData
|
||||
}
|
||||
|
||||
func DecodeDataTrackerListChunk(bytes []byte) DataTrackerListChunk {
|
||||
chunk := DecodeChunk(bytes)
|
||||
data := decodeDataTrackerListChunkData(chunk)
|
||||
|
||||
return DataTrackerListChunk{
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user