mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-09-10 08:39:37 +00:00
add crude encoding of PSN chunks
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user