forked from bblanchon/ArduinoJson
Fix JsonVariant::memoryUsage()
for raw strings
This commit is contained in:
@ -11,6 +11,7 @@ HEAD
|
||||
* Add `as<JsonString>()` and `is<JsonString>()`
|
||||
* Add safe bool idiom in `JsonString`
|
||||
* Remove `DeserializationError == bool` and `DeserializationError != bool`
|
||||
* Fix `JsonVariant::memoryUsage()` for raw strings
|
||||
|
||||
v6.18.5 (2021-09-28)
|
||||
-------
|
||||
|
@ -30,10 +30,12 @@ TEST_CASE("JsonVariant::memoryUsage()") {
|
||||
SECTION("returns size of owned string") {
|
||||
var.set(std::string("hello"));
|
||||
REQUIRE(var.memoryUsage() == 6);
|
||||
REQUIRE(var.memoryUsage() == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("returns size of owned raw") {
|
||||
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:
|
||||
return strlen(_content.asString) + 1;
|
||||
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_ARRAY:
|
||||
return _content.asCollection.memoryUsage();
|
||||
|
Reference in New Issue
Block a user