Remove the zero-copy mode

After removing the string size from `VariantContent`, `deserializeJson()` and `deserializeMsgPack()` could not support NUL in strings in the zero-copy mode anymore.
Instead of adding a complicated warning in the documentation, I thought it was better to remove the zero-copy mode entirely.
The zero-copy mode has always been a source of bugs because many users used it without realizing it.
Also, the memory savings are smaller now that we deduplicate strings, so this feature should not be missed much.
This commit is contained in:
Benoit Blanchon committed 2023-05-10 09:55:21 +02:00
1 parent 9321f8fdab
commit 37357086e2
5 files changed
+6 -68

No files matched your search

@@ -10,20 +10,17 @@
#include "CustomReader.hpp"
using ArduinoJson::detail::sizeofObject;
using ArduinoJson::detail::sizeofString;
TEST_CASE("deserializeJson(char*)") {
JsonDocument doc(1024);
SECTION("should not duplicate strings") {
char input[] = "{\"hello\":\"world\"}";
char input[] = "{\"hello\":\"world\"}";
DeserializationError err = deserializeJson(doc, input);
DeserializationError err = deserializeJson(doc, input);
REQUIRE(err == DeserializationError::Ok);
CHECK(doc.memoryUsage() == sizeofObject(1));
CHECK(doc.as<JsonVariant>().memoryUsage() ==
sizeofObject(1)); // issue #1318
}
REQUIRE(err == DeserializationError::Ok);
CHECK(doc.memoryUsage() == sizeofObject(1) + 2 * sizeofString(5));
}
TEST_CASE("deserializeJson(unsigned char*, unsigned int)") { // issue #1897
-6
View File
@@ -154,12 +154,6 @@ TEST_CASE("String allocation fails") {
REQUIRE(spyingAllocator.log() ==
AllocatorLog() << AllocatorLog::AllocateFail(sizeofString(31)));
}
SECTION("Input is const char*") {
char hello[] = "\"hello\"";
REQUIRE(deserializeJson(doc, hello) == DeserializationError::Ok);
REQUIRE(spyingAllocator.log() == AllocatorLog());
}
}
TEST_CASE("Deduplicate values") {