add decode functions for info and data packets

This commit is contained in:
2024-12-18 22:48:08 -06:00
parent 90c734a023
commit 0a74b6a956
18 changed files with 724 additions and 0 deletions
@@ -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,
}
}