mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-09-11 00:59:39 +00:00
add decode functions for info and data packets
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package decoders
|
||||
|
||||
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 += CHUNK_HEADER_SIZE
|
||||
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
|
||||
}
|
||||
|
||||
func DecodeInfoTrackerListChunk(bytes []byte) InfoTrackerListChunk {
|
||||
chunk := DecodeChunk(bytes)
|
||||
data := decodeInfoTrackerListChunkData(chunk)
|
||||
|
||||
return InfoTrackerListChunk{
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user