-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto.go
55 lines (49 loc) · 1.12 KB
/
proto.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
const (
OP_HEARTBEAT = int32(2)
OP_HEARTBEAT_REPLY = int32(3)
OP_SEND_SMS_REPLY = int32(5)
OP_AUTH = int32(7)
OP_AUTH_REPLY = int32(8)
)
const (
MaxBodySize = int32(1 << 11)
// size
CmdSize = 4
PackSize = 4
HeaderSize = 2
VerSize = 2
OperationSize = 4
SeqIdSize = 4
HeartbeatSize = 4
RawHeaderSize = PackSize + HeaderSize + VerSize + OperationSize + SeqIdSize
MaxPackSize = MaxBodySize + int32(RawHeaderSize)
// offset
PackOffset = 0
HeaderOffset = PackOffset + PackSize
VerOffset = HeaderOffset + HeaderSize
OperationOffset = VerOffset + VerSize
SeqIdOffset = OperationOffset + OperationSize
HeartbeatOffset = SeqIdOffset + SeqIdSize
OP_RAW = int32(11)
)
const (
ProtoVersion0 = iota
ProtoVersion1
ProtoVersion2
ProtoVersion3
)
type Proto struct {
PacketLength int32
HeaderLength int16
Version int16
Operation int32
SequenceId int32
Body []byte
BodyMuti [][]byte
// 解析时的错误消息,非消息内容
ErrMsg error
}
type AuthRespParam struct {
Code int64 `json:"code,omitempty"`
}