From 7775fe4138909e79da0169811206ad8530988515 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Mon, 27 Jun 2022 17:05:53 +0200 Subject: [PATCH] Allow repeated calls to parsePublishData() --- mqttpacket.cpp | 7 +++++++ mqttpacket.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) 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; -- libgit2 0.21.4