-
Notifications
You must be signed in to change notification settings - Fork 7
/
recvack.go
executable file
·50 lines (41 loc) · 1.24 KB
/
recvack.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
package wkproto
import (
"fmt"
"github.com/pkg/errors"
)
// RecvackPacket 对收取包回执
type RecvackPacket struct {
Framer
MessageID int64 // 服务端的消息ID(全局唯一)
MessageSeq uint32 // 消息序列号
}
// GetPacketType 包类型
func (s *RecvackPacket) GetFrameType() FrameType {
return RECVACK
}
func (s *RecvackPacket) String() string {
return fmt.Sprintf("Framer:%s MessageId:%d MessageSeq:%d", s.Framer.String(), s.MessageID, s.MessageSeq)
}
func decodeRecvack(frame Frame, data []byte, _ uint8) (Frame, error) {
dec := NewDecoder(data)
recvackPacket := &RecvackPacket{}
recvackPacket.Framer = frame.(Framer)
var err error
// 消息唯一ID
if recvackPacket.MessageID, err = dec.Int64(); err != nil {
return nil, errors.Wrap(err, "解码MessageId失败!")
}
// 消息唯序列号
if recvackPacket.MessageSeq, err = dec.Uint32(); err != nil {
return nil, errors.Wrap(err, "解码MessageSeq失败!")
}
return recvackPacket, err
}
func encodeRecvack(recvackPacket *RecvackPacket, enc *Encoder, _ uint8) error {
enc.WriteInt64(recvackPacket.MessageID)
enc.WriteUint32(recvackPacket.MessageSeq)
return nil
}
func encodeRecvackSize(_ *RecvackPacket, _ uint8) int {
return MessageIDByteSize + MessageSeqByteSize
}