-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathutildebug.go
90 lines (69 loc) · 1.83 KB
/
utildebug.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package canopus
// PrintOptions pretty prints out a given Message's options
func PrintOptions(msg Message) {
opts := msg.GetAllOptions()
logMsg(" - - - OPTIONS - - - ")
if len(opts) > 0 {
for _, opts := range msg.GetAllOptions() {
logMsg("Code/Number: ", opts.GetCode(), ", Name: ", OptionNumberToString(opts.GetCode()), ", Value: ", opts.GetValue())
}
} else {
logMsg("None")
}
}
// PrintMessage pretty prints out a given Message
func PrintMessage(msg Message) {
logMsg("= = = = = = = = = = = = = = = = ")
logMsg("Code: ", msg.GetCode())
logMsg("Code String: ", CoapCodeToString(msg.GetCode()))
logMsg("MessageId: ", msg.GetMessageId())
logMsg("MessageType: ", msg.GetMessageType())
logMsg("Token: ", string(msg.GetToken()))
logMsg("Token Length: ", msg.GetTokenLength())
logMsg("Payload: ", PayloadAsString(msg.GetPayload()))
PrintOptions(msg)
logMsg("= = = = = = = = = = = = = = = = ")
}
// OptionNumberToString returns the string representation of a given Option Code
func OptionNumberToString(o OptionCode) string {
switch o {
case OptionIfMatch:
return "If-Match"
case OptionURIHost:
return "Uri-Host"
case OptionEtag:
return "ETag"
case OptionIfNoneMatch:
return "If-None-Match"
case OptionURIPort:
return "Uri-Port"
case OptionLocationPath:
return "Location-Path"
case OptionURIPath:
return "Uri-Path"
case OptionContentFormat:
return "Content-Format"
case OptionMaxAge:
return "Max-Age"
case OptionURIQuery:
return "Uri-Query"
case OptionAccept:
return "Accept"
case OptionLocationQuery:
return "Location-Query"
case OptionBlock2:
return "Block2"
case OptionBlock1:
return "Block1"
case OptionProxyURI:
return "Proxy-Uri"
case OptionProxyScheme:
return "Proxy-Scheme"
case OptionSize1:
return "Size1"
case OptionSize2:
return "Size2"
default:
return ""
}
}