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
2023-05-10 09:55:21 +02:00
parent 9321f8fdab
commit 37357086e2
5 changed files with 6 additions and 68 deletions
@@ -1,47 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/JsonString.hpp>
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
class StringMover {
public:
StringMover(char* ptr) : writePtr_(ptr) {}
void startString() {
startPtr_ = writePtr_;
}
FORCE_INLINE const char* save() {
*writePtr_++ = 0; // terminator
return startPtr_;
}
void append(char c) {
*writePtr_++ = c;
}
bool isValid() const {
return true;
}
JsonString str() const {
writePtr_[0] = 0; // terminator
return JsonString(startPtr_, size(), JsonString::Linked);
}
size_t size() const {
return size_t(writePtr_ - startPtr_);
}
private:
char* writePtr_;
char* startPtr_;
};
ARDUINOJSON_END_PRIVATE_NAMESPACE
@@ -5,7 +5,6 @@
#pragma once
#include <ArduinoJson/StringStorage/StringCopier.hpp>
#include <ArduinoJson/StringStorage/StringMover.hpp>
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
@@ -15,10 +14,4 @@ StringCopier makeStringStorage(TInput&, MemoryPool* pool) {
return StringCopier(pool);
}
template <typename TChar>
StringMover makeStringStorage(
TChar* input, MemoryPool*,
typename enable_if<!is_const<TChar>::value>::type* = 0) {
return StringMover(reinterpret_cast<char*>(input));
}
ARDUINOJSON_END_PRIVATE_NAMESPACE