aboutsummaryrefslogtreecommitdiffstats
path: root/demo/qwd/data.go
blob: cc00c23d706dfc312fca16f553833c65fb014996 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package qwd

import (
	"github.com/osm/quake/common/buffer"
	"github.com/osm/quake/protocol"
)

type Data struct {
	Timestamp float32
	Command   byte
	Cmd       *Cmd
	Read      *Read
	Set       *Set
}

func (d *Data) Bytes() []byte {
	buf := buffer.New()

	buf.PutFloat32(d.Timestamp)
	buf.PutByte(d.Command)

	switch d.Command {
	case protocol.DemoCmd:
		buf.PutBytes(d.Cmd.Bytes())
	case protocol.DemoRead:
		buf.PutBytes(d.Read.Bytes())
	case protocol.DemoSet:
		buf.PutBytes(d.Set.Bytes())
	}

	return buf.Bytes()
}