Skip to content

Commit 7c4cc01

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 ad914cd commit 7c4cc01

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Adafruit_MQTT.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ bool Adafruit_MQTT::disconnect() {
311311
}
312312

313313
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
314-
return publish(topic, (uint8_t *)(data), strlen(data), qos);
314+
return publish(topic, (const uint8_t *)(data), strlen(data), qos);
315315
}
316316

317-
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen,
317+
bool Adafruit_MQTT::publish(const char *topic, const uint8_t *data, uint16_t bLen,
318318
uint8_t qos) {
319319
// Construct and send publish packet.
320320
uint16_t len = publishPacket(buffer, topic, data, bLen, qos,
@@ -678,7 +678,7 @@ uint16_t Adafruit_MQTT::packetAdditionalLen(uint16_t currLen)
678678
// as per
679679
// http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718040
680680
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
681-
uint8_t *data, uint16_t bLen,
681+
const uint8_t *data, uint16_t bLen,
682682
uint8_t qos, uint16_t maxPacketLen) {
683683
uint8_t *p = packet;
684684
uint16_t len = 0;
@@ -855,7 +855,7 @@ bool Adafruit_MQTT_Publish::publish(const char *payload) {
855855
}
856856

857857
// publish buffer of arbitrary length
858-
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen) {
858+
bool Adafruit_MQTT_Publish::publish(const uint8_t *payload, uint16_t bLen) {
859859

860860
return mqtt->publish(topic, payload, bLen, qos);
861861
}

Adafruit_MQTT.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Adafruit_MQTT {
187187
// Publish a message to a topic using the specified QoS level. Returns true
188188
// if the message was published, false otherwise.
189189
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
190-
bool publish(const char *topic, uint8_t *payload, uint16_t bLen,
190+
bool publish(const char *topic, const uint8_t *payload, uint16_t bLen,
191191
uint8_t qos = 0);
192192

193193
// Add a subscription to receive messages for a topic. Returns true if the
@@ -258,7 +258,7 @@ class Adafruit_MQTT {
258258
uint8_t connectPacket(uint8_t *packet);
259259
uint8_t disconnectPacket(uint8_t *packet);
260260
static uint16_t packetAdditionalLen(uint16_t currLen);
261-
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
261+
uint16_t publishPacket(uint8_t *packet, const char *topic, const uint8_t *payload,
262262
uint16_t bLen, uint8_t qos, uint16_t maxPacketLen);
263263
uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos);
264264
uint8_t unsubscribePacket(uint8_t *packet, const char *topic);
@@ -279,7 +279,7 @@ class Adafruit_MQTT_Publish {
279279
// This might be ignored and a higher precision value sent.
280280
bool publish(int32_t i);
281281
bool publish(uint32_t i);
282-
bool publish(uint8_t *b, uint16_t bLen);
282+
bool publish(const uint8_t *b, uint16_t bLen);
283283

284284
private:
285285
Adafruit_MQTT *mqtt;

0 commit comments

Comments
 (0)