go-teeworlds-protocol/messages7/snap.go

69 lines
1.2 KiB
Go
Raw Normal View History

2024-06-23 04:19:27 +00:00
package messages7
import (
"slices"
"github.com/teeworlds-go/go-teeworlds-protocol/chunk7"
"github.com/teeworlds-go/go-teeworlds-protocol/network7"
"github.com/teeworlds-go/go-teeworlds-protocol/packer"
)
type Snap struct {
ChunkHeader *chunk7.ChunkHeader
GameTick int
DeltaTick int
NumParts int
Part int
Crc int
PartSize int
Data []byte
}
func (msg *Snap) MsgId() int {
2024-06-23 04:19:27 +00:00
return network7.MsgSysSnap
}
func (msg *Snap) MsgType() network7.MsgType {
2024-06-23 04:19:27 +00:00
return network7.TypeNet
}
func (msg *Snap) System() bool {
2024-06-23 04:19:27 +00:00
return true
}
func (msg *Snap) Vital() bool {
2024-06-23 04:19:27 +00:00
return false
}
func (msg *Snap) Pack() []byte {
2024-06-23 04:19:27 +00:00
return slices.Concat(
packer.PackInt(msg.GameTick),
packer.PackInt(msg.DeltaTick),
packer.PackInt(msg.NumParts),
packer.PackInt(msg.Part),
packer.PackInt(msg.Crc),
packer.PackInt(msg.PartSize),
msg.Data,
2024-06-23 04:19:27 +00:00
)
}
func (msg *Snap) Unpack(u *packer.Unpacker) error {
2024-06-23 04:19:27 +00:00
msg.GameTick = u.GetInt()
msg.DeltaTick = u.GetInt()
msg.NumParts = u.GetInt()
msg.Part = u.GetInt()
msg.Crc = u.GetInt()
msg.PartSize = u.GetInt()
msg.Data = u.Rest()
return nil
2024-06-23 04:19:27 +00:00
}
func (msg *Snap) Header() *chunk7.ChunkHeader {
return msg.ChunkHeader
}
func (msg *Snap) SetHeader(header *chunk7.ChunkHeader) {
msg.ChunkHeader = header
}