Skip to content

Commit d589f5b

Browse files
authored
Merge pull request #152 from arduino-libraries/fix-cbor-msg-exceeds-buffer
Fix: Handle encoded CBOR message exceeding buffer size
2 parents 54f2d7d + b4cc977 commit d589f5b

24 files changed

+227
-123
lines changed

extras/test/src/test_encode.cpp

+56-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
TEST CODE
2121
**************************************************************************************/
2222

23-
SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]") {
23+
SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode-1]") {
2424
/************************************************************************************/
2525

2626
WHEN("A 'bool' property is added") {
@@ -381,4 +381,59 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]")
381381
}
382382

383383
/************************************************************************************/
384+
385+
WHEN("The size of the encoded properties is exceeding the CBOR buffer size") {
386+
GIVEN("CloudProtocol::V2") {
387+
PropertyContainer property_container;
388+
389+
CloudString str_0; str_0 = "This string is 30 bytes long.";
390+
CloudString str_1; str_1 = "This string is 30 bytes long.";
391+
CloudString str_2; str_2 = "This string is 30 bytes long.";
392+
CloudString str_3; str_3 = "This string is 30 bytes long.";
393+
CloudString str_4; str_4 = "This string is 30 bytes long.";
394+
CloudString str_5; str_5 = "This string is 30 bytes long.";
395+
CloudString str_6; str_6 = "This string is 30 bytes long.";
396+
CloudString str_7; str_7 = "This string is 30 bytes long.";
397+
CloudString str_8; str_8 = "This string is 30 bytes long.";
398+
CloudString str_9; str_9 = "This string is 30 bytes long.";
399+
400+
addPropertyToContainer(property_container, str_0, "str_0", Permission::ReadWrite);
401+
addPropertyToContainer(property_container, str_1, "str_1", Permission::ReadWrite);
402+
addPropertyToContainer(property_container, str_2, "str_2", Permission::ReadWrite);
403+
addPropertyToContainer(property_container, str_3, "str_3", Permission::ReadWrite);
404+
addPropertyToContainer(property_container, str_4, "str_4", Permission::ReadWrite);
405+
addPropertyToContainer(property_container, str_5, "str_5", Permission::ReadWrite);
406+
addPropertyToContainer(property_container, str_6, "str_6", Permission::ReadWrite);
407+
addPropertyToContainer(property_container, str_7, "str_7", Permission::ReadWrite);
408+
addPropertyToContainer(property_container, str_8, "str_8", Permission::ReadWrite);
409+
addPropertyToContainer(property_container, str_9, "str_9", Permission::ReadWrite);
410+
411+
/* Due to the size if the encoded properties exceeding 256 bytes if encoded all at
412+
* once they are encoded in subsequent calls to CBOREncoder::encode.
413+
*/
414+
415+
/* [{0: "str_0", 3: "This string is 30 bytes long."}, {0: "str_1", 3: "This string is 30 bytes long."}, {0: "str_2", 3: "This string is 30 bytes long."}, {0: "str_3", 3: "This string is 30 bytes long."}]
416+
* = 9F A2 00 65 73 74 72 5F 30 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 31 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 32 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 33 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E FF
417+
*/
418+
std::vector<uint8_t> const expected_1 = {0x9F, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x30, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x31, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x32, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x33, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xFF};
419+
std::vector<uint8_t> const actual_1 = cbor::encode(property_container);
420+
REQUIRE(actual_1 == expected_1);
421+
422+
/* [{0: "str_4", 3: "This string is 30 bytes long."}, {0: "str_5", 3: "This string is 30 bytes long."}, {0: "str_6", 3: "This string is 30 bytes long."}, {0: "str_7", 3: "This string is 30 bytes long."}]
423+
* = 9F A2 00 65 73 74 72 5F 34 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 35 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 36 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 37 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E FF
424+
*/
425+
std::vector<uint8_t> const expected_2 = {0x9F, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x34, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x35, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x36, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x37, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xFF};
426+
std::vector<uint8_t> const actual_2 = cbor::encode(property_container);
427+
REQUIRE(actual_2 == expected_2);
428+
429+
/* [{0: "str_8", 3: "This string is 30 bytes long."}, {0: "str_9", 3: "This string is 30 bytes long."}]
430+
* = 9F A2 00 65 73 74 72 5F 38 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E A2 00 65 73 74 72 5F 39 03 78 1D 54 68 69 73 20 73 74 72 69 6E 67 20 69 73 20 33 30 20 62 79 74 65 73 20 6C 6F 6E 67 2E FF
431+
*/
432+
std::vector<uint8_t> const expected_3 = {0x9F, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x38, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xA2, 0x00, 0x65, 0x73, 0x74, 0x72, 0x5F, 0x39, 0x03, 0x78, 0x1D, 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20, 0x33, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x6C, 0x6F, 0x6E, 0x67, 0x2E, 0xFF};
433+
std::vector<uint8_t> const actual_3 = cbor::encode(property_container);
434+
REQUIRE(actual_3 == expected_3);
435+
}
436+
}
437+
438+
/************************************************************************************/
384439
}

extras/test/src/util/CBORTestUtil.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ namespace cbor
2525
**************************************************************************************/
2626

2727
std::vector<uint8_t> encode(PropertyContainer & property_container, bool lightPayload) {
28+
int bytes_encoded = 0;
2829
uint8_t buf[200] = {0};
29-
int const bytes_buf = CBOREncoder::encode(property_container, buf, 200, lightPayload);
30-
if (bytes_buf == -1) {
30+
31+
if (CBOREncoder::encode(property_container, buf, 200, bytes_encoded, lightPayload) == CborNoError)
32+
return std::vector<uint8_t>(buf, buf + bytes_encoded);
33+
else
3134
return std::vector<uint8_t>();
32-
} else {
33-
return std::vector<uint8_t>(buf, buf + bytes_buf);
34-
}
3535
}
3636

3737
void print(std::vector<uint8_t> const & vect) {

src/ArduinoIoTCloudLPWAN.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ void ArduinoIoTCloudLPWAN::disconnect()
126126

127127
void ArduinoIoTCloudLPWAN::sendPropertiesToCloud()
128128
{
129+
int bytes_encoded = 0;
129130
uint8_t data[CBOR_LORA_MSG_MAX_SIZE];
130-
int const length = CBOREncoder::encode(_property_container, data, sizeof(data), true);
131-
if (length > 0) {
132-
writeProperties(data, length);
133-
}
131+
132+
if (CBOREncoder::encode(_property_container, data, sizeof(data), bytes_encoded, true) == CborNoError)
133+
if (bytes_encoded > 0)
134+
writeProperties(data, bytes_encoded);
134135
}
135136

136137
int ArduinoIoTCloudLPWAN::writeProperties(const byte data[], int length)

src/ArduinoIoTCloudTCP.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,20 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
283283

284284
void ArduinoIoTCloudTCP::sendPropertiesToCloud()
285285
{
286+
int bytes_encoded = 0;
286287
uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE];
287-
int const length = CBOREncoder::encode(_property_container, data, sizeof(data));
288-
if (length > 0)
289-
{
290-
/* If properties have been encoded store them in the back-up buffer
291-
* in order to allow retransmission in case of failure.
292-
*/
293-
_mqtt_data_len = length;
294-
memcpy(_mqtt_data_buf, data, _mqtt_data_len);
295-
/* Transmit the properties to the MQTT broker */
296-
write(_dataTopicOut, _mqtt_data_buf, _mqtt_data_len);
297-
}
288+
289+
if (CBOREncoder::encode(_property_container, data, sizeof(data), bytes_encoded, false) == CborNoError)
290+
if (bytes_encoded > 0)
291+
{
292+
/* If properties have been encoded store them in the back-up buffer
293+
* in order to allow retransmission in case of failure.
294+
*/
295+
_mqtt_data_len = bytes_encoded;
296+
memcpy(_mqtt_data_buf, data, _mqtt_data_len);
297+
/* Transmit the properties to the MQTT broker */
298+
write(_dataTopicOut, _mqtt_data_buf, _mqtt_data_len);
299+
}
298300
}
299301

300302
void ArduinoIoTCloudTCP::requestLastValue()

src/cbor/CBOREncoder.cpp

+31-9
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,53 @@
2121

2222
#include "CBOREncoder.h"
2323

24+
#undef max
25+
#undef min
26+
#include <algorithm>
27+
2428
#include "lib/tinycbor/cbor-lib.h"
2529

2630
/******************************************************************************
2731
* PUBLIC MEMBER FUNCTIONS
2832
******************************************************************************/
2933

30-
int CBOREncoder::encode(PropertyContainer & property_container, uint8_t * data, size_t const size, bool lightPayload)
34+
CborError CBOREncoder::encode(PropertyContainer & property_container, uint8_t * data, size_t const size, int & bytes_encoded, bool lightPayload)
3135
{
3236
CborEncoder encoder, arrayEncoder;
3337

3438
cbor_encoder_init(&encoder, data, size, 0);
3539

36-
if (cbor_encoder_create_array(&encoder, &arrayEncoder, CborIndefiniteLength) != CborNoError)
37-
return -1;
40+
CHECK_CBOR(cbor_encoder_create_array(&encoder, &arrayEncoder, CborIndefiniteLength));
3841

3942
/* Check if backing storage and cloud has diverged
4043
* time interval may be elapsed or property may be changed
4144
* and if that's the case encode the property into the CBOR.
4245
*/
43-
if (appendChangedProperties(property_container, &arrayEncoder, lightPayload) < 1)
44-
return -1;
46+
CborError error = CborNoError;
47+
int num_encoded_properties = 0;
48+
std::for_each(property_container.begin(),
49+
property_container.end(),
50+
[lightPayload, &arrayEncoder, &error, &num_encoded_properties](Property * p)
51+
{
52+
if (p->shouldBeUpdated() && p->isReadableByCloud())
53+
{
54+
error = p->append(&arrayEncoder, lightPayload);
55+
if(error == CborNoError)
56+
num_encoded_properties++;
57+
else
58+
return;
59+
}
60+
});
61+
if ((CborNoError != error) &&
62+
(CborErrorOutOfMemory != error))
63+
return error;
64+
65+
CHECK_CBOR(cbor_encoder_close_container(&encoder, &arrayEncoder));
4566

46-
if (cbor_encoder_close_container(&encoder, &arrayEncoder) != CborNoError)
47-
return -1;
67+
if (num_encoded_properties > 0)
68+
bytes_encoded = cbor_encoder_get_buffer_size(&encoder, data);
69+
else
70+
bytes_encoded = 0;
4871

49-
int const bytes_encoded = cbor_encoder_get_buffer_size(&encoder, data);
50-
return bytes_encoded;
72+
return CborNoError;
5173
}

src/cbor/CBOREncoder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CBOREncoder
3535

3636
/* encode return > 0 if a property has changed and encodes the changed properties in CBOR format into the provided buffer */
3737
/* if lightPayload is true the integer identifier of the property will be encoded in the message instead of the property name in order to reduce the size of the message payload*/
38-
static int encode(PropertyContainer & property_container, uint8_t * data, size_t const size, bool lightPayload = false);
38+
static CborError encode(PropertyContainer & property_container, uint8_t * data, size_t const size, int & bytes_encoded, bool lightPayload = false);
3939

4040
private:
4141

src/cbor/lib/tinycbor/cbor-lib.h

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
#ifndef CBOR_LIB_H
22
#define CBOR_LIB_H
33

4+
/******************************************************************************
5+
INCLUDE
6+
******************************************************************************/
7+
48
#include "src/cbor.h"
59

10+
/******************************************************************************
11+
* DEFINE
12+
******************************************************************************/
13+
14+
#ifndef CHECK_CBOR
15+
#define CHECK_CBOR(expr) \
16+
do { \
17+
CborError error = CborNoError; \
18+
error = (expr); \
19+
if (CborNoError != error) \
20+
return error; \
21+
} while(0);
22+
#endif /* CHECK_CBOR */
23+
624
#endif

src/property/Property.cpp

+43-29
Original file line numberDiff line numberDiff line change
@@ -142,78 +142,92 @@ void Property::execCallbackOnSync() {
142142
}
143143
}
144144

145-
void Property::append(CborEncoder *encoder, bool lightPayload) {
145+
CborError Property::append(CborEncoder *encoder, bool lightPayload) {
146146
_lightPayload = lightPayload;
147147
_attributeIdentifier = 0;
148-
appendAttributesToCloudReal(encoder);
148+
CHECK_CBOR(appendAttributesToCloudReal(encoder));
149149
fromLocalToCloud();
150150
_has_been_updated_once = true;
151151
_update_requested = false;
152152
_last_updated_millis = millis();
153+
return CborNoError;
153154
}
154155

155-
void Property::appendAttributeReal(bool value, String attributeName, CborEncoder *encoder) {
156-
appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) {
157-
cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::BooleanValue));
158-
cbor_encode_boolean(&mapEncoder, value);
156+
CborError Property::appendAttributeReal(bool value, String attributeName, CborEncoder *encoder) {
157+
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
158+
{
159+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::BooleanValue)));
160+
CHECK_CBOR(cbor_encode_boolean(&mapEncoder, value));
161+
return CborNoError;
159162
}, encoder);
160163
}
161164

162-
void Property::appendAttributeReal(int value, String attributeName, CborEncoder *encoder) {
163-
appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) {
164-
cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value));
165-
cbor_encode_int(&mapEncoder, value);
165+
CborError Property::appendAttributeReal(int value, String attributeName, CborEncoder *encoder) {
166+
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
167+
{
168+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
169+
CHECK_CBOR(cbor_encode_int(&mapEncoder, value));
170+
return CborNoError;
166171
}, encoder);
167172
}
168173

169-
void Property::appendAttributeReal(float value, String attributeName, CborEncoder *encoder) {
170-
appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) {
171-
cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value));
172-
cbor_encode_float(&mapEncoder, value);
174+
CborError Property::appendAttributeReal(float value, String attributeName, CborEncoder *encoder) {
175+
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
176+
{
177+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
178+
CHECK_CBOR(cbor_encode_float(&mapEncoder, value));
179+
return CborNoError;
173180
}, encoder);
174181
}
175182

176-
void Property::appendAttributeReal(String value, String attributeName, CborEncoder *encoder) {
177-
appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) {
178-
cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::StringValue));
179-
cbor_encode_text_stringz(&mapEncoder, value.c_str());
183+
CborError Property::appendAttributeReal(String value, String attributeName, CborEncoder *encoder) {
184+
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
185+
{
186+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::StringValue)));
187+
CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, value.c_str()));
188+
return CborNoError;
180189
}, encoder);
181190
}
182191

183-
void Property::appendAttributeName(String attributeName, std::function<void (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder) {
192+
CborError Property::appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder) {
184193
if (attributeName != "") {
185194
// when the attribute name string is not empty, the attribute identifier is incremented in order to be encoded in the message if the _lightPayload flag is set
186195
_attributeIdentifier++;
187196
}
188197
CborEncoder mapEncoder;
189198
unsigned int num_map_properties = _encode_timestamp ? 3 : 2;
190-
cbor_encoder_create_map(encoder, &mapEncoder, num_map_properties);
191-
cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Name));
199+
CHECK_CBOR(cbor_encoder_create_map(encoder, &mapEncoder, num_map_properties));
200+
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Name)));
192201

193202
// if _lightPayload is true, the property and attribute identifiers will be encoded instead of the property name
194-
if (_lightPayload) {
203+
if (_lightPayload)
204+
{
195205
// the most significant byte of the identifier to be encoded represent the property identifier
196206
int completeIdentifier = _attributeIdentifier * 256;
197207
// the least significant byte of the identifier to be encoded represent the attribute identifier
198208
completeIdentifier += _identifier;
199-
cbor_encode_int(&mapEncoder, completeIdentifier);
200-
} else {
209+
CHECK_CBOR(cbor_encode_int(&mapEncoder, completeIdentifier));
210+
}
211+
else
212+
{
201213
String completeName = _name;
202214
if (attributeName != "") {
203215
completeName += ":" + attributeName;
204216
}
205-
cbor_encode_text_stringz(&mapEncoder, completeName.c_str());
217+
CHECK_CBOR(cbor_encode_text_stringz(&mapEncoder, completeName.c_str()));
206218
}
207219
/* Encode the value */
208-
appendValue(mapEncoder);
220+
CHECK_CBOR(appendValue(mapEncoder));
221+
209222
/* Encode the timestamp if that has been required. */
210223
if(_encode_timestamp)
211224
{
212-
cbor_encode_int (&mapEncoder, static_cast<int>(CborIntegerMapKey::Time));
213-
cbor_encode_uint(&mapEncoder, _timestamp);
225+
CHECK_CBOR(cbor_encode_int (&mapEncoder, static_cast<int>(CborIntegerMapKey::Time)));
226+
CHECK_CBOR(cbor_encode_uint(&mapEncoder, _timestamp));
214227
}
215228
/* Close the container */
216-
cbor_encoder_close_container(encoder, &mapEncoder);
229+
CHECK_CBOR(cbor_encoder_close_container(encoder, &mapEncoder));
230+
return CborNoError;
217231
}
218232

219233
void Property::setAttributesFromCloud(std::list<CborMapData> * map_data_list) {

0 commit comments

Comments
 (0)