@@ -142,78 +142,92 @@ void Property::execCallbackOnSync() {
142
142
}
143
143
}
144
144
145
- void Property::append (CborEncoder *encoder, bool lightPayload) {
145
+ CborError Property::append (CborEncoder *encoder, bool lightPayload) {
146
146
_lightPayload = lightPayload;
147
147
_attributeIdentifier = 0 ;
148
- appendAttributesToCloudReal (encoder);
148
+ CHECK_CBOR ( appendAttributesToCloudReal (encoder) );
149
149
fromLocalToCloud ();
150
150
_has_been_updated_once = true ;
151
151
_update_requested = false ;
152
152
_last_updated_millis = millis ();
153
+ return CborNoError;
153
154
}
154
155
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;
159
162
}, encoder);
160
163
}
161
164
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;
166
171
}, encoder);
167
172
}
168
173
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;
173
180
}, encoder);
174
181
}
175
182
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;
180
189
}, encoder);
181
190
}
182
191
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) {
184
193
if (attributeName != " " ) {
185
194
// 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
186
195
_attributeIdentifier++;
187
196
}
188
197
CborEncoder mapEncoder;
189
198
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) ));
192
201
193
202
// if _lightPayload is true, the property and attribute identifiers will be encoded instead of the property name
194
- if (_lightPayload) {
203
+ if (_lightPayload)
204
+ {
195
205
// the most significant byte of the identifier to be encoded represent the property identifier
196
206
int completeIdentifier = _attributeIdentifier * 256 ;
197
207
// the least significant byte of the identifier to be encoded represent the attribute identifier
198
208
completeIdentifier += _identifier;
199
- cbor_encode_int (&mapEncoder, completeIdentifier);
200
- } else {
209
+ CHECK_CBOR (cbor_encode_int (&mapEncoder, completeIdentifier));
210
+ }
211
+ else
212
+ {
201
213
String completeName = _name;
202
214
if (attributeName != " " ) {
203
215
completeName += " :" + attributeName;
204
216
}
205
- cbor_encode_text_stringz (&mapEncoder, completeName.c_str ());
217
+ CHECK_CBOR ( cbor_encode_text_stringz (&mapEncoder, completeName.c_str () ));
206
218
}
207
219
/* Encode the value */
208
- appendValue (mapEncoder);
220
+ CHECK_CBOR (appendValue (mapEncoder));
221
+
209
222
/* Encode the timestamp if that has been required. */
210
223
if (_encode_timestamp)
211
224
{
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) );
214
227
}
215
228
/* Close the container */
216
- cbor_encoder_close_container (encoder, &mapEncoder);
229
+ CHECK_CBOR (cbor_encoder_close_container (encoder, &mapEncoder));
230
+ return CborNoError;
217
231
}
218
232
219
233
void Property::setAttributesFromCloud (std::list<CborMapData> * map_data_list) {
0 commit comments