-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_util.t
52 lines (47 loc) · 1.22 KB
/
msg_util.t
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
package ${pkgName}
// ${pkgName}/${filePrefix}msg_util.go
// Utility functions for messages betweeen Upax servers.
import (
"errors"
"fmt"
"github.com/jddixon/xlattice_go/reg"
)
// Verify that the message number on the incoming message has been
// increased by one.
//
func check${CapShortPrefix}MsgN(h *${TypePrefix}InHandler) (err error) {
byeMsg := h.msgIn
peerMsgN := byeMsg.GetMsgN()
expectedMsgN := h.peerMsgN + 1
if peerMsgN != expectedMsgN {
msg := fmt.Sprintf("expected MsgN %d, got %d",
expectedMsgN, peerMsgN)
err = errors.New(msg)
} else {
h.peerMsgN++
}
return
}
func send${CapShortPrefix}Ack(h *${TypePrefix}InHandler) {
h.myMsgN++
op := Upax${TypePrefix}Msg_Ack
h.msgOut = &Upax${TypePrefix}Msg{
Op: &op,
MsgN: &h.myMsgN,
YourMsgN: &h.peerMsgN,
}
}
func send${CapShortPrefix}NotFound(h *${TypePrefix}InHandler) {
h.myMsgN++
op := Upax${TypePrefix}Msg_NotFound
h.msgOut = &Upax${TypePrefix}Msg{
Op: &op,
MsgN: &h.myMsgN,
YourMsgN: &h.peerMsgN,
}
}
// Dispatch table entry where a message received is inappropriate
// the the state of the connection. For example, ...
func bad${CapShortPrefix}Combo(h *${TypePrefix}InHandler) {
h.errOut = reg.RcvdInvalidMsgForState
}