Skip to content

Commit 8426a06

Browse files
Adafruit_MQTT (API): the payload of publish method is read-only
The payload param provided in publish is a const. This change fixes the API to ensure caller that this is the case for all variations of the publish method.
1 parent 6bcc819 commit 8426a06

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Adafruit_MQTT.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ bool Adafruit_MQTT::disconnect() {
298298

299299

300300
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
301-
return publish(topic, (uint8_t*)(data), strlen(data), qos);
301+
return publish(topic, (const uint8_t*)(data), strlen(data), qos);
302302
}
303303

304-
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen, uint8_t qos) {
304+
bool Adafruit_MQTT::publish(const char *topic, const uint8_t *data, uint16_t bLen, uint8_t qos) {
305305
// Construct and send publish packet.
306306
uint16_t len = publishPacket(buffer, (uint16_t) sizeof(buffer), topic, data, bLen, qos);
307307
if (!sendPacket(buffer, len))
@@ -648,7 +648,7 @@ uint16_t Adafruit_MQTT::packetAdditionalLen(uint16_t currLen)
648648

649649
// as per http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718040
650650
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, uint16_t maxPacketLen, const char *topic,
651-
uint8_t *data, uint16_t bLen, uint8_t qos) {
651+
const uint8_t *data, uint16_t bLen, uint8_t qos) {
652652
uint8_t *p = packet;
653653
uint16_t len=0;
654654

@@ -826,7 +826,7 @@ bool Adafruit_MQTT_Publish::publish(const char *payload) {
826826
}
827827

828828
//publish buffer of arbitrary length
829-
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen) {
829+
bool Adafruit_MQTT_Publish::publish(const uint8_t *payload, uint16_t bLen) {
830830

831831
return mqtt->publish(topic, payload, bLen, qos);
832832
}

Adafruit_MQTT.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Adafruit_MQTT {
178178
// Publish a message to a topic using the specified QoS level. Returns true
179179
// if the message was published, false otherwise.
180180
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
181-
bool publish(const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos = 0);
181+
bool publish(const char *topic, const uint8_t *payload, uint16_t bLen, uint8_t qos = 0);
182182

183183
// Add a subscription to receive messages for a topic. Returns true if the
184184
// subscription could be added or was already present, false otherwise.
@@ -245,7 +245,7 @@ class Adafruit_MQTT {
245245
uint8_t disconnectPacket(uint8_t *packet);
246246
static uint16_t packetAdditionalLen(uint16_t currLen);
247247
uint16_t publishPacket(uint8_t *packet, uint16_t maxPacketLen,
248-
const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos);
248+
const char *topic, const uint8_t *payload, uint16_t bLen, uint8_t qos);
249249
uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos);
250250
uint8_t unsubscribePacket(uint8_t *packet, const char *topic);
251251
uint8_t pingPacket(uint8_t *packet);
@@ -262,7 +262,7 @@ class Adafruit_MQTT_Publish {
262262
// This might be ignored and a higher precision value sent.
263263
bool publish(int32_t i);
264264
bool publish(uint32_t i);
265-
bool publish(uint8_t *b, uint16_t bLen);
265+
bool publish(const uint8_t *b, uint16_t bLen);
266266

267267

268268
private:

0 commit comments

Comments
 (0)