Skip to content

Commit 6cdd63b

Browse files
fixup! implementing cbor message decoder following cloud utils definition
1 parent 6baf58d commit 6cdd63b

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

src/cbor/IoTCloudMessageDecoder.cpp

+28-18
Original file line numberDiff line numberDiff line change
@@ -80,44 +80,54 @@ MessageDecoder::Status TimezoneCommandDownDecoder::decode(CborValue* iter, Messa
8080

8181
// Message is composed of 2 parameters, offset 32-bit signed integer and until 32-bit unsigned integer
8282
// Get offset
83-
if (cbor_value_is_integer(iter)) {
84-
int64_t val = 0;
85-
if (cbor_value_get_int64(iter, &val) == CborNoError) {
86-
setTz->params.offset = static_cast<int32_t>(val);
87-
}
83+
if (!cbor_value_is_integer(iter)) {
84+
return MessageDecoder::Status::Error;
85+
}
86+
87+
int64_t val = 0;
88+
if (cbor_value_get_int64(iter, &val) != CborNoError) {
89+
return MessageDecoder::Status::Error;
8890
}
8991

92+
setTz->params.offset = static_cast<int32_t>(val);
93+
9094
// Next
9195
if (cbor_value_advance(iter) != CborNoError) {
9296
return MessageDecoder::Status::Error;
9397
}
9498

9599
// Get until
96-
if (cbor_value_is_integer(iter)) {
97-
uint64_t val = 0;
98-
if (cbor_value_get_uint64(iter, &val) == CborNoError) {
99-
setTz->params.until = static_cast<uint32_t>(val);
100-
}
100+
if (!cbor_value_is_integer(iter)) {
101+
return MessageDecoder::Status::Error;
101102
}
102103

104+
uint64_t val1 = 0;
105+
if (cbor_value_get_uint64(iter, &val1) != CborNoError) {
106+
return MessageDecoder::Status::Error;
107+
}
108+
109+
setTz->params.until = static_cast<uint32_t>(val1);
110+
103111
return MessageDecoder::Status::Complete;
104112
}
105113

106114
MessageDecoder::Status LastValuesUpdateCommandDecoder::decode(CborValue* iter, Message *msg) {
107115
LastValuesUpdateCmd * setLv = (LastValuesUpdateCmd *) msg;
108116

109117
// Message is composed by a single parameter, a variable length byte array.
110-
if (cbor_value_is_byte_string(iter)) {
111-
// Cortex M0 is not able to assign a value to pointed memory that is not 32bit aligned
112-
// we use a support variable to cope with that
113-
size_t s;
114-
if (cbor_value_dup_byte_string(iter, &setLv->params.last_values, &s, NULL) != CborNoError) {
115-
return MessageDecoder::Status::Error;
116-
}
118+
if (!cbor_value_is_byte_string(iter)) {
119+
return MessageDecoder::Status::Error;
120+
}
117121

118-
setLv->params.length = s;
122+
// Cortex M0 is not able to assign a value to pointed memory that is not 32bit aligned
123+
// we use a support variable to cope with that
124+
size_t s;
125+
if (cbor_value_dup_byte_string(iter, &setLv->params.last_values, &s, NULL) != CborNoError) {
126+
return MessageDecoder::Status::Error;
119127
}
120128

129+
setLv->params.length = s;
130+
121131
return MessageDecoder::Status::Complete;
122132
}
123133

0 commit comments

Comments
 (0)