Commit deace4939e7a2333a0588878af6521b427154c3d
1 parent
96c1dd91
Some suback mqtt5 stuff
Showing
3 changed files
with
18 additions
and
3 deletions
mqttpacket.cpp
| ... | ... | @@ -63,6 +63,11 @@ MqttPacket::MqttPacket(const SubAck &subAck) : |
| 63 | 63 | first_byte = static_cast<char>(packetType) << 4; |
| 64 | 64 | writeUint16(subAck.packet_id); |
| 65 | 65 | |
| 66 | + if (subAck.protocol_version >= ProtocolVersion::Mqtt5) | |
| 67 | + { | |
| 68 | + writeProperties(subAck.propertyBuilder); | |
| 69 | + } | |
| 70 | + | |
| 66 | 71 | std::vector<char> returnList; |
| 67 | 72 | for (SubAckReturnCodes code : subAck.responses) |
| 68 | 73 | { |
| ... | ... | @@ -665,7 +670,7 @@ void MqttPacket::handleSubscribe() |
| 665 | 670 | throw ProtocolError("No topics specified to subscribe to."); |
| 666 | 671 | } |
| 667 | 672 | |
| 668 | - SubAck subAck(packet_id, subs_reponse_codes); | |
| 673 | + SubAck subAck(this->protocolVersion, packet_id, subs_reponse_codes); | |
| 669 | 674 | MqttPacket response(subAck); |
| 670 | 675 | sender->writeMqttPacket(response); |
| 671 | 676 | } | ... | ... |
types.cpp
| ... | ... | @@ -82,7 +82,8 @@ size_t ConnAck::getLengthWithoutFixedHeader() const |
| 82 | 82 | return result; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | -SubAck::SubAck(uint16_t packet_id, const std::list<char> &subs_qos_reponses) : | |
| 85 | +SubAck::SubAck(const ProtocolVersion protVersion, uint16_t packet_id, const std::list<char> &subs_qos_reponses) : | |
| 86 | + protocol_version(protVersion), | |
| 86 | 87 | packet_id(packet_id) |
| 87 | 88 | { |
| 88 | 89 | assert(!subs_qos_reponses.empty()); |
| ... | ... | @@ -97,6 +98,12 @@ size_t SubAck::getLengthWithoutFixedHeader() const |
| 97 | 98 | { |
| 98 | 99 | size_t result = responses.size(); |
| 99 | 100 | result += 2; // Packet ID |
| 101 | + | |
| 102 | + if (this->protocol_version >= ProtocolVersion::Mqtt5) | |
| 103 | + { | |
| 104 | + const size_t proplen = propertyBuilder ? propertyBuilder->getLength() : 1; | |
| 105 | + result += proplen; | |
| 106 | + } | |
| 100 | 107 | return result; |
| 101 | 108 | } |
| 102 | 109 | ... | ... |
types.h
| ... | ... | @@ -175,9 +175,12 @@ enum class SubAckReturnCodes |
| 175 | 175 | class SubAck |
| 176 | 176 | { |
| 177 | 177 | public: |
| 178 | + const ProtocolVersion protocol_version; | |
| 178 | 179 | uint16_t packet_id; |
| 179 | 180 | std::list<SubAckReturnCodes> responses; |
| 180 | - SubAck(uint16_t packet_id, const std::list<char> &subs_qos_reponses); | |
| 181 | + std::shared_ptr<Mqtt5PropertyBuilder> propertyBuilder; | |
| 182 | + | |
| 183 | + SubAck(const ProtocolVersion protVersion, uint16_t packet_id, const std::list<char> &subs_qos_reponses); | |
| 181 | 184 | size_t getLengthWithoutFixedHeader() const; |
| 182 | 185 | }; |
| 183 | 186 | ... | ... |