Files
psn-go/internal/encoders/chunk.go
2024-12-19 21:48:46 -06:00

25 lines
468 B
Go

package encoders
import "encoding/binary"
func EncodeChunk(id uint16, chunkData []byte, hasSubchunks bool) []byte {
header := []byte{}
header = binary.LittleEndian.AppendUint16(header, id)
hasSubchunksBit := 0
if hasSubchunks {
hasSubchunksBit = 1
}
hasSubchunksBit = hasSubchunksBit << 15
header = binary.LittleEndian.AppendUint16(header, uint16(len(chunkData)+hasSubchunksBit))
bytes := header
bytes = append(bytes, chunkData...)
return bytes
}