Fix payload content
This commit is contained in:
@@ -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)
|
||||
{
|
||||
if (addLength)
|
||||
{
|
||||
incoming(len>>8);
|
||||
incoming(len & 0xFF);
|
||||
}
|
||||
while(len--) incoming(*p++);
|
||||
}
|
||||
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user