mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fix JsonVariant::memoryUsage() for raw strings
				
					
				
			This commit is contained in:
		| @@ -11,6 +11,7 @@ HEAD | |||||||
| * Add `as<JsonString>()` and `is<JsonString>()` | * Add `as<JsonString>()` and `is<JsonString>()` | ||||||
| * Add safe bool idiom in `JsonString` | * Add safe bool idiom in `JsonString` | ||||||
| * Remove `DeserializationError == bool` and `DeserializationError != bool` | * Remove `DeserializationError == bool` and `DeserializationError != bool` | ||||||
|  | * Fix `JsonVariant::memoryUsage()` for raw strings | ||||||
|  |  | ||||||
| v6.18.5 (2021-09-28) | v6.18.5 (2021-09-28) | ||||||
| ------- | ------- | ||||||
|   | |||||||
| @@ -30,10 +30,12 @@ TEST_CASE("JsonVariant::memoryUsage()") { | |||||||
|   SECTION("returns size of owned string") { |   SECTION("returns size of owned string") { | ||||||
|     var.set(std::string("hello")); |     var.set(std::string("hello")); | ||||||
|     REQUIRE(var.memoryUsage() == 6); |     REQUIRE(var.memoryUsage() == 6); | ||||||
|  |     REQUIRE(var.memoryUsage() == doc.memoryUsage()); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   SECTION("returns size of owned raw") { |   SECTION("returns size of owned raw") { | ||||||
|     var.set(serialized(std::string("hello"))); |     var.set(serialized(std::string("hello"))); | ||||||
|     REQUIRE(var.memoryUsage() == 5); |     REQUIRE(var.memoryUsage() == 6); | ||||||
|  |     REQUIRE(var.memoryUsage() == doc.memoryUsage()); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -257,7 +257,9 @@ class VariantData { | |||||||
|       case VALUE_IS_OWNED_STRING: |       case VALUE_IS_OWNED_STRING: | ||||||
|         return strlen(_content.asString) + 1; |         return strlen(_content.asString) + 1; | ||||||
|       case VALUE_IS_OWNED_RAW: |       case VALUE_IS_OWNED_RAW: | ||||||
|         return _content.asRaw.size; |         // We always add a zero at the end: the deduplication function uses it | ||||||
|  |         // to detect the beginning of the next string. | ||||||
|  |         return _content.asRaw.size + 1; | ||||||
|       case VALUE_IS_OBJECT: |       case VALUE_IS_OBJECT: | ||||||
|       case VALUE_IS_ARRAY: |       case VALUE_IS_ARRAY: | ||||||
|         return _content.asCollection.memoryUsage(); |         return _content.asCollection.memoryUsage(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user