forked from aceld/zinx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bili0x14router.go
38 lines (33 loc) · 961 Bytes
/
bili0x14router.go
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
33
34
35
36
37
38
package router
import (
"bytes"
"fmt"
"github.com/Yeuoly/zinx/zdecoder"
"github.com/Yeuoly/zinx/ziface"
"github.com/Yeuoly/zinx/znet"
)
type Data0x14Router struct {
znet.BaseRouter
}
func (this *Data0x14Router) Handle(request ziface.IRequest) {
fmt.Println("Data0x14Router Handle", request.GetMessage().GetData())
_response := request.GetResponse()
if _response != nil {
switch _response.(type) {
case zdecoder.HtlvCrcDecoder:
_data := _response.(zdecoder.HtlvCrcDecoder)
fmt.Println("Data0x14Router", _data)
buffer := pack14(_data)
request.GetConnection().Send(buffer)
}
}
}
// 头码 功能码 数据长度 Body CRC
// A2 10 0E 0102030405060708091011121314 050B
func pack14(_data zdecoder.HtlvCrcDecoder) []byte {
_data.Data[0] = 0xA1
buffer := bytes.NewBuffer(_data.Data[:len(_data.Data)-2])
crc := zdecoder.GetCrC(buffer.Bytes())
buffer.Write(crc)
return buffer.Bytes()
}