yalgaar 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/doc/Encoding.html +250 -0
- data/doc/MQTT.html +119 -0
- data/doc/MQTT/Client.html +1520 -0
- data/doc/MQTT/Exception.html +104 -0
- data/doc/MQTT/MQTT.html +95 -0
- data/doc/MQTT/MQTT/MQTT.html +95 -0
- data/doc/MQTT/MQTT/MQTT/Packet.html +1263 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Connack.html +433 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Connect.html +596 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Disconnect.html +214 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Pingreq.html +212 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Pingresp.html +212 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Puback.html +235 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Pubcomp.html +235 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Publish.html +590 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Pubrec.html +235 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Pubrel.html +334 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Suback.html +441 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Subscribe.html +449 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Unsuback.html +284 -0
- data/doc/MQTT/MQTT/MQTT/Packet/Unsubscribe.html +403 -0
- data/doc/MQTT/NotConnectedException.html +106 -0
- data/doc/MQTT/ProtocolException.html +105 -0
- data/doc/MQTT/Proxy.html +400 -0
- data/doc/MQTT/SN.html +116 -0
- data/doc/MQTT/SN/Packet.html +802 -0
- data/doc/MQTT/SN/Packet/Advertise.html +236 -0
- data/doc/MQTT/SN/Packet/Connack.html +259 -0
- data/doc/MQTT/SN/Packet/Connect.html +246 -0
- data/doc/MQTT/SN/Packet/Disconnect.html +231 -0
- data/doc/MQTT/SN/Packet/Gwinfo.html +241 -0
- data/doc/MQTT/SN/Packet/Pingreq.html +102 -0
- data/doc/MQTT/SN/Packet/Pingresp.html +102 -0
- data/doc/MQTT/SN/Packet/Puback.html +257 -0
- data/doc/MQTT/SN/Packet/Pubcomp.html +227 -0
- data/doc/MQTT/SN/Packet/Publish.html +255 -0
- data/doc/MQTT/SN/Packet/Pubrec.html +227 -0
- data/doc/MQTT/SN/Packet/Pubrel.html +227 -0
- data/doc/MQTT/SN/Packet/Regack.html +257 -0
- data/doc/MQTT/SN/Packet/Register.html +257 -0
- data/doc/MQTT/SN/Packet/Searchgw.html +223 -0
- data/doc/MQTT/SN/Packet/Suback.html +255 -0
- data/doc/MQTT/SN/Packet/Subscribe.html +255 -0
- data/doc/MQTT/SN/Packet/Unsuback.html +227 -0
- data/doc/MQTT/SN/Packet/Unsubscribe.html +255 -0
- data/doc/MQTT/SN/Packet/Willmsg.html +209 -0
- data/doc/MQTT/SN/Packet/Willmsgreq.html +102 -0
- data/doc/MQTT/SN/Packet/Willmsgresp.html +227 -0
- data/doc/MQTT/SN/Packet/Willmsgupd.html +209 -0
- data/doc/MQTT/SN/Packet/Willtopic.html +233 -0
- data/doc/MQTT/SN/Packet/Willtopicreq.html +102 -0
- data/doc/MQTT/SN/Packet/Willtopicresp.html +227 -0
- data/doc/MQTT/SN/Packet/Willtopicupd.html +232 -0
- data/doc/MQTT/SN/ProtocolException.html +105 -0
- data/doc/MYalgaar.html +212 -0
- data/doc/Object.html +396 -0
- data/doc/SSLcomDVCA_2_crt.html +115 -0
- data/doc/String.html +227 -0
- data/doc/YALGAAR.html +110 -0
- data/doc/Yalgaar.html +189 -0
- data/doc/YalgaarApis.html +619 -0
- data/doc/YalgaarChannelList.html +228 -0
- data/doc/YalgaarConnect.html +439 -0
- data/doc/YalgaarHistory.html +174 -0
- data/doc/YalgaarInit.html +206 -0
- data/doc/YalgaarPublish.html +196 -0
- data/doc/YalgaarSubcribe.html +266 -0
- data/doc/ca_crt.html +97 -0
- data/doc/css/fonts.css +167 -0
- data/doc/css/rdoc.css +590 -0
- data/doc/examples/SSLcomDVCA_2_crt.html +115 -0
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +219 -0
- data/doc/js/darkfish.js +161 -0
- data/doc/js/jquery.js +4 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +109 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +228 -0
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +1296 -0
- data/doc/yalgaar_gemspec.html +116 -0
- data/examples/SSLcomDVCA_2.crt +34 -0
- data/examples/channelList.rb +64 -0
- data/examples/connect.rb +37 -0
- data/examples/history.rb +37 -0
- data/examples/publish.rb +21 -0
- data/examples/subcribe.rb +53 -0
- data/examples/yalgaarUser.rb +92 -0
- data/lib/mqttbridge/YalgaarChannellist.rb +71 -0
- data/lib/mqttbridge/YalgaarConnect.rb +277 -0
- data/lib/mqttbridge/YalgaarHistory.rb +48 -0
- data/lib/mqttbridge/YalgaarInitModule.rb +333 -0
- data/lib/mqttbridge/YalgaarPublish.rb +39 -0
- data/lib/mqttbridge/YalgaarSubscribe.rb +99 -0
- data/lib/mqttbridge/client.rb +601 -0
- data/lib/mqttbridge/mqtt.rb +54 -0
- data/lib/mqttbridge/packet.rb +1113 -0
- data/lib/mqttbridge/patches/string_encoding.rb +34 -0
- data/lib/mqttbridge/proxy.rb +119 -0
- data/lib/mqttbridge/sn/packet.rb +763 -0
- data/lib/mqttbridge/version.rb +4 -0
- data/lib/yalgaar.rb +24 -0
- metadata +178 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class MQTT::Exception - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../";
|
11
|
+
</script>
|
12
|
+
|
13
|
+
<script src="../js/jquery.js"></script>
|
14
|
+
<script src="../js/darkfish.js"></script>
|
15
|
+
|
16
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
17
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
<body id="top" role="document" class="class">
|
22
|
+
<nav role="navigation">
|
23
|
+
<div id="project-navigation">
|
24
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
25
|
+
<h2>
|
26
|
+
<a href="../index.html" rel="home">Home</a>
|
27
|
+
</h2>
|
28
|
+
|
29
|
+
<div id="table-of-contents-navigation">
|
30
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
31
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
32
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
37
|
+
<form action="#" method="get" accept-charset="utf-8">
|
38
|
+
<div id="search-field-wrapper">
|
39
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
40
|
+
aria-autocomplete="list" aria-controls="search-results"
|
41
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
42
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<ul id="search-results" aria-label="Search Results"
|
46
|
+
aria-busy="false" aria-expanded="false"
|
47
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
48
|
+
</form>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
</div>
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
<div id="class-metadata">
|
56
|
+
|
57
|
+
<div id="parent-class-section" class="nav-section">
|
58
|
+
<h3>Parent</h3>
|
59
|
+
|
60
|
+
|
61
|
+
<p class="link">Exception
|
62
|
+
|
63
|
+
</div>
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
</div>
|
69
|
+
</nav>
|
70
|
+
|
71
|
+
<main role="main" aria-labelledby="class-MQTT::Exception">
|
72
|
+
<h1 id="class-MQTT::Exception" class="class">
|
73
|
+
class MQTT::Exception
|
74
|
+
</h1>
|
75
|
+
|
76
|
+
<section class="description">
|
77
|
+
|
78
|
+
<p>Super-class for other <a href="MQTT.html">MQTT</a> related exceptions</p>
|
79
|
+
|
80
|
+
</section>
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
</section>
|
96
|
+
</main>
|
97
|
+
|
98
|
+
|
99
|
+
<footer id="validator-badges" role="contentinfo">
|
100
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
101
|
+
<p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.1.
|
102
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
103
|
+
</footer>
|
104
|
+
|
data/doc/MQTT/MQTT.html
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>module MQTT::MQTT - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../";
|
11
|
+
</script>
|
12
|
+
|
13
|
+
<script src="../js/jquery.js"></script>
|
14
|
+
<script src="../js/darkfish.js"></script>
|
15
|
+
|
16
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
17
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
<body id="top" role="document" class="module">
|
22
|
+
<nav role="navigation">
|
23
|
+
<div id="project-navigation">
|
24
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
25
|
+
<h2>
|
26
|
+
<a href="../index.html" rel="home">Home</a>
|
27
|
+
</h2>
|
28
|
+
|
29
|
+
<div id="table-of-contents-navigation">
|
30
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
31
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
32
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
37
|
+
<form action="#" method="get" accept-charset="utf-8">
|
38
|
+
<div id="search-field-wrapper">
|
39
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
40
|
+
aria-autocomplete="list" aria-controls="search-results"
|
41
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
42
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<ul id="search-results" aria-label="Search Results"
|
46
|
+
aria-busy="false" aria-expanded="false"
|
47
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
48
|
+
</form>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
</div>
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
<div id="class-metadata">
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
</div>
|
62
|
+
</nav>
|
63
|
+
|
64
|
+
<main role="main" aria-labelledby="module-MQTT::MQTT">
|
65
|
+
<h1 id="module-MQTT::MQTT" class="module">
|
66
|
+
module MQTT::MQTT
|
67
|
+
</h1>
|
68
|
+
|
69
|
+
<section class="description">
|
70
|
+
|
71
|
+
</section>
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
</section>
|
87
|
+
</main>
|
88
|
+
|
89
|
+
|
90
|
+
<footer id="validator-badges" role="contentinfo">
|
91
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
92
|
+
<p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.1.
|
93
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
94
|
+
</footer>
|
95
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>module MQTT::MQTT::MQTT - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../../";
|
11
|
+
</script>
|
12
|
+
|
13
|
+
<script src="../../js/jquery.js"></script>
|
14
|
+
<script src="../../js/darkfish.js"></script>
|
15
|
+
|
16
|
+
<link href="../../css/fonts.css" rel="stylesheet">
|
17
|
+
<link href="../../css/rdoc.css" rel="stylesheet">
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
<body id="top" role="document" class="module">
|
22
|
+
<nav role="navigation">
|
23
|
+
<div id="project-navigation">
|
24
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
25
|
+
<h2>
|
26
|
+
<a href="../../index.html" rel="home">Home</a>
|
27
|
+
</h2>
|
28
|
+
|
29
|
+
<div id="table-of-contents-navigation">
|
30
|
+
<a href="../../table_of_contents.html#pages">Pages</a>
|
31
|
+
<a href="../../table_of_contents.html#classes">Classes</a>
|
32
|
+
<a href="../../table_of_contents.html#methods">Methods</a>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
37
|
+
<form action="#" method="get" accept-charset="utf-8">
|
38
|
+
<div id="search-field-wrapper">
|
39
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
40
|
+
aria-autocomplete="list" aria-controls="search-results"
|
41
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
42
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<ul id="search-results" aria-label="Search Results"
|
46
|
+
aria-busy="false" aria-expanded="false"
|
47
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
48
|
+
</form>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
</div>
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
<div id="class-metadata">
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
</div>
|
62
|
+
</nav>
|
63
|
+
|
64
|
+
<main role="main" aria-labelledby="module-MQTT::MQTT::MQTT">
|
65
|
+
<h1 id="module-MQTT::MQTT::MQTT" class="module">
|
66
|
+
module MQTT::MQTT::MQTT
|
67
|
+
</h1>
|
68
|
+
|
69
|
+
<section class="description">
|
70
|
+
|
71
|
+
</section>
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
</section>
|
87
|
+
</main>
|
88
|
+
|
89
|
+
|
90
|
+
<footer id="validator-badges" role="contentinfo">
|
91
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
92
|
+
<p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.1.
|
93
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
94
|
+
</footer>
|
95
|
+
|
@@ -0,0 +1,1263 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class MQTT::MQTT::MQTT::Packet - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "../../../";
|
11
|
+
</script>
|
12
|
+
|
13
|
+
<script src="../../../js/jquery.js"></script>
|
14
|
+
<script src="../../../js/darkfish.js"></script>
|
15
|
+
|
16
|
+
<link href="../../../css/fonts.css" rel="stylesheet">
|
17
|
+
<link href="../../../css/rdoc.css" rel="stylesheet">
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
<body id="top" role="document" class="class">
|
22
|
+
<nav role="navigation">
|
23
|
+
<div id="project-navigation">
|
24
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
25
|
+
<h2>
|
26
|
+
<a href="../../../index.html" rel="home">Home</a>
|
27
|
+
</h2>
|
28
|
+
|
29
|
+
<div id="table-of-contents-navigation">
|
30
|
+
<a href="../../../table_of_contents.html#pages">Pages</a>
|
31
|
+
<a href="../../../table_of_contents.html#classes">Classes</a>
|
32
|
+
<a href="../../../table_of_contents.html#methods">Methods</a>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
37
|
+
<form action="#" method="get" accept-charset="utf-8">
|
38
|
+
<div id="search-field-wrapper">
|
39
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
40
|
+
aria-autocomplete="list" aria-controls="search-results"
|
41
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
42
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<ul id="search-results" aria-label="Search Results"
|
46
|
+
aria-busy="false" aria-expanded="false"
|
47
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
48
|
+
</form>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
</div>
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
<div id="class-metadata">
|
56
|
+
|
57
|
+
<div id="parent-class-section" class="nav-section">
|
58
|
+
<h3>Parent</h3>
|
59
|
+
|
60
|
+
|
61
|
+
<p class="link"><a href="../../../Object.html">Object</a>
|
62
|
+
|
63
|
+
</div>
|
64
|
+
|
65
|
+
<div id="includes-section" class="nav-section">
|
66
|
+
<h3>Included Modules</h3>
|
67
|
+
|
68
|
+
<ul class="link-list">
|
69
|
+
|
70
|
+
|
71
|
+
<li><a class="include" href="../../../YalgaarApis.html">YalgaarApis</a>
|
72
|
+
|
73
|
+
|
74
|
+
</ul>
|
75
|
+
</div>
|
76
|
+
|
77
|
+
|
78
|
+
<!-- Method Quickref -->
|
79
|
+
<div id="method-list-section" class="nav-section">
|
80
|
+
<h3>Methods</h3>
|
81
|
+
|
82
|
+
<ul class="link-list" role="directory">
|
83
|
+
|
84
|
+
<li ><a href="#method-c-create_from_header">::create_from_header</a>
|
85
|
+
|
86
|
+
<li ><a href="#method-c-new">::new</a>
|
87
|
+
|
88
|
+
<li ><a href="#method-c-parse">::parse</a>
|
89
|
+
|
90
|
+
<li ><a href="#method-c-parse_header">::parse_header</a>
|
91
|
+
|
92
|
+
<li ><a href="#method-c-read">::read</a>
|
93
|
+
|
94
|
+
<li ><a href="#method-i-body_length-3D">#body_length=</a>
|
95
|
+
|
96
|
+
<li ><a href="#method-i-encode_bits">#encode_bits</a>
|
97
|
+
|
98
|
+
<li ><a href="#method-i-encode_body">#encode_body</a>
|
99
|
+
|
100
|
+
<li ><a href="#method-i-encode_bytes">#encode_bytes</a>
|
101
|
+
|
102
|
+
<li ><a href="#method-i-encode_short">#encode_short</a>
|
103
|
+
|
104
|
+
<li ><a href="#method-i-encode_string">#encode_string</a>
|
105
|
+
|
106
|
+
<li ><a href="#method-i-inspect">#inspect</a>
|
107
|
+
|
108
|
+
<li ><a href="#method-i-message_id">#message_id</a>
|
109
|
+
|
110
|
+
<li ><a href="#method-i-message_id-3D">#message_id=</a>
|
111
|
+
|
112
|
+
<li ><a href="#method-i-parse_body">#parse_body</a>
|
113
|
+
|
114
|
+
<li ><a href="#method-i-shift_bits">#shift_bits</a>
|
115
|
+
|
116
|
+
<li ><a href="#method-i-shift_byte">#shift_byte</a>
|
117
|
+
|
118
|
+
<li ><a href="#method-i-shift_data">#shift_data</a>
|
119
|
+
|
120
|
+
<li ><a href="#method-i-shift_short">#shift_short</a>
|
121
|
+
|
122
|
+
<li ><a href="#method-i-shift_string">#shift_string</a>
|
123
|
+
|
124
|
+
<li ><a href="#method-i-to_s">#to_s</a>
|
125
|
+
|
126
|
+
<li ><a href="#method-i-type_id">#type_id</a>
|
127
|
+
|
128
|
+
<li ><a href="#method-i-type_name">#type_name</a>
|
129
|
+
|
130
|
+
<li ><a href="#method-i-update_attributes">#update_attributes</a>
|
131
|
+
|
132
|
+
<li ><a href="#method-i-validate_flags">#validate_flags</a>
|
133
|
+
|
134
|
+
<li ><a href="#method-i-version-3D">#version=</a>
|
135
|
+
|
136
|
+
</ul>
|
137
|
+
</div>
|
138
|
+
|
139
|
+
</div>
|
140
|
+
</nav>
|
141
|
+
|
142
|
+
<main role="main" aria-labelledby="class-MQTT::MQTT::MQTT::Packet">
|
143
|
+
<h1 id="class-MQTT::MQTT::MQTT::Packet" class="class">
|
144
|
+
class MQTT::MQTT::MQTT::Packet
|
145
|
+
</h1>
|
146
|
+
|
147
|
+
<section class="description">
|
148
|
+
|
149
|
+
<p>Class representing a <a href="../../MQTT.html">MQTT</a> <a
|
150
|
+
href="Packet.html">Packet</a> Performs binary encoding and decoding of
|
151
|
+
headers</p>
|
152
|
+
|
153
|
+
</section>
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
<section class="constants-list">
|
165
|
+
<header>
|
166
|
+
<h3>Constants</h3>
|
167
|
+
</header>
|
168
|
+
<dl>
|
169
|
+
|
170
|
+
<dt id="ATTR_DEFAULTS">ATTR_DEFAULTS
|
171
|
+
|
172
|
+
<dd><p>Default attribute values</p>
|
173
|
+
|
174
|
+
|
175
|
+
</dl>
|
176
|
+
</section>
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
<section class="attribute-method-details" class="method-section">
|
181
|
+
<header>
|
182
|
+
<h3>Attributes</h3>
|
183
|
+
</header>
|
184
|
+
|
185
|
+
|
186
|
+
<div id="attribute-i-body_length" class="method-detail">
|
187
|
+
<div class="method-heading attribute-method-heading">
|
188
|
+
<span class="method-name">body_length</span><span
|
189
|
+
class="attribute-access-type">[R]</span>
|
190
|
+
</div>
|
191
|
+
|
192
|
+
<div class="method-description">
|
193
|
+
|
194
|
+
<p>The length of the parsed packet body</p>
|
195
|
+
|
196
|
+
</div>
|
197
|
+
</div>
|
198
|
+
|
199
|
+
<div id="attribute-i-flags" class="method-detail">
|
200
|
+
<div class="method-heading attribute-method-heading">
|
201
|
+
<span class="method-name">flags</span><span
|
202
|
+
class="attribute-access-type">[RW]</span>
|
203
|
+
</div>
|
204
|
+
|
205
|
+
<div class="method-description">
|
206
|
+
|
207
|
+
<p>Array of 4 bits in the fixed header</p>
|
208
|
+
|
209
|
+
</div>
|
210
|
+
</div>
|
211
|
+
|
212
|
+
<div id="attribute-i-id" class="method-detail">
|
213
|
+
<div class="method-heading attribute-method-heading">
|
214
|
+
<span class="method-name">id</span><span
|
215
|
+
class="attribute-access-type">[RW]</span>
|
216
|
+
</div>
|
217
|
+
|
218
|
+
<div class="method-description">
|
219
|
+
|
220
|
+
<p>Identifier to link related control packets together</p>
|
221
|
+
|
222
|
+
</div>
|
223
|
+
</div>
|
224
|
+
|
225
|
+
<div id="attribute-i-version" class="method-detail">
|
226
|
+
<div class="method-heading attribute-method-heading">
|
227
|
+
<span class="method-name">version</span><span
|
228
|
+
class="attribute-access-type">[RW]</span>
|
229
|
+
</div>
|
230
|
+
|
231
|
+
<div class="method-description">
|
232
|
+
|
233
|
+
<p>The version number of the <a href="../../MQTT.html">MQTT</a> protocol to
|
234
|
+
use (default 3.1.0)</p>
|
235
|
+
|
236
|
+
</div>
|
237
|
+
</div>
|
238
|
+
|
239
|
+
</section>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
244
|
+
<header>
|
245
|
+
<h3>Public Class Methods</h3>
|
246
|
+
</header>
|
247
|
+
|
248
|
+
|
249
|
+
<div id="method-c-create_from_header" class="method-detail ">
|
250
|
+
|
251
|
+
<div class="method-heading">
|
252
|
+
<span class="method-name">create_from_header</span><span
|
253
|
+
class="method-args">(byte)</span>
|
254
|
+
|
255
|
+
<span class="method-click-advice">click to toggle source</span>
|
256
|
+
|
257
|
+
</div>
|
258
|
+
|
259
|
+
|
260
|
+
<div class="method-description">
|
261
|
+
|
262
|
+
<p>Create a new packet object from the first byte of a <a
|
263
|
+
href="../../MQTT.html">MQTT</a> packet</p>
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
<div class="method-source-code" id="create_from_header-source">
|
269
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 102</span>
|
270
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">create_from_header</span>(<span class="ruby-identifier">byte</span>)
|
271
|
+
<span class="ruby-comment"># Work out the class</span>
|
272
|
+
<span class="ruby-identifier">type_id</span> = ((<span class="ruby-identifier">byte</span> <span class="ruby-operator">&</span> <span class="ruby-value">0xF0</span>) <span class="ruby-operator">>></span> <span class="ruby-value">4</span>)
|
273
|
+
<span class="ruby-identifier">packet_class</span> = <span class="ruby-constant">MQTT</span><span class="ruby-operator">::</span><span class="ruby-constant">PACKET_TYPES</span>[<span class="ruby-identifier">type_id</span>]
|
274
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">packet_class</span>.<span class="ruby-identifier">nil?</span>
|
275
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ProtocolException</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"Invalid packet type identifier: #{type_id}"</span>)
|
276
|
+
<span class="ruby-keyword">end</span>
|
277
|
+
|
278
|
+
<span class="ruby-comment"># Convert the last 4 bits of byte into array of true/false</span>
|
279
|
+
<span class="ruby-identifier">flags</span> = (<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">byte</span> <span class="ruby-operator">&</span> (<span class="ruby-value">2</span> <span class="ruby-operator">**</span> <span class="ruby-identifier">i</span>) <span class="ruby-operator">!=</span> <span class="ruby-value">0</span> }
|
280
|
+
|
281
|
+
<span class="ruby-comment"># Create a new packet object</span>
|
282
|
+
<span class="ruby-identifier">packet_class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:flags</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">flags</span>)
|
283
|
+
<span class="ruby-keyword">end</span></pre>
|
284
|
+
</div>
|
285
|
+
|
286
|
+
</div>
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
</div>
|
292
|
+
|
293
|
+
|
294
|
+
<div id="method-c-new" class="method-detail ">
|
295
|
+
|
296
|
+
<div class="method-heading">
|
297
|
+
<span class="method-name">new</span><span
|
298
|
+
class="method-args">(args={})</span>
|
299
|
+
|
300
|
+
<span class="method-click-advice">click to toggle source</span>
|
301
|
+
|
302
|
+
</div>
|
303
|
+
|
304
|
+
|
305
|
+
<div class="method-description">
|
306
|
+
|
307
|
+
<p>Create a new empty packet</p>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
<div class="method-source-code" id="new-source">
|
313
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 118</span>
|
314
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">args</span>={})
|
315
|
+
<span class="ruby-comment"># We must set flags before the other values</span>
|
316
|
+
<span class="ruby-ivar">@flags</span> = [<span class="ruby-keyword">false</span>, <span class="ruby-keyword">false</span>, <span class="ruby-keyword">false</span>, <span class="ruby-keyword">false</span>]
|
317
|
+
<span class="ruby-identifier">update_attributes</span>(<span class="ruby-constant">ATTR_DEFAULTS</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">args</span>))
|
318
|
+
<span class="ruby-keyword">end</span></pre>
|
319
|
+
</div>
|
320
|
+
|
321
|
+
</div>
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
</div>
|
327
|
+
|
328
|
+
|
329
|
+
<div id="method-c-parse" class="method-detail ">
|
330
|
+
|
331
|
+
<div class="method-heading">
|
332
|
+
<span class="method-name">parse</span><span
|
333
|
+
class="method-args">(buffer)</span>
|
334
|
+
|
335
|
+
<span class="method-click-advice">click to toggle source</span>
|
336
|
+
|
337
|
+
</div>
|
338
|
+
|
339
|
+
|
340
|
+
<div class="method-description">
|
341
|
+
|
342
|
+
<p>Parse buffer into new packet object</p>
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
<div class="method-source-code" id="parse-source">
|
348
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 59</span>
|
349
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">buffer</span>)
|
350
|
+
<span class="ruby-identifier">packet</span> = <span class="ruby-identifier">parse_header</span>(<span class="ruby-identifier">buffer</span>)
|
351
|
+
<span class="ruby-identifier">packet</span>.<span class="ruby-identifier">parse_body</span>(<span class="ruby-identifier">buffer</span>)
|
352
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">packet</span>
|
353
|
+
<span class="ruby-keyword">end</span></pre>
|
354
|
+
</div>
|
355
|
+
|
356
|
+
</div>
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
</div>
|
362
|
+
|
363
|
+
|
364
|
+
<div id="method-c-parse_header" class="method-detail ">
|
365
|
+
|
366
|
+
<div class="method-heading">
|
367
|
+
<span class="method-name">parse_header</span><span
|
368
|
+
class="method-args">(buffer)</span>
|
369
|
+
|
370
|
+
<span class="method-click-advice">click to toggle source</span>
|
371
|
+
|
372
|
+
</div>
|
373
|
+
|
374
|
+
|
375
|
+
<div class="method-description">
|
376
|
+
|
377
|
+
<p>Parse the header and create a new packet object of the correct type The
|
378
|
+
header is removed from the buffer passed into this function</p>
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
<div class="method-source-code" id="parse_header-source">
|
384
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 67</span>
|
385
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">parse_header</span>(<span class="ruby-identifier">buffer</span>)
|
386
|
+
<span class="ruby-comment"># Check that the packet is a long as the minimum packet size</span>
|
387
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">bytesize</span> <span class="ruby-operator"><</span> <span class="ruby-value">2</span>
|
388
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ProtocolException</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"Invalid packet: less than 2 bytes long"</span>)
|
389
|
+
<span class="ruby-keyword">end</span>
|
390
|
+
|
391
|
+
<span class="ruby-comment"># Create a new packet object</span>
|
392
|
+
<span class="ruby-identifier">bytes</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">"C5"</span>)
|
393
|
+
<span class="ruby-identifier">packet</span> = <span class="ruby-identifier">create_from_header</span>(<span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">first</span>)
|
394
|
+
<span class="ruby-identifier">packet</span>.<span class="ruby-identifier">validate_flags</span>
|
395
|
+
|
396
|
+
<span class="ruby-comment"># Parse the packet length</span>
|
397
|
+
<span class="ruby-identifier">body_length</span> = <span class="ruby-value">0</span>
|
398
|
+
<span class="ruby-identifier">multiplier</span> = <span class="ruby-value">1</span>
|
399
|
+
<span class="ruby-identifier">pos</span> = <span class="ruby-value">1</span>
|
400
|
+
<span class="ruby-keyword">begin</span>
|
401
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">bytesize</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">pos</span>
|
402
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ProtocolException</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"The packet length header is incomplete"</span>)
|
403
|
+
<span class="ruby-keyword">end</span>
|
404
|
+
<span class="ruby-identifier">digit</span> = <span class="ruby-identifier">bytes</span>[<span class="ruby-identifier">pos</span>]
|
405
|
+
<span class="ruby-identifier">body_length</span> <span class="ruby-operator">+=</span> ((<span class="ruby-identifier">digit</span> <span class="ruby-operator">&</span> <span class="ruby-value">0x7F</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">multiplier</span>)
|
406
|
+
<span class="ruby-identifier">multiplier</span> <span class="ruby-operator">*=</span> <span class="ruby-value">0x80</span>
|
407
|
+
<span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
408
|
+
<span class="ruby-keyword">end</span> <span class="ruby-keyword">while</span> ((<span class="ruby-identifier">digit</span> <span class="ruby-operator">&</span> <span class="ruby-value">0x80</span>) <span class="ruby-operator">!=</span> <span class="ruby-value">0x00</span>) <span class="ruby-keyword">and</span> <span class="ruby-identifier">pos</span> <span class="ruby-operator"><=</span> <span class="ruby-value">4</span>
|
409
|
+
|
410
|
+
<span class="ruby-comment"># Store the expected body length in the packet</span>
|
411
|
+
<span class="ruby-identifier">packet</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-string">'@body_length'</span>, <span class="ruby-identifier">body_length</span>)
|
412
|
+
|
413
|
+
<span class="ruby-comment"># Delete the fixed header from the raw packet passed in</span>
|
414
|
+
<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">pos</span>)
|
415
|
+
|
416
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">packet</span>
|
417
|
+
<span class="ruby-keyword">end</span></pre>
|
418
|
+
</div>
|
419
|
+
|
420
|
+
</div>
|
421
|
+
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
</div>
|
426
|
+
|
427
|
+
|
428
|
+
<div id="method-c-read" class="method-detail ">
|
429
|
+
|
430
|
+
<div class="method-heading">
|
431
|
+
<span class="method-name">read</span><span
|
432
|
+
class="method-args">(socket)</span>
|
433
|
+
|
434
|
+
<span class="method-click-advice">click to toggle source</span>
|
435
|
+
|
436
|
+
</div>
|
437
|
+
|
438
|
+
|
439
|
+
<div class="method-description">
|
440
|
+
|
441
|
+
<p>Read in a packet from a socket</p>
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
<div class="method-source-code" id="read-source">
|
447
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 28</span>
|
448
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">socket</span>)
|
449
|
+
<span class="ruby-comment"># Read in the packet header and create a new packet object</span>
|
450
|
+
<span class="ruby-identifier">packet</span> = <span class="ruby-identifier">create_from_header</span>(
|
451
|
+
<span class="ruby-identifier">read_byte</span>(<span class="ruby-identifier">socket</span>)
|
452
|
+
)
|
453
|
+
|
454
|
+
|
455
|
+
<span class="ruby-identifier">packet</span>.<span class="ruby-identifier">validate_flags</span>
|
456
|
+
<span class="ruby-comment"># Read in the packet length</span>
|
457
|
+
<span class="ruby-identifier">multiplier</span> = <span class="ruby-value">1</span>
|
458
|
+
<span class="ruby-identifier">body_length</span> = <span class="ruby-value">0</span>
|
459
|
+
<span class="ruby-identifier">pos</span> = <span class="ruby-value">1</span>
|
460
|
+
<span class="ruby-keyword">begin</span>
|
461
|
+
<span class="ruby-identifier">digit</span> = <span class="ruby-identifier">read_byte</span>(<span class="ruby-identifier">socket</span>)
|
462
|
+
<span class="ruby-identifier">body_length</span> <span class="ruby-operator">+=</span> ((<span class="ruby-identifier">digit</span> <span class="ruby-operator">&</span> <span class="ruby-value">0x7F</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">multiplier</span>)
|
463
|
+
<span class="ruby-identifier">multiplier</span> <span class="ruby-operator">*=</span> <span class="ruby-value">0x80</span>
|
464
|
+
<span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
465
|
+
<span class="ruby-keyword">end</span> <span class="ruby-keyword">while</span> ((<span class="ruby-identifier">digit</span> <span class="ruby-operator">&</span> <span class="ruby-value">0x80</span>) <span class="ruby-operator">!=</span> <span class="ruby-value">0x00</span>) <span class="ruby-keyword">and</span> <span class="ruby-identifier">pos</span> <span class="ruby-operator"><=</span> <span class="ruby-value">4</span>
|
466
|
+
|
467
|
+
<span class="ruby-comment"># Store the expected body length in the packet</span>
|
468
|
+
<span class="ruby-identifier">packet</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-string">'@body_length'</span>, <span class="ruby-identifier">body_length</span>)
|
469
|
+
|
470
|
+
<span class="ruby-comment"># Read in the packet body</span>
|
471
|
+
<span class="ruby-identifier">$subackret</span>=<span class="ruby-identifier">packet</span>.<span class="ruby-identifier">parse_body</span>(<span class="ruby-identifier">socket</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">body_length</span>))
|
472
|
+
<span class="ruby-comment">#~ puts $subackret</span>
|
473
|
+
<span class="ruby-comment"># puts @return_codes</span>
|
474
|
+
<span class="ruby-comment">#~ puts $subackret</span>
|
475
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">packet</span>
|
476
|
+
<span class="ruby-keyword">end</span></pre>
|
477
|
+
</div>
|
478
|
+
|
479
|
+
</div>
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
</div>
|
485
|
+
|
486
|
+
|
487
|
+
</section>
|
488
|
+
|
489
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
490
|
+
<header>
|
491
|
+
<h3>Public Instance Methods</h3>
|
492
|
+
</header>
|
493
|
+
|
494
|
+
|
495
|
+
<div id="method-i-body_length-3D" class="method-detail ">
|
496
|
+
|
497
|
+
<div class="method-heading">
|
498
|
+
<span class="method-name">body_length=</span><span
|
499
|
+
class="method-args">(arg)</span>
|
500
|
+
|
501
|
+
<span class="method-click-advice">click to toggle source</span>
|
502
|
+
|
503
|
+
</div>
|
504
|
+
|
505
|
+
|
506
|
+
<div class="method-description">
|
507
|
+
|
508
|
+
<p>Set the length of the packet body</p>
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
<div class="method-source-code" id="body_length-3D-source">
|
514
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 158</span>
|
515
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">body_length=</span>(<span class="ruby-identifier">arg</span>)
|
516
|
+
<span class="ruby-ivar">@body_length</span> = <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">to_i</span>
|
517
|
+
<span class="ruby-keyword">end</span></pre>
|
518
|
+
</div>
|
519
|
+
|
520
|
+
</div>
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
</div>
|
526
|
+
|
527
|
+
|
528
|
+
<div id="method-i-encode_body" class="method-detail ">
|
529
|
+
|
530
|
+
<div class="method-heading">
|
531
|
+
<span class="method-name">encode_body</span><span
|
532
|
+
class="method-args">()</span>
|
533
|
+
|
534
|
+
<span class="method-click-advice">click to toggle source</span>
|
535
|
+
|
536
|
+
</div>
|
537
|
+
|
538
|
+
|
539
|
+
<div class="method-description">
|
540
|
+
|
541
|
+
<p>Get serialisation of packet's body (variable header and payload)</p>
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
<div class="method-source-code" id="encode_body-source">
|
547
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 172</span>
|
548
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">encode_body</span>
|
549
|
+
<span class="ruby-string">''</span> <span class="ruby-comment"># No body by default</span>
|
550
|
+
<span class="ruby-keyword">end</span></pre>
|
551
|
+
</div>
|
552
|
+
|
553
|
+
</div>
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
</div>
|
559
|
+
|
560
|
+
|
561
|
+
<div id="method-i-inspect" class="method-detail ">
|
562
|
+
|
563
|
+
<div class="method-heading">
|
564
|
+
<span class="method-name">inspect</span><span
|
565
|
+
class="method-args">()</span>
|
566
|
+
|
567
|
+
<span class="method-click-advice">click to toggle source</span>
|
568
|
+
|
569
|
+
</div>
|
570
|
+
|
571
|
+
|
572
|
+
<div class="method-description">
|
573
|
+
|
574
|
+
<p>Returns a human readable string</p>
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
<div class="method-source-code" id="inspect-source">
|
580
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 219</span>
|
581
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">inspect</span>
|
582
|
+
<span class="ruby-node">"\#<#{self.class}>"</span>
|
583
|
+
<span class="ruby-keyword">end</span></pre>
|
584
|
+
</div>
|
585
|
+
|
586
|
+
</div>
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
</div>
|
592
|
+
|
593
|
+
|
594
|
+
<div id="method-i-message_id" class="method-detail ">
|
595
|
+
|
596
|
+
<div class="method-heading">
|
597
|
+
<span class="method-name">message_id</span><span
|
598
|
+
class="method-args">()</span>
|
599
|
+
|
600
|
+
<span class="method-click-advice">click to toggle source</span>
|
601
|
+
|
602
|
+
</div>
|
603
|
+
|
604
|
+
|
605
|
+
<div class="method-description">
|
606
|
+
|
607
|
+
<p>@deprecated Please use {#id} instead</p>
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
<div class="method-source-code" id="message_id-source">
|
613
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 1081</span>
|
614
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">message_id</span>
|
615
|
+
<span class="ruby-identifier">id</span>
|
616
|
+
<span class="ruby-keyword">end</span></pre>
|
617
|
+
</div>
|
618
|
+
|
619
|
+
</div>
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
</div>
|
625
|
+
|
626
|
+
|
627
|
+
<div id="method-i-message_id-3D" class="method-detail ">
|
628
|
+
|
629
|
+
<div class="method-heading">
|
630
|
+
<span class="method-name">message_id=</span><span
|
631
|
+
class="method-args">(args)</span>
|
632
|
+
|
633
|
+
<span class="method-click-advice">click to toggle source</span>
|
634
|
+
|
635
|
+
</div>
|
636
|
+
|
637
|
+
|
638
|
+
<div class="method-description">
|
639
|
+
|
640
|
+
<p>@deprecated Please use {#id=} instead</p>
|
641
|
+
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
<div class="method-source-code" id="message_id-3D-source">
|
646
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 1086</span>
|
647
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">message_id=</span>(<span class="ruby-identifier">args</span>)
|
648
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span> = <span class="ruby-identifier">args</span>
|
649
|
+
<span class="ruby-keyword">end</span></pre>
|
650
|
+
</div>
|
651
|
+
|
652
|
+
</div>
|
653
|
+
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
</div>
|
658
|
+
|
659
|
+
|
660
|
+
<div id="method-i-parse_body" class="method-detail ">
|
661
|
+
|
662
|
+
<div class="method-heading">
|
663
|
+
<span class="method-name">parse_body</span><span
|
664
|
+
class="method-args">(buffer)</span>
|
665
|
+
|
666
|
+
<span class="method-click-advice">click to toggle source</span>
|
667
|
+
|
668
|
+
</div>
|
669
|
+
|
670
|
+
|
671
|
+
<div class="method-description">
|
672
|
+
|
673
|
+
<p>Parse the body (variable header and payload) of a packet</p>
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
|
678
|
+
<div class="method-source-code" id="parse_body-source">
|
679
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 163</span>
|
680
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">parse_body</span>(<span class="ruby-identifier">buffer</span>)
|
681
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">bytesize</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">body_length</span>
|
682
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ProtocolException</span>.<span class="ruby-identifier">new</span>(
|
683
|
+
<span class="ruby-node">"Failed to parse packet - input buffer (#{buffer.bytesize}) is not the same as the body length header (#{body_length})"</span>
|
684
|
+
)
|
685
|
+
<span class="ruby-keyword">end</span>
|
686
|
+
<span class="ruby-keyword">end</span></pre>
|
687
|
+
</div>
|
688
|
+
|
689
|
+
</div>
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
|
694
|
+
</div>
|
695
|
+
|
696
|
+
|
697
|
+
<div id="method-i-to_s" class="method-detail ">
|
698
|
+
|
699
|
+
<div class="method-heading">
|
700
|
+
<span class="method-name">to_s</span><span
|
701
|
+
class="method-args">()</span>
|
702
|
+
|
703
|
+
<span class="method-click-advice">click to toggle source</span>
|
704
|
+
|
705
|
+
</div>
|
706
|
+
|
707
|
+
|
708
|
+
<div class="method-description">
|
709
|
+
|
710
|
+
<p>Serialise the packet</p>
|
711
|
+
|
712
|
+
|
713
|
+
|
714
|
+
|
715
|
+
<div class="method-source-code" id="to_s-source">
|
716
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 178</span>
|
717
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_s</span>
|
718
|
+
<span class="ruby-comment"># Encode the fixed header</span>
|
719
|
+
<span class="ruby-identifier">header</span> = [
|
720
|
+
((<span class="ruby-identifier">type_id</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&</span> <span class="ruby-value">0x0F</span>) <span class="ruby-operator"><<</span> <span class="ruby-value">4</span>) <span class="ruby-operator">|</span>
|
721
|
+
(<span class="ruby-identifier">flags</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">?</span> <span class="ruby-value">0x8</span> <span class="ruby-operator">:</span> <span class="ruby-value">0x0</span>) <span class="ruby-operator">|</span>
|
722
|
+
(<span class="ruby-identifier">flags</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">?</span> <span class="ruby-value">0x4</span> <span class="ruby-operator">:</span> <span class="ruby-value">0x0</span>) <span class="ruby-operator">|</span>
|
723
|
+
(<span class="ruby-identifier">flags</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">?</span> <span class="ruby-value">0x2</span> <span class="ruby-operator">:</span> <span class="ruby-value">0x0</span>) <span class="ruby-operator">|</span>
|
724
|
+
(<span class="ruby-identifier">flags</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">?</span> <span class="ruby-value">0x1</span> <span class="ruby-operator">:</span> <span class="ruby-value">0x0</span>)
|
725
|
+
]
|
726
|
+
|
727
|
+
<span class="ruby-comment"># Get the packet's variable header and payload</span>
|
728
|
+
<span class="ruby-identifier">body</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">encode_body</span>
|
729
|
+
|
730
|
+
<span class="ruby-comment"># Check that that packet isn't too big</span>
|
731
|
+
<span class="ruby-identifier">body_length</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">bytesize</span>
|
732
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">body_length</span> <span class="ruby-operator">></span> <span class="ruby-value">268435455</span>
|
733
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-string">"Error serialising packet: body is more than 256MB"</span>
|
734
|
+
<span class="ruby-keyword">end</span>
|
735
|
+
|
736
|
+
<span class="ruby-comment"># Build up the body length field bytes</span>
|
737
|
+
<span class="ruby-keyword">begin</span>
|
738
|
+
<span class="ruby-identifier">digit</span> = (<span class="ruby-identifier">body_length</span> <span class="ruby-operator">%</span> <span class="ruby-value">128</span>)
|
739
|
+
<span class="ruby-identifier">body_length</span> = <span class="ruby-identifier">body_length</span>.<span class="ruby-identifier">div</span>(<span class="ruby-value">128</span>)
|
740
|
+
<span class="ruby-comment"># if there are more digits to encode, set the top bit of this digit</span>
|
741
|
+
<span class="ruby-identifier">digit</span> <span class="ruby-operator">|=</span> <span class="ruby-value">0x80</span> <span class="ruby-keyword">if</span> (<span class="ruby-identifier">body_length</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>)
|
742
|
+
<span class="ruby-identifier">header</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">digit</span>)
|
743
|
+
<span class="ruby-keyword">end</span> <span class="ruby-keyword">while</span> (<span class="ruby-identifier">body_length</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>)
|
744
|
+
|
745
|
+
<span class="ruby-comment"># Convert header to binary and add on body</span>
|
746
|
+
<span class="ruby-identifier">header</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-string">'C*'</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">body</span>
|
747
|
+
<span class="ruby-keyword">end</span></pre>
|
748
|
+
</div>
|
749
|
+
|
750
|
+
</div>
|
751
|
+
|
752
|
+
|
753
|
+
|
754
|
+
|
755
|
+
</div>
|
756
|
+
|
757
|
+
|
758
|
+
<div id="method-i-type_id" class="method-detail ">
|
759
|
+
|
760
|
+
<div class="method-heading">
|
761
|
+
<span class="method-name">type_id</span><span
|
762
|
+
class="method-args">()</span>
|
763
|
+
|
764
|
+
<span class="method-click-advice">click to toggle source</span>
|
765
|
+
|
766
|
+
</div>
|
767
|
+
|
768
|
+
|
769
|
+
<div class="method-description">
|
770
|
+
|
771
|
+
<p>Get the identifer for this packet type</p>
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
|
776
|
+
<div class="method-source-code" id="type_id-source">
|
777
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 136</span>
|
778
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">type_id</span>
|
779
|
+
<span class="ruby-identifier">index</span> = <span class="ruby-constant">MQTT</span><span class="ruby-operator">::</span><span class="ruby-constant">PACKET_TYPES</span>.<span class="ruby-identifier">index</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>)
|
780
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">nil?</span>
|
781
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"Invalid packet type: #{self.class}"</span>
|
782
|
+
<span class="ruby-keyword">end</span>
|
783
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">index</span>
|
784
|
+
<span class="ruby-keyword">end</span></pre>
|
785
|
+
</div>
|
786
|
+
|
787
|
+
</div>
|
788
|
+
|
789
|
+
|
790
|
+
|
791
|
+
|
792
|
+
</div>
|
793
|
+
|
794
|
+
|
795
|
+
<div id="method-i-type_name" class="method-detail ">
|
796
|
+
|
797
|
+
<div class="method-heading">
|
798
|
+
<span class="method-name">type_name</span><span
|
799
|
+
class="method-args">()</span>
|
800
|
+
|
801
|
+
<span class="method-click-advice">click to toggle source</span>
|
802
|
+
|
803
|
+
</div>
|
804
|
+
|
805
|
+
|
806
|
+
<div class="method-description">
|
807
|
+
|
808
|
+
<p>Get the name of the packet type as a string in capitals (like the <a
|
809
|
+
href="../../MQTT.html">MQTT</a> specification uses)</p>
|
810
|
+
|
811
|
+
<p>Example: CONNACK</p>
|
812
|
+
|
813
|
+
|
814
|
+
|
815
|
+
|
816
|
+
<div class="method-source-code" id="type_name-source">
|
817
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 148</span>
|
818
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">type_name</span>
|
819
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'::'</span>).<span class="ruby-identifier">last</span>.<span class="ruby-identifier">upcase</span>
|
820
|
+
<span class="ruby-keyword">end</span></pre>
|
821
|
+
</div>
|
822
|
+
|
823
|
+
</div>
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
|
828
|
+
</div>
|
829
|
+
|
830
|
+
|
831
|
+
<div id="method-i-update_attributes" class="method-detail ">
|
832
|
+
|
833
|
+
<div class="method-heading">
|
834
|
+
<span class="method-name">update_attributes</span><span
|
835
|
+
class="method-args">(attr={})</span>
|
836
|
+
|
837
|
+
<span class="method-click-advice">click to toggle source</span>
|
838
|
+
|
839
|
+
</div>
|
840
|
+
|
841
|
+
|
842
|
+
<div class="method-description">
|
843
|
+
|
844
|
+
<p>Set packet attributes from a hash of attribute names and values</p>
|
845
|
+
|
846
|
+
|
847
|
+
|
848
|
+
|
849
|
+
<div class="method-source-code" id="update_attributes-source">
|
850
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 125</span>
|
851
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">attr</span>={})
|
852
|
+
<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
853
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-keyword">or</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
854
|
+
<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{k}="</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">dup</span>)
|
855
|
+
<span class="ruby-keyword">else</span>
|
856
|
+
<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{k}="</span>, <span class="ruby-identifier">v</span>)
|
857
|
+
<span class="ruby-keyword">end</span>
|
858
|
+
<span class="ruby-keyword">end</span>
|
859
|
+
<span class="ruby-keyword">end</span></pre>
|
860
|
+
</div>
|
861
|
+
|
862
|
+
</div>
|
863
|
+
|
864
|
+
|
865
|
+
|
866
|
+
|
867
|
+
</div>
|
868
|
+
|
869
|
+
|
870
|
+
<div id="method-i-validate_flags" class="method-detail ">
|
871
|
+
|
872
|
+
<div class="method-heading">
|
873
|
+
<span class="method-name">validate_flags</span><span
|
874
|
+
class="method-args">()</span>
|
875
|
+
|
876
|
+
<span class="method-click-advice">click to toggle source</span>
|
877
|
+
|
878
|
+
</div>
|
879
|
+
|
880
|
+
|
881
|
+
<div class="method-description">
|
882
|
+
|
883
|
+
<p>Check that fixed header flags are valid for types that don't use the
|
884
|
+
flags @private</p>
|
885
|
+
|
886
|
+
|
887
|
+
|
888
|
+
|
889
|
+
<div class="method-source-code" id="validate_flags-source">
|
890
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 212</span>
|
891
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">validate_flags</span>
|
892
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">flags</span> <span class="ruby-operator">!=</span> [<span class="ruby-keyword">false</span>, <span class="ruby-keyword">false</span>, <span class="ruby-keyword">false</span>, <span class="ruby-keyword">false</span>]
|
893
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ProtocolException</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"Invalid flags in #{type_name} packet header"</span>)
|
894
|
+
<span class="ruby-keyword">end</span>
|
895
|
+
<span class="ruby-keyword">end</span></pre>
|
896
|
+
</div>
|
897
|
+
|
898
|
+
</div>
|
899
|
+
|
900
|
+
|
901
|
+
|
902
|
+
|
903
|
+
</div>
|
904
|
+
|
905
|
+
|
906
|
+
<div id="method-i-version-3D" class="method-detail ">
|
907
|
+
|
908
|
+
<div class="method-heading">
|
909
|
+
<span class="method-name">version=</span><span
|
910
|
+
class="method-args">(arg)</span>
|
911
|
+
|
912
|
+
<span class="method-click-advice">click to toggle source</span>
|
913
|
+
|
914
|
+
</div>
|
915
|
+
|
916
|
+
|
917
|
+
<div class="method-description">
|
918
|
+
|
919
|
+
<p>Set the protocol version number</p>
|
920
|
+
|
921
|
+
|
922
|
+
|
923
|
+
|
924
|
+
<div class="method-source-code" id="version-3D-source">
|
925
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 153</span>
|
926
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">version=</span>(<span class="ruby-identifier">arg</span>)
|
927
|
+
<span class="ruby-ivar">@version</span> = <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">to_s</span>
|
928
|
+
<span class="ruby-keyword">end</span></pre>
|
929
|
+
</div>
|
930
|
+
|
931
|
+
</div>
|
932
|
+
|
933
|
+
|
934
|
+
|
935
|
+
|
936
|
+
</div>
|
937
|
+
|
938
|
+
|
939
|
+
</section>
|
940
|
+
|
941
|
+
<section id="protected-instance-5Buntitled-5D-method-details" class="method-section">
|
942
|
+
<header>
|
943
|
+
<h3>Protected Instance Methods</h3>
|
944
|
+
</header>
|
945
|
+
|
946
|
+
|
947
|
+
<div id="method-i-encode_bits" class="method-detail ">
|
948
|
+
|
949
|
+
<div class="method-heading">
|
950
|
+
<span class="method-name">encode_bits</span><span
|
951
|
+
class="method-args">(bits)</span>
|
952
|
+
|
953
|
+
<span class="method-click-advice">click to toggle source</span>
|
954
|
+
|
955
|
+
</div>
|
956
|
+
|
957
|
+
|
958
|
+
<div class="method-description">
|
959
|
+
|
960
|
+
<p>Encode an array of bits and return them</p>
|
961
|
+
|
962
|
+
|
963
|
+
|
964
|
+
|
965
|
+
<div class="method-source-code" id="encode_bits-source">
|
966
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 231</span>
|
967
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">encode_bits</span>(<span class="ruby-identifier">bits</span>)
|
968
|
+
[<span class="ruby-identifier">bits</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">?</span> <span class="ruby-string">'1'</span> <span class="ruby-operator">:</span> <span class="ruby-string">'0'</span>}.<span class="ruby-identifier">join</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-string">'b*'</span>)
|
969
|
+
<span class="ruby-keyword">end</span></pre>
|
970
|
+
</div>
|
971
|
+
|
972
|
+
</div>
|
973
|
+
|
974
|
+
|
975
|
+
|
976
|
+
|
977
|
+
</div>
|
978
|
+
|
979
|
+
|
980
|
+
<div id="method-i-encode_bytes" class="method-detail ">
|
981
|
+
|
982
|
+
<div class="method-heading">
|
983
|
+
<span class="method-name">encode_bytes</span><span
|
984
|
+
class="method-args">(*bytes)</span>
|
985
|
+
|
986
|
+
<span class="method-click-advice">click to toggle source</span>
|
987
|
+
|
988
|
+
</div>
|
989
|
+
|
990
|
+
|
991
|
+
<div class="method-description">
|
992
|
+
|
993
|
+
<p>Encode an array of bytes and return them</p>
|
994
|
+
|
995
|
+
|
996
|
+
|
997
|
+
|
998
|
+
<div class="method-source-code" id="encode_bytes-source">
|
999
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 226</span>
|
1000
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">encode_bytes</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">bytes</span>)
|
1001
|
+
<span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-string">'C*'</span>)
|
1002
|
+
<span class="ruby-keyword">end</span></pre>
|
1003
|
+
</div>
|
1004
|
+
|
1005
|
+
</div>
|
1006
|
+
|
1007
|
+
|
1008
|
+
|
1009
|
+
|
1010
|
+
</div>
|
1011
|
+
|
1012
|
+
|
1013
|
+
<div id="method-i-encode_short" class="method-detail ">
|
1014
|
+
|
1015
|
+
<div class="method-heading">
|
1016
|
+
<span class="method-name">encode_short</span><span
|
1017
|
+
class="method-args">(val)</span>
|
1018
|
+
|
1019
|
+
<span class="method-click-advice">click to toggle source</span>
|
1020
|
+
|
1021
|
+
</div>
|
1022
|
+
|
1023
|
+
|
1024
|
+
<div class="method-description">
|
1025
|
+
|
1026
|
+
<p>Encode a 16-bit unsigned integer and return it</p>
|
1027
|
+
|
1028
|
+
|
1029
|
+
|
1030
|
+
|
1031
|
+
<div class="method-source-code" id="encode_short-source">
|
1032
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 236</span>
|
1033
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">encode_short</span>(<span class="ruby-identifier">val</span>)
|
1034
|
+
[<span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_i</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-string">'n'</span>)
|
1035
|
+
<span class="ruby-keyword">end</span></pre>
|
1036
|
+
</div>
|
1037
|
+
|
1038
|
+
</div>
|
1039
|
+
|
1040
|
+
|
1041
|
+
|
1042
|
+
|
1043
|
+
</div>
|
1044
|
+
|
1045
|
+
|
1046
|
+
<div id="method-i-encode_string" class="method-detail ">
|
1047
|
+
|
1048
|
+
<div class="method-heading">
|
1049
|
+
<span class="method-name">encode_string</span><span
|
1050
|
+
class="method-args">(str)</span>
|
1051
|
+
|
1052
|
+
<span class="method-click-advice">click to toggle source</span>
|
1053
|
+
|
1054
|
+
</div>
|
1055
|
+
|
1056
|
+
|
1057
|
+
<div class="method-description">
|
1058
|
+
|
1059
|
+
<p>Encode a UTF-8 string and return it (preceded by the length of the string)</p>
|
1060
|
+
|
1061
|
+
|
1062
|
+
|
1063
|
+
|
1064
|
+
<div class="method-source-code" id="encode_string-source">
|
1065
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 242</span>
|
1066
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">encode_string</span>(<span class="ruby-identifier">str</span>)
|
1067
|
+
<span class="ruby-identifier">str</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">encode</span>(<span class="ruby-string">'UTF-8'</span>)
|
1068
|
+
|
1069
|
+
<span class="ruby-comment"># Force to binary, when assembling the packet</span>
|
1070
|
+
<span class="ruby-identifier">str</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">'ASCII-8BIT'</span>)
|
1071
|
+
<span class="ruby-identifier">encode_short</span>(<span class="ruby-identifier">str</span>.<span class="ruby-identifier">bytesize</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">str</span>
|
1072
|
+
<span class="ruby-keyword">end</span></pre>
|
1073
|
+
</div>
|
1074
|
+
|
1075
|
+
</div>
|
1076
|
+
|
1077
|
+
|
1078
|
+
|
1079
|
+
|
1080
|
+
</div>
|
1081
|
+
|
1082
|
+
|
1083
|
+
<div id="method-i-shift_bits" class="method-detail ">
|
1084
|
+
|
1085
|
+
<div class="method-heading">
|
1086
|
+
<span class="method-name">shift_bits</span><span
|
1087
|
+
class="method-args">(buffer)</span>
|
1088
|
+
|
1089
|
+
<span class="method-click-advice">click to toggle source</span>
|
1090
|
+
|
1091
|
+
</div>
|
1092
|
+
|
1093
|
+
|
1094
|
+
<div class="method-description">
|
1095
|
+
|
1096
|
+
<p>Remove 8 bits from the front of buffer</p>
|
1097
|
+
|
1098
|
+
|
1099
|
+
|
1100
|
+
|
1101
|
+
<div class="method-source-code" id="shift_bits-source">
|
1102
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 262</span>
|
1103
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">shift_bits</span>(<span class="ruby-identifier">buffer</span>)
|
1104
|
+
<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">1</span>).<span class="ruby-identifier">unpack</span>(<span class="ruby-string">'b8'</span>).<span class="ruby-identifier">first</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">''</span>).<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">==</span> <span class="ruby-string">'1'</span>}
|
1105
|
+
<span class="ruby-keyword">end</span></pre>
|
1106
|
+
</div>
|
1107
|
+
|
1108
|
+
</div>
|
1109
|
+
|
1110
|
+
|
1111
|
+
|
1112
|
+
|
1113
|
+
</div>
|
1114
|
+
|
1115
|
+
|
1116
|
+
<div id="method-i-shift_byte" class="method-detail ">
|
1117
|
+
|
1118
|
+
<div class="method-heading">
|
1119
|
+
<span class="method-name">shift_byte</span><span
|
1120
|
+
class="method-args">(buffer)</span>
|
1121
|
+
|
1122
|
+
<span class="method-click-advice">click to toggle source</span>
|
1123
|
+
|
1124
|
+
</div>
|
1125
|
+
|
1126
|
+
|
1127
|
+
<div class="method-description">
|
1128
|
+
|
1129
|
+
<p>Remove one byte from the front of the string</p>
|
1130
|
+
|
1131
|
+
|
1132
|
+
|
1133
|
+
|
1134
|
+
<div class="method-source-code" id="shift_byte-source">
|
1135
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 257</span>
|
1136
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">shift_byte</span>(<span class="ruby-identifier">buffer</span>)
|
1137
|
+
<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">1</span>).<span class="ruby-identifier">unpack</span>(<span class="ruby-string">'C'</span>).<span class="ruby-identifier">first</span>
|
1138
|
+
<span class="ruby-keyword">end</span></pre>
|
1139
|
+
</div>
|
1140
|
+
|
1141
|
+
</div>
|
1142
|
+
|
1143
|
+
|
1144
|
+
|
1145
|
+
|
1146
|
+
</div>
|
1147
|
+
|
1148
|
+
|
1149
|
+
<div id="method-i-shift_data" class="method-detail ">
|
1150
|
+
|
1151
|
+
<div class="method-heading">
|
1152
|
+
<span class="method-name">shift_data</span><span
|
1153
|
+
class="method-args">(buffer,bytes)</span>
|
1154
|
+
|
1155
|
+
<span class="method-click-advice">click to toggle source</span>
|
1156
|
+
|
1157
|
+
</div>
|
1158
|
+
|
1159
|
+
|
1160
|
+
<div class="method-description">
|
1161
|
+
|
1162
|
+
<p>Remove n bytes from the front of buffer</p>
|
1163
|
+
|
1164
|
+
|
1165
|
+
|
1166
|
+
|
1167
|
+
<div class="method-source-code" id="shift_data-source">
|
1168
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 267</span>
|
1169
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">shift_data</span>(<span class="ruby-identifier">buffer</span>,<span class="ruby-identifier">bytes</span>)
|
1170
|
+
<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">bytes</span>)
|
1171
|
+
<span class="ruby-keyword">end</span></pre>
|
1172
|
+
</div>
|
1173
|
+
|
1174
|
+
</div>
|
1175
|
+
|
1176
|
+
|
1177
|
+
|
1178
|
+
|
1179
|
+
</div>
|
1180
|
+
|
1181
|
+
|
1182
|
+
<div id="method-i-shift_short" class="method-detail ">
|
1183
|
+
|
1184
|
+
<div class="method-heading">
|
1185
|
+
<span class="method-name">shift_short</span><span
|
1186
|
+
class="method-args">(buffer)</span>
|
1187
|
+
|
1188
|
+
<span class="method-click-advice">click to toggle source</span>
|
1189
|
+
|
1190
|
+
</div>
|
1191
|
+
|
1192
|
+
|
1193
|
+
<div class="method-description">
|
1194
|
+
|
1195
|
+
<p>Remove a 16-bit unsigned integer from the front of buffer</p>
|
1196
|
+
|
1197
|
+
|
1198
|
+
|
1199
|
+
|
1200
|
+
<div class="method-source-code" id="shift_short-source">
|
1201
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 251</span>
|
1202
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">shift_short</span>(<span class="ruby-identifier">buffer</span>)
|
1203
|
+
<span class="ruby-identifier">bytes</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>)
|
1204
|
+
<span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">'n'</span>).<span class="ruby-identifier">first</span>
|
1205
|
+
<span class="ruby-keyword">end</span></pre>
|
1206
|
+
</div>
|
1207
|
+
|
1208
|
+
</div>
|
1209
|
+
|
1210
|
+
|
1211
|
+
|
1212
|
+
|
1213
|
+
</div>
|
1214
|
+
|
1215
|
+
|
1216
|
+
<div id="method-i-shift_string" class="method-detail ">
|
1217
|
+
|
1218
|
+
<div class="method-heading">
|
1219
|
+
<span class="method-name">shift_string</span><span
|
1220
|
+
class="method-args">(buffer)</span>
|
1221
|
+
|
1222
|
+
<span class="method-click-advice">click to toggle source</span>
|
1223
|
+
|
1224
|
+
</div>
|
1225
|
+
|
1226
|
+
|
1227
|
+
<div class="method-description">
|
1228
|
+
|
1229
|
+
<p>Remove string from the front of buffer</p>
|
1230
|
+
|
1231
|
+
|
1232
|
+
|
1233
|
+
|
1234
|
+
<div class="method-source-code" id="shift_string-source">
|
1235
|
+
<pre><span class="ruby-comment"># File lib/mqttbridge/packet.rb, line 272</span>
|
1236
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">shift_string</span>(<span class="ruby-identifier">buffer</span>)
|
1237
|
+
<span class="ruby-identifier">len</span> = <span class="ruby-identifier">shift_short</span>(<span class="ruby-identifier">buffer</span>)
|
1238
|
+
<span class="ruby-identifier">str</span> = <span class="ruby-identifier">shift_data</span>(<span class="ruby-identifier">buffer</span>,<span class="ruby-identifier">len</span>)
|
1239
|
+
<span class="ruby-comment"># Strings in MQTT v3.1 are all UTF-8</span>
|
1240
|
+
<span class="ruby-identifier">str</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">'UTF-8'</span>)
|
1241
|
+
<span class="ruby-keyword">end</span></pre>
|
1242
|
+
</div>
|
1243
|
+
|
1244
|
+
</div>
|
1245
|
+
|
1246
|
+
|
1247
|
+
|
1248
|
+
|
1249
|
+
</div>
|
1250
|
+
|
1251
|
+
|
1252
|
+
</section>
|
1253
|
+
|
1254
|
+
</section>
|
1255
|
+
</main>
|
1256
|
+
|
1257
|
+
|
1258
|
+
<footer id="validator-badges" role="contentinfo">
|
1259
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
1260
|
+
<p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.1.
|
1261
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
1262
|
+
</footer>
|
1263
|
+
|