diff --git a/src/TinyMqtt.cpp b/src/TinyMqtt.cpp index e653599..99505ae 100644 --- a/src/TinyMqtt.cpp +++ b/src/TinyMqtt.cpp @@ -400,7 +400,7 @@ MqttError MqttClient::publish(const Topic& topic, const char* payload, size_t pa MqttMessage msg; msg.create(MqttMessage::Publish); msg.add(topic); - msg.add(payload, pay_length); + msg.add(payload, pay_length, false); if (parent) return parent->publish(this, topic, msg); else if (client) @@ -491,10 +491,13 @@ void MqttMessage::incoming(char in_byte) } } -void MqttMessage::add(const char* p, size_t len) +void MqttMessage::add(const char* p, size_t len, bool addLength) { - incoming(len>>8); - incoming(len & 0xFF); + if (addLength) + { + incoming(len>>8); + incoming(len & 0xFF); + } while(len--) incoming(*p++); } diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index bb64ede..43965d2 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -57,7 +57,7 @@ class MqttMessage MqttMessage(Type t) { create(t); } void incoming(char byte); void add(char byte) { incoming(byte); } - void add(const char* p, size_t len); + void add(const char* p, size_t len, bool addLength=true ); void add(const std::string& s) { add(s.c_str(), s.length()); } void add(const Topic& t) { add(t.str()); } const char* end() const { return &buffer[0]+buffer.size(); }