-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg.go
62 lines (50 loc) · 1.21 KB
/
msg.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
56
57
58
59
60
61
62
package bpop
import (
"encoding/json"
"github.com/realbmail/go-bmail-protocol/bmp"
"github.com/realbmail/go-bmail-protocol/translayer"
)
type Command interface {
Hash() []byte
MsgType() uint16
}
type CommandSyn struct {
SN bmp.BMailSN `json:"sn"`
Sig []byte `json:"sig"`
Cmd Command `json:"cmd"`
}
func (cs *CommandSyn) MsgType() uint16 {
return cs.Cmd.MsgType()
}
func (cs *CommandSyn) GetBytes() ([]byte, error) {
return json.Marshal(*cs)
}
func (cs *CommandSyn) VerifyHeader(header *bmp.Header) bool {
return header.MsgTyp == cs.Cmd.MsgType() &&
header.MsgLen != 0
}
type CommandContent interface {
MsgType() uint16
Hash() []byte
}
const (
EC_Success int = iota
EC_No_Mail
)
type CommandAck struct {
NextSN bmp.BMailSN `json:"next_sn"`
Hash []byte `json:"hash"`
Sig []byte `json:"sig"`
ErrorCode int `json:"error_code"`
CmdCxt CommandContent `json:"cmd"`
}
func (cs *CommandAck) MsgType() uint16 {
return cs.CmdCxt.MsgType()
}
func (cs *CommandAck) GetBytes() ([]byte, error) {
return json.Marshal(*cs)
}
func (cs *CommandAck) VerifyHeader(header *bmp.Header) bool {
return header.MsgTyp == translayer.RETR_RESP &&
header.MsgLen != 0
}