README: added a link to ARDUINOJSON_ENABLE_ARDUINO_STREAM

This commit is contained in:
Benoit Blanchon
2021-03-29 09:20:49 +02:00
parent 347ac422f4
commit c81e8fc93a
3 changed files with 42 additions and 50 deletions

View File

@ -263,7 +263,7 @@ inline bool convertToJson(VariantRef variant, const ::Printable& value) {
data->setNull();
return false;
}
data->setOwnedString(print.c_str());
data->setStringPointer(print.c_str(), storage_policies::store_by_copy());
return true;
}

View File

@ -244,64 +244,21 @@ class VariantData {
setType(VALUE_IS_NULL);
}
void setOwnedString(const char *s) {
void setStringPointer(const char *s, storage_policies::store_by_copy) {
ARDUINOJSON_ASSERT(s != 0);
setType(VALUE_IS_OWNED_STRING);
_content.asString = s;
}
void setLinkedString(const char *s) {
void setStringPointer(const char *s, storage_policies::store_by_address) {
ARDUINOJSON_ASSERT(s != 0);
setType(VALUE_IS_LINKED_STRING);
_content.asString = s;
}
void setStringPointer(const char *s, storage_policies::store_by_copy) {
setOwnedString(s);
}
void setStringPointer(const char *s, storage_policies::store_by_address) {
setLinkedString(s);
}
template <typename TAdaptedString>
bool setString(TAdaptedString value, MemoryPool *pool) {
return setString(value, pool, typename TAdaptedString::storage_policy());
}
template <typename TAdaptedString>
inline bool setString(TAdaptedString value, MemoryPool *pool,
storage_policies::decide_at_runtime) {
if (value.isStatic())
return setString(value, pool, storage_policies::store_by_address());
else
return setString(value, pool, storage_policies::store_by_copy());
}
template <typename TAdaptedString>
inline bool setString(TAdaptedString value, MemoryPool *,
storage_policies::store_by_address) {
if (value.isNull())
setNull();
else
setStringPointer(value.data(), storage_policies::store_by_address());
return true;
}
template <typename TAdaptedString>
inline bool setString(TAdaptedString value, MemoryPool *pool,
storage_policies::store_by_copy) {
if (value.isNull()) {
setNull();
return true;
}
const char *copy = pool->saveString(value);
if (!copy) {
setNull();
return false;
}
setStringPointer(copy, storage_policies::store_by_copy());
return true;
return storeString(value, pool, typename TAdaptedString::storage_policy());
}
CollectionData &toArray() {
@ -388,6 +345,41 @@ class VariantData {
_flags &= KEY_IS_OWNED;
_flags |= t;
}
template <typename TAdaptedString>
inline bool storeString(TAdaptedString value, MemoryPool *pool,
storage_policies::decide_at_runtime) {
if (value.isStatic())
return storeString(value, pool, storage_policies::store_by_address());
else
return storeString(value, pool, storage_policies::store_by_copy());
}
template <typename TAdaptedString>
inline bool storeString(TAdaptedString value, MemoryPool *,
storage_policies::store_by_address) {
if (value.isNull())
setNull();
else
setStringPointer(value.data(), storage_policies::store_by_address());
return true;
}
template <typename TAdaptedString>
inline bool storeString(TAdaptedString value, MemoryPool *pool,
storage_policies::store_by_copy) {
if (value.isNull()) {
setNull();
return true;
}
const char *copy = pool->saveString(value);
if (!copy) {
setNull();
return false;
}
setStringPointer(copy, storage_policies::store_by_copy());
return true;
}
};
} // namespace ARDUINOJSON_NAMESPACE