diff --git a/publishcopyfactory.cpp b/publishcopyfactory.cpp index 923f377..47e85f9 100644 --- a/publishcopyfactory.cpp +++ b/publishcopyfactory.cpp @@ -21,6 +21,7 @@ MqttPacket *PublishCopyFactory::getOptimumPacket(const char max_qos, const Proto { if (packet) { + // TODO: you can't do this when there are client specific mqtt5 properties if (packet->getProtocolVersion() == protocolVersion && orgQos == max_qos) { assert(orgQos == packet->getQos()); diff --git a/types.cpp b/types.cpp index 2b012ab..02a5ee4 100644 --- a/types.cpp +++ b/types.cpp @@ -100,7 +100,7 @@ size_t SubAck::getLengthWithoutFixedHeader() const return result; } -Publish::Publish(const std::string &topic, const std::string &payload, char qos) : +PublishBase::PublishBase(const std::string &topic, const std::string &payload, char qos) : topic(topic), payload(payload), qos(qos) @@ -108,7 +108,7 @@ Publish::Publish(const std::string &topic, const std::string &payload, char qos) } -size_t Publish::getLengthWithoutFixedHeader() const +size_t PublishBase::getLengthWithoutFixedHeader() const { int result = topic.length() + payload.length() + 2; @@ -122,13 +122,25 @@ size_t Publish::getLengthWithoutFixedHeader() const * @brief Publish::setClientSpecificProperties generates the properties byte array for one client. You're supposed to call it before any publish. * */ -void Publish::setClientSpecificProperties() +void PublishBase::setClientSpecificProperties() { if (propertyBuilder) propertyBuilder->clearClientSpecificBytes(); // TODO. Expires at? } +Publish::Publish(const Publish &other) : + PublishBase(other) +{ + +} + +Publish::Publish(const std::string &topic, const std::string &payload, char qos) : + PublishBase(topic, payload, qos) +{ + +} + PubAck::PubAck(uint16_t packet_id) : packet_id(packet_id) { diff --git a/types.h b/types.h index ce222c8..a155290 100644 --- a/types.h +++ b/types.h @@ -189,11 +189,13 @@ public: size_t getLengthWithoutFixedHeader() const; }; -class Publish +/** + * @brief The PublishBase class was incepted to have an easy default copy constuctor that doesn't copy all fields. + */ +class PublishBase { public: std::string topic; - std::vector subtopics; std::string payload; char qos = 0; bool retain = false; // Note: existing subscribers don't get publishes of retained messages with retain=1. [MQTT-3.3.1-9] @@ -203,12 +205,22 @@ public: std::chrono::seconds expiresAfter; std::shared_ptr propertyBuilder; - Publish() = default; - Publish(const std::string &topic, const std::string &payload, char qos); + PublishBase() = default; + PublishBase(const std::string &topic, const std::string &payload, char qos); size_t getLengthWithoutFixedHeader() const; void setClientSpecificProperties(); }; +class Publish : public PublishBase +{ +public: + std::vector subtopics; + + Publish() = default; + Publish(const Publish &other); + Publish(const std::string &topic, const std::string &payload, char qos); +}; + class PubAck { public: