SNode.C
Loading...
Searching...
No Matches
Connect.cpp
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#include "iot/mqtt-fast/packets/Connect.h"
21
22#ifndef DOXYGEN_SHOULD_SKIP_THIS
23
24#endif // DOXYGEN_SHOULD_SKIP_THIS
25
26namespace iot::mqtt_fast::packets {
27
28 Connect::Connect(const std::string& clientId, const std::string& protocol, uint8_t version, uint8_t flags, uint16_t keepAlive)
30 , protocol(protocol)
31 , level(version)
32 , flags(flags)
33 , keepAlive(keepAlive)
34 , clientId(clientId) {
35 // V-Header
37 putInt8(this->level);
38 putInt8(this->flags);
40
41 // Payload
43 }
44
45 Connect::Connect(iot::mqtt_fast::ControlPacketFactory& controlPacketFactory)
46 : iot::mqtt_fast::ControlPacket(controlPacketFactory) {
47 // V-Header
49 level = getInt8();
50 flags = getInt8();
52
53 usernameFlag = (flags & 0x80) != 0;
54 passwordFlag = (flags & 0x40) != 0;
55 willRetain = (flags & 0x20) != 0;
56 willQoS = (flags & 0x18) >> 3;
57 willFlag = (flags & 0x04) != 0;
58 cleanSession = (flags & 0x02) != 0;
59 reserved = (flags & 0x01) != 0;
60
61 // Payload
62 if (!isError()) {
64 } else {
65 error = true;
66 }
67
68 if (!error && willFlag) {
71 }
72
73 if (!error && usernameFlag) {
75 }
76
77 if (!error && passwordFlag) {
79 }
80 }
81
82 std::string Connect::getProtocol() const {
83 return protocol;
84 }
85
86 uint8_t Connect::getLevel() const {
87 return level;
88 }
89
90 uint8_t Connect::getFlags() const {
91 return flags;
92 }
93
94 uint16_t Connect::getKeepAlive() const {
95 return keepAlive;
96 }
97
98 const std::string& Connect::getClientId() const {
99 return clientId;
100 }
101
102 bool Connect::getUsernameFlag() const {
103 return usernameFlag;
104 }
105
106 bool Connect::getPasswordFlag() const {
107 return passwordFlag;
108 }
109
110 bool Connect::getWillRetain() const {
111 return willRetain;
112 }
113
114 uint8_t Connect::getWillQoS() const {
115 return willQoS;
116 }
117
118 bool Connect::getWillFlag() const {
119 return willFlag;
120 }
121
122 bool Connect::getCleanSession() const {
123 return cleanSession;
124 }
125
126 const std::string& Connect::getWillTopic() const {
127 return willTopic;
128 }
129
130 const std::string& Connect::getWillMessage() const {
131 return willMessage;
132 }
133
134 const std::string& Connect::getUsername() const {
135 return username;
136 }
137
138 const std::string& Connect::getPassword() const {
139 return password;
140 }
141
142} // namespace iot::mqtt_fast::packets
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:126
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:28
uint16_t getKeepAlive() const
Definition Connect.cpp:94
std::string getProtocol() const
Definition Connect.cpp:82
const std::string & getUsername() const
Definition Connect.cpp:134
const std::string & getWillMessage() const
Definition Connect.cpp:130
const std::string & getClientId() const
Definition Connect.cpp:98
const std::string & getPassword() const
Definition Connect.cpp:138
Connect(iot::mqtt_fast::ControlPacketFactory &controlPacketFactory)
Definition Connect.cpp:45
#define MQTT_CONNECT
Definition Connect.h:36