mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added support for JsonDocument to copyArray() (issue #1255)
				
					
				
			This commit is contained in:
		| @@ -5,6 +5,7 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <ArduinoJson/Array/ArrayRef.hpp> | ||||
| #include <ArduinoJson/Document/JsonDocument.hpp> | ||||
|  | ||||
| namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| @@ -14,6 +15,12 @@ inline bool copyArray(T (&src)[N], ArrayRef dst) { | ||||
|   return copyArray(src, N, dst); | ||||
| } | ||||
|  | ||||
| // Copy a 1D array to a JsonDocument | ||||
| template <typename T, size_t N> | ||||
| inline bool copyArray(T (&src)[N], JsonDocument& dst) { | ||||
|   return copyArray(src, dst.to<ArrayRef>()); | ||||
| } | ||||
|  | ||||
| // Copy a 1D array to a JsonArray | ||||
| template <typename T> | ||||
| inline bool copyArray(T* src, size_t len, ArrayRef dst) { | ||||
| @@ -24,6 +31,12 @@ inline bool copyArray(T* src, size_t len, ArrayRef dst) { | ||||
|   return ok; | ||||
| } | ||||
|  | ||||
| // Copy a 1D array to a JsonDocument | ||||
| template <typename T> | ||||
| inline bool copyArray(T* src, size_t len, JsonDocument& dst) { | ||||
|   return copyArray(src, len, dst.to<ArrayRef>()); | ||||
| } | ||||
|  | ||||
| // Copy a 2D array to a JsonArray | ||||
| template <typename T, size_t N1, size_t N2> | ||||
| inline bool copyArray(T (&src)[N1][N2], ArrayRef dst) { | ||||
| @@ -37,12 +50,24 @@ inline bool copyArray(T (&src)[N1][N2], ArrayRef dst) { | ||||
|   return ok; | ||||
| } | ||||
|  | ||||
| // Copy a 2D array to a JsonDocument | ||||
| template <typename T, size_t N1, size_t N2> | ||||
| inline bool copyArray(T (&src)[N1][N2], JsonDocument& dst) { | ||||
|   return copyArray(src, dst.to<ArrayRef>()); | ||||
| } | ||||
|  | ||||
| // Copy a JsonArray to a 1D array | ||||
| template <typename T, size_t N> | ||||
| inline size_t copyArray(ArrayConstRef src, T (&dst)[N]) { | ||||
|   return copyArray(src, dst, N); | ||||
| } | ||||
|  | ||||
| // Copy a JsonDocument to a 1D array | ||||
| template <typename T, size_t N> | ||||
| inline size_t copyArray(const JsonDocument& src, T (&dst)[N]) { | ||||
|   return copyArray(src.as<ArrayConstRef>(), dst, N); | ||||
| } | ||||
|  | ||||
| // Copy a JsonArray to a 1D array | ||||
| template <typename T> | ||||
| inline size_t copyArray(ArrayConstRef src, T* dst, size_t len) { | ||||
| @@ -63,4 +88,10 @@ inline void copyArray(ArrayConstRef src, T (&dst)[N1][N2]) { | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Copy a JsonDocument to a 2D array | ||||
| template <typename T, size_t N1, size_t N2> | ||||
| inline void copyArray(const JsonDocument& src, T (&dst)[N1][N2]) { | ||||
|   copyArray(src.as<ArrayConstRef>(), dst); | ||||
| } | ||||
|  | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
		Reference in New Issue
	
	Block a user