Commit 546c8348aa071a46ee580f0dbfa1752fd4398623
1 parent
4bf112b6
Add parseSubAckData()
Will be used for the test client I have in mind.
Showing
3 changed files
with
54 additions
and
0 deletions
mqttpacket.cpp
| ... | ... | @@ -1275,6 +1275,52 @@ void MqttPacket::handlePubComp() |
| 1275 | 1275 | sender->getSession()->removeOutgoingQoS2MessageId(packet_id); |
| 1276 | 1276 | } |
| 1277 | 1277 | |
| 1278 | +SubAckData MqttPacket::parseSubAckData() | |
| 1279 | +{ | |
| 1280 | + if (this->packetType != PacketType::SUBACK) | |
| 1281 | + throw std::runtime_error("Packet must be suback packet."); | |
| 1282 | + | |
| 1283 | + setPosToDataStart(); | |
| 1284 | + | |
| 1285 | + SubAckData result; | |
| 1286 | + | |
| 1287 | + result.packet_id = readTwoBytesToUInt16(); | |
| 1288 | + this->packet_id = result.packet_id; | |
| 1289 | + | |
| 1290 | + if (this->protocolVersion >= ProtocolVersion::Mqtt5 ) | |
| 1291 | + { | |
| 1292 | + const size_t proplen = decodeVariableByteIntAtPos(); | |
| 1293 | + const size_t prop_end_at = pos + proplen; | |
| 1294 | + | |
| 1295 | + while (pos < prop_end_at) | |
| 1296 | + { | |
| 1297 | + const Mqtt5Properties prop = static_cast<Mqtt5Properties>(readByte()); | |
| 1298 | + | |
| 1299 | + switch (prop) | |
| 1300 | + { | |
| 1301 | + case Mqtt5Properties::ReasonString: | |
| 1302 | + result.reasonString = readBytesToString(); | |
| 1303 | + break; | |
| 1304 | + case Mqtt5Properties::UserProperty: | |
| 1305 | + readUserProperty(); | |
| 1306 | + break; | |
| 1307 | + default: | |
| 1308 | + throw ProtocolError("Invalid property in suback.", ReasonCodes::ProtocolError); | |
| 1309 | + } | |
| 1310 | + } | |
| 1311 | + } | |
| 1312 | + | |
| 1313 | + // payload starts here | |
| 1314 | + | |
| 1315 | + while (!atEnd()) | |
| 1316 | + { | |
| 1317 | + uint8_t code = readByte(); | |
| 1318 | + result.subAckCodes.push_back(code); | |
| 1319 | + } | |
| 1320 | + | |
| 1321 | + return result; | |
| 1322 | +} | |
| 1323 | + | |
| 1278 | 1324 | void MqttPacket::calculateRemainingLength() |
| 1279 | 1325 | { |
| 1280 | 1326 | assert(fixed_header_length == 0); // because you're not supposed to call this on packet that we already know the length of. | ... | ... |
mqttpacket.h
packetdatatypes.h