Commit 7775fe4138909e79da0169811206ad8530988515

Authored by Wiebe Cazemier
1 parent 370e9115

Allow repeated calls to parsePublishData()

And also to future parse... methods.

This is necessary for the upcoming new test client.
mqttpacket.cpp
@@ -1012,6 +1012,8 @@ void MqttPacket::handleUnsubscribe() @@ -1012,6 +1012,8 @@ void MqttPacket::handleUnsubscribe()
1012 1012
1013 void MqttPacket::parsePublishData() 1013 void MqttPacket::parsePublishData()
1014 { 1014 {
  1015 + setPosToDataStart();
  1016 +
1015 publishData.retain = (first_byte & 0b00000001); 1017 publishData.retain = (first_byte & 0b00000001);
1016 const bool duplicate = !!(first_byte & 0b00001000); 1018 const bool duplicate = !!(first_byte & 0b00001000);
1017 publishData.qos = (first_byte & 0b00000110) >> 1; 1019 publishData.qos = (first_byte & 0b00000110) >> 1;
@@ -1256,6 +1258,11 @@ void MqttPacket::calculateRemainingLength() @@ -1256,6 +1258,11 @@ void MqttPacket::calculateRemainingLength()
1256 this->remainingLength = bites.size(); 1258 this->remainingLength = bites.size();
1257 } 1259 }
1258 1260
  1261 +void MqttPacket::setPosToDataStart()
  1262 +{
  1263 + this->pos = this->fixed_header_length;
  1264 +}
  1265 +
1259 bool MqttPacket::atEnd() const 1266 bool MqttPacket::atEnd() const
1260 { 1267 {
1261 assert(pos <= bites.size()); 1268 assert(pos <= bites.size());
mqttpacket.h
@@ -85,7 +85,7 @@ class MqttPacket @@ -85,7 +85,7 @@ class MqttPacket
85 std::string readBytesToString(bool validateUtf8 = true, bool alsoCheckInvalidPublishChars = false); 85 std::string readBytesToString(bool validateUtf8 = true, bool alsoCheckInvalidPublishChars = false);
86 86
87 void calculateRemainingLength(); 87 void calculateRemainingLength();
88 - 88 + void setPosToDataStart();
89 bool atEnd() const; 89 bool atEnd() const;
90 90
91 MqttPacket(const MqttPacket &other) = delete; 91 MqttPacket(const MqttPacket &other) = delete;