Skip to content

Commit d397dc4

Browse files
committed
MsgPackSerializer: use iterators to serialize array and objects
1 parent 8ff4dd9 commit d397dc4

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
@@ -250,10 +250,6 @@ class VariantImpl {
250250
}
251251
#endif
252252

253-
SlotId head() const {
254-
return getCollectionData()->head;
255-
}
256-
257253
iterator createIterator() const;
258254

259255
VariantData* getElement(size_t index) const;

0 commit comments

Comments
 (0)