mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-29 10:17:39 +02:00
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:
@ -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
|
||||
|
@ -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") {
|
||||
|
Reference in New Issue
Block a user