Skip to content

Commit caeeeec

Browse files
fixup! implementing cbor message decoder following cloud utils definition
1 parent 1328265 commit caeeeec

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: src/cbor/IoTCloudMessageDecoder.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,17 @@ MessageDecoder::Status TimezoneCommandDownDecoder::decode(CborValue* iter, Messa
114114
MessageDecoder::Status LastValuesUpdateCommandDecoder::decode(CborValue* iter, Message *msg) {
115115
LastValuesUpdateCmd * setLv = (LastValuesUpdateCmd *) msg;
116116

117+
if(!cbor_value_is_byte_string(iter)) {
118+
return MessageDecoder::Status::Error;
119+
}
120+
117121
// Cortex M0 is not able to assign a value to pointed memory that is not 32bit aligned
118122
// we use a support variable to cope with that
119123
size_t s;
124+
125+
// NOTE: cbor_value_dup_byte_string calls malloc and assigns it to the second parameter of the call,
126+
// free must be called. Free has to be called only if decode succeeds.
127+
// Read tinyCbor documentation for more information.
120128
if (cbor_value_dup_byte_string(iter, &setLv->params.last_values, &s, NULL) != CborNoError) {
121129
return MessageDecoder::Status::Error;
122130
}

0 commit comments

Comments
 (0)