forked from bblanchon/ArduinoJson
Remove StoragePolicy
This commit is contained in:
@ -27,10 +27,14 @@ inline VariantData* collectionAddMember(CollectionData* obj, TAdaptedString key,
|
|||||||
auto slot = pool->allocVariant();
|
auto slot = pool->allocVariant();
|
||||||
if (!slot)
|
if (!slot)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto storedKey = storeString(pool, key);
|
if (key.isLinked())
|
||||||
if (!storedKey)
|
slot->setKey(JsonString(key.data(), key.size(), JsonString::Linked));
|
||||||
return nullptr;
|
else {
|
||||||
slot->setKey(storedKey);
|
auto storedKey = pool->saveString(key);
|
||||||
|
if (!storedKey)
|
||||||
|
return nullptr;
|
||||||
|
slot->setKey(JsonString(storedKey, key.size(), JsonString::Copied));
|
||||||
|
}
|
||||||
obj->add(slot);
|
obj->add(slot);
|
||||||
return slot->data();
|
return slot->data();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ArduinoJson/Collection/CollectionData.hpp>
|
#include <ArduinoJson/Collection/CollectionData.hpp>
|
||||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
|
||||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include <ArduinoJson/Object/JsonObject.hpp>
|
#include <ArduinoJson/Object/JsonObject.hpp>
|
||||||
#include <ArduinoJson/Object/MemberProxy.hpp>
|
#include <ArduinoJson/Object/MemberProxy.hpp>
|
||||||
#include <ArduinoJson/Polyfills/utility.hpp>
|
#include <ArduinoJson/Polyfills/utility.hpp>
|
||||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
|
||||||
#include <ArduinoJson/Variant/JsonVariantConst.hpp>
|
#include <ArduinoJson/Variant/JsonVariantConst.hpp>
|
||||||
#include <ArduinoJson/Variant/VariantTo.hpp>
|
#include <ArduinoJson/Variant/VariantTo.hpp>
|
||||||
|
|
||||||
|
@ -296,30 +296,4 @@ class MemoryPool {
|
|||||||
StringNode* strings_ = nullptr;
|
StringNode* strings_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
|
||||||
JsonString storeString(MemoryPool* pool, TAdaptedString str,
|
|
||||||
StringStoragePolicy::Copy) {
|
|
||||||
return JsonString(pool->saveString(str), str.size(), JsonString::Copied);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
|
||||||
JsonString storeString(MemoryPool*, TAdaptedString str,
|
|
||||||
StringStoragePolicy::Link) {
|
|
||||||
return JsonString(str.data(), str.size(), JsonString::Linked);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
|
||||||
JsonString storeString(MemoryPool* pool, TAdaptedString str,
|
|
||||||
StringStoragePolicy::LinkOrCopy policy) {
|
|
||||||
if (policy.link)
|
|
||||||
return storeString(pool, str, StringStoragePolicy::Link());
|
|
||||||
else
|
|
||||||
return storeString(pool, str, StringStoragePolicy::Copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
|
||||||
JsonString storeString(MemoryPool* pool, TAdaptedString str) {
|
|
||||||
return storeString(pool, str, str.storagePolicy());
|
|
||||||
}
|
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||||
|
@ -26,6 +26,10 @@ class FlashString {
|
|||||||
return static_cast<char>(pgm_read_byte(str_ + i));
|
return static_cast<char>(pgm_read_byte(str_ + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* data() const {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
return size_;
|
return size_;
|
||||||
}
|
}
|
||||||
@ -59,8 +63,8 @@ class FlashString {
|
|||||||
::memcpy_P(p, s.str_, n);
|
::memcpy_P(p, s.str_, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringStoragePolicy::Copy storagePolicy() const {
|
bool isLinked() const {
|
||||||
return StringStoragePolicy::Copy();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -15,9 +15,8 @@ class JsonStringAdapter : public SizedRamString {
|
|||||||
JsonStringAdapter(const JsonString& s)
|
JsonStringAdapter(const JsonString& s)
|
||||||
: SizedRamString(s.c_str(), s.size()), linked_(s.isLinked()) {}
|
: SizedRamString(s.c_str(), s.size()), linked_(s.isLinked()) {}
|
||||||
|
|
||||||
StringStoragePolicy::LinkOrCopy storagePolicy() const {
|
bool isLinked() const {
|
||||||
StringStoragePolicy::LinkOrCopy policy = {linked_};
|
return linked_;
|
||||||
return policy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <string.h> // strcmp
|
#include <string.h> // strcmp
|
||||||
|
|
||||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
|
||||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||||
@ -53,8 +52,8 @@ class ZeroTerminatedRamString {
|
|||||||
return stringCompare(a, b) == 0;
|
return stringCompare(a, b) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringStoragePolicy::Copy storagePolicy() const {
|
bool isLinked() const {
|
||||||
return StringStoragePolicy::Copy();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -83,8 +82,8 @@ class StaticStringAdapter : public ZeroTerminatedRamString {
|
|||||||
public:
|
public:
|
||||||
StaticStringAdapter(const char* str) : ZeroTerminatedRamString(str) {}
|
StaticStringAdapter(const char* str) : ZeroTerminatedRamString(str) {}
|
||||||
|
|
||||||
StringStoragePolicy::Link storagePolicy() const {
|
bool isLinked() const {
|
||||||
return StringStoragePolicy::Link();
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,8 +120,8 @@ class SizedRamString {
|
|||||||
return str_;
|
return str_;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringStoragePolicy::Copy storagePolicy() const {
|
bool isLinked() const {
|
||||||
return StringStoragePolicy::Copy();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
// ArduinoJson - https://arduinojson.org
|
|
||||||
// Copyright © 2014-2023, Benoit BLANCHON
|
|
||||||
// MIT License
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
|
||||||
|
|
||||||
namespace StringStoragePolicy {
|
|
||||||
|
|
||||||
struct Link {};
|
|
||||||
struct Copy {};
|
|
||||||
struct LinkOrCopy {
|
|
||||||
bool link;
|
|
||||||
};
|
|
||||||
} // namespace StringStoragePolicy
|
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include <ArduinoJson/Polyfills/assert.hpp>
|
#include <ArduinoJson/Polyfills/assert.hpp>
|
||||||
#include <ArduinoJson/Polyfills/attributes.hpp>
|
#include <ArduinoJson/Polyfills/attributes.hpp>
|
||||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
|
||||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||||
#include <ArduinoJson/Variant/Visitor.hpp>
|
#include <ArduinoJson/Variant/Visitor.hpp>
|
||||||
|
|
||||||
@ -59,18 +58,18 @@ inline bool variantCopyFrom(VariantData* dst, const VariantData* src,
|
|||||||
return collectionCopy(&dst->toObject(), src->asObject(), pool);
|
return collectionCopy(&dst->toObject(), src->asObject(), pool);
|
||||||
case VALUE_IS_OWNED_STRING: {
|
case VALUE_IS_OWNED_STRING: {
|
||||||
auto str = adaptString(src->asString());
|
auto str = adaptString(src->asString());
|
||||||
auto dup = storeString(pool, str, StringStoragePolicy::Copy());
|
auto dup = pool->saveString(str);
|
||||||
if (!dup)
|
if (!dup)
|
||||||
return false;
|
return false;
|
||||||
dst->setString(dup);
|
dst->setString(JsonString(dup, str.size(), JsonString::Copied));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case VALUE_IS_RAW_STRING: {
|
case VALUE_IS_RAW_STRING: {
|
||||||
auto str = adaptString(src->asRawString());
|
auto str = adaptString(src->asRawString());
|
||||||
auto dup = storeString(pool, str, StringStoragePolicy::Copy());
|
auto dup = pool->saveString(str);
|
||||||
if (!dup)
|
if (!dup)
|
||||||
return false;
|
return false;
|
||||||
dst->setRawString(dup.c_str(), str.size());
|
dst->setRawString(dup, str.size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -115,9 +114,20 @@ inline void variantSetString(VariantData* var, TAdaptedString value,
|
|||||||
if (!var)
|
if (!var)
|
||||||
return;
|
return;
|
||||||
variantRelease(var, pool);
|
variantRelease(var, pool);
|
||||||
JsonString str = storeString(pool, value);
|
|
||||||
if (str)
|
if (value.isNull()) {
|
||||||
var->setString(str);
|
var->setNull();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.isLinked()) {
|
||||||
|
var->setString(JsonString(value.data(), value.size(), JsonString::Linked));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dup = pool->saveString(value);
|
||||||
|
if (dup)
|
||||||
|
var->setString(JsonString(dup, value.size(), JsonString::Copied));
|
||||||
else
|
else
|
||||||
var->setNull();
|
var->setNull();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user