SNode.C
Loading...
Searching...
No Matches
ControlPacket.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/ControlPacket.h"
21
22#include "iot/mqtt/FixedHeader.h"
23
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
25
26#endif // DOXYGEN_SHOULD_SKIP_THIS
27
28namespace iot::mqtt {
29
31 "Reserved",
32 "CONNECT",
33 "CONNACK",
34 "PUBLISH",
35 "PUBACK",
36 "PUBREC",
37 "PUBREL",
38 "PUBCOMP",
39 "SUBSCRIBE",
40 "SUBACK",
41 "UNSUBSCRIBE",
42 "UNSUBACK",
43 "PINGREQ",
44 "PINGRESP",
45 "DISCONNECT",
46 "Reserved"};
47
48 ControlPacket::ControlPacket(uint8_t type, const std::string& name)
49 : name(name)
50 , type(type) {
51 switch (type) {
52 case MQTT_CONNECT:
54 break;
55 case MQTT_CONNACK:
57 break;
58 case MQTT_PUBLISH:
59 // no flags for MQTT_PUBLISH_FLAGS
60 break;
61 case MQTT_PUBACK:
63 break;
64 case MQTT_PUBREC:
66 break;
67 case MQTT_PUBREL:
69 break;
70 case MQTT_PUBCOMP:
72 break;
73 case MQTT_SUBSCRIBE:
75 break;
76 case MQTT_SUBACK:
78 break;
81 break;
82 case MQTT_UNSUBACK:
84 break;
85 case MQTT_PINGREQ:
87 break;
88 case MQTT_PINGRESP:
90 break;
91 case MQTT_DISCONNECT:
93 break;
94 }
95 }
96
99
100 const std::string& ControlPacket::getName() const {
101 return name;
102 }
103
105 std::vector<char> variablHeaderPayload = serializeVP();
106
107 const FixedHeader fixedHeader(type, flags, static_cast<uint32_t>(variablHeaderPayload.size()));
108
109 std::vector<char> packet = fixedHeader.serialize();
110 packet.insert(packet.end(), variablHeaderPayload.begin(), variablHeaderPayload.end());
111
112 return packet;
113 }
114
115 uint8_t ControlPacket::getType() const {
116 return type;
117 }
118
119 uint8_t ControlPacket::getFlags() const {
120 return flags;
121 }
122
123} // namespace iot::mqtt
std::vector< char > serialize() const
const std::string & getName() const
ControlPacket(uint8_t type, const std::string &name)
#define MQTT_CONNACK
Definition Connack.h:35
#define MQTT_CONNECT
Definition Connect.h:36
#define MQTT_DISCONNECT
Definition Disconnect.h:33
#define MQTT_PINGREQ
Definition Pingreq.h:33
#define MQTT_PINGRESP
Definition Pingresp.h:33
#define MQTT_PUBACK
Definition Puback.h:35
#define MQTT_PUBCOMP
Definition Pubcomp.h:35
#define MQTT_PUBLISH
Definition Publish.h:36
#define MQTT_PUBREC
Definition Pubrec.h:35
#define MQTT_PUBREL
Definition Pubrel.h:35
#define MQTT_SUBACK
Definition Suback.h:36
#define MQTT_SUBSCRIBE
Definition Subscribe.h:37
#define MQTT_UNSUBACK
Definition Unsuback.h:35
#define MQTT_UNSUBSCRIBE
Definition Unsubscribe.h:37
#define MQTT_CONNECT_FLAGS
#define MQTT_PUBREL_FLAGS
#define MQTT_PUBCOMP_FLAGS
#define MQTT_SUBSCRIBE_FLAGS
#define MQTT_SUBACK_FLAGS
#define MQTT_DISCONNECT_FLAGS
#define MQTT_PUBACK_FLAGS
#define MQTT_UNSUBSCRIBE_FLAGS
#define MQTT_CONNACK_FLAGS
#define MQTT_PINGREQ_FLAGS
#define MQTT_PUBREC_FLAGS
#define MQTT_UNSUBACK_FLAGS
#define MQTT_PINGRESP_FLAGS
const std::vector< std::string > mqttPackageName