mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added JsonDocument::size()
				
					
				
			This commit is contained in:
		| @@ -6,7 +6,7 @@ HEAD | ||||
|  | ||||
| * Decode escaped Unicode characters like \u00DE (issue #304, PR #791) | ||||
|   Many thanks to Daniel Schulte (aka @trilader) who implemented this feature. | ||||
| * Add option ARDUINOJSON_DECODE_UNICODE to enable it | ||||
| * Added option ARDUINOJSON_DECODE_UNICODE to enable it | ||||
| * Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()` | ||||
| * Renamed `JsonArray::copyFrom()` and `JsonObject::copyFrom()` to `set()` | ||||
| * Renamed `JsonArray::get()` to `getElement()` | ||||
| @@ -16,6 +16,7 @@ HEAD | ||||
| * Fixed `JsonVariant::isNull()` not returning `true` after `set((char*)0)` | ||||
| * Fixed segfault after `variant.set(serialized((char*)0))` | ||||
| * Detect `IncompleteInput` in `false`, `true`, and `null` | ||||
| * Added `JsonDocument::size()` | ||||
|  | ||||
| v6.8.0-beta (2019-01-30) | ||||
| ----------- | ||||
|   | ||||
| @@ -57,6 +57,10 @@ class JsonDocument : public Visitable { | ||||
|     return _pool.capacity(); | ||||
|   } | ||||
|  | ||||
|   size_t size() const { | ||||
|     return _data.size(); | ||||
|   } | ||||
|  | ||||
|   bool set(const JsonDocument& src) { | ||||
|     return to<VariantRef>().set(src.as<VariantRef>()); | ||||
|   } | ||||
|   | ||||
| @@ -63,6 +63,10 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >, | ||||
|     return getUpstreamMember().template is<TValue>(); | ||||
|   } | ||||
|  | ||||
|   FORCE_INLINE size_t size() const { | ||||
|     return getUpstreamMember().size(); | ||||
|   } | ||||
|  | ||||
|   template <typename TValue> | ||||
|   FORCE_INLINE typename VariantTo<TValue>::type to() { | ||||
|     return getOrAddUpstreamMember().template to<TValue>(); | ||||
|   | ||||
| @@ -5,6 +5,7 @@ | ||||
| add_executable(ElementProxyTests | ||||
| 	add.cpp | ||||
| 	set.cpp | ||||
| 	size.cpp | ||||
| ) | ||||
|  | ||||
| target_link_libraries(ElementProxyTests catch) | ||||
|   | ||||
							
								
								
									
										30
									
								
								test/ElementProxy/size.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								test/ElementProxy/size.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| // ArduinoJson - arduinojson.org | ||||
| // Copyright Benoit Blanchon 2014-2019 | ||||
| // MIT License | ||||
|  | ||||
| #include <ArduinoJson.h> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| TEST_CASE("ElementProxy::size()") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|   doc.addElement(); | ||||
|   ElementProxy<JsonDocument&> ep = doc[0]; | ||||
|  | ||||
|   SECTION("returns 0") { | ||||
|     REQUIRE(ep.size() == 0); | ||||
|   } | ||||
|  | ||||
|   SECTION("as an array, returns 2") { | ||||
|     ep.add(1); | ||||
|     ep.add(2); | ||||
|     REQUIRE(ep.size() == 2); | ||||
|   } | ||||
|  | ||||
|   SECTION("as an object, returns 2") { | ||||
|     ep["a"] = 1; | ||||
|     ep["b"] = 2; | ||||
|     REQUIRE(ep.size() == 2); | ||||
|   } | ||||
| } | ||||
| @@ -8,6 +8,7 @@ add_executable(JsonDocumentTests | ||||
| 	DynamicJsonDocument.cpp | ||||
| 	isNull.cpp | ||||
| 	nesting.cpp | ||||
| 	size.cpp | ||||
| 	StaticJsonDocument.cpp | ||||
| 	subscript.cpp | ||||
| ) | ||||
|   | ||||
							
								
								
									
										28
									
								
								test/JsonDocument/size.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								test/JsonDocument/size.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| // ArduinoJson - arduinojson.org | ||||
| // Copyright Benoit Blanchon 2014-2019 | ||||
| // MIT License | ||||
|  | ||||
| #include <ArduinoJson.h> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| TEST_CASE("JsonDocument::size()") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|  | ||||
|   SECTION("returns 0") { | ||||
|     REQUIRE(doc.size() == 0); | ||||
|   } | ||||
|  | ||||
|   SECTION("as an array, return 2") { | ||||
|     doc.add(1); | ||||
|     doc.add(2); | ||||
|  | ||||
|     REQUIRE(doc.size() == 2); | ||||
|   } | ||||
|  | ||||
|   SECTION("as an object, return 2") { | ||||
|     doc["a"] = 1; | ||||
|     doc["b"] = 2; | ||||
|  | ||||
|     REQUIRE(doc.size() == 2); | ||||
|   } | ||||
| } | ||||
| @@ -6,6 +6,7 @@ add_executable(MemberProxyTests | ||||
| 	add.cpp | ||||
| 	subscript.cpp | ||||
| 	set.cpp | ||||
| 	size.cpp | ||||
| ) | ||||
|  | ||||
| target_link_libraries(MemberProxyTests catch) | ||||
|   | ||||
							
								
								
									
										31
									
								
								test/MemberProxy/size.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								test/MemberProxy/size.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| // ArduinoJson - arduinojson.org | ||||
| // Copyright Benoit Blanchon 2014-2019 | ||||
| // MIT License | ||||
|  | ||||
| #include <ArduinoJson.h> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| TEST_CASE("MemberProxy::size()") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; | ||||
|  | ||||
|   SECTION("returns 0") { | ||||
|     REQUIRE(mp.size() == 0); | ||||
|   } | ||||
|  | ||||
|   SECTION("as an array, return 2") { | ||||
|     mp.add(1); | ||||
|     mp.add(2); | ||||
|  | ||||
|     REQUIRE(mp.size() == 2); | ||||
|   } | ||||
|  | ||||
|   SECTION("as an object, return 2") { | ||||
|     mp["a"] = 1; | ||||
|     mp["b"] = 2; | ||||
|  | ||||
|     REQUIRE(mp.size() == 2); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user