paho-mqtt 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,17 +1,34 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
5
22
  class Connack < PahoMqtt::Packet::Base
6
23
  # Session Present flag
7
24
  attr_accessor :session_present
8
-
25
+
9
26
  # The return code (defaults to 0 for connection accepted)
10
27
  attr_accessor :return_code
11
28
 
12
29
  # Default attribute values
13
30
  ATTR_DEFAULTS = {:return_code => 0x00}
14
-
31
+
15
32
  # Create a new Client Connect packet
16
33
  def initialize(args={})
17
34
  # We must set flags before other attributes
@@ -81,4 +98,3 @@ module PahoMqtt
81
98
  end
82
99
  end
83
100
  end
84
-
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -67,28 +84,14 @@ module PahoMqtt
67
84
  # Get serialisation of packet's body
68
85
  def encode_body
69
86
  body = ''
70
- if @version == '3.1.0'
71
- if @client_id.nil? or @client_id.bytesize < 1
72
- raise "Client identifier too short while serialising packet"
73
- elsif @client_id.bytesize > 23
74
- raise "Client identifier too long when serialising packet"
75
- end
76
- end
87
+ check_version
77
88
  body += encode_string(@protocol_name)
78
89
  body += encode_bytes(@protocol_level.to_i)
79
90
  if @keep_alive < 0
80
91
  raise "Invalid keep-alive value: cannot be less than 0"
81
92
  end
82
93
 
83
- # Set the Connect flags
84
- @connect_flags = 0
85
- @connect_flags |= 0x02 if @clean_session
86
- @connect_flags |= 0x04 unless @will_topic.nil?
87
- @connect_flags |= ((@will_qos & 0x03) << 3)
88
- @connect_flags |= 0x20 if @will_retain
89
- @connect_flags |= 0x40 unless @password.nil?
90
- @connect_flags |= 0x80 unless @username.nil?
91
- body += encode_bytes(@connect_flags)
94
+ body += encode_flags(@connect_flags)
92
95
  body += encode_short(@keep_alive)
93
96
  body += encode_string(@client_id)
94
97
  unless will_topic.nil?
@@ -98,7 +101,29 @@ module PahoMqtt
98
101
  end
99
102
  body += encode_string(@username) unless @username.nil?
100
103
  body += encode_string(@password) unless @password.nil?
101
- return body
104
+ body
105
+ end
106
+
107
+ def check_version
108
+ if @version == '3.1.0'
109
+ if @client_id.nil? or @client_id.bytesize < 1
110
+ raise "Client identifier too short while serialising packet"
111
+ elsif @client_id.bytesize > 23
112
+ raise "Client identifier too long when serialising packet"
113
+ end
114
+ end
115
+ end
116
+
117
+ def encode_flags(flags)
118
+ # Set the Connect flags
119
+ flags = 0
120
+ flags |= 0x02 if @clean_session
121
+ flags |= 0x04 unless @will_topic.nil?
122
+ flags |= ((@will_qos & 0x03) << 3)
123
+ flags |= 0x20 if @will_retain
124
+ flags |= 0x40 unless @password.nil?
125
+ flags |= 0x80 unless @username.nil?
126
+ encode_bytes(flags)
102
127
  end
103
128
 
104
129
  # Parse the body (variable header and payload) of a Connect packet
@@ -115,13 +140,17 @@ module PahoMqtt
115
140
  end
116
141
 
117
142
  @connect_flags = shift_byte(buffer)
118
- @clean_session = ((@connect_flags & 0x02) >> 1) == 0x01
119
143
  @keep_alive = shift_short(buffer)
120
144
  @client_id = shift_string(buffer)
121
- if ((@connect_flags & 0x04) >> 2) == 0x01
145
+ parse_connect_flags(@connect_flag, buffer)
146
+ end
147
+
148
+ def parse_connect_flags(flags, buffer)
149
+ @clean_session = ((@connect_flags & 0x02) >> 1) == 0x01
150
+ if ((flags & 0x04) >> 2) == 0x01
122
151
  # Last Will and Testament
123
- @will_qos = ((@connect_flags & 0x18) >> 3)
124
- @will_retain = ((@connect_flags & 0x20) >> 5) == 0x01
152
+ @will_qos = ((flags & 0x18) >> 3)
153
+ @will_retain = ((flags & 0x20) >> 5) == 0x01
125
154
  @will_topic = shift_string(buffer)
126
155
  # The MQTT v3.1 specification says that the payload is a UTF-8 string
127
156
  @will_payload = shift_string(buffer)
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -7,7 +24,7 @@ module PahoMqtt
7
24
  def initialize(args={})
8
25
  super(args)
9
26
  end
10
-
27
+
11
28
  # Check the body
12
29
  def parse_body(buffer)
13
30
  super(buffer)
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -24,4 +41,3 @@ module PahoMqtt
24
41
  end
25
42
  end
26
43
  end
27
-
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet
@@ -1,4 +1,21 @@
1
1
  # encoding: BINARY
2
+ ### original file from the ruby-mqtt gem
3
+ ### located at https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb
4
+ ### Copyright (c) 2009-2013 Nicholas J Humfrey
5
+
6
+ # Copyright (c) 2016-2017 Pierre Goudet <p-goudet@ruby-dev.jp>
7
+ #
8
+ # All rights reserved. This program and the accompanying materials
9
+ # are made available under the terms of the Eclipse Public License v1.0
10
+ # and Eclipse Distribution License v1.0 which accompany this distribution.
11
+ #
12
+ # The Eclipse Public License is available at
13
+ # https://eclipse.org/org/documents/epl-v10.php.
14
+ # and the Eclipse Distribution License is available at
15
+ # https://eclipse.org/org/documents/edl-v10.php.
16
+ #
17
+ # Contributors:
18
+ # Pierre Goudet - initial committer
2
19
 
3
20
  module PahoMqtt
4
21
  module Packet