SNode.C
Loading...
Searching...
No Matches
Connect.h
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef IOT_MQTTFAST_PACKETS_CONNECT_H
43#define IOT_MQTTFAST_PACKETS_CONNECT_H
44
45#include "iot/mqtt-fast/ControlPacket.h"
46
47namespace iot::mqtt_fast {
49}
50
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
53#include <cstdint>
54#include <string>
55
56#endif // DOXYGEN_SHOULD_SKIP_THIS
57
58#define MQTT_CONNECT 0x01
59
60#define MQTT_VERSION_3_1_1 0x04
61
62namespace iot::mqtt_fast::packets {
63
64 class Connect : public iot::mqtt_fast::ControlPacket {
65 public:
66 explicit Connect(const std::string& clientId,
67 const std::string& protocol = "MQTT",
68 uint8_t version = 4,
69 uint8_t flags = 0,
70 uint16_t keepAlive = 0x003C);
71 explicit Connect(iot::mqtt_fast::ControlPacketFactory& controlPacketFactory);
72
73 std::string getProtocol() const;
74 uint8_t getLevel() const;
75 uint8_t getFlags() const;
76 uint16_t getKeepAlive() const;
77
78 const std::string& getClientId() const;
79
80 bool getUsernameFlag() const;
81 bool getPasswordFlag() const;
82 bool getWillRetain() const;
83 uint8_t getWillQoS() const;
84 bool getWillFlag() const;
85 bool getCleanSession() const;
86
87 const std::string& getWillTopic() const;
88 const std::string& getWillMessage() const;
89 const std::string& getUsername() const;
90 const std::string& getPassword() const;
91
92 private:
93 std::string protocol;
94 uint8_t level = 0;
95 uint8_t flags = 0;
96 uint16_t keepAlive = 0;
97
98 std::string clientId;
99 std::string willTopic;
100 std::string willMessage;
101 std::string username;
102 std::string password;
103
104 bool usernameFlag = false;
105 bool passwordFlag = false;
106 bool willRetain = false;
107 uint8_t willQoS = 0;
108 bool willFlag = false;
109 bool cleanSession = false;
110 bool reserved = false;
111 };
112
113} // namespace iot::mqtt_fast::packets
114
115/*
116
117V5
118 VARIABLE HEADER
119 2022-09-19 17:37:53 0000000012: 1. - 0x00 Length MSB
120 2022-09-19 17:37:53 0000000012: 2. - 0x04 Length LSB
121 2022-09-19 17:37:53 0000000012: 3. M - 0x4d Protocol
122 2022-09-19 17:37:53 0000000012: 4. Q - 0x51
123 2022-09-19 17:37:53 0000000012: 5. T - 0x54
124 2022-09-19 17:37:53 0000000012: 6. T - 0x54
125
126 2022-09-19 17:37:53 0000000012: 7. - 0x05 Version
127 2022-09-19 17:37:53 0000000012: 8. - 0x02 Flags
128
129 2022-09-19 17:37:53 0000000012: 9. - 0x00 Keep Aliva MSB 0x003c = 60sec
130 2022-09-19 17:37:53 0000000012: 10. < - 0x3c Keep Alive LSB
131
132 2022-09-19 17:37:53 0000000012: 11. - 0x03 Properties Length
133
134 2022-09-19 17:37:53 0000000012: 12. ! - 0x21 Property: Receive Maximum (2Byte)
135 2022-09-19 17:37:53 0000000012: 13. - 0x00 Receive Maximum MSB
136 2022-09-19 17:37:53 0000000012: 14. - 0x14 Receive Maximum LSB
137
138 PAYLOAD
139 2022-09-19 17:37:53 0000000012: 15. - 0x00 ID Length MSB
140 2022-09-19 17:37:53 0000000012: 16. - 0x02 ID Length LSB
141 2022-09-19 17:37:53 0000000012: 17. d - 0x64 ID-Byte 1
142 2022-09-19 17:37:53 0000000012: 18. f - 0x66 ID-Byte 2
143
144 WILL Properties (optional)
145 WILL Topic (optional)
146 User Name
147 Password
148
149 */
150
151#endif // IOT_MQTTFAST_PACKETS_CONNECT_H
ControlPacket(iot::mqtt_fast::ControlPacketFactory &controlPacketFactory)
void putInt16(uint16_t value)
void putString(const std::string &value)
ControlPacket(uint8_t type, uint8_t reserved=0)
const std::string & getWillTopic() const
Definition Connect.cpp:148
Connect(const std::string &clientId, const std::string &protocol="MQTT", uint8_t version=4, uint8_t flags=0, uint16_t keepAlive=0x003C)
Definition Connect.cpp:50
std::string getProtocol() const
Definition Connect.cpp:104
const std::string & getUsername() const
Definition Connect.cpp:156
const std::string & getWillMessage() const
Definition Connect.cpp:152
const std::string & getClientId() const
Definition Connect.cpp:120
const std::string & getPassword() const
Definition Connect.cpp:160
Connect(iot::mqtt_fast::ControlPacketFactory &controlPacketFactory)
Definition Connect.cpp:67
#define MQTT_CONNECT
Definition Connect.h:58