Przeglądaj źródła

MsgPackSerializer: use iterators to serialize array and objects

Benoit Blanchon 7 miesięcy temu
rodzic
commit
03da4aad99

+ 4 - 12
src/ArduinoJson/MsgPack/MsgPackSerializer.hpp

@@ -59,12 +59,8 @@ class MsgPackSerializer : public VariantDataVisitor<size_t> {
       writeInteger(uint32_t(n));
     }
 
-    auto slotId = array.head();
-    while (slotId != NULL_SLOT) {
-      auto slot = resources_->getVariant(slotId);
-      VariantImpl(slot, resources_).accept(*this);
-      slotId = slot->next;
-    }
+    for (auto it = array.createIterator(); !it.done(); it.move())
+      it->accept(*this);
 
     return bytesWritten();
   }
@@ -81,12 +77,8 @@ class MsgPackSerializer : public VariantDataVisitor<size_t> {
       writeInteger(uint32_t(n));
     }
 
-    auto slotId = object.head();
-    while (slotId != NULL_SLOT) {
-      auto slot = resources_->getVariant(slotId);
-      VariantImpl(slot, resources_).accept(*this);
-      slotId = slot->next;
-    }
+    for (auto it = object.createIterator(); !it.done(); it.move())
+      it->accept(*this);
 
     return bytesWritten();
   }

+ 0 - 4
src/ArduinoJson/Variant/VariantImpl.hpp

@@ -266,10 +266,6 @@ class VariantImpl {
   }
 #endif
 
-  SlotId head() const {
-    return getCollectionData()->head;
-  }
-
   iterator createIterator() const;
 
   VariantData* getElement(size_t index) const;