SNode.C
Loading...
Searching...
No Matches
String.h
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#ifndef IOT_MQTT_TYPES_STRING_H
43#define IOT_MQTT_TYPES_STRING_H
44
45#include "iot/mqtt/types/TypeBase.h"
46#include "iot/mqtt/types/UInt16.h"
47
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
49
50#include <cstddef>
51#include <string>
52
53#endif // DOXYGEN_SHOULD_SKIP_THIS
54
55namespace iot::mqtt::types {
56
57 class String : public TypeBase<std::string> {
58 public:
59 String();
60 explicit String(const std::string& value);
61 String(const String&) = default;
62 String(String&&) noexcept = default;
63
64 ~String() override;
65
66 String& operator=(const String&) = default;
67 String& operator=(String&&) noexcept = default;
68
69 std::size_t deserialize(iot::mqtt::MqttContext* mqttContext) override;
70 std::vector<char> serialize() const override;
71
72 String& operator=(const std::string& newValue);
73 operator std::string() const;
74
75 bool operator==(const std::string& rhsValue) const;
76 bool operator!=(const std::string& rhsValue) const;
77
78 void reset(std::size_t size = 0) override;
79
80 private:
82 };
83
84 extern template class TypeBase<std::string>;
85
86} // namespace iot::mqtt::types
87
88#endif // IOT_MQTT_TYPES_STRING_H
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext)
virtual std::size_t deserializeVP(iot::mqtt::MqttContext *mqttContext)=0
ControlPacketDeserializer & operator=(const ControlPacketDeserializer &)=default
ControlPacketDeserializer(uint32_t remainingLength, uint8_t flags, uint8_t mustFlags)
std::vector< char > serialize() const
const std::string & getName() const
ControlPacket & operator=(const ControlPacket &)=default
virtual std::vector< char > serializeVP() const =0
ControlPacket(const ControlPacket &)=default
ControlPacket(ControlPacket &&)=default
ControlPacket(uint8_t type, const std::string &name)
ControlPacket & operator=(ControlPacket &&)=default
uint8_t getType() const
FixedHeader(uint8_t type, uint8_t flags, uint32_t remainingLength=0)
uint32_t getRemainingLength() const
uint8_t getFlags() const
void setRemainingLength(uint32_t remainingLength)
std::vector< char > serialize() const
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext)
types::UInt8 typeFlags
Definition FixedHeader.h:84
types::UIntV remainingLength
Definition FixedHeader.h:85
MqttContext * mqttContext
Definition Mqtt.h:158
static std::string toHexString(const std::string &data)
Definition Mqtt.cpp:394
const std::string & getConnectionName() const
Definition Mqtt.cpp:170
virtual void onConnected()
Definition Mqtt.cpp:95
static std::string toHexString(const std::vector< char > &data)
Definition Mqtt.cpp:389
virtual void onPubcomp(const iot::mqtt::packets::Pubcomp &pubcomp)
Definition Mqtt.cpp:265
virtual void onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:253
core::timer::Timer keepAliveTimer
Definition Mqtt.h:151
iot::mqtt::FixedHeader fixedHeader
Definition Mqtt.h:146
const MqttContext * getMqttContext() const
Definition Mqtt.cpp:91
std::size_t onReceivedFromPeer()
Definition Mqtt.cpp:99
virtual void onDisconnected()
Definition Mqtt.cpp:166
void send(const std::vector< char > &data) const
Definition Mqtt.cpp:211
void setMqttContext(MqttContext *mqttContext)
Definition Mqtt.cpp:87
void sendPuback(uint16_t packetIdentifier) const
Definition Mqtt.cpp:237
virtual void onPuback(const iot::mqtt::packets::Puback &puback)
Definition Mqtt.cpp:256
std::string connectionName
Definition Mqtt.h:142
void _onPubrec(const iot::mqtt::packets::Pubrec &pubrec)
Definition Mqtt.cpp:320
virtual void deliverPacket(iot::mqtt::ControlPacketDeserializer *controlPacketDeserializer)=0
Mqtt(const std::string &connectionName, const std::string &clientId)
Definition Mqtt.cpp:73
void sendPubrel(uint16_t packetIdentifier) const
Definition Mqtt.cpp:245
uint16_t getPacketIdentifier()
Definition Mqtt.cpp:398
bool _onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:268
virtual iot::mqtt::ControlPacketDeserializer * createControlPacketDeserializer(iot::mqtt::FixedHeader &staticHeader)=0
Mqtt & operator=(Mqtt &&)=delete
void sendPublish(const std::string &topic, const std::string &message, uint8_t qoS, bool retain)
Definition Mqtt.cpp:217
virtual ~Mqtt()
Definition Mqtt.cpp:78
void printFixedHeader(const iot::mqtt::FixedHeader &fixedHeader) const
Definition Mqtt.cpp:377
uint16_t _packetIdentifier
Definition Mqtt.h:149
Mqtt(const Mqtt &)=delete
Session * session
Definition Mqtt.h:155
void _onPubrel(const iot::mqtt::packets::Pubrel &pubrel)
Definition Mqtt.cpp:337
virtual void onPubrec(const iot::mqtt::packets::Pubrec &pubrec)
Definition Mqtt.cpp:259
virtual void onPubrel(const iot::mqtt::packets::Pubrel &pubrel)
Definition Mqtt.cpp:262
void send(const iot::mqtt::ControlPacket &controlPacket) const
Definition Mqtt.cpp:205
virtual bool onSignal(int sig)=0
std::string clientId
Definition Mqtt.h:143
Mqtt(const std::string &connectionName)
Definition Mqtt.cpp:69
void initSession(Session *session, utils::Timeval keepAlive)
Definition Mqtt.cpp:174
Mqtt & operator=(const Mqtt &)=delete
void printVP(const iot::mqtt::ControlPacket &packet) const
Definition Mqtt.cpp:368
Mqtt(Mqtt &&)=delete
iot::mqtt::ControlPacketDeserializer * controlPacketDeserializer
Definition Mqtt.h:147
void sendPubcomp(uint16_t packetIdentifier) const
Definition Mqtt.cpp:249
void sendPubrec(uint16_t packetIdentifier) const
Definition Mqtt.cpp:241
void _onPubcomp(const iot::mqtt::packets::Pubcomp &pubcomp)
Definition Mqtt.cpp:353
void _onPuback(const iot::mqtt::packets::Puback &puback)
Definition Mqtt.cpp:308
Session & operator=(const Session &)=default
std::set< uint16_t > publishPacketIdentifierSet
Definition Session.h:85
virtual nlohmann::json toJson() const
Definition Session.cpp:59
std::map< uint16_t, iot::mqtt::packets::Publish > publishMap
Definition Session.h:81
Session(const nlohmann::json &json)
Definition Session.cpp:55
bool isCleanSession() const
Session(const Session &)=default
virtual ~Session()=default
void fromJson(const nlohmann::json &json)
Definition Session.cpp:89
std::set< uint16_t > pubrelPacketIdentifierSet
Definition Session.h:82
virtual void deliverPacket(iot::mqtt::client::Mqtt *mqtt)=0
void _onPublish(const iot::mqtt::client::packets::Publish &publish)
Definition Mqtt.cpp:213
void sendConnect(uint16_t keepAlive, const std::string &clientId, bool cleanSession, const std::string &willTopic, const std::string &willMessage, uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, bool loopPrevention=false)
Definition Mqtt.cpp:261
iot::mqtt::Session session
Definition Mqtt.h:141
std::string sessionStoreFileName
Definition Mqtt.h:140
Mqtt(const std::string &connectionName, const std::string &clientId, const std::string &sessionStoreFileName)
Definition Mqtt.cpp:78
void _onPingresp(const iot::mqtt::client::packets::Pingresp &pingresp)
Definition Mqtt.cpp:257
virtual void onConnack(const iot::mqtt::packets::Connack &connack)
Definition Mqtt.cpp:181
virtual void onPingresp(const iot::mqtt::packets::Pingresp &pingresp)
Definition Mqtt.cpp:190
void sendSubscribe(const std::list< Topic > &topics)
Definition Mqtt.cpp:281
iot::mqtt::ControlPacketDeserializer * createControlPacketDeserializer(iot::mqtt::FixedHeader &fixedHeader) final
Definition Mqtt.cpp:134
void _onSuback(const iot::mqtt::client::packets::Suback &suback)
Definition Mqtt.cpp:219
virtual void onUnsuback(const iot::mqtt::packets::Unsuback &unsuback)
Definition Mqtt.cpp:187
void _onConnack(const iot::mqtt::client::packets::Connack &connack)
Definition Mqtt.cpp:193
void _onUnsuback(const iot::mqtt::client::packets::Unsuback &unsuback)
Definition Mqtt.cpp:245
void sendUnsubscribe(const std::list< std::string > &topics)
Definition Mqtt.cpp:285
bool onSignal(int sig) override
Definition Mqtt.cpp:177
virtual void onSuback(const iot::mqtt::packets::Suback &suback)
Definition Mqtt.cpp:184
void deliverPacket(iot::mqtt::ControlPacketDeserializer *controlPacketDeserializer) override
Definition Mqtt.cpp:173
void sendPingreq() const
Definition Mqtt.cpp:289
void sendDisconnect() const
Definition Mqtt.cpp:293
core::timer::Timer pingTimer
Definition Mqtt.h:143
std::size_t deserializeVP(iot::mqtt::MqttContext *mqttContext) override
Definition Connack.cpp:57
Connack(uint32_t remainingLength, uint8_t flags)
Definition Connack.cpp:52
void deliverPacket(iot::mqtt::client::Mqtt *mqtt) override
Definition Connack.cpp:87
uint8_t getReturnCode() const
Definition Connack.cpp:76
std::vector< char > serializeVP() const override
Definition Connack.cpp:63
Connack(uint8_t returncode, uint8_t acknowledgeFlags)
Definition Connack.cpp:57
iot::mqtt::types::UInt8 acknowledgeFlags
Definition Connack.h:81
bool getSessionPresent() const
Definition Connack.cpp:80
uint8_t getAcknowledgeFlags() const
Definition Connack.cpp:72
iot::mqtt::types::UInt8 returnCode
Definition Connack.h:82
uint8_t getQoS() const
Definition Publish.cpp:85
iot::mqtt::types::StringRaw message
Definition Publish.h:79
std::string getTopic() const
Definition Publish.cpp:93
std::string getMessage() const
Definition Publish.cpp:97
Publish(uint16_t packetIdentifier, const std::string &topic, const std::string &message, uint8_t qoS, bool dup, bool retain)
Definition Publish.cpp:56
iot::mqtt::types::UInt16 packetIdentifier
Definition Publish.h:77
uint16_t getPacketIdentifier() const
Definition Publish.cpp:89
iot::mqtt::types::String topic
Definition Publish.h:78
std::vector< char > serializeVP() const override
Definition Publish.cpp:67
operator std::string() const
Definition String.cpp:111
bool operator==(const std::string &rhsValue) const
Definition String.cpp:115
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext) override
Definition String.cpp:67
void reset(std::size_t size=0) override
Definition String.cpp:123
bool operator!=(const std::string &rhsValue) const
Definition String.cpp:119
String(const std::string &value)
Definition String.cpp:59
String(const String &)=default
String(String &&) noexcept=default
std::vector< char > serialize() const override
Definition String.cpp:97
String & operator=(String &&) noexcept=default
String & operator=(const std::string &newValue)
Definition String.cpp:104
String & operator=(const String &)=default
std::vector< char > value
Definition TypeBase.h:85
TypeBase(const TypeBase &)=default
void setSize(std::size_t size)
Definition TypeBase.hpp:70
virtual std::vector< char > serialize() const
Definition TypeBase.hpp:83
virtual std::size_t deserialize(iot::mqtt::MqttContext *mqttContext)
Definition TypeBase.hpp:59
TypeBase & operator=(TypeBase &&) noexcept=default
TypeBase(std::size_t size=sizeof(ValueType))
Definition TypeBase.hpp:52
virtual ~TypeBase()=default
TypeBase(TypeBase &&) noexcept=default
virtual void reset(std::size_t size=sizeof(ValueType))
Definition TypeBase.hpp:93
TypeBase & operator=(const TypeBase &)=default
UInt8 & operator=(const uint8_t &newValue)
Definition UInt8.cpp:57
UInt8(UInt8 &&) noexcept=default
UInt8 & operator=(UInt8 &&) noexcept=default
UInt8 & operator=(const UInt8 &)=default
UInt8(const UInt8 &)=default
UIntV & operator=(UIntV &&) noexcept=default
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext) override
Definition UIntV.cpp:62
bool isError() const
Definition UIntV.cpp:112
UIntV & operator=(const uint32_t &newValue)
Definition UIntV.cpp:83
UIntV(UIntV &&) noexcept=default
UIntV(const UIntV &)=default
UIntV & operator=(const UIntV &)=default
void reset(std::size_t size=sizeof(ValueType)) override
Definition UIntV.cpp:116
#define MQTT_CONNACK_FLAGS
Definition Timer.h:59
const std::vector< std::string > mqttPackageName