Commit 80cad8fe04de166633cc8acbb5d5f927fef80c76

Authored by Wiebe Cazemier
1 parent b342be22

Only make property builder on publish when necessary

Showing 1 changed file with 5 additions and 4 deletions
mqttpacket.cpp
... ... @@ -806,10 +806,6 @@ void MqttPacket::handlePublish()
806 806 const size_t proplen = decodeVariableByteIntAtPos();
807 807 const size_t prop_end_at = pos + proplen;
808 808  
809   - // TODO: don't do this when the only properties are expiry and topic alias; they don't need the builder.
810   - if (proplen > 0)
811   - publishData.constructPropertyBuilder();
812   -
813 809 while (pos < prop_end_at)
814 810 {
815 811 const Mqtt5Properties prop = static_cast<Mqtt5Properties>(readByte());
... ... @@ -817,6 +813,7 @@ void MqttPacket::handlePublish()
817 813 switch (prop)
818 814 {
819 815 case Mqtt5Properties::PayloadFormatIndicator:
  816 + publishData.constructPropertyBuilder();
820 817 publishData.propertyBuilder->writePayloadFormatIndicator(readByte());
821 818 break;
822 819 case Mqtt5Properties::MessageExpiryInterval:
... ... @@ -841,6 +838,7 @@ void MqttPacket::handlePublish()
841 838 }
842 839 case Mqtt5Properties::ResponseTopic:
843 840 {
  841 + publishData.constructPropertyBuilder();
844 842 const uint16_t len = readTwoBytesToUInt16();
845 843 const std::string responseTopic(readBytes(len), len);
846 844 publishData.propertyBuilder->writeResponseTopic(responseTopic);
... ... @@ -848,6 +846,7 @@ void MqttPacket::handlePublish()
848 846 }
849 847 case Mqtt5Properties::CorrelationData:
850 848 {
  849 + publishData.constructPropertyBuilder();
851 850 const uint16_t len = readTwoBytesToUInt16();
852 851 const std::string correlationData(readBytes(len), len);
853 852 publishData.propertyBuilder->writeCorrelationData(correlationData);
... ... @@ -855,6 +854,7 @@ void MqttPacket::handlePublish()
855 854 }
856 855 case Mqtt5Properties::UserProperty:
857 856 {
  857 + publishData.constructPropertyBuilder();
858 858 const uint16_t lenKey = readTwoBytesToUInt16();
859 859 std::string userPropKey(readBytes(lenKey), lenKey);
860 860 const uint16_t lenVal = readTwoBytesToUInt16();
... ... @@ -869,6 +869,7 @@ void MqttPacket::handlePublish()
869 869 }
870 870 case Mqtt5Properties::ContentType:
871 871 {
  872 + publishData.constructPropertyBuilder();
872 873 const uint16_t len = readTwoBytesToUInt16();
873 874 const std::string contentType(readBytes(len), len);
874 875 publishData.propertyBuilder->writeContentType(contentType);
... ...