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
29
namespace
iot::mqtt::server::
broker
{
30
31
Message
::
Message
(
32
const
std::string& originClientId,
const
std::string& topic,
const
std::string& message, uint8_t qoS,
bool
originRetain)
33
:
originClientId
(
originClientId
)
34
,
topic
(
topic
)
35
,
message
(
message
)
36
,
qoS
(qoS)
37
,
originRetain
(originRetain) {
38
}
39
40
const
std
::
string
&
Message
::
getOriginClientId
()
const
{
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
72
nlohmann
::
json
Message
::
toJson
()
const
{
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
iot::mqtt::server::broker::Message
Definition
Message.h:33
iot::mqtt::server::broker::Message::setMessage
void setMessage(const std::string &message)
Definition
Message.cpp:56
iot::mqtt::server::broker::Message::getOriginClientId
const std::string & getOriginClientId() const
Definition
Message.cpp:40
iot::mqtt::server::broker::Message::toJson
nlohmann::json toJson() const
Definition
Message.cpp:72
iot::mqtt::server::broker::Message::getTopic
const std::string & getTopic() const
Definition
Message.cpp:44
iot::mqtt::server::broker::Message::qoS
uint8_t qoS
Definition
Message.h:61
iot::mqtt::server::broker::Message::setTopic
void setTopic(const std::string &topic)
Definition
Message.cpp:48
iot::mqtt::server::broker::Message::setQoS
void setQoS(uint8_t qoS)
Definition
Message.cpp:64
iot::mqtt::server::broker::Message::getOriginRetain
bool getOriginRetain() const
Definition
Message.cpp:68
iot::mqtt::server::broker::Message::getMessage
const std::string & getMessage() const
Definition
Message.cpp:52
iot::mqtt::server::broker::Message::getQoS
uint8_t getQoS() const
Definition
Message.cpp:60
iot::mqtt::server::broker::Message::originRetain
bool originRetain
Definition
Message.h:62
iot::mqtt::server::broker::Message::Message
Message(const std::string &originClientId, const std::string &topic, const std::string &message, uint8_t qoS, bool originRetain)
Definition
Message.cpp:31
iot::mqtt::server::broker::Message::fromJson
Message & fromJson(const nlohmann::json &json)
Definition
Message.cpp:83
iot::mqtt::server
Definition
Broker.cpp:37
iot
mqtt
server
broker
Message.cpp
Generated on Mon Feb 10 2025 20:21:09 for SNode.C by
1.11.0