diff --git a/mqttpacket.cpp b/mqttpacket.cpp index 8662f4a..0423adf 100644 --- a/mqttpacket.cpp +++ b/mqttpacket.cpp @@ -1012,6 +1012,8 @@ void MqttPacket::handleUnsubscribe() void MqttPacket::parsePublishData() { + setPosToDataStart(); + publishData.retain = (first_byte & 0b00000001); const bool duplicate = !!(first_byte & 0b00001000); publishData.qos = (first_byte & 0b00000110) >> 1; @@ -1256,6 +1258,11 @@ void MqttPacket::calculateRemainingLength() this->remainingLength = bites.size(); } +void MqttPacket::setPosToDataStart() +{ + this->pos = this->fixed_header_length; +} + bool MqttPacket::atEnd() const { assert(pos <= bites.size()); diff --git a/mqttpacket.h b/mqttpacket.h index ec024f6..41bfad1 100644 --- a/mqttpacket.h +++ b/mqttpacket.h @@ -85,7 +85,7 @@ class MqttPacket std::string readBytesToString(bool validateUtf8 = true, bool alsoCheckInvalidPublishChars = false); void calculateRemainingLength(); - + void setPosToDataStart(); bool atEnd() const; MqttPacket(const MqttPacket &other) = delete;