30
30
/* *****************************************************************************
31
31
* PUBLIC MEMBER FUNCTIONS
32
32
******************************************************************************/
33
- # include < iostream >
33
+
34
34
CborError CBOREncoder::encode (PropertyContainer & property_container, uint8_t * data, size_t const size, int & bytes_encoded, bool lightPayload)
35
35
{
36
- CborError error = CborNoError;
37
36
CborEncoder encoder, arrayEncoder;
38
37
39
38
cbor_encoder_init (&encoder, data, size, 0 );
40
39
41
- error = cbor_encoder_create_array (&encoder, &arrayEncoder, CborIndefiniteLength);
42
- if (CborNoError != error)
43
- return error;
40
+ CHECK_CBOR (cbor_encoder_create_array (&encoder, &arrayEncoder, CborIndefiniteLength));
44
41
45
42
/* Check if backing storage and cloud has diverged
46
43
* time interval may be elapsed or property may be changed
47
44
* and if that's the case encode the property into the CBOR.
48
45
*/
46
+ CborError error = CborNoError;
49
47
int num_encoded_properties = 0 ;
50
48
std::for_each (property_container.begin (),
51
49
property_container.end (),
@@ -64,9 +62,7 @@ CborError CBOREncoder::encode(PropertyContainer & property_container, uint8_t *
64
62
(CborErrorOutOfMemory != error))
65
63
return error;
66
64
67
- error = cbor_encoder_close_container (&encoder, &arrayEncoder);
68
- if (CborNoError != error)
69
- return error;
65
+ CHECK_CBOR (cbor_encoder_close_container (&encoder, &arrayEncoder));
70
66
71
67
if (num_encoded_properties > 0 )
72
68
bytes_encoded = cbor_encoder_get_buffer_size (&encoder, data);
0 commit comments