26 lines
470 B
Go
26 lines
470 B
Go
package shared
|
|
|
|
import "encoding/binary"
|
|
|
|
const PROTO_VERSION uint16 = 1
|
|
|
|
const (
|
|
unused uint16 = iota
|
|
REQ_REGISTER
|
|
RESP_REGISTER
|
|
)
|
|
|
|
func Uint16(v uint16) []byte {
|
|
out := make([]byte, 2)
|
|
binary.LittleEndian.PutUint16(out, v)
|
|
return out
|
|
}
|
|
|
|
func BuildPkt(pktType uint16, data []byte) []byte {
|
|
out := make([]byte, 4+len(data))
|
|
binary.LittleEndian.PutUint16(out[0:], PROTO_VERSION)
|
|
binary.LittleEndian.PutUint16(out[2:], pktType)
|
|
copy(out[4:], data)
|
|
return out
|
|
}
|