func (b BinaryProtocol) Encode(id int, currentGameTime uint32, message *model.NetworkMessage) []byte {
	buf := make([]byte, 0)
	buf = append(buf, byte(uint8(id)))
	buf = append(buf, byte(message.MessageType))
	currentTime := make([]byte, 4)
	binary.LittleEndian.PutUint32(currentTime[:], currentGameTime)
	buf = append(buf, currentTime...)
	if encodeHandler, ok := b.encodeHandlers[message.MessageType]; ok {
		buf = append(buf, encodeHandler(message)...)
	}
	return buf
}
Encode data to send to clients
package protocol
import (
	"encoding/binary"
	"math"
	"github.com/awdng/triebwerk/model"
)
type BinaryProtocol struct {
	encodeHandlers map[uint8]func(message *model.NetworkMessage) []byte
	decodeHandlers map[uint8]func(data []byte, message *model.NetworkMessage)
}
func NewBinaryProtocol() BinaryProtocol {
	protocol := BinaryProtocol{
		encodeHandlers: make(map[uint8]func(message *model.NetworkMessage) []byte),
		decodeHandlers: make(map[uint8]func(data []byte, message *model.NetworkMessage)),
	}
	protocol.encodeHandlers[1] = encodePlayerState
	protocol.encodeHandlers[2] = encodePlayerRegister
	protocol.encodeHandlers[5] = encodePlayerTime
	protocol.decodeHandlers[0] = decodePlayerAuth
	protocol.decodeHandlers[1] = decodePlayerInput
	protocol.decodeHandlers[5] = decodePlayerTime
	return protocol
}