Hello, World!
This commit is contained in:
25
shared/proto.go
Normal file
25
shared/proto.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user