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
/*
21
* MIT License
22
*
23
* Permission is hereby granted, free of charge, to any person obtaining a copy
24
* of this software and associated documentation files (the "Software"), to deal
25
* in the Software without restriction, including without limitation the rights
26
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
* copies of the Software, and to permit persons to whom the Software is
28
* furnished to do so, subject to the following conditions:
29
*
30
* The above copyright notice and this permission notice shall be included in
31
* all copies or substantial portions of the Software.
32
*
33
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39
* THE SOFTWARE.
40
*/
41
42
#
include
"iot/mqtt/server/broker/Message.h"
43
44
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
45
46
#
include
<
map
>
47
#
include
<
nlohmann
/
json
.
hpp
>
48
49
#
endif
// DOXYGEN_SHOULD_SKIP_THIS
50
51
namespace
iot::mqtt::server::
broker
{
52
53
Message
::
Message
(
54
const
std::string& originClientId,
const
std::string& topic,
const
std::string& message, uint8_t qoS,
bool
originRetain)
55
:
originClientId
(originClientId)
56
,
topic
(topic)
57
,
message
(message)
58
,
qoS
(qoS)
59
,
originRetain
(originRetain) {
60
}
61
62
const
std::string&
Message
::
getOriginClientId
()
const
{
63
return
originClientId
;
64
}
65
66
const
std::string&
Message
::
getTopic
()
const
{
67
return
topic
;
68
}
69
70
void
Message
::
setTopic
(
const
std::string& topic) {
71
this
->
topic
= topic;
72
}
73
74
const
std::string&
Message
::
getMessage
()
const
{
75
return
message
;
76
}
77
78
void
Message
::
setMessage
(
const
std::string& message) {
79
this
->
message
= message;
80
}
81
82
uint8_t
Message
::
getQoS
()
const
{
83
return
qoS
;
84
}
85
86
void
Message
::
setQoS
(uint8_t qoS) {
87
this
->
qoS
= qoS;
88
}
89
90
bool
Message
::
getOriginRetain
()
const
{
91
return
originRetain
;
92
}
93
94
nlohmann::json
Message
::
toJson
()
const
{
95
nlohmann::json json;
96
97
json[
"origin_client_id"
] =
originClientId
;
98
json[
"topic"
] =
topic
;
99
json[
"message"
] =
message
;
100
json[
"qos"
] =
qoS
;
101
102
return
json;
103
}
104
105
Message
&
Message
::
fromJson
(
const
nlohmann::json& json) {
106
if
(!json.empty()) {
107
originClientId
= json[
"origin_client_id"
];
108
topic
= json[
"topic"
];
109
message
= json[
"message"
];
110
qoS
= json[
"qos"
];
111
}
112
113
return
*
this
;
114
}
115
116
}
// namespace iot::mqtt::server::broker
iot::mqtt::server::broker::Message
Definition
Message.h:55
iot::mqtt::server::broker::Message::setMessage
void setMessage(const std::string &message)
Definition
Message.cpp:78
iot::mqtt::server::broker::Message::getOriginClientId
const std::string & getOriginClientId() const
Definition
Message.cpp:62
iot::mqtt::server::broker::Message::originClientId
std::string originClientId
Definition
Message.h:80
iot::mqtt::server::broker::Message::toJson
nlohmann::json toJson() const
Definition
Message.cpp:94
iot::mqtt::server::broker::Message::getTopic
const std::string & getTopic() const
Definition
Message.cpp:66
iot::mqtt::server::broker::Message::qoS
uint8_t qoS
Definition
Message.h:83
iot::mqtt::server::broker::Message::setTopic
void setTopic(const std::string &topic)
Definition
Message.cpp:70
iot::mqtt::server::broker::Message::topic
std::string topic
Definition
Message.h:81
iot::mqtt::server::broker::Message::setQoS
void setQoS(uint8_t qoS)
Definition
Message.cpp:86
iot::mqtt::server::broker::Message::getOriginRetain
bool getOriginRetain() const
Definition
Message.cpp:90
iot::mqtt::server::broker::Message::getMessage
const std::string & getMessage() const
Definition
Message.cpp:74
iot::mqtt::server::broker::Message::getQoS
uint8_t getQoS() const
Definition
Message.cpp:82
iot::mqtt::server::broker::Message::originRetain
bool originRetain
Definition
Message.h:84
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:53
iot::mqtt::server::broker::Message::fromJson
Message & fromJson(const nlohmann::json &json)
Definition
Message.cpp:105
iot::mqtt::server::broker::Message::message
std::string message
Definition
Message.h:82
iot::mqtt::server
Definition
Broker.cpp:58
iot
mqtt
server
broker
Message.cpp
Generated on
for SNode.C by
1.15.0