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,10 +806,6 @@ void MqttPacket::handlePublish()
806 const size_t proplen = decodeVariableByteIntAtPos(); 806 const size_t proplen = decodeVariableByteIntAtPos();
807 const size_t prop_end_at = pos + proplen; 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 while (pos < prop_end_at) 809 while (pos < prop_end_at)
814 { 810 {
815 const Mqtt5Properties prop = static_cast<Mqtt5Properties>(readByte()); 811 const Mqtt5Properties prop = static_cast<Mqtt5Properties>(readByte());
@@ -817,6 +813,7 @@ void MqttPacket::handlePublish() @@ -817,6 +813,7 @@ void MqttPacket::handlePublish()
817 switch (prop) 813 switch (prop)
818 { 814 {
819 case Mqtt5Properties::PayloadFormatIndicator: 815 case Mqtt5Properties::PayloadFormatIndicator:
  816 + publishData.constructPropertyBuilder();
820 publishData.propertyBuilder->writePayloadFormatIndicator(readByte()); 817 publishData.propertyBuilder->writePayloadFormatIndicator(readByte());
821 break; 818 break;
822 case Mqtt5Properties::MessageExpiryInterval: 819 case Mqtt5Properties::MessageExpiryInterval:
@@ -841,6 +838,7 @@ void MqttPacket::handlePublish() @@ -841,6 +838,7 @@ void MqttPacket::handlePublish()
841 } 838 }
842 case Mqtt5Properties::ResponseTopic: 839 case Mqtt5Properties::ResponseTopic:
843 { 840 {
  841 + publishData.constructPropertyBuilder();
844 const uint16_t len = readTwoBytesToUInt16(); 842 const uint16_t len = readTwoBytesToUInt16();
845 const std::string responseTopic(readBytes(len), len); 843 const std::string responseTopic(readBytes(len), len);
846 publishData.propertyBuilder->writeResponseTopic(responseTopic); 844 publishData.propertyBuilder->writeResponseTopic(responseTopic);
@@ -848,6 +846,7 @@ void MqttPacket::handlePublish() @@ -848,6 +846,7 @@ void MqttPacket::handlePublish()
848 } 846 }
849 case Mqtt5Properties::CorrelationData: 847 case Mqtt5Properties::CorrelationData:
850 { 848 {
  849 + publishData.constructPropertyBuilder();
851 const uint16_t len = readTwoBytesToUInt16(); 850 const uint16_t len = readTwoBytesToUInt16();
852 const std::string correlationData(readBytes(len), len); 851 const std::string correlationData(readBytes(len), len);
853 publishData.propertyBuilder->writeCorrelationData(correlationData); 852 publishData.propertyBuilder->writeCorrelationData(correlationData);
@@ -855,6 +854,7 @@ void MqttPacket::handlePublish() @@ -855,6 +854,7 @@ void MqttPacket::handlePublish()
855 } 854 }
856 case Mqtt5Properties::UserProperty: 855 case Mqtt5Properties::UserProperty:
857 { 856 {
  857 + publishData.constructPropertyBuilder();
858 const uint16_t lenKey = readTwoBytesToUInt16(); 858 const uint16_t lenKey = readTwoBytesToUInt16();
859 std::string userPropKey(readBytes(lenKey), lenKey); 859 std::string userPropKey(readBytes(lenKey), lenKey);
860 const uint16_t lenVal = readTwoBytesToUInt16(); 860 const uint16_t lenVal = readTwoBytesToUInt16();
@@ -869,6 +869,7 @@ void MqttPacket::handlePublish() @@ -869,6 +869,7 @@ void MqttPacket::handlePublish()
869 } 869 }
870 case Mqtt5Properties::ContentType: 870 case Mqtt5Properties::ContentType:
871 { 871 {
  872 + publishData.constructPropertyBuilder();
872 const uint16_t len = readTwoBytesToUInt16(); 873 const uint16_t len = readTwoBytesToUInt16();
873 const std::string contentType(readBytes(len), len); 874 const std::string contentType(readBytes(len), len);
874 publishData.propertyBuilder->writeContentType(contentType); 875 publishData.propertyBuilder->writeContentType(contentType);