mqtt-ccutrer 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/mqtt/client.rb +65 -41
- data/lib/mqtt/packet.rb +113 -113
- data/lib/mqtt/proxy.rb +5 -5
- data/lib/mqtt/sn/packet.rb +80 -80
- data/lib/mqtt/version.rb +1 -1
- data/lib/mqtt-ccutrer.rb +1 -1
- data/lib/mqtt.rb +8 -8
- metadata +18 -131
- data/spec/zz_client_integration_spec.rb +0 -180
data/lib/mqtt/proxy.rb
CHANGED
|
@@ -40,7 +40,7 @@ module MQTT
|
|
|
40
40
|
#
|
|
41
41
|
# NOTE: be careful not to connect to yourself!
|
|
42
42
|
def initialize(args = {})
|
|
43
|
-
@local_host = args[:local_host] ||
|
|
43
|
+
@local_host = args[:local_host] || "0.0.0.0"
|
|
44
44
|
@local_port = args[:local_port] || MQTT::DEFAULT_PORT
|
|
45
45
|
@server_host = args[:server_host]
|
|
46
46
|
@server_port = args[:server_port] || 18_830
|
|
@@ -67,14 +67,14 @@ module MQTT
|
|
|
67
67
|
loop do
|
|
68
68
|
# Wait for a client to connect and then create a thread for it
|
|
69
69
|
Thread.new(@server.accept) do |client_socket|
|
|
70
|
-
logger.info "Accepted client: #{client_socket.peeraddr.join(
|
|
70
|
+
logger.info "Accepted client: #{client_socket.peeraddr.join(":")}"
|
|
71
71
|
server_socket = TCPSocket.new(@server_host, @server_port)
|
|
72
72
|
begin
|
|
73
73
|
process_packets(client_socket, server_socket)
|
|
74
74
|
rescue => e
|
|
75
75
|
logger.error e.to_s
|
|
76
76
|
end
|
|
77
|
-
logger.info "Disconnected: #{client_socket.peeraddr.join(
|
|
77
|
+
logger.info "Disconnected: #{client_socket.peeraddr.join(":")}"
|
|
78
78
|
server_socket.close
|
|
79
79
|
client_socket.close
|
|
80
80
|
end
|
|
@@ -89,7 +89,7 @@ module MQTT
|
|
|
89
89
|
selected = IO.select([client_socket, server_socket], nil, nil, @select_timeout)
|
|
90
90
|
|
|
91
91
|
# Timeout
|
|
92
|
-
raise
|
|
92
|
+
raise "Timeout in select" if selected.nil?
|
|
93
93
|
|
|
94
94
|
# Iterate through each of the sockets with data to read
|
|
95
95
|
if selected[0].include?(client_socket)
|
|
@@ -109,7 +109,7 @@ module MQTT
|
|
|
109
109
|
logger.debug "<#{packet.type_name}> -> client"
|
|
110
110
|
end
|
|
111
111
|
else
|
|
112
|
-
logger.error
|
|
112
|
+
logger.error "Problem with select: socket is neither server or client"
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
end
|
data/lib/mqtt/sn/packet.rb
CHANGED
|
@@ -18,11 +18,11 @@ module MQTT
|
|
|
18
18
|
# Parse buffer into new packet object
|
|
19
19
|
def self.parse(buffer)
|
|
20
20
|
# Parse the fixed header (length and type)
|
|
21
|
-
length, type_id, body = buffer.unpack(
|
|
22
|
-
length, type_id, body = buffer.unpack(
|
|
21
|
+
length, type_id, body = buffer.unpack("CCa*")
|
|
22
|
+
length, type_id, body = buffer.unpack("xnCa*") if length == 1
|
|
23
23
|
|
|
24
24
|
# Double-check the length
|
|
25
|
-
raise ProtocolException,
|
|
25
|
+
raise ProtocolException, "Length of packet is not the same as the length header" if buffer.length != length
|
|
26
26
|
|
|
27
27
|
packet_class = PACKET_TYPES[type_id]
|
|
28
28
|
raise ProtocolException, "Invalid packet type identifier: #{type_id}" if packet_class.nil?
|
|
@@ -60,12 +60,12 @@ module MQTT
|
|
|
60
60
|
|
|
61
61
|
# Build up the body length field bytes
|
|
62
62
|
body_length = body.length
|
|
63
|
-
raise
|
|
63
|
+
raise "MQTT-SN Packet is too big, maximum packet body size is 65531" if body_length > 65_531
|
|
64
64
|
|
|
65
65
|
if body_length > 253
|
|
66
|
-
[0x01, body_length + 4, type_id].pack(
|
|
66
|
+
[0x01, body_length + 4, type_id].pack("CnC") + body
|
|
67
67
|
else
|
|
68
|
-
[body_length + 2, type_id].pack(
|
|
68
|
+
[body_length + 2, type_id].pack("CC") + body
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
@@ -94,7 +94,7 @@ module MQTT
|
|
|
94
94
|
|
|
95
95
|
# Get serialisation of packet's body (variable header and payload)
|
|
96
96
|
def encode_body
|
|
97
|
-
|
|
97
|
+
"" # No body by default
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def encode_flags
|
|
@@ -113,7 +113,7 @@ module MQTT
|
|
|
113
113
|
flags += 0x04 if clean_session
|
|
114
114
|
case topic_id_type
|
|
115
115
|
when :normal
|
|
116
|
-
flags += 0x0
|
|
116
|
+
# flags += 0x0
|
|
117
117
|
when :predefined
|
|
118
118
|
flags += 0x1
|
|
119
119
|
when :short
|
|
@@ -137,7 +137,7 @@ module MQTT
|
|
|
137
137
|
def parse_topic_id(topic_id)
|
|
138
138
|
if topic_id_type == :short
|
|
139
139
|
int = topic_id.to_i
|
|
140
|
-
self.topic_id = [(int >> 8) & 0xFF, int & 0xFF].pack(
|
|
140
|
+
self.topic_id = [(int >> 8) & 0xFF, int & 0xFF].pack("CC")
|
|
141
141
|
else
|
|
142
142
|
self.topic_id = topic_id
|
|
143
143
|
end
|
|
@@ -156,7 +156,7 @@ module MQTT
|
|
|
156
156
|
topic_name
|
|
157
157
|
end
|
|
158
158
|
when :predefined
|
|
159
|
-
[topic_id].pack(
|
|
159
|
+
[topic_id].pack("n")
|
|
160
160
|
end
|
|
161
161
|
end
|
|
162
162
|
|
|
@@ -170,7 +170,7 @@ module MQTT
|
|
|
170
170
|
self.topic_name = topic
|
|
171
171
|
self.topic_id = topic
|
|
172
172
|
when :predefined
|
|
173
|
-
self.topic_id = topic.unpack1(
|
|
173
|
+
self.topic_id = topic.unpack1("n")
|
|
174
174
|
end
|
|
175
175
|
end
|
|
176
176
|
|
|
@@ -184,11 +184,11 @@ module MQTT
|
|
|
184
184
|
}.freeze
|
|
185
185
|
|
|
186
186
|
def encode_body
|
|
187
|
-
[gateway_id, duration].pack(
|
|
187
|
+
[gateway_id, duration].pack("Cn")
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
def parse_body(buffer)
|
|
191
|
-
self.gateway_id, self.duration = buffer.unpack(
|
|
191
|
+
self.gateway_id, self.duration = buffer.unpack("Cn")
|
|
192
192
|
end
|
|
193
193
|
end
|
|
194
194
|
|
|
@@ -200,11 +200,11 @@ module MQTT
|
|
|
200
200
|
}.freeze
|
|
201
201
|
|
|
202
202
|
def encode_body
|
|
203
|
-
[radius].pack(
|
|
203
|
+
[radius].pack("C")
|
|
204
204
|
end
|
|
205
205
|
|
|
206
206
|
def parse_body(buffer)
|
|
207
|
-
self.radius, _ignore = buffer.unpack(
|
|
207
|
+
self.radius, _ignore = buffer.unpack("C")
|
|
208
208
|
end
|
|
209
209
|
end
|
|
210
210
|
|
|
@@ -217,14 +217,14 @@ module MQTT
|
|
|
217
217
|
}.freeze
|
|
218
218
|
|
|
219
219
|
def encode_body
|
|
220
|
-
[gateway_id, gateway_address].pack(
|
|
220
|
+
[gateway_id, gateway_address].pack("Ca*")
|
|
221
221
|
end
|
|
222
222
|
|
|
223
223
|
def parse_body(buffer)
|
|
224
224
|
if buffer.length > 1
|
|
225
|
-
self.gateway_id, self.gateway_address = buffer.unpack(
|
|
225
|
+
self.gateway_id, self.gateway_address = buffer.unpack("Ca*")
|
|
226
226
|
else
|
|
227
|
-
self.gateway_id, _ignore = buffer.unpack(
|
|
227
|
+
self.gateway_id, _ignore = buffer.unpack("C")
|
|
228
228
|
self.gateway_address = nil
|
|
229
229
|
end
|
|
230
230
|
end
|
|
@@ -243,14 +243,14 @@ module MQTT
|
|
|
243
243
|
# Get serialisation of packet's body
|
|
244
244
|
def encode_body
|
|
245
245
|
if @client_id.nil? || @client_id.empty? || @client_id.length > 23
|
|
246
|
-
raise
|
|
246
|
+
raise "Invalid client identifier when serialising packet"
|
|
247
247
|
end
|
|
248
248
|
|
|
249
|
-
[encode_flags, 0x01, keep_alive, client_id].pack(
|
|
249
|
+
[encode_flags, 0x01, keep_alive, client_id].pack("CCna*")
|
|
250
250
|
end
|
|
251
251
|
|
|
252
252
|
def parse_body(buffer)
|
|
253
|
-
flags, protocol_id, self.keep_alive, self.client_id = buffer.unpack(
|
|
253
|
+
flags, protocol_id, self.keep_alive, self.client_id = buffer.unpack("CCna*")
|
|
254
254
|
|
|
255
255
|
raise ProtocolException, "Unsupported protocol ID number: #{protocol_id}" if protocol_id != 0x01
|
|
256
256
|
|
|
@@ -265,26 +265,26 @@ module MQTT
|
|
|
265
265
|
def return_msg
|
|
266
266
|
case return_code
|
|
267
267
|
when 0x00
|
|
268
|
-
|
|
268
|
+
"Accepted"
|
|
269
269
|
when 0x01
|
|
270
|
-
|
|
270
|
+
"Rejected: congestion"
|
|
271
271
|
when 0x02
|
|
272
|
-
|
|
272
|
+
"Rejected: invalid topic ID"
|
|
273
273
|
when 0x03
|
|
274
|
-
|
|
274
|
+
"Rejected: not supported"
|
|
275
275
|
else
|
|
276
276
|
"Rejected: error code #{return_code}"
|
|
277
277
|
end
|
|
278
278
|
end
|
|
279
279
|
|
|
280
280
|
def encode_body
|
|
281
|
-
raise
|
|
281
|
+
raise "return_code must be an Integer" unless return_code.is_a?(Integer)
|
|
282
282
|
|
|
283
|
-
[return_code].pack(
|
|
283
|
+
[return_code].pack("C")
|
|
284
284
|
end
|
|
285
285
|
|
|
286
286
|
def parse_body(buffer)
|
|
287
|
-
self.return_code = buffer.unpack1(
|
|
287
|
+
self.return_code = buffer.unpack1("C")
|
|
288
288
|
end
|
|
289
289
|
end
|
|
290
290
|
|
|
@@ -303,17 +303,17 @@ module MQTT
|
|
|
303
303
|
|
|
304
304
|
def encode_body
|
|
305
305
|
if topic_name.nil? || topic_name.empty?
|
|
306
|
-
|
|
306
|
+
""
|
|
307
307
|
else
|
|
308
|
-
[encode_flags, topic_name].pack(
|
|
308
|
+
[encode_flags, topic_name].pack("Ca*")
|
|
309
309
|
end
|
|
310
310
|
end
|
|
311
311
|
|
|
312
312
|
def parse_body(buffer)
|
|
313
313
|
if buffer.length > 1
|
|
314
|
-
flags, self.topic_name = buffer.unpack(
|
|
314
|
+
flags, self.topic_name = buffer.unpack("Ca*")
|
|
315
315
|
else
|
|
316
|
-
flags, _ignore = buffer.unpack(
|
|
316
|
+
flags, _ignore = buffer.unpack("C")
|
|
317
317
|
self.topic_name = nil
|
|
318
318
|
end
|
|
319
319
|
parse_flags(flags)
|
|
@@ -347,15 +347,15 @@ module MQTT
|
|
|
347
347
|
}.freeze
|
|
348
348
|
|
|
349
349
|
def encode_body
|
|
350
|
-
raise
|
|
350
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
351
351
|
|
|
352
|
-
raise
|
|
352
|
+
raise "topic_id must be an Integer" unless topic_id.is_a?(Integer)
|
|
353
353
|
|
|
354
|
-
[topic_id, id, topic_name].pack(
|
|
354
|
+
[topic_id, id, topic_name].pack("nna*")
|
|
355
355
|
end
|
|
356
356
|
|
|
357
357
|
def parse_body(buffer)
|
|
358
|
-
self.topic_id, self.id, self.topic_name = buffer.unpack(
|
|
358
|
+
self.topic_id, self.id, self.topic_name = buffer.unpack("nna*")
|
|
359
359
|
end
|
|
360
360
|
end
|
|
361
361
|
|
|
@@ -371,15 +371,15 @@ module MQTT
|
|
|
371
371
|
}.freeze
|
|
372
372
|
|
|
373
373
|
def encode_body
|
|
374
|
-
raise
|
|
374
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
375
375
|
|
|
376
|
-
raise
|
|
376
|
+
raise "topic_id must be an Integer" unless topic_id.is_a?(Integer)
|
|
377
377
|
|
|
378
|
-
[topic_id, id, return_code].pack(
|
|
378
|
+
[topic_id, id, return_code].pack("nnC")
|
|
379
379
|
end
|
|
380
380
|
|
|
381
381
|
def parse_body(buffer)
|
|
382
|
-
self.topic_id, self.id, self.return_code = buffer.unpack(
|
|
382
|
+
self.topic_id, self.id, self.return_code = buffer.unpack("nnC")
|
|
383
383
|
end
|
|
384
384
|
end
|
|
385
385
|
|
|
@@ -397,13 +397,13 @@ module MQTT
|
|
|
397
397
|
}.freeze
|
|
398
398
|
|
|
399
399
|
def encode_body
|
|
400
|
-
raise
|
|
400
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
401
401
|
|
|
402
|
-
[encode_flags, encode_topic_id, id, data].pack(
|
|
402
|
+
[encode_flags, encode_topic_id, id, data].pack("Cnna*")
|
|
403
403
|
end
|
|
404
404
|
|
|
405
405
|
def parse_body(buffer)
|
|
406
|
-
flags, topic_id, self.id, self.data = buffer.unpack(
|
|
406
|
+
flags, topic_id, self.id, self.data = buffer.unpack("Cnna*")
|
|
407
407
|
parse_flags(flags)
|
|
408
408
|
parse_topic_id(topic_id)
|
|
409
409
|
end
|
|
@@ -421,15 +421,15 @@ module MQTT
|
|
|
421
421
|
}.freeze
|
|
422
422
|
|
|
423
423
|
def encode_body
|
|
424
|
-
raise
|
|
424
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
425
425
|
|
|
426
|
-
raise
|
|
426
|
+
raise "topic_id must be an Integer" unless topic_id.is_a?(Integer)
|
|
427
427
|
|
|
428
|
-
[topic_id, id, return_code].pack(
|
|
428
|
+
[topic_id, id, return_code].pack("nnC")
|
|
429
429
|
end
|
|
430
430
|
|
|
431
431
|
def parse_body(buffer)
|
|
432
|
-
self.topic_id, self.id, self.return_code = buffer.unpack(
|
|
432
|
+
self.topic_id, self.id, self.return_code = buffer.unpack("nnC")
|
|
433
433
|
end
|
|
434
434
|
end
|
|
435
435
|
|
|
@@ -441,13 +441,13 @@ module MQTT
|
|
|
441
441
|
}.freeze
|
|
442
442
|
|
|
443
443
|
def encode_body
|
|
444
|
-
raise
|
|
444
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
445
445
|
|
|
446
|
-
[id].pack(
|
|
446
|
+
[id].pack("n")
|
|
447
447
|
end
|
|
448
448
|
|
|
449
449
|
def parse_body(buffer)
|
|
450
|
-
self.id, _ignore = buffer.unpack(
|
|
450
|
+
self.id, _ignore = buffer.unpack("n")
|
|
451
451
|
end
|
|
452
452
|
end
|
|
453
453
|
|
|
@@ -459,13 +459,13 @@ module MQTT
|
|
|
459
459
|
}.freeze
|
|
460
460
|
|
|
461
461
|
def encode_body
|
|
462
|
-
raise
|
|
462
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
463
463
|
|
|
464
|
-
[id].pack(
|
|
464
|
+
[id].pack("n")
|
|
465
465
|
end
|
|
466
466
|
|
|
467
467
|
def parse_body(buffer)
|
|
468
|
-
self.id, _ignore = buffer.unpack(
|
|
468
|
+
self.id, _ignore = buffer.unpack("n")
|
|
469
469
|
end
|
|
470
470
|
end
|
|
471
471
|
|
|
@@ -477,13 +477,13 @@ module MQTT
|
|
|
477
477
|
}.freeze
|
|
478
478
|
|
|
479
479
|
def encode_body
|
|
480
|
-
raise
|
|
480
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
481
481
|
|
|
482
|
-
[id].pack(
|
|
482
|
+
[id].pack("n")
|
|
483
483
|
end
|
|
484
484
|
|
|
485
485
|
def parse_body(buffer)
|
|
486
|
-
self.id, _ignore = buffer.unpack(
|
|
486
|
+
self.id, _ignore = buffer.unpack("n")
|
|
487
487
|
end
|
|
488
488
|
end
|
|
489
489
|
|
|
@@ -498,13 +498,13 @@ module MQTT
|
|
|
498
498
|
}.freeze
|
|
499
499
|
|
|
500
500
|
def encode_body
|
|
501
|
-
raise
|
|
501
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
502
502
|
|
|
503
|
-
[encode_flags, id, encode_topic].pack(
|
|
503
|
+
[encode_flags, id, encode_topic].pack("Cna*")
|
|
504
504
|
end
|
|
505
505
|
|
|
506
506
|
def parse_body(buffer)
|
|
507
|
-
flags, self.id, topic = buffer.unpack(
|
|
507
|
+
flags, self.id, topic = buffer.unpack("Cna*")
|
|
508
508
|
parse_flags(flags)
|
|
509
509
|
parse_topic(topic)
|
|
510
510
|
end
|
|
@@ -523,13 +523,13 @@ module MQTT
|
|
|
523
523
|
}.freeze
|
|
524
524
|
|
|
525
525
|
def encode_body
|
|
526
|
-
raise
|
|
526
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
527
527
|
|
|
528
|
-
[encode_flags, encode_topic_id, id, return_code].pack(
|
|
528
|
+
[encode_flags, encode_topic_id, id, return_code].pack("CnnC")
|
|
529
529
|
end
|
|
530
530
|
|
|
531
531
|
def parse_body(buffer)
|
|
532
|
-
flags, topic_id, self.id, self.return_code = buffer.unpack(
|
|
532
|
+
flags, topic_id, self.id, self.return_code = buffer.unpack("CnnC")
|
|
533
533
|
parse_flags(flags)
|
|
534
534
|
parse_topic_id(topic_id)
|
|
535
535
|
end
|
|
@@ -546,13 +546,13 @@ module MQTT
|
|
|
546
546
|
}.freeze
|
|
547
547
|
|
|
548
548
|
def encode_body
|
|
549
|
-
raise
|
|
549
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
550
550
|
|
|
551
|
-
[encode_flags, id, encode_topic].pack(
|
|
551
|
+
[encode_flags, id, encode_topic].pack("Cna*")
|
|
552
552
|
end
|
|
553
553
|
|
|
554
554
|
def parse_body(buffer)
|
|
555
|
-
flags, self.id, topic = buffer.unpack(
|
|
555
|
+
flags, self.id, topic = buffer.unpack("Cna*")
|
|
556
556
|
parse_flags(flags)
|
|
557
557
|
parse_topic(topic)
|
|
558
558
|
end
|
|
@@ -566,13 +566,13 @@ module MQTT
|
|
|
566
566
|
}.freeze
|
|
567
567
|
|
|
568
568
|
def encode_body
|
|
569
|
-
raise
|
|
569
|
+
raise "id must be an Integer" unless id.is_a?(Integer)
|
|
570
570
|
|
|
571
|
-
[id].pack(
|
|
571
|
+
[id].pack("n")
|
|
572
572
|
end
|
|
573
573
|
|
|
574
574
|
def parse_body(buffer)
|
|
575
|
-
self.id = buffer.unpack1(
|
|
575
|
+
self.id = buffer.unpack1("n")
|
|
576
576
|
end
|
|
577
577
|
end
|
|
578
578
|
|
|
@@ -593,14 +593,14 @@ module MQTT
|
|
|
593
593
|
|
|
594
594
|
def encode_body
|
|
595
595
|
if duration.nil? || duration.zero?
|
|
596
|
-
|
|
596
|
+
""
|
|
597
597
|
else
|
|
598
|
-
[duration].pack(
|
|
598
|
+
[duration].pack("n")
|
|
599
599
|
end
|
|
600
600
|
end
|
|
601
601
|
|
|
602
602
|
def parse_body(buffer)
|
|
603
|
-
self.duration = buffer.length == 2 ? buffer.unpack1(
|
|
603
|
+
self.duration = (buffer.length == 2) ? buffer.unpack1("n") : nil
|
|
604
604
|
end
|
|
605
605
|
end
|
|
606
606
|
|
|
@@ -615,15 +615,15 @@ module MQTT
|
|
|
615
615
|
|
|
616
616
|
def encode_body
|
|
617
617
|
if topic_name.nil? || topic_name.empty?
|
|
618
|
-
|
|
618
|
+
""
|
|
619
619
|
else
|
|
620
|
-
[encode_flags, topic_name].pack(
|
|
620
|
+
[encode_flags, topic_name].pack("Ca*")
|
|
621
621
|
end
|
|
622
622
|
end
|
|
623
623
|
|
|
624
624
|
def parse_body(buffer)
|
|
625
625
|
if buffer.length > 1
|
|
626
|
-
flags, self.topic_name = buffer.unpack(
|
|
626
|
+
flags, self.topic_name = buffer.unpack("Ca*")
|
|
627
627
|
parse_flags(flags)
|
|
628
628
|
else
|
|
629
629
|
self.topic_name = nil
|
|
@@ -639,13 +639,13 @@ module MQTT
|
|
|
639
639
|
}.freeze
|
|
640
640
|
|
|
641
641
|
def encode_body
|
|
642
|
-
raise
|
|
642
|
+
raise "return_code must be an Integer" unless return_code.is_a?(Integer)
|
|
643
643
|
|
|
644
|
-
[return_code].pack(
|
|
644
|
+
[return_code].pack("C")
|
|
645
645
|
end
|
|
646
646
|
|
|
647
647
|
def parse_body(buffer)
|
|
648
|
-
self.return_code, _ignore = buffer.unpack(
|
|
648
|
+
self.return_code, _ignore = buffer.unpack("C")
|
|
649
649
|
end
|
|
650
650
|
end
|
|
651
651
|
|
|
@@ -669,13 +669,13 @@ module MQTT
|
|
|
669
669
|
}.freeze
|
|
670
670
|
|
|
671
671
|
def encode_body
|
|
672
|
-
raise
|
|
672
|
+
raise "return_code must be an Integer" unless return_code.is_a?(Integer)
|
|
673
673
|
|
|
674
|
-
[return_code].pack(
|
|
674
|
+
[return_code].pack("C")
|
|
675
675
|
end
|
|
676
676
|
|
|
677
677
|
def parse_body(buffer)
|
|
678
|
-
self.return_code, _ignore = buffer.unpack(
|
|
678
|
+
self.return_code, _ignore = buffer.unpack("C")
|
|
679
679
|
end
|
|
680
680
|
end
|
|
681
681
|
end
|
data/lib/mqtt/version.rb
CHANGED
data/lib/mqtt-ccutrer.rb
CHANGED
data/lib/mqtt.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require "logger"
|
|
4
|
+
require "socket"
|
|
5
|
+
require "timeout"
|
|
6
6
|
|
|
7
|
-
require
|
|
7
|
+
require "mqtt/version"
|
|
8
8
|
|
|
9
9
|
module MQTT
|
|
10
10
|
# Default port number for unencrypted connections
|
|
@@ -42,9 +42,9 @@ module MQTT
|
|
|
42
42
|
class ResendLimitExceededException < Exception
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
autoload :Client,
|
|
46
|
-
autoload :Packet,
|
|
47
|
-
autoload :Proxy,
|
|
45
|
+
autoload :Client, "mqtt/client"
|
|
46
|
+
autoload :Packet, "mqtt/packet"
|
|
47
|
+
autoload :Proxy, "mqtt/proxy"
|
|
48
48
|
|
|
49
49
|
# MQTT-SN
|
|
50
50
|
module SN
|
|
@@ -56,6 +56,6 @@ module MQTT
|
|
|
56
56
|
class ProtocolException < MQTT::Exception
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
autoload :Packet,
|
|
59
|
+
autoload :Packet, "mqtt/sn/packet"
|
|
60
60
|
end
|
|
61
61
|
end
|