aboutsummaryrefslogtreecommitdiff
path: root/inform/inform.go
diff options
context:
space:
mode:
Diffstat (limited to 'inform/inform.go')
-rw-r--r--inform/inform.go56
1 files changed, 49 insertions, 7 deletions
diff --git a/inform/inform.go b/inform/inform.go
index ac3b57d..59f969c 100644
--- a/inform/inform.go
+++ b/inform/inform.go
@@ -11,8 +11,10 @@ const (
11 INFORM_VERSION int32 = 0 11 INFORM_VERSION int32 = 0
12 DATA_VERSION int32 = 1 12 DATA_VERSION int32 = 1
13 13
14 ENCRYPTED_FLAG = 1 14 ENCRYPTED_FLAG = 1
15 COMPRESSED_FLAG = 2 15 ZLIB_COMPRESSED_FLAG = 2
16 SNAPPY_COMPRESSED_FLAG = 4
17 AES_GCM_FLAG = 8
16) 18)
17 19
18// Wrapper around an inform message, serializes directly into the wire 20// Wrapper around an inform message, serializes directly into the wire
@@ -22,6 +24,7 @@ type InformWrapper struct {
22 MacAddr []byte 24 MacAddr []byte
23 Flags int16 25 Flags int16
24 DataVersion int32 26 DataVersion int32
27 DataLength int32
25 Payload []byte 28 Payload []byte
26} 29}
27 30
@@ -86,7 +89,18 @@ func (i *InformWrapper) String() string {
86 fmt.Fprintf(b, "Mac Addr: \t%s\n", i.FormattedMac()) 89 fmt.Fprintf(b, "Mac Addr: \t%s\n", i.FormattedMac())
87 fmt.Fprintf(b, "Flags: \t%d\n", i.Flags) 90 fmt.Fprintf(b, "Flags: \t%d\n", i.Flags)
88 fmt.Fprintf(b, " Encrypted: \t%t\n", i.IsEncrypted()) 91 fmt.Fprintf(b, " Encrypted: \t%t\n", i.IsEncrypted())
89 fmt.Fprintf(b, " Compressed: \t%t\n", i.IsCompressed()) 92 fmt.Fprintf(b, " Compressed: \t%t", i.IsCompressed())
93 if i.IsCompressed() {
94 if i.IsZlibCompressed() {
95 fmt.Fprintf(b, " (zlib)\n")
96 } else if i.IsSnappyCompressed() {
97 fmt.Fprintf(b, " (snappy)\n")
98 } else {
99 fmt.Fprintf(b, " (unknown)\n")
100 }
101 } else {
102 fmt.Fprintf(b, "\n")
103 }
90 fmt.Fprintf(b, "Data Version: \t%d\n", i.DataVersion) 104 fmt.Fprintf(b, "Data Version: \t%d\n", i.DataVersion)
91 fmt.Fprintf(b, "Payload: \t%q\n", i.Payload) 105 fmt.Fprintf(b, "Payload: \t%q\n", i.Payload)
92 106
@@ -105,14 +119,42 @@ func (i *InformWrapper) SetEncrypted(e bool) {
105 } 119 }
106} 120}
107 121
122func (i *InformWrapper) IsGCMEncrypted() bool {
123 return i.Flags&AES_GCM_FLAG != 0
124}
125
126func (i *InformWrapper) SetGCMEncrypted(e bool) {
127 if e {
128 i.Flags |= AES_GCM_FLAG
129 } else {
130 i.Flags &= AES_GCM_FLAG
131 }
132}
133
108func (i *InformWrapper) IsCompressed() bool { 134func (i *InformWrapper) IsCompressed() bool {
109 return i.Flags&COMPRESSED_FLAG != 0 135 return i.IsZlibCompressed() || i.IsSnappyCompressed()
136}
137
138func (i *InformWrapper) IsZlibCompressed() bool {
139 return i.Flags&ZLIB_COMPRESSED_FLAG != 0
140}
141
142func (i *InformWrapper) IsSnappyCompressed() bool {
143 return i.Flags&SNAPPY_COMPRESSED_FLAG != 0
144}
145
146func (i *InformWrapper) SetSnappyCompressed(c bool) {
147 if c {
148 i.Flags |= SNAPPY_COMPRESSED_FLAG
149 } else {
150 i.Flags &= SNAPPY_COMPRESSED_FLAG
151 }
110} 152}
111 153
112func (i *InformWrapper) SetCompressed(c bool) { 154func (i *InformWrapper) SetZlibCompressed(c bool) {
113 if c { 155 if c {
114 i.Flags |= COMPRESSED_FLAG 156 i.Flags |= ZLIB_COMPRESSED_FLAG
115 } else { 157 } else {
116 i.Flags &= COMPRESSED_FLAG 158 i.Flags &= ZLIB_COMPRESSED_FLAG
117 } 159 }
118} 160}