@@ -191,6 +191,89 @@ describe("MQTT v5.0 protocol: making packets: CONNECT[1]", function()
191
191
end )
192
192
end )
193
193
194
+ describe (" MQTT v5.0 protocol: making packets: CONNACK[2]" , function ()
195
+ local tools = require (" mqtt.tools" )
196
+ local extract_hex = require (" mqtt.tools" ).extract_hex
197
+ local protocol = require (" mqtt.protocol" )
198
+ local protocol5 = require (" mqtt.protocol5" )
199
+
200
+ it (" CONNACK with minimum params" , function ()
201
+ assert .are .equal (
202
+ extract_hex [[
203
+ 20 -- packet type == 2 (CONNACK), flags == 0
204
+ 03 -- length == 3 bytes
205
+
206
+ 00 -- Connect Acknowledge Flags, sp=false
207
+ 00 -- Connect Reason Code == 0
208
+ 00 -- no props
209
+ ]] ,
210
+ tools .hex (tostring (protocol5 .make_packet {
211
+ type = protocol .packet_type .CONNACK ,
212
+ sp = false , rc = 0 ,
213
+ }))
214
+ )
215
+ end )
216
+
217
+ it (" CONNACK with flags, rc, and full properties" , function ()
218
+ assert .are .equal (
219
+ extract_hex [[
220
+ 20 -- packet type == 2 (CONNACK), flags == 0
221
+ 75 -- variable length == 117 bytes
222
+
223
+ 01 -- Connect Acknowledge Flags, sp=true
224
+ 82 -- Connect Reason Code == 0x82
225
+ 72 -- properties length
226
+
227
+ 11 00000E10 -- property 0x11 == 3600, -- DOC: 3.2.2.3.2 Session Expiry Interval
228
+ 12 0005 736C617665 -- property 0x12 == "slave", -- DOC: 3.2.2.3.7 Assigned Client Identifier
229
+ 13 0078 -- property 0x13 == 120, -- DOC: 3.2.2.3.14 Server Keep Alive
230
+ 15 0005 6775657373 -- property 0x15 == "guess", -- DOC: 3.2.2.3.17 Authentication Method
231
+ 16 0002 3130 -- property 0x16 == "10", -- DOC: 3.2.2.3.18 Authentication Data
232
+ 1A 0005 686572652F -- property 0x1A == "here/", -- DOC: 3.2.2.3.15 Response Information
233
+ 1C 000D 736565202F6465762F6E756C6C -- property 0x1C == "see /dev/null", -- DOC: 3.2.2.3.16 Server Reference
234
+ 1F 0007 70726F63656564 -- property 0x1F == "proceed", -- DOC: 3.2.2.3.9 Reason String
235
+ 21 1234 -- property 0x21 == 0x1234, -- DOC: 3.2.2.3.3 Receive Maximum
236
+ 22 4321 -- property 0x22 == 0x4321, -- DOC: 3.2.2.3.8 Topic Alias Maximum
237
+ 24 01 -- property 0x24 == 1, -- DOC: 3.2.2.3.4 Maximum QoS
238
+ 25 01 -- property 0x25 == 1, -- DOC: 3.2.2.3.5 Retain Available
239
+ 27 00004567 -- property 0x27 == 0x4567, -- DOC: 3.2.2.3.6 Maximum Packet Size
240
+ 28 01 -- property 0x28 == 1, -- DOC: 3.2.2.3.11 Wildcard Subscription Available
241
+ 29 00 -- property 0x29 == 0, -- DOC: 3.2.2.3.12 Subscription Identifiers Available
242
+ 2A 01 -- property 0x2A == 1, -- DOC: 3.2.2.3.13 Shared Subscription Available
243
+ 26 0005 68656C6C6F 0005 776F726C64 -- property 0x26 (user) == ("hello", "world") -- DOC: 3.2.2.3.10 User Property
244
+ 26 0005 68656C6C6F 0005 616761696E -- property 0x26 (user) == ("hello", "again") -- DOC: 3.2.2.3.10 User Property
245
+ ]] ,
246
+ tools .hex (tostring (protocol5 .make_packet {
247
+ type = protocol .packet_type .CONNACK ,
248
+ sp = true , rc = 0x82 ,
249
+ properties = {
250
+ session_expiry_interval = 3600 ,
251
+ receive_maximum = 0x1234 ,
252
+ maximum_qos = 1 ,
253
+ retain_available = 1 ,
254
+ maximum_packet_size = 0x4567 ,
255
+ assigned_client_identifier = " slave" ,
256
+ topic_alias_maximum = 0x4321 ,
257
+ reason_string = " proceed" ,
258
+ wildcard_subscription_available = 1 ,
259
+ subscription_identifiers_available = 0 ,
260
+ shared_subscription_available = 1 ,
261
+ server_keep_alive = 120 ,
262
+ response_information = " here/" ,
263
+ server_reference = " see /dev/null" ,
264
+ authentication_method = " guess" ,
265
+ authentication_data = " 10" ,
266
+ },
267
+ user_properties = {
268
+ hello = " again" , -- NOTE: that key+value pair is equivalent of {"hello", "again"} below, thus that pair will be skipped
269
+ {" hello" , " world" },
270
+ {" hello" , " again" },
271
+ },
272
+ }))
273
+ )
274
+ end )
275
+ end )
276
+
194
277
describe (" MQTT v5.0 protocol: making packets: PUBLISH[3]" , function ()
195
278
local tools = require (" mqtt.tools" )
196
279
local extract_hex = require (" mqtt.tools" ).extract_hex
0 commit comments