SNode.C
Loading...
Searching...
No Matches
Subscribe.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/packets/Subscribe.h"
21
22#include "iot/mqtt/types/String.h"
23#include "iot/mqtt/types/UInt16.h"
24
25#ifndef DOXYGEN_SHOULD_SKIP_THIS
26
27#include <string>
28#include <vector>
29
30#endif // DOXYGEN_SHOULD_SKIP_THIS
31
32namespace iot::mqtt::packets {
33
35 : iot::mqtt::ControlPacket(MQTT_SUBSCRIBE, "SUBSCRIBE") {
36 }
37
38 Subscribe::Subscribe(uint16_t packetIdentifier, const std::list<Topic>& topics)
39 : Subscribe() {
40 this->packetIdentifier = packetIdentifier;
41 this->topics = topics;
42 }
43
44 std::vector<char> Subscribe::serializeVP() const {
45 std::vector<char> packet(packetIdentifier.serialize());
46
47 for (const Topic& topic : topics) {
48 iot::mqtt::types::String topicString;
49 topicString = topic.getName();
50
51 std::vector<char> tmpPacket = topicString.serialize();
52 packet.insert(packet.end(), tmpPacket.begin(), tmpPacket.end());
53
54 packet.push_back(static_cast<char>(topic.getQoS()));
55 }
56
57 return packet;
58 }
59
60 uint16_t Subscribe::getPacketIdentifier() const {
61 return packetIdentifier;
62 }
63
64 const std::list<Topic>& Subscribe::getTopics() const {
65 return topics;
66 }
67
68} // namespace iot::mqtt::packets
Subscribe(uint16_t packetIdentifier, const std::list< iot::mqtt::Topic > &topics)
Definition Subscribe.cpp:38
std::vector< char > serializeVP() const override
Definition Subscribe.cpp:44
const std::list< iot::mqtt::Topic > & getTopics() const
Definition Subscribe.cpp:64
uint16_t getPacketIdentifier() const
Definition Subscribe.cpp:60
#define MQTT_SUBSCRIBE
Definition Subscribe.h:37