Skip to content

Commit 03da4aa

Browse files
committed
MsgPackSerializer: use iterators to serialize array and objects
1 parent 60a767c commit 03da4aa

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/ArduinoJson/MsgPack/MsgPackSerializer.hpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ class MsgPackSerializer : public VariantDataVisitor<size_t> {
5959
writeInteger(uint32_t(n));
6060
}
6161

62-
auto slotId = array.head();
63-
while (slotId != NULL_SLOT) {
64-
auto slot = resources_->getVariant(slotId);
65-
VariantImpl(slot, resources_).accept(*this);
66-
slotId = slot->next;
67-
}
62+
for (auto it = array.createIterator(); !it.done(); it.move())
63+
it->accept(*this);
6864

6965
return bytesWritten();
7066
}
@@ -81,12 +77,8 @@ class MsgPackSerializer : public VariantDataVisitor<size_t> {
8177
writeInteger(uint32_t(n));
8278
}
8379

84-
auto slotId = object.head();
85-
while (slotId != NULL_SLOT) {
86-
auto slot = resources_->getVariant(slotId);
87-
VariantImpl(slot, resources_).accept(*this);
88-
slotId = slot->next;
89-
}
80+
for (auto it = object.createIterator(); !it.done(); it.move())
81+
it->accept(*this);
9082

9183
return bytesWritten();
9284
}

src/ArduinoJson/Variant/VariantImpl.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ class VariantImpl {
266266
}
267267
#endif
268268

269-
SlotId head() const {
270-
return getCollectionData()->head;
271-
}
272-
273269
iterator createIterator() const;
274270

275271
VariantData* getElement(size_t index) const;

0 commit comments

Comments
 (0)