-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
54 lines (48 loc) · 1000 Bytes
/
message.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
package gott
import (
"fmt"
)
const (
PROTONAME = "MQIsdp"
PROTOVERSION = uint8(3)
)
var (
MessageIDNum = 0
)
func MessageID() int {
MessageIDNum++
return MessageIDNum
}
func ClientID() string {
// TODO make this an actual random string
return fmt.Sprintf("TEMPCLIENTID%d", MessageID())
}
func NewConnect(will, willRetain, cleanSession bool, willQos uint8, username, password string, keepAlive int, willTopic, willMessage string) Message {
fh := FixedHeader{
MessageType: CONNECT,
}
ch := ConnectHeader{
ProtoName: PROTONAME,
ProtoVersion: PROTOVERSION,
CleanSession: cleanSession,
Will: will,
WillQos: willQos,
WillRetain: willRetain,
Pass: password != "",
User: username != "",
KeepAlive: keepAlive,
}
cp := ConnectPayload{
ClientID: ClientID(),
WillTopic: willTopic,
WillMessage: willMessage,
Username: username,
Password: password,
}
connectMessage := Message{
FixedHeader: fh,
VariableHeader: ch,
Payload: cp,
}
return connectMessage
}