// ArduinoJson - https://arduinojson.org // Copyright Benoit Blanchon 2014-2021 // MIT License #pragma once #include #include namespace ARDUINOJSON_NAMESPACE { // Trivial form to stop the recursion template inline typename enable_if::value, bool>::type copyArray( const T& src, VariantRef dst) { return dst.set(src); } // Copy array to a JsonArray/JsonVariant/MemberProxy/ElementProxy template inline typename enable_if::value, bool>::type copyArray(T (&src)[N], const TDestination& dst) { return copyArray(src, N, dst); } // Copy ptr+size to a JsonArray/JsonVariant/MemberProxy/ElementProxy template inline typename enable_if::value, bool>::type copyArray(const T* src, size_t len, const TDestination& dst) { bool ok = true; for (size_t i = 0; i < len; i++) { ok &= copyArray(src[i], dst.addElement()); } return ok; } // Special case for char[] which much be treated as const char* template inline bool copyArray(const char* src, size_t, const TDestination& dst) { return dst.set(src); } // Copy array to a JsonDocument template inline bool copyArray(const T& src, JsonDocument& dst) { return copyArray(src, dst.to()); } // Copy a ptr+size array to a JsonDocument template inline bool copyArray(const T* src, size_t len, JsonDocument& dst) { return copyArray(src, len, dst.to()); } // Trivial case form to stop the recursion template inline typename enable_if::value, size_t>::type copyArray( VariantConstRef src, T& dst) { dst = src.as(); return 1; } // Copy a JsonArray to array template inline size_t copyArray(ArrayConstRef src, T (&dst)[N]) { return copyArray(src, dst, N); } // Copy a JsonArray to ptr+size template inline size_t copyArray(ArrayConstRef src, T* dst, size_t len) { size_t i = 0; for (ArrayConstRef::iterator it = src.begin(); it != src.end() && i < len; ++it) copyArray(*it, dst[i++]); return i; } // Special case for char[] which must be treated as a string template inline size_t copyArray(VariantConstRef src, char (&dst)[N]) { String s = src; size_t len = N - 1; if (len > s.size()) len = s.size(); memcpy(dst, s.c_str(), len); dst[len] = 0; return 1; } // Copy a JsonDocument to an array // (JsonDocument doesn't implicitly convert to JsonArrayConst) template inline typename enable_if::value && is_base_of::value, size_t>::type copyArray(const TSource& src, T& dst) { return copyArray(src.template as(), dst); } } // namespace ARDUINOJSON_NAMESPACE