Skip to content

Commit c226bde

Browse files
committed
Pass external buffer size explicitely
1 parent 57d63fd commit c226bde

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

ArduinoCloudThing.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ void ArduinoCloudThing::begin() {
4747
addPropertyReal(status, "status").readOnly();
4848
}
4949

50-
int ArduinoCloudThing::publish(CborArray& object, uint8_t* data) {
50+
int ArduinoCloudThing::publish(CborArray& object, uint8_t* data, size_t size) {
5151

52-
ssize_t size = object.encode(data, sizeof(data));
52+
ssize_t len = object.encode(data, size);
5353

5454
#ifdef TESTING_PROTOCOL
55-
decode(data, size);
55+
decode(data, len);
5656
#endif
5757

5858
for (int i = 0; i < list.size(); i++) {
5959
ArduinoCloudPropertyGeneric *p = list.get(i);
6060
p->updateShadow();
6161
}
6262

63-
return size;
63+
return len;
6464
}
6565

66-
int ArduinoCloudThing::poll(uint8_t* data) {
66+
int ArduinoCloudThing::poll(uint8_t* data, size_t size) {
6767

6868
// check if backing storage and cloud has diverged
6969
int diff = 0;
@@ -73,7 +73,7 @@ int ArduinoCloudThing::poll(uint8_t* data) {
7373
CborBuffer buffer(1024);
7474
CborArray object = CborArray(buffer);
7575
compress(object, buffer);
76-
diff = publish(object, data);
76+
diff = publish(object, data, size);
7777
}
7878

7979
#if defined(DEBUG_MEMORY) && defined(ARDUINO_ARCH_SAMD)

ArduinoCloudThing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ class ArduinoCloudThing {
210210
ArduinoCloudPropertyGeneric& addPropertyReal(void* property, String name);
211211
ArduinoCloudPropertyGeneric& addPropertyReal(String property, String name);
212212
// poll should return > 0 if something has changed
213-
int poll(uint8_t* data);
213+
int poll(uint8_t* data, size_t size);
214214
void decode(uint8_t * payload, size_t length);
215215

216216
private:
217-
int publish(CborArray& object, uint8_t* data);
217+
int publish(CborArray& object, uint8_t* data, size_t size);
218218

219219
void update();
220220
int checkNewData();

0 commit comments

Comments
 (0)