mqtt 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +24 -0
- data/README +1 -0
- data/lib/mqtt/client.rb +40 -20
- data/lib/mqtt/packet.rb +60 -63
- data/lib/mqtt/version.rb +1 -1
- data/spec/mqtt_client_spec.rb +70 -1
- data/spec/mqtt_packet_spec.rb +17 -17
- metadata +16 -16
data/NEWS
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
Ruby MQTT NEWS
|
2
2
|
==============
|
3
3
|
|
4
|
+
Ruby MQTT Version 0.0.8 (2011-02-04)
|
5
|
+
------------------------------------
|
6
|
+
|
7
|
+
* Implemented Last Will and Testament feature.
|
8
|
+
* Renamed dup attribute to duplicate to avoid method name clash.
|
9
|
+
* Made the random client_id generator a public class method.
|
10
|
+
|
11
|
+
|
12
|
+
Ruby MQTT Version 0.0.7 (2011-01-19)
|
13
|
+
------------------------------------
|
14
|
+
|
15
|
+
* You can now pass a topic and block to client.get
|
16
|
+
* Added MQTT::Client.connect class method.
|
17
|
+
|
18
|
+
|
19
|
+
Ruby MQTT Version 0.0.5 (2011-01-18)
|
20
|
+
------------------------------------
|
21
|
+
|
22
|
+
* Implemented setting username and password (MQTT 3.1)
|
23
|
+
* Renamed clean_start to clean_session
|
24
|
+
* Started using autoload to load classes
|
25
|
+
* Modernised Gem building mechanisms
|
26
|
+
|
27
|
+
|
4
28
|
Ruby MQTT Version 0.0.4 (2009-02-22)
|
5
29
|
------------------------------------
|
6
30
|
|
data/README
CHANGED
data/lib/mqtt/client.rb
CHANGED
@@ -8,6 +8,10 @@ class MQTT::Client
|
|
8
8
|
attr_accessor :ack_timeout # Number of seconds to wait for acknowledgement packets
|
9
9
|
attr_accessor :username # Username to authenticate to the broker with
|
10
10
|
attr_accessor :password # Password to authenticate to the broker with
|
11
|
+
attr_accessor :will_topic # The topic that the Will message is published to
|
12
|
+
attr_accessor :will_payload # Contents of message that is sent by broker when client disconnect
|
13
|
+
attr_accessor :will_qos # The QoS level of the will message sent by the broker
|
14
|
+
attr_accessor :will_retain # If the Will message should be retain by the broker after it is sent
|
11
15
|
|
12
16
|
# OLD deprecated clean_start
|
13
17
|
alias :clean_start :clean_session
|
@@ -25,7 +29,11 @@ class MQTT::Client
|
|
25
29
|
:client_id => nil,
|
26
30
|
:ack_timeout => 5,
|
27
31
|
:username => nil,
|
28
|
-
:password => nil
|
32
|
+
:password => nil,
|
33
|
+
:will_topic => nil,
|
34
|
+
:will_payload => nil,
|
35
|
+
:will_qos => 0,
|
36
|
+
:will_retain => false
|
29
37
|
}
|
30
38
|
|
31
39
|
# Create and connect a new MQTT Client
|
@@ -43,6 +51,24 @@ class MQTT::Client
|
|
43
51
|
return client
|
44
52
|
end
|
45
53
|
|
54
|
+
# Generate a random client identifier
|
55
|
+
# (using the characters 0-9 and a-z)
|
56
|
+
def self.generate_client_id(prefix='ruby_', length=16)
|
57
|
+
str = prefix.dup
|
58
|
+
length.times do
|
59
|
+
num = rand(36)
|
60
|
+
if (num<10)
|
61
|
+
# Number
|
62
|
+
num += 48
|
63
|
+
else
|
64
|
+
# Letter
|
65
|
+
num += 87
|
66
|
+
end
|
67
|
+
str += num.chr
|
68
|
+
end
|
69
|
+
return str
|
70
|
+
end
|
71
|
+
|
46
72
|
# Create a new MQTT Client instance
|
47
73
|
#
|
48
74
|
# Examples:
|
@@ -79,13 +105,20 @@ class MQTT::Client
|
|
79
105
|
@write_semaphore = Mutex.new
|
80
106
|
end
|
81
107
|
|
108
|
+
def set_will(topic, payload, retain=false, qos=0)
|
109
|
+
self.will_topic = topic
|
110
|
+
self.will_payload = payload
|
111
|
+
self.will_retain = retain
|
112
|
+
self.will_qos = qos
|
113
|
+
end
|
114
|
+
|
82
115
|
# Connect to the MQTT broker
|
83
116
|
# If a block is given, then yield to that block and then disconnect again.
|
84
117
|
def connect(clientid=nil)
|
85
118
|
if !clientid.nil?
|
86
119
|
@client_id = clientid
|
87
120
|
elsif @clientid.nil?
|
88
|
-
@client_id =
|
121
|
+
@client_id = MQTT::Client.generate_client_id
|
89
122
|
@clean_session = true
|
90
123
|
end
|
91
124
|
|
@@ -99,7 +132,11 @@ class MQTT::Client
|
|
99
132
|
:keep_alive => @keep_alive,
|
100
133
|
:client_id => @client_id,
|
101
134
|
:username => @username,
|
102
|
-
:password => @password
|
135
|
+
:password => @password,
|
136
|
+
:will_topic => @will_topic,
|
137
|
+
:will_payload => @will_payload,
|
138
|
+
:will_qos => @will_qos,
|
139
|
+
:will_retain => @will_retain
|
103
140
|
)
|
104
141
|
|
105
142
|
# Send packet
|
@@ -284,21 +321,4 @@ private
|
|
284
321
|
end
|
285
322
|
end
|
286
323
|
|
287
|
-
# Generate a string of random letters (0-9,a-z)
|
288
|
-
def random_letters(count)
|
289
|
-
str = ''
|
290
|
-
count.times do
|
291
|
-
num = rand(36)
|
292
|
-
if (num<10)
|
293
|
-
# Number
|
294
|
-
num += 48
|
295
|
-
else
|
296
|
-
# Letter
|
297
|
-
num += 87
|
298
|
-
end
|
299
|
-
str += num.chr
|
300
|
-
end
|
301
|
-
return str
|
302
|
-
end
|
303
|
-
|
304
324
|
end
|
data/lib/mqtt/packet.rb
CHANGED
@@ -3,12 +3,19 @@ module MQTT
|
|
3
3
|
# Class representing a MQTT Packet
|
4
4
|
# Performs binary encoding and decoding of headers
|
5
5
|
class MQTT::Packet
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :duplicate # Duplicate delivery flag
|
7
7
|
attr_reader :retain # Retain flag
|
8
8
|
attr_reader :qos # Quality of Service level
|
9
9
|
attr_reader :body_length # The length of the parsed packet body
|
10
10
|
|
11
|
-
|
11
|
+
DEFAULTS = {
|
12
|
+
:duplicate => false,
|
13
|
+
:qos => 0,
|
14
|
+
:retain => false,
|
15
|
+
:body_length => nil
|
16
|
+
}
|
17
|
+
|
18
|
+
# Read in a packet from a socket
|
12
19
|
def self.read(socket)
|
13
20
|
# Read in the packet header and work out the class
|
14
21
|
header = read_byte(socket)
|
@@ -17,7 +24,7 @@ module MQTT
|
|
17
24
|
|
18
25
|
# Create a new packet object
|
19
26
|
packet = packet_class.new(
|
20
|
-
:
|
27
|
+
:duplicate => ((header & 0x08) >> 3),
|
21
28
|
:qos => ((header & 0x06) >> 1),
|
22
29
|
:retain => ((header & 0x01) >> 0)
|
23
30
|
)
|
@@ -60,7 +67,7 @@ module MQTT
|
|
60
67
|
|
61
68
|
# Create a new packet object
|
62
69
|
packet = packet_class.new(
|
63
|
-
:
|
70
|
+
:duplicate => ((buffer[0] & 0x08) >> 3) == 0x01,
|
64
71
|
:qos => ((buffer[0] & 0x06) >> 1),
|
65
72
|
:retain => ((buffer[0] & 0x01) >> 0) == 0x01
|
66
73
|
)
|
@@ -91,12 +98,7 @@ module MQTT
|
|
91
98
|
|
92
99
|
# Create a new empty packet
|
93
100
|
def initialize(args={})
|
94
|
-
update_attributes(
|
95
|
-
:dup => false,
|
96
|
-
:qos => 0,
|
97
|
-
:retain => false,
|
98
|
-
:body_length => nil
|
99
|
-
}.merge(args))
|
101
|
+
update_attributes(DEFAULTS.merge(args))
|
100
102
|
end
|
101
103
|
|
102
104
|
def update_attributes(attr={})
|
@@ -115,11 +117,11 @@ module MQTT
|
|
115
117
|
end
|
116
118
|
|
117
119
|
# Set the dup flag (true/false)
|
118
|
-
def
|
120
|
+
def duplicate=(arg)
|
119
121
|
if arg.kind_of?(Integer)
|
120
|
-
@
|
122
|
+
@duplicate = (arg != 0)
|
121
123
|
else
|
122
|
-
@
|
124
|
+
@duplicate = arg
|
123
125
|
end
|
124
126
|
end
|
125
127
|
|
@@ -162,7 +164,7 @@ module MQTT
|
|
162
164
|
# Encode the fixed header
|
163
165
|
header = [
|
164
166
|
((type_id.to_i & 0x0F) << 4) |
|
165
|
-
((
|
167
|
+
((duplicate ? 0x1 : 0x0) << 3) |
|
166
168
|
((qos.to_i & 0x03) << 1) |
|
167
169
|
(retain ? 0x1 : 0x0)
|
168
170
|
]
|
@@ -249,13 +251,15 @@ module MQTT
|
|
249
251
|
attr_accessor :message_id
|
250
252
|
attr_accessor :payload
|
251
253
|
|
252
|
-
|
253
|
-
def initialize(args={})
|
254
|
-
super({
|
254
|
+
DEFAULTS = {
|
255
255
|
:topic => nil,
|
256
256
|
:message_id => 0,
|
257
257
|
:payload => ''
|
258
|
-
|
258
|
+
}
|
259
|
+
|
260
|
+
# Create a new Publish packet
|
261
|
+
def initialize(args={})
|
262
|
+
super(DEFAULTS.merge(args))
|
259
263
|
end
|
260
264
|
|
261
265
|
# Get serialisation of packet's body
|
@@ -297,21 +301,23 @@ module MQTT
|
|
297
301
|
alias :clean_start :clean_session
|
298
302
|
alias :clean_start= :clean_session=
|
299
303
|
|
304
|
+
DEFAULTS = {
|
305
|
+
:protocol_name => 'MQIsdp',
|
306
|
+
:protocol_version => 0x03,
|
307
|
+
:client_id => nil,
|
308
|
+
:clean_session => true,
|
309
|
+
:keep_alive => 15,
|
310
|
+
:will_topic => nil,
|
311
|
+
:will_qos => 0,
|
312
|
+
:will_retain => false,
|
313
|
+
:will_payload => '',
|
314
|
+
:username => nil,
|
315
|
+
:password => nil,
|
316
|
+
}
|
317
|
+
|
300
318
|
# Create a new Client Connect packet
|
301
319
|
def initialize(args={})
|
302
|
-
super(
|
303
|
-
:protocol_name => 'MQIsdp',
|
304
|
-
:protocol_version => 0x03,
|
305
|
-
:client_id => nil,
|
306
|
-
:clean_session => true,
|
307
|
-
:keep_alive => 10,
|
308
|
-
:will_topic => nil,
|
309
|
-
:will_qos => 0,
|
310
|
-
:will_retain => false,
|
311
|
-
:will_payload => '',
|
312
|
-
:username => nil,
|
313
|
-
:password => nil,
|
314
|
-
}.merge(args))
|
320
|
+
super(DEFAULTS.merge(args))
|
315
321
|
end
|
316
322
|
|
317
323
|
# Get serialisation of packet's body
|
@@ -372,12 +378,11 @@ module MQTT
|
|
372
378
|
# Class representing an MQTT Connect Acknowledgment Packet
|
373
379
|
class Connack < MQTT::Packet
|
374
380
|
attr_accessor :return_code
|
381
|
+
DEFAULTS = {:return_code => 0x00}
|
375
382
|
|
376
383
|
# Create a new Client Connect packet
|
377
384
|
def initialize(args={})
|
378
|
-
super(
|
379
|
-
:return_code => 0x00
|
380
|
-
}.merge(args))
|
385
|
+
super(DEFAULTS.merge(args))
|
381
386
|
end
|
382
387
|
|
383
388
|
# Get a string message corresponding to a return code
|
@@ -422,12 +427,11 @@ module MQTT
|
|
422
427
|
# Class representing an MQTT Publish Acknowledgment packet
|
423
428
|
class Puback < MQTT::Packet
|
424
429
|
attr_accessor :message_id
|
430
|
+
DEFAULTS = {:message_id => 0}
|
425
431
|
|
426
432
|
# Create a new Publish Acknowledgment packet
|
427
433
|
def initialize(args={})
|
428
|
-
super(
|
429
|
-
:message_id => 0
|
430
|
-
}.merge(args))
|
434
|
+
super(DEFAULTS.merge(args))
|
431
435
|
end
|
432
436
|
|
433
437
|
# Get serialisation of packet's body
|
@@ -448,12 +452,11 @@ module MQTT
|
|
448
452
|
# Class representing an MQTT Publish Received packet
|
449
453
|
class Pubrec < MQTT::Packet
|
450
454
|
attr_accessor :message_id
|
455
|
+
DEFAULTS = {:message_id => 0}
|
451
456
|
|
452
457
|
# Create a new Publish Recieved packet
|
453
458
|
def initialize(args={})
|
454
|
-
super(
|
455
|
-
:message_id => 0
|
456
|
-
}.merge(args))
|
459
|
+
super(DEFAULTS.merge(args))
|
457
460
|
end
|
458
461
|
|
459
462
|
# Get serialisation of packet's body
|
@@ -474,12 +477,11 @@ module MQTT
|
|
474
477
|
# Class representing an MQTT Publish Release packet
|
475
478
|
class Pubrel < MQTT::Packet
|
476
479
|
attr_accessor :message_id
|
480
|
+
DEFAULTS = {:message_id => 0}
|
477
481
|
|
478
482
|
# Create a new Publish Release packet
|
479
483
|
def initialize(args={})
|
480
|
-
super(
|
481
|
-
:message_id => 0
|
482
|
-
}.merge(args))
|
484
|
+
super(DEFAULTS.merge(args))
|
483
485
|
end
|
484
486
|
|
485
487
|
# Get serialisation of packet's body
|
@@ -500,12 +502,11 @@ module MQTT
|
|
500
502
|
# Class representing an MQTT Publish Complete packet
|
501
503
|
class Pubcomp < MQTT::Packet
|
502
504
|
attr_accessor :message_id
|
505
|
+
DEFAULTS = {:message_id => 0}
|
503
506
|
|
504
507
|
# Create a new Publish Complete packet
|
505
508
|
def initialize(args={})
|
506
|
-
super(
|
507
|
-
:message_id => 0
|
508
|
-
}.merge(args))
|
509
|
+
super(DEFAULTS.merge(args))
|
509
510
|
end
|
510
511
|
|
511
512
|
# Get serialisation of packet's body
|
@@ -527,14 +528,13 @@ module MQTT
|
|
527
528
|
class Subscribe < MQTT::Packet
|
528
529
|
attr_accessor :message_id
|
529
530
|
attr_reader :topics
|
531
|
+
DEFAULTS = {:message_id => 0}
|
530
532
|
|
531
533
|
# Create a new Subscribe packet
|
532
534
|
def initialize(args={})
|
533
|
-
super(
|
534
|
-
|
535
|
-
|
536
|
-
}.merge(args))
|
537
|
-
self.qos = 1 # Force a QOS of 1
|
535
|
+
super(DEFAULTS.merge(args))
|
536
|
+
@topics ||= []
|
537
|
+
@qos = 1 # Force a QOS of 1
|
538
538
|
end
|
539
539
|
|
540
540
|
# Set one or more topics for the Subscrible packet
|
@@ -609,13 +609,12 @@ module MQTT
|
|
609
609
|
class Suback < MQTT::Packet
|
610
610
|
attr_accessor :message_id
|
611
611
|
attr_reader :granted_qos
|
612
|
+
DEFAULTS = {:message_id => 0}
|
612
613
|
|
613
614
|
# Create a new Subscribe Acknowledgment packet
|
614
615
|
def initialize(args={})
|
615
|
-
super(
|
616
|
-
|
617
|
-
:message_id => 0
|
618
|
-
}.merge(args))
|
616
|
+
super(DEFAULTS.merge(args))
|
617
|
+
@granted_qos ||= []
|
619
618
|
end
|
620
619
|
|
621
620
|
def granted_qos=(value)
|
@@ -649,14 +648,13 @@ module MQTT
|
|
649
648
|
class Unsubscribe < MQTT::Packet
|
650
649
|
attr_reader :topics
|
651
650
|
attr_accessor :message_id
|
651
|
+
DEFAULTS = {:message_id => 0}
|
652
652
|
|
653
653
|
# Create a new Unsubscribe packet
|
654
654
|
def initialize(args={})
|
655
|
-
super(
|
656
|
-
|
657
|
-
|
658
|
-
}.merge(args))
|
659
|
-
self.qos = 1 # Force a QOS of 1
|
655
|
+
super(DEFAULTS.merge(args))
|
656
|
+
@topics ||= []
|
657
|
+
@qos = 1 # Force a QOS of 1
|
660
658
|
end
|
661
659
|
|
662
660
|
def topics=(value)
|
@@ -690,12 +688,11 @@ module MQTT
|
|
690
688
|
# Class representing an MQTT Unsubscribe Acknowledgment packet
|
691
689
|
class Unsuback < MQTT::Packet
|
692
690
|
attr_accessor :message_id
|
691
|
+
DEFAULTS = {:message_id => 0}
|
693
692
|
|
694
693
|
# Create a new Unsubscribe Acknowledgment packet
|
695
694
|
def initialize(args={})
|
696
|
-
super(
|
697
|
-
:message_id => 0
|
698
|
-
}.merge(args))
|
695
|
+
super(DEFAULTS.merge(args))
|
699
696
|
end
|
700
697
|
|
701
698
|
# Get serialisation of packet's body
|
data/lib/mqtt/version.rb
CHANGED
data/spec/mqtt_client_spec.rb
CHANGED
@@ -62,7 +62,6 @@ describe MQTT::Client do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
65
|
describe "when calling the 'connect' method" do
|
67
66
|
before(:each) do
|
68
67
|
TCPSocket.stubs(:new).returns(@socket)
|
@@ -125,6 +124,39 @@ describe MQTT::Client do
|
|
125
124
|
@client.connect
|
126
125
|
@client.clean_session.should be_true
|
127
126
|
end
|
127
|
+
|
128
|
+
context "with a last will and testament set" do
|
129
|
+
before(:each) do
|
130
|
+
@client.set_will('topic', 'hello', retain=false, qos=1)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should have set the Will's topic" do
|
134
|
+
@client.will_topic.should == 'topic'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should have set the Will's payload" do
|
138
|
+
@client.will_payload.should == 'hello'
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should have set the Will's retain flag to true" do
|
142
|
+
@client.will_retain.should be_false
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should have set the Will's retain QOS value to 1" do
|
146
|
+
@client.will_qos.should == 1
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should include the will in the CONNECT message" do
|
150
|
+
@client.connect('myclient')
|
151
|
+
@socket.string.should ==
|
152
|
+
"\x10\x24"+
|
153
|
+
"\x00\x06MQIsdp"+
|
154
|
+
"\x03\x0e\x00\x0f"+
|
155
|
+
"\x00\x08myclient"+
|
156
|
+
"\x00\x05topic\x00\x05hello"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
128
160
|
end
|
129
161
|
|
130
162
|
describe "when calling the 'receive_connack' method" do
|
@@ -350,7 +382,44 @@ describe MQTT::Client do
|
|
350
382
|
MQTT::Packet.stubs(:read).raises(MQTT::Exception)
|
351
383
|
@client.send(:receive_packet)
|
352
384
|
end
|
385
|
+
end
|
353
386
|
|
387
|
+
describe "generating a client identifier" do
|
388
|
+
context "with default parameters" do
|
389
|
+
before :all do
|
390
|
+
@client_id = MQTT::Client.generate_client_id
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should be less or equal to 23 characters long" do
|
394
|
+
@client_id.length.should <= 23
|
395
|
+
end
|
396
|
+
|
397
|
+
it "should have a prefix of ruby_" do
|
398
|
+
@client_id.should match(/^ruby_/)
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should end in 16 characters of lowercase letters and numbers" do
|
402
|
+
@client_id.should match(/_[a-z0-9]{16}$/)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context "with an alternative prefix" do
|
407
|
+
before :all do
|
408
|
+
@client_id = MQTT::Client.generate_client_id('test_')
|
409
|
+
end
|
410
|
+
|
411
|
+
it "should be less or equal to 23 characters long" do
|
412
|
+
@client_id.length.should <= 23
|
413
|
+
end
|
414
|
+
|
415
|
+
it "should have a prefix of test_" do
|
416
|
+
@client_id.should match(/^test_/)
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should end in 16 characters of lowercase letters and numbers" do
|
420
|
+
@client_id.should match(/_[a-z0-9]{16}$/)
|
421
|
+
end
|
422
|
+
end
|
354
423
|
end
|
355
424
|
|
356
425
|
end
|
data/spec/mqtt_packet_spec.rb
CHANGED
@@ -7,8 +7,8 @@ describe MQTT::Packet do
|
|
7
7
|
|
8
8
|
describe "when creating a new packet" do
|
9
9
|
it "should allow you to set the packet dup flag as a hash parameter" do
|
10
|
-
packet = MQTT::Packet.new( :
|
11
|
-
packet.
|
10
|
+
packet = MQTT::Packet.new( :duplicate => true )
|
11
|
+
packet.duplicate.should be_true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should allow you to set the packet QOS level as a hash parameter" do
|
@@ -25,7 +25,7 @@ describe MQTT::Packet do
|
|
25
25
|
describe "when setting packet parameters" do
|
26
26
|
before(:each) do
|
27
27
|
@packet = MQTT::Packet.new(
|
28
|
-
:
|
28
|
+
:duplicate => false,
|
29
29
|
:qos => 0,
|
30
30
|
:retain => false
|
31
31
|
)
|
@@ -37,13 +37,13 @@ describe MQTT::Packet do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should let you change the dup flag of a packet" do
|
40
|
-
@packet.
|
41
|
-
@packet.
|
40
|
+
@packet.duplicate = true
|
41
|
+
@packet.duplicate.should be_true
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should let you change the dup flag of a packet using an integer" do
|
45
|
-
@packet.
|
46
|
-
@packet.
|
45
|
+
@packet.duplicate = 1
|
46
|
+
@packet.duplicate.should be_true
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should let you change the retain flag of a packet" do
|
@@ -121,7 +121,7 @@ describe MQTT::Packet::Publish do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should output the correct bytes for a packet with QOS 2 and dup flag set" do
|
124
|
-
packet = MQTT::Packet::Publish.new( :qos => 2, :
|
124
|
+
packet = MQTT::Packet::Publish.new( :qos => 2, :duplicate => true, :message_id => 5, :topic => 'c/d', :payload => 'hello world' )
|
125
125
|
packet.to_s.should == "\x3C\x12\x00\x03c/d\x00\x05hello world"
|
126
126
|
end
|
127
127
|
|
@@ -152,7 +152,7 @@ describe MQTT::Packet::Publish do
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should set the DUP flag correctly" do
|
155
|
-
@packet.
|
155
|
+
@packet.duplicate.should be_false
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should set the topic name correctly" do
|
@@ -182,7 +182,7 @@ describe MQTT::Packet::Publish do
|
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should set the DUP flag correctly" do
|
185
|
-
@packet.
|
185
|
+
@packet.duplicate.should be_true
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should set the topic name correctly" do
|
@@ -243,7 +243,7 @@ describe MQTT::Packet::Connect do
|
|
243
243
|
describe "when serialising a packet" do
|
244
244
|
it "should output the correct bytes for a packet with no flags" do
|
245
245
|
packet = MQTT::Packet::Connect.new( :client_id => 'myclient' )
|
246
|
-
packet.to_s.should == "\020\026\x00\x06MQIsdp\x03\x02\x00\
|
246
|
+
packet.to_s.should == "\020\026\x00\x06MQIsdp\x03\x02\x00\x0f\x00\x08myclient"
|
247
247
|
end
|
248
248
|
|
249
249
|
it "should output the correct bytes for a packet with clean session turned off" do
|
@@ -251,7 +251,7 @@ describe MQTT::Packet::Connect do
|
|
251
251
|
:client_id => 'myclient',
|
252
252
|
:clean_session => false
|
253
253
|
)
|
254
|
-
packet.to_s.should == "\020\026\x00\x06MQIsdp\x03\x00\x00\
|
254
|
+
packet.to_s.should == "\020\026\x00\x06MQIsdp\x03\x00\x00\x0f\x00\x08myclient"
|
255
255
|
end
|
256
256
|
|
257
257
|
it "should throw an exception when there is no client identifier" do
|
@@ -274,7 +274,7 @@ describe MQTT::Packet::Connect do
|
|
274
274
|
packet.to_s.should ==
|
275
275
|
"\x10\x24"+
|
276
276
|
"\x00\x06MQIsdp"+
|
277
|
-
"\x03\x0e\x00\
|
277
|
+
"\x03\x0e\x00\x0f"+
|
278
278
|
"\x00\x08myclient"+
|
279
279
|
"\x00\x05topic\x00\x05hello"
|
280
280
|
end
|
@@ -288,8 +288,8 @@ describe MQTT::Packet::Connect do
|
|
288
288
|
packet.to_s.should ==
|
289
289
|
"\x10\x2A"+
|
290
290
|
"\x00\x06MQIsdp"+
|
291
|
-
"\x03\xC2\x00\
|
292
|
-
"\x08myclient"+
|
291
|
+
"\x03\xC2\x00\x0f"+
|
292
|
+
"\x00\x08myclient"+
|
293
293
|
"\x00\x08username"+
|
294
294
|
"\x00\x08password"
|
295
295
|
end
|
@@ -429,8 +429,8 @@ describe MQTT::Packet::Connect do
|
|
429
429
|
@packet = MQTT::Packet.parse(
|
430
430
|
"\x10\x2A"+
|
431
431
|
"\x00\x06MQIsdp"+
|
432
|
-
"\x03\xC0\x00\x0a
|
433
|
-
"\x08myclient"+
|
432
|
+
"\x03\xC0\x00\x0a"+
|
433
|
+
"\x00\x08myclient"+
|
434
434
|
"\x00\x08username"+
|
435
435
|
"\x00\x08password"
|
436
436
|
)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicholas J Humfrey
|
@@ -15,10 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-02-04 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
22
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
25
|
none: false
|
24
26
|
requirements:
|
@@ -31,10 +33,10 @@ dependencies:
|
|
31
33
|
- 7
|
32
34
|
version: 1.0.7
|
33
35
|
type: :development
|
34
|
-
name: bundler
|
35
|
-
prerelease: false
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
prerelease: false
|
38
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
@@ -47,10 +49,10 @@ dependencies:
|
|
47
49
|
- 2
|
48
50
|
version: 0.7.2
|
49
51
|
type: :development
|
50
|
-
name: yard
|
51
|
-
prerelease: false
|
52
52
|
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
+
name: rake
|
55
|
+
prerelease: false
|
54
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
57
|
none: false
|
56
58
|
requirements:
|
@@ -63,10 +65,10 @@ dependencies:
|
|
63
65
|
- 7
|
64
66
|
version: 0.8.7
|
65
67
|
type: :development
|
66
|
-
name: rake
|
67
|
-
prerelease: false
|
68
68
|
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
prerelease: false
|
70
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
73
|
none: false
|
72
74
|
requirements:
|
@@ -79,10 +81,10 @@ dependencies:
|
|
79
81
|
- 0
|
80
82
|
version: 2.6.0
|
81
83
|
type: :development
|
82
|
-
name: rspec
|
83
|
-
prerelease: false
|
84
84
|
version_requirements: *id004
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
|
+
name: mocha
|
87
|
+
prerelease: false
|
86
88
|
requirement: &id005 !ruby/object:Gem::Requirement
|
87
89
|
none: false
|
88
90
|
requirements:
|
@@ -95,10 +97,10 @@ dependencies:
|
|
95
97
|
- 0
|
96
98
|
version: 0.10.0
|
97
99
|
type: :development
|
98
|
-
name: mocha
|
99
|
-
prerelease: false
|
100
100
|
version_requirements: *id005
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
|
+
name: rcov
|
103
|
+
prerelease: false
|
102
104
|
requirement: &id006 !ruby/object:Gem::Requirement
|
103
105
|
none: false
|
104
106
|
requirements:
|
@@ -111,8 +113,6 @@ dependencies:
|
|
111
113
|
- 0
|
112
114
|
version: 0.9.0
|
113
115
|
type: :development
|
114
|
-
name: rcov
|
115
|
-
prerelease: false
|
116
116
|
version_requirements: *id006
|
117
117
|
description: Pure Ruby gem that implements the MQTT (Message Queue Telemetry Transport) protocol, a lightweight protocol for publish/subscribe messaging.
|
118
118
|
email: njh@aelius.com
|