Skip to content

Commit f16a696

Browse files
committed
Use a more fair way to send properties to the cloud
1 parent 7141e71 commit f16a696

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/cbor/CBOREncoder.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#undef max
2525
#undef min
2626
#include <algorithm>
27+
#include <iterator>
2728

2829
#include "lib/tinycbor/cbor-lib.h"
2930

@@ -45,9 +46,18 @@ CborError CBOREncoder::encode(PropertyContainer & property_container, uint8_t *
4546
*/
4647
CborError error = CborNoError;
4748
int num_encoded_properties = 0;
48-
std::for_each(property_container.begin(),
49+
int num_checked_properties = 0;
50+
static unsigned int last_property_index = 0;
51+
52+
if(last_property_index >= property_container.size())
53+
last_property_index = 0;
54+
55+
PropertyContainer::iterator iter = property_container.begin();
56+
std::advance(iter, last_property_index);
57+
58+
std::for_each(iter,
4959
property_container.end(),
50-
[lightPayload, &arrayEncoder, &error, &num_encoded_properties](Property * p)
60+
[lightPayload, &arrayEncoder, &error, &num_encoded_properties, &num_checked_properties](Property * p)
5161
{
5262
if(error == CborNoError)
5363
{
@@ -59,8 +69,12 @@ CborError CBOREncoder::encode(PropertyContainer & property_container, uint8_t *
5969
else
6070
return;
6171
}
72+
num_checked_properties++;
6273
}
6374
});
75+
76+
last_property_index += num_checked_properties;
77+
6478
if ((CborNoError != error) &&
6579
(CborErrorOutOfMemory != error))
6680
return error;

0 commit comments

Comments
 (0)