SNode.C
Loading...
Searching...
No Matches
Message.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/server/broker/Message.h"
21
22#ifndef DOXYGEN_SHOULD_SKIP_THIS
23
24#include <map>
25#include <nlohmann/json.hpp>
26
27#endif // DOXYGEN_SHOULD_SKIP_THIS
28
29namespace iot::mqtt::server::broker {
30
32 const std::string& originClientId, const std::string& topic, const std::string& message, uint8_t qoS, bool originRetain)
34 , topic(topic)
36 , qoS(qoS)
37 , originRetain(originRetain) {
38 }
39
41 return originClientId;
42 }
43
44 const std::string& Message::getTopic() const {
45 return topic;
46 }
47
48 void Message::setTopic(const std::string& topic) {
49 this->topic = topic;
50 }
51
52 const std::string& Message::getMessage() const {
53 return message;
54 }
55
56 void Message::setMessage(const std::string& message) {
57 this->message = message;
58 }
59
60 uint8_t Message::getQoS() const {
61 return qoS;
62 }
63
64 void Message::setQoS(uint8_t qoS) {
65 this->qoS = qoS;
66 }
67
68 bool Message::getOriginRetain() const {
69 return originRetain;
70 }
71
73 nlohmann::json json;
74
75 json["origin_client_id"] = originClientId;
76 json["topic"] = topic;
77 json["message"] = message;
78 json["qos"] = qoS;
79
80 return json;
81 }
82
83 Message& Message::fromJson(const nlohmann::json& json) {
84 if (!json.empty()) {
85 originClientId = json["origin_client_id"];
86 topic = json["topic"];
87 message = json["message"];
88 qoS = json["qos"];
89 }
90
91 return *this;
92 }
93
94} // namespace iot::mqtt::server::broker
void setMessage(const std::string &message)
Definition Message.cpp:56
const std::string & getOriginClientId() const
Definition Message.cpp:40
nlohmann::json toJson() const
Definition Message.cpp:72
const std::string & getTopic() const
Definition Message.cpp:44
void setTopic(const std::string &topic)
Definition Message.cpp:48
const std::string & getMessage() const
Definition Message.cpp:52
Message(const std::string &originClientId, const std::string &topic, const std::string &message, uint8_t qoS, bool originRetain)
Definition Message.cpp:31
Message & fromJson(const nlohmann::json &json)
Definition Message.cpp:83