go-teeworlds-protocol/chunk7/splitter.go

28 lines
585 B
Go
Raw Normal View History

2024-06-20 00:26:04 +00:00
package chunk7
2024-06-07 07:38:35 +00:00
// data has to be the uncompressed payload of a teeworlds packet
// without the packet header
//
// It will return all the chunks (messages) in that packet
func UnpackChunks(data []byte) []Chunk {
chunks := []Chunk{}
payloadSize := len(data)
i := 0
for i < payloadSize {
chunk := Chunk{}
chunk.Header.Unpack(data[i:])
i += 2 // header
if chunk.Header.Flags.Vital {
i++
}
end := i + chunk.Header.Size
2024-06-17 04:24:08 +00:00
chunk.Data = make([]byte, end-i)
2024-06-07 07:38:35 +00:00
copy(chunk.Data[:], data[i:end])
i += chunk.Header.Size
chunks = append(chunks, chunk)
}
return chunks
}