Skip to content

Commit 39a78e6

Browse files
committed
Directly integrate function for property encoding into CBOREncoder::encode
1 parent f5b729a commit 39a78e6

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/cbor/CBOREncoder.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
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
/******************************************************************************
@@ -40,10 +44,22 @@ int CBOREncoder::encode(PropertyContainer & property_container, uint8_t * data,
4044
* time interval may be elapsed or property may be changed
4145
* and if that's the case encode the property into the CBOR.
4246
*/
43-
CborError err = appendChangedProperties(property_container, &arrayEncoder, lightPayload);
47+
CborError err = CborNoError;
48+
std::for_each(property_container.begin(),
49+
property_container.end(),
50+
[lightPayload, &arrayEncoder, &err](Property * p)
51+
{
52+
if (p->shouldBeUpdated() && p->isReadableByCloud())
53+
{
54+
err = p->append(&arrayEncoder, lightPayload);
55+
if(err != CborNoError)
56+
return;
57+
}
58+
});
4459
if ((err != CborNoError) && (err != CborErrorOutOfMemory))
4560
return -1;
4661

62+
4763
if (cbor_encoder_close_container(&encoder, &arrayEncoder) != CborNoError)
4864
return -1;
4965

src/property/PropertyContainer.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,6 @@ Property * getProperty(PropertyContainer & prop_cont, int const identifier)
8383
return (*iter);
8484
}
8585

86-
CborError appendChangedProperties(PropertyContainer & prop_cont, CborEncoder * arrayEncoder, bool lightPayload)
87-
{
88-
CborError err = CborNoError;
89-
std::for_each(prop_cont.begin(),
90-
prop_cont.end(),
91-
[arrayEncoder, lightPayload, &err](Property * p)
92-
{
93-
if (p->shouldBeUpdated() && p->isReadableByCloud())
94-
{
95-
err = p->append(arrayEncoder, lightPayload);
96-
if(err != CborNoError)
97-
return;
98-
}
99-
});
100-
return err;
101-
}
102-
10386
void requestUpdateForAllProperties(PropertyContainer & prop_cont)
10487
{
10588
std::for_each(prop_cont.begin(),

src/property/PropertyContainer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ Property * getProperty(PropertyContainer & prop_cont, String const & name);
7878
Property * getProperty(PropertyContainer & prop_cont, int const identifier);
7979

8080

81-
CborError appendChangedProperties(PropertyContainer & prop_cont, CborEncoder * arrayEncoder, bool lightPayload);
8281
void updateTimestampOnLocallyChangedProperties(PropertyContainer & prop_cont);
8382
void requestUpdateForAllProperties(PropertyContainer & prop_cont);
8483
void updateProperty(PropertyContainer & prop_cont, String propertyName, unsigned long cloudChangeEventTime, bool const is_sync_message, std::list<CborMapData> * map_data_list);

0 commit comments

Comments
 (0)