forked from bblanchon/ArduinoJson
Add documentation to most public symbols
This commit is contained in:
@ -14,6 +14,7 @@ HEAD
|
||||
* Remove undocumented `JsonDocument::data()` and `JsonDocument::memoryPool()`
|
||||
* Remove undocumented `JsonArrayIterator::internal()` and `JsonObjectIterator::internal()`
|
||||
* Rename things in `ARDUINOJSON_NAMESPACE` to match the public names
|
||||
* Add documentation to most public symbols
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// A proxy class to get or set an element of an array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/subscript/
|
||||
template <typename TUpstream>
|
||||
class ElementProxy : public VariantRefBase<ElementProxy<TUpstream> >,
|
||||
public VariantOperators<ElementProxy<TUpstream> > {
|
||||
|
@ -11,89 +11,123 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class JsonObject;
|
||||
|
||||
// A reference to an array in a JsonDocument
|
||||
// https://arduinojson.org/v6/api/jsonarray/
|
||||
class JsonArray : public VariantOperators<JsonArray> {
|
||||
friend class VariantAttorney;
|
||||
|
||||
public:
|
||||
typedef JsonArrayIterator iterator;
|
||||
|
||||
// Constructs an unbound reference.
|
||||
FORCE_INLINE JsonArray() : _data(0), _pool(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
FORCE_INLINE JsonArray(MemoryPool* pool, CollectionData* data)
|
||||
: _data(data), _pool(pool) {}
|
||||
|
||||
// Returns a JsonVariant pointing to the array.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/
|
||||
operator JsonVariant() {
|
||||
void* data = _data; // prevent warning cast-align
|
||||
return JsonVariant(_pool, reinterpret_cast<VariantData*>(data));
|
||||
}
|
||||
|
||||
// Returns a read-only reference to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/
|
||||
operator JsonArrayConst() const {
|
||||
return JsonArrayConst(_data);
|
||||
}
|
||||
|
||||
// Appends a new (null) element to the array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsonarray/add/
|
||||
JsonVariant add() const {
|
||||
if (!_data)
|
||||
return JsonVariant();
|
||||
return JsonVariant(_pool, _data->addElement(_pool));
|
||||
}
|
||||
|
||||
// Appends a value to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/add/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool add(const T& value) const {
|
||||
return add().set(value);
|
||||
}
|
||||
|
||||
// Appends a value to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/add/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool add(T* value) const {
|
||||
return add().set(value);
|
||||
}
|
||||
|
||||
// Returns an iterator to the first element of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/begin/
|
||||
FORCE_INLINE iterator begin() const {
|
||||
if (!_data)
|
||||
return iterator();
|
||||
return iterator(_pool, _data->head());
|
||||
}
|
||||
|
||||
// Returns an iterator following the last element of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/end/
|
||||
FORCE_INLINE iterator end() const {
|
||||
return iterator();
|
||||
}
|
||||
|
||||
// Copy a JsonArray
|
||||
// Copies an array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/set/
|
||||
FORCE_INLINE bool set(JsonArrayConst src) const {
|
||||
if (!_data || !src._data)
|
||||
return false;
|
||||
return _data->copyFrom(*src._data, _pool);
|
||||
}
|
||||
|
||||
// Compares the content of two arrays.
|
||||
FORCE_INLINE bool operator==(JsonArray rhs) const {
|
||||
return JsonArrayConst(_data) == JsonArrayConst(rhs._data);
|
||||
}
|
||||
|
||||
// Removes element at specified position.
|
||||
// Removes the element at the specified iterator.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsonarray/remove/
|
||||
FORCE_INLINE void remove(iterator it) const {
|
||||
if (!_data)
|
||||
return;
|
||||
_data->removeSlot(it._slot);
|
||||
}
|
||||
|
||||
// Removes element at specified index.
|
||||
// Removes the element at the specified index.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsonarray/remove/
|
||||
FORCE_INLINE void remove(size_t index) const {
|
||||
if (!_data)
|
||||
return;
|
||||
_data->removeElement(index);
|
||||
}
|
||||
|
||||
// Removes all the elements of the array.
|
||||
// ⚠️ Doesn't release the memory associated with the removed elements.
|
||||
// https://arduinojson.org/v6/api/jsonarray/clear/
|
||||
void clear() const {
|
||||
if (!_data)
|
||||
return;
|
||||
_data->clear();
|
||||
}
|
||||
|
||||
// Returns the element at specified index if the variant is an array.
|
||||
// Gets or sets the element at the specified index.
|
||||
// https://arduinojson.org/v6/api/jsonarray/subscript/
|
||||
FORCE_INLINE ElementProxy<JsonArray> operator[](size_t index) const {
|
||||
return ElementProxy<JsonArray>(*this, index);
|
||||
}
|
||||
|
||||
// Creates an object and appends it to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/createnestedobject/
|
||||
FORCE_INLINE JsonObject createNestedObject() const;
|
||||
|
||||
// Creates an array and appends it to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/createnestedarray/
|
||||
FORCE_INLINE JsonArray createNestedArray() const {
|
||||
return add().to<JsonArray>();
|
||||
}
|
||||
@ -102,22 +136,32 @@ class JsonArray : public VariantOperators<JsonArray> {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns true if the reference is unbound.
|
||||
// https://arduinojson.org/v6/api/jsonarray/isnull/
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return _data == 0;
|
||||
}
|
||||
|
||||
// Returns true if the reference is bound.
|
||||
// https://arduinojson.org/v6/api/jsonarray/isnull/
|
||||
FORCE_INLINE operator bool() const {
|
||||
return _data != 0;
|
||||
}
|
||||
|
||||
// Returns the number of bytes occupied by the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/memoryusage/
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return _data ? _data->memoryUsage() : 0;
|
||||
}
|
||||
|
||||
// Returns the depth (nesting level) of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/nesting/
|
||||
FORCE_INLINE size_t nesting() const {
|
||||
return variantNesting(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns the number of elements in the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/size/
|
||||
FORCE_INLINE size_t size() const {
|
||||
return _data ? _data->size() : 0;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class JsonObject;
|
||||
|
||||
// A read-only reference to an array in a JsonDocument
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/
|
||||
class JsonArrayConst : public VariantOperators<JsonArrayConst> {
|
||||
friend class JsonArray;
|
||||
friend class VariantAttorney;
|
||||
@ -19,19 +21,28 @@ class JsonArrayConst : public VariantOperators<JsonArrayConst> {
|
||||
public:
|
||||
typedef JsonArrayConstIterator iterator;
|
||||
|
||||
// Returns an iterator to the first element of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/begin/
|
||||
FORCE_INLINE iterator begin() const {
|
||||
if (!_data)
|
||||
return iterator();
|
||||
return iterator(_data->head());
|
||||
}
|
||||
|
||||
// Returns an iterator to the element following the last element of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/end/
|
||||
FORCE_INLINE iterator end() const {
|
||||
return iterator();
|
||||
}
|
||||
|
||||
// Creates an unbound reference.
|
||||
FORCE_INLINE JsonArrayConst() : _data(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
FORCE_INLINE JsonArrayConst(const CollectionData* data) : _data(data) {}
|
||||
|
||||
// Compares the content of two arrays.
|
||||
// Returns true if the two arrays are equal.
|
||||
FORCE_INLINE bool operator==(JsonArrayConst rhs) const {
|
||||
if (_data == rhs._data)
|
||||
return true;
|
||||
@ -55,6 +66,8 @@ class JsonArrayConst : public VariantOperators<JsonArrayConst> {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the element at the specified index.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/subscript/
|
||||
FORCE_INLINE JsonVariantConst operator[](size_t index) const {
|
||||
return JsonVariantConst(_data ? _data->getElement(index) : 0);
|
||||
}
|
||||
@ -63,22 +76,32 @@ class JsonArrayConst : public VariantOperators<JsonArrayConst> {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns true if the reference is unbound.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/isnull/
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return _data == 0;
|
||||
}
|
||||
|
||||
// Returns true if the reference is bound.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/isnull/
|
||||
FORCE_INLINE operator bool() const {
|
||||
return _data != 0;
|
||||
}
|
||||
|
||||
// Returns the number of bytes occupied by the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/memoryusage/
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return _data ? _data->memoryUsage() : 0;
|
||||
}
|
||||
|
||||
// Returns the depth (nesting level) of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/nesting/
|
||||
FORCE_INLINE size_t nesting() const {
|
||||
return variantNesting(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns the number of elements in the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/size/
|
||||
FORCE_INLINE size_t size() const {
|
||||
return _data ? _data->size() : 0;
|
||||
}
|
||||
|
@ -9,14 +9,16 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// Trivial form to stop the recursion
|
||||
// Copies a value to a JsonVariant.
|
||||
// This is a degenerated form of copyArray() to stop the recursion.
|
||||
template <typename T>
|
||||
inline typename enable_if<!is_array<T>::value, bool>::type copyArray(
|
||||
const T& src, JsonVariant dst) {
|
||||
return dst.set(src);
|
||||
}
|
||||
|
||||
// Copy array to a JsonArray/JsonVariant/MemberProxy/ElementProxy
|
||||
// Copies values from an array to a JsonArray or a JsonVariant.
|
||||
// https://arduinojson.org/v6/api/misc/copyarray/
|
||||
template <typename T, size_t N, typename TDestination>
|
||||
inline typename enable_if<!is_base_of<JsonDocument, TDestination>::value,
|
||||
bool>::type
|
||||
@ -24,7 +26,8 @@ copyArray(T (&src)[N], const TDestination& dst) {
|
||||
return copyArray(src, N, dst);
|
||||
}
|
||||
|
||||
// Copy ptr+size to a JsonArray/JsonVariant/MemberProxy/ElementProxy
|
||||
// Copies values from an array to a JsonArray or a JsonVariant.
|
||||
// https://arduinojson.org/v6/api/misc/copyarray/
|
||||
template <typename T, typename TDestination>
|
||||
inline typename enable_if<!is_base_of<JsonDocument, TDestination>::value,
|
||||
bool>::type
|
||||
@ -36,25 +39,29 @@ copyArray(const T* src, size_t len, const TDestination& dst) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Special case for char[] which much be treated as const char*
|
||||
// Copies a string to a JsonVariant.
|
||||
// This is a degenerated form of copyArray() to handle strings.
|
||||
template <typename TDestination>
|
||||
inline bool copyArray(const char* src, size_t, const TDestination& dst) {
|
||||
return dst.set(src);
|
||||
}
|
||||
|
||||
// Copy array to a JsonDocument
|
||||
// Copies values from an array to a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/misc/copyarray/
|
||||
template <typename T>
|
||||
inline bool copyArray(const T& src, JsonDocument& dst) {
|
||||
return copyArray(src, dst.to<JsonArray>());
|
||||
}
|
||||
|
||||
// Copy a ptr+size array to a JsonDocument
|
||||
// Copies an array to a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/misc/copyarray/
|
||||
template <typename T>
|
||||
inline bool copyArray(const T* src, size_t len, JsonDocument& dst) {
|
||||
return copyArray(src, len, dst.to<JsonArray>());
|
||||
}
|
||||
|
||||
// Trivial case form to stop the recursion
|
||||
// Copies a value from a JsonVariant.
|
||||
// This is a degenerated form of copyArray() to stop the recursion.
|
||||
template <typename T>
|
||||
inline typename enable_if<!is_array<T>::value, size_t>::type copyArray(
|
||||
JsonVariantConst src, T& dst) {
|
||||
@ -62,13 +69,15 @@ inline typename enable_if<!is_array<T>::value, size_t>::type copyArray(
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Copy a JsonArray to array
|
||||
// Copies values from a JsonArray or JsonVariant to an array.
|
||||
// https://arduinojson.org/v6/api/misc/copyarray/
|
||||
template <typename T, size_t N>
|
||||
inline size_t copyArray(JsonArrayConst src, T (&dst)[N]) {
|
||||
return copyArray(src, dst, N);
|
||||
}
|
||||
|
||||
// Copy a JsonArray to ptr+size
|
||||
// Copies values from a JsonArray or JsonVariant to an array.
|
||||
// https://arduinojson.org/v6/api/misc/copyarray/
|
||||
template <typename T>
|
||||
inline size_t copyArray(JsonArrayConst src, T* dst, size_t len) {
|
||||
size_t i = 0;
|
||||
@ -78,7 +87,8 @@ inline size_t copyArray(JsonArrayConst src, T* dst, size_t len) {
|
||||
return i;
|
||||
}
|
||||
|
||||
// Special case for char[] which must be treated as a string
|
||||
// Copies a string from a JsonVariant.
|
||||
// This is a degenerated form of copyArray() to handle strings.
|
||||
template <size_t N>
|
||||
inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) {
|
||||
JsonString s = src;
|
||||
@ -90,8 +100,8 @@ inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Copy a JsonDocument to an array
|
||||
// (JsonDocument doesn't implicitly convert to JsonArrayConst)
|
||||
// Copies values from a JsonDocument to an array.
|
||||
// https://arduinojson.org/v6/api/misc/copyarray/
|
||||
template <typename TSource, typename T>
|
||||
inline typename enable_if<is_array<T>::value &&
|
||||
is_base_of<JsonDocument, TSource>::value,
|
||||
|
@ -37,6 +37,8 @@ class AllocatorOwner {
|
||||
TAllocator _allocator;
|
||||
};
|
||||
|
||||
// A JsonDocument that uses the provided allocator to allocate its memory pool.
|
||||
// https://arduinojson.org/v6/api/basicjsondocument/
|
||||
template <typename TAllocator>
|
||||
class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
|
||||
public:
|
||||
@ -104,6 +106,8 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Reduces the capacity of the memory pool to match the current usage.
|
||||
// https://arduinojson.org/v6/api/basicjsondocument/shrinktofit/
|
||||
void shrinkToFit() {
|
||||
ptrdiff_t bytes_reclaimed = _pool.squash();
|
||||
if (bytes_reclaimed == 0)
|
||||
@ -119,6 +123,8 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
|
||||
_data.movePointers(ptr_offset, ptr_offset - bytes_reclaimed);
|
||||
}
|
||||
|
||||
// Reclaims the memory leaked when removing and replacing values.
|
||||
// https://arduinojson.org/v6/api/jsondocument/garbagecollect/
|
||||
bool garbageCollect() {
|
||||
// make a temporary clone and move assign
|
||||
BasicJsonDocument tmp(*this);
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// The allocator of DynamicJsonDocument.
|
||||
struct DefaultAllocator {
|
||||
void* allocate(size_t size) {
|
||||
return malloc(size);
|
||||
@ -24,6 +25,8 @@ struct DefaultAllocator {
|
||||
}
|
||||
};
|
||||
|
||||
// A JsonDocument with a memory pool in the heap.
|
||||
// https://arduinojson.org/v6/api/dynamicjsondocument/
|
||||
typedef BasicJsonDocument<DefaultAllocator> DynamicJsonDocument;
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -14,130 +14,161 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// A JSON document.
|
||||
// https://arduinojson.org/v6/api/jsondocument/
|
||||
class JsonDocument : public VariantOperators<const JsonDocument&> {
|
||||
friend class VariantAttorney;
|
||||
|
||||
public:
|
||||
// Casts the root to the specified type.
|
||||
// https://arduinojson.org/v6/api/jsondocument/as/
|
||||
template <typename T>
|
||||
T as() {
|
||||
return getVariant().template as<T>();
|
||||
}
|
||||
|
||||
// Casts the root to the specified type.
|
||||
// https://arduinojson.org/v6/api/jsondocument/as/
|
||||
template <typename T>
|
||||
T as() const {
|
||||
return getVariant().template as<T>();
|
||||
}
|
||||
|
||||
// Empties the document and resets the memory pool
|
||||
// https://arduinojson.org/v6/api/jsondocument/clear/
|
||||
void clear() {
|
||||
_pool.clear();
|
||||
_data.init();
|
||||
}
|
||||
|
||||
// Returns true if the root is of the specified type.
|
||||
// https://arduinojson.org/v6/api/jsondocument/is/
|
||||
template <typename T>
|
||||
bool is() {
|
||||
return getVariant().template is<T>();
|
||||
}
|
||||
|
||||
// Returns true if the root is of the specified type.
|
||||
// https://arduinojson.org/v6/api/jsondocument/is/
|
||||
template <typename T>
|
||||
bool is() const {
|
||||
return getVariant().template is<T>();
|
||||
}
|
||||
|
||||
// Returns true if the root is null.
|
||||
// https://arduinojson.org/v6/api/jsondocument/isnull/
|
||||
bool isNull() const {
|
||||
return getVariant().isNull();
|
||||
}
|
||||
|
||||
// Returns the number of used bytes in the memory pool.
|
||||
// https://arduinojson.org/v6/api/jsondocument/memoryusage/
|
||||
size_t memoryUsage() const {
|
||||
return _pool.size();
|
||||
}
|
||||
|
||||
// Returns trues if the memory pool was too small.
|
||||
// https://arduinojson.org/v6/api/jsondocument/overflowed/
|
||||
bool overflowed() const {
|
||||
return _pool.overflowed();
|
||||
}
|
||||
|
||||
// Returns the depth (nesting level) of the array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/nesting/
|
||||
size_t nesting() const {
|
||||
return variantNesting(&_data);
|
||||
}
|
||||
|
||||
// Returns the capacity of the memory pool.
|
||||
// https://arduinojson.org/v6/api/jsondocument/capacity/
|
||||
size_t capacity() const {
|
||||
return _pool.capacity();
|
||||
}
|
||||
|
||||
// Returns the number of elements in the root array or object.
|
||||
// https://arduinojson.org/v6/api/jsondocument/size/
|
||||
size_t size() const {
|
||||
return _data.size();
|
||||
}
|
||||
|
||||
// Copies the specified document.
|
||||
// https://arduinojson.org/v6/api/jsondocument/set/
|
||||
bool set(const JsonDocument& src) {
|
||||
return to<JsonVariant>().set(src.as<JsonVariantConst>());
|
||||
}
|
||||
|
||||
// Replaces the root with the specified value.
|
||||
// https://arduinojson.org/v6/api/jsondocument/set/
|
||||
template <typename T>
|
||||
typename enable_if<!is_base_of<JsonDocument, T>::value, bool>::type set(
|
||||
const T& src) {
|
||||
return to<JsonVariant>().set(src);
|
||||
}
|
||||
|
||||
// Clears the document and converts it to the specified type.
|
||||
// https://arduinojson.org/v6/api/jsondocument/to/
|
||||
template <typename T>
|
||||
typename VariantTo<T>::type to() {
|
||||
clear();
|
||||
return getVariant().template to<T>();
|
||||
}
|
||||
|
||||
// Creates an array and appends it to the root array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedarray/
|
||||
JsonArray createNestedArray() {
|
||||
return add().to<JsonArray>();
|
||||
}
|
||||
|
||||
// createNestedArray(char*)
|
||||
// createNestedArray(const char*)
|
||||
// createNestedArray(const __FlashStringHelper*)
|
||||
// Creates an array and adds it to the root object.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedarray/
|
||||
template <typename TChar>
|
||||
JsonArray createNestedArray(TChar* key) {
|
||||
return operator[](key).template to<JsonArray>();
|
||||
}
|
||||
|
||||
// createNestedArray(const std::string&)
|
||||
// createNestedArray(const String&)
|
||||
// Creates an array and adds it to the root object.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedarray/
|
||||
template <typename TString>
|
||||
JsonArray createNestedArray(const TString& key) {
|
||||
return operator[](key).template to<JsonArray>();
|
||||
}
|
||||
|
||||
// Creates an object and appends it to the root array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedobject/
|
||||
JsonObject createNestedObject() {
|
||||
return add().to<JsonObject>();
|
||||
}
|
||||
|
||||
// createNestedObject(char*)
|
||||
// createNestedObject(const char*)
|
||||
// createNestedObject(const __FlashStringHelper*)
|
||||
// Creates an object and adds it to the root object.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedobject/
|
||||
template <typename TChar>
|
||||
JsonObject createNestedObject(TChar* key) {
|
||||
return operator[](key).template to<JsonObject>();
|
||||
}
|
||||
|
||||
// createNestedObject(const std::string&)
|
||||
// createNestedObject(const String&)
|
||||
// Creates an object and adds it to the root object.
|
||||
// https://arduinojson.org/v6/api/jsondocument/createnestedobject/
|
||||
template <typename TString>
|
||||
JsonObject createNestedObject(const TString& key) {
|
||||
return operator[](key).template to<JsonObject>();
|
||||
}
|
||||
|
||||
// containsKey(char*) const
|
||||
// containsKey(const char*) const
|
||||
// containsKey(const __FlashStringHelper*) const
|
||||
// Returns true if the root object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsondocument/containskey/
|
||||
template <typename TChar>
|
||||
bool containsKey(TChar* key) const {
|
||||
return _data.getMember(adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// containsKey(const std::string&) const
|
||||
// containsKey(const String&) const
|
||||
// Returns true if the root object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsondocument/containskey/
|
||||
template <typename TString>
|
||||
bool containsKey(const TString& key) const {
|
||||
return _data.getMember(adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// operator[](const std::string&)
|
||||
// operator[](const String&)
|
||||
// Gets or sets a root object's member.
|
||||
// https://arduinojson.org/v6/api/jsondocument/subscript/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value,
|
||||
MemberProxy<JsonDocument&, TString> >::type
|
||||
@ -145,9 +176,8 @@ class JsonDocument : public VariantOperators<const JsonDocument&> {
|
||||
return MemberProxy<JsonDocument&, TString>(*this, key);
|
||||
}
|
||||
|
||||
// operator[](char*)
|
||||
// operator[](const char*)
|
||||
// operator[](const __FlashStringHelper*)
|
||||
// Gets or sets a root object's member.
|
||||
// https://arduinojson.org/v6/api/jsondocument/subscript/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value,
|
||||
MemberProxy<JsonDocument&, TChar*> >::type
|
||||
@ -155,8 +185,8 @@ class JsonDocument : public VariantOperators<const JsonDocument&> {
|
||||
return MemberProxy<JsonDocument&, TChar*>(*this, key);
|
||||
}
|
||||
|
||||
// operator[](const std::string&) const
|
||||
// operator[](const String&) const
|
||||
// Gets a root object's member.
|
||||
// https://arduinojson.org/v6/api/jsondocument/subscript/
|
||||
template <typename TString>
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TString>::value, JsonVariantConst>::type
|
||||
@ -164,9 +194,8 @@ class JsonDocument : public VariantOperators<const JsonDocument&> {
|
||||
return JsonVariantConst(_data.getMember(adaptString(key)));
|
||||
}
|
||||
|
||||
// operator[](char*) const
|
||||
// operator[](const char*) const
|
||||
// operator[](const __FlashStringHelper*) const
|
||||
// Gets a root object's member.
|
||||
// https://arduinojson.org/v6/api/jsondocument/subscript/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TChar*>::value, JsonVariantConst>::type
|
||||
@ -174,44 +203,58 @@ class JsonDocument : public VariantOperators<const JsonDocument&> {
|
||||
return JsonVariantConst(_data.getMember(adaptString(key)));
|
||||
}
|
||||
|
||||
// Gets or sets a root array's element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/subscript/
|
||||
FORCE_INLINE ElementProxy<JsonDocument&> operator[](size_t index) {
|
||||
return ElementProxy<JsonDocument&>(*this, index);
|
||||
}
|
||||
|
||||
// Gets a root array's member.
|
||||
// https://arduinojson.org/v6/api/jsondocument/subscript/
|
||||
FORCE_INLINE JsonVariantConst operator[](size_t index) const {
|
||||
return JsonVariantConst(_data.getElement(index));
|
||||
}
|
||||
|
||||
// Appends a new (null) element to the root array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
FORCE_INLINE JsonVariant add() {
|
||||
return JsonVariant(&_pool, _data.addElement(&_pool));
|
||||
}
|
||||
|
||||
// Appends a value to the root array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
template <typename TValue>
|
||||
FORCE_INLINE bool add(const TValue& value) {
|
||||
return add().set(value);
|
||||
}
|
||||
|
||||
// add(char*) const
|
||||
// add(const char*) const
|
||||
// add(const __FlashStringHelper*) const
|
||||
// Appends a value to the root array.
|
||||
// https://arduinojson.org/v6/api/jsondocument/add/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE bool add(TChar* value) {
|
||||
return add().set(value);
|
||||
}
|
||||
|
||||
// Removes an element of the root array.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/remove/
|
||||
FORCE_INLINE void remove(size_t index) {
|
||||
_data.remove(index);
|
||||
}
|
||||
// remove(char*)
|
||||
// remove(const char*)
|
||||
// remove(const __FlashStringHelper*)
|
||||
|
||||
// Removes a member of the root object.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/remove/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value>::type remove(
|
||||
TChar* key) {
|
||||
_data.remove(adaptString(key));
|
||||
}
|
||||
// remove(const std::string&)
|
||||
// remove(const String&)
|
||||
|
||||
// Removes a member of the root object.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsondocument/remove/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove(
|
||||
const TString& key) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// A JsonDocument with a memory pool on the stack.
|
||||
template <size_t desiredCapacity>
|
||||
class StaticJsonDocument : public JsonDocument {
|
||||
static const size_t _capacity =
|
||||
@ -45,6 +46,8 @@ class StaticJsonDocument : public JsonDocument {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Reclaims the memory leaked when removing and replacing values.
|
||||
// https://arduinojson.org/v6/api/jsondocument/garbagecollect/
|
||||
void garbageCollect() {
|
||||
StaticJsonDocument tmp(*this);
|
||||
set(tmp);
|
||||
|
@ -661,10 +661,8 @@ class JsonDeserializer {
|
||||
// code
|
||||
};
|
||||
|
||||
//
|
||||
// deserializeJson(JsonDocument&, const std::string&, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a JSON input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TString>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, const TString& input,
|
||||
@ -672,24 +670,26 @@ DeserializationError deserializeJson(
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TString>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, const TString& input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TString>
|
||||
DeserializationError deserializeJson(JsonDocument& doc, const TString& input,
|
||||
NestingLimit nestingLimit, Filter filter) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
//
|
||||
// deserializeJson(JsonDocument&, std::istream&, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a JSON input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, TStream& input,
|
||||
@ -697,24 +697,26 @@ DeserializationError deserializeJson(
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, TStream& input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeJson(JsonDocument& doc, TStream& input,
|
||||
NestingLimit nestingLimit, Filter filter) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
//
|
||||
// deserializeJson(JsonDocument&, char*, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a JSON input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, TChar* input,
|
||||
@ -722,24 +724,26 @@ DeserializationError deserializeJson(
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, TChar* input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeJson(JsonDocument& doc, TChar* input,
|
||||
NestingLimit nestingLimit, Filter filter) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
//
|
||||
// deserializeJson(JsonDocument&, char*, size_t, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a JSON input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, TChar* input, size_t inputSize,
|
||||
@ -747,7 +751,9 @@ DeserializationError deserializeJson(
|
||||
return deserialize<JsonDeserializer>(doc, input, inputSize, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument& doc, TChar* input, size_t inputSize, Filter filter,
|
||||
@ -755,7 +761,9 @@ DeserializationError deserializeJson(
|
||||
return deserialize<JsonDeserializer>(doc, input, inputSize, nestingLimit,
|
||||
filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a JSON input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/json/deserializejson/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeJson(JsonDocument& doc, TChar* input,
|
||||
size_t inputSize,
|
||||
|
@ -115,16 +115,22 @@ class JsonSerializer : public Visitor<size_t> {
|
||||
TextFormatter<TWriter> _formatter;
|
||||
};
|
||||
|
||||
// Produces a minified JSON document.
|
||||
// https://arduinojson.org/v6/api/json/serializejson/
|
||||
template <typename TDestination>
|
||||
size_t serializeJson(JsonVariantConst source, TDestination& destination) {
|
||||
return serialize<JsonSerializer>(source, destination);
|
||||
}
|
||||
|
||||
// Produces a minified JSON document.
|
||||
// https://arduinojson.org/v6/api/json/serializejson/
|
||||
inline size_t serializeJson(JsonVariantConst source, void* buffer,
|
||||
size_t bufferSize) {
|
||||
return serialize<JsonSerializer>(source, buffer, bufferSize);
|
||||
}
|
||||
|
||||
// Computes the length of the document that serializeJson() produces.
|
||||
// https://arduinojson.org/v6/api/json/measurejson/
|
||||
inline size_t measureJson(JsonVariantConst source) {
|
||||
return measure<JsonSerializer>(source);
|
||||
}
|
||||
|
@ -70,16 +70,22 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
|
||||
uint8_t _nesting;
|
||||
};
|
||||
|
||||
// Produces JsonDocument to create a prettified JSON document.
|
||||
// https://arduinojson.org/v6/api/json/serializejsonpretty/
|
||||
template <typename TDestination>
|
||||
size_t serializeJsonPretty(JsonVariantConst source, TDestination& destination) {
|
||||
return serialize<PrettyJsonSerializer>(source, destination);
|
||||
}
|
||||
|
||||
// Produces JsonDocument to create a prettified JSON document.
|
||||
// https://arduinojson.org/v6/api/json/serializejsonpretty/
|
||||
inline size_t serializeJsonPretty(JsonVariantConst source, void* buffer,
|
||||
size_t bufferSize) {
|
||||
return serialize<PrettyJsonSerializer>(source, buffer, bufferSize);
|
||||
}
|
||||
|
||||
// Computes the length of the document that serializeJsonPretty() produces.
|
||||
// https://arduinojson.org/v6/api/json/measurejsonpretty/
|
||||
inline size_t measureJsonPretty(JsonVariantConst source) {
|
||||
return measure<PrettyJsonSerializer>(source);
|
||||
}
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
#define JSON_STRING_SIZE(SIZE) (SIZE + 1)
|
||||
|
||||
// Returns the size (in bytes) of an array with n elements.
|
||||
// Can be very handy to determine the size of a StaticMemoryPool.
|
||||
// Computes the size required to store an array in a JsonDocument.
|
||||
// https://arduinojson.org/v6/how-to/determine-the-capacity-of-the-jsondocument/
|
||||
#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \
|
||||
((NUMBER_OF_ELEMENTS) * sizeof(ARDUINOJSON_NAMESPACE::VariantSlot))
|
||||
|
||||
|
@ -544,10 +544,8 @@ class MsgPackDeserializer {
|
||||
bool _foundSomething;
|
||||
};
|
||||
|
||||
//
|
||||
// deserializeMsgPack(JsonDocument&, const std::string&, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a MessagePack input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TString>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, const TString& input,
|
||||
@ -555,14 +553,18 @@ DeserializationError deserializeMsgPack(
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TString>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, const TString& input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TString>
|
||||
DeserializationError deserializeMsgPack(JsonDocument& doc, const TString& input,
|
||||
NestingLimit nestingLimit,
|
||||
@ -570,10 +572,8 @@ DeserializationError deserializeMsgPack(JsonDocument& doc, const TString& input,
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
//
|
||||
// deserializeMsgPack(JsonDocument&, std::istream&, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a MessagePack input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, TStream& input,
|
||||
@ -581,14 +581,18 @@ DeserializationError deserializeMsgPack(
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, TStream& input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TStream>
|
||||
DeserializationError deserializeMsgPack(JsonDocument& doc, TStream& input,
|
||||
NestingLimit nestingLimit,
|
||||
@ -596,10 +600,8 @@ DeserializationError deserializeMsgPack(JsonDocument& doc, TStream& input,
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
//
|
||||
// deserializeMsgPack(JsonDocument&, char*, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a MessagePack input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, TChar* input,
|
||||
@ -607,14 +609,18 @@ DeserializationError deserializeMsgPack(
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, TChar* input, Filter filter,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(JsonDocument& doc, TChar* input,
|
||||
NestingLimit nestingLimit,
|
||||
@ -622,10 +628,8 @@ DeserializationError deserializeMsgPack(JsonDocument& doc, TChar* input,
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit, filter);
|
||||
}
|
||||
|
||||
//
|
||||
// deserializeMsgPack(JsonDocument&, char*, size_t, ...)
|
||||
//
|
||||
// ... = NestingLimit
|
||||
// Parses a MessagePack input and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, TChar* input, size_t inputSize,
|
||||
@ -633,7 +637,9 @@ DeserializationError deserializeMsgPack(
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit,
|
||||
AllowAllFilter());
|
||||
}
|
||||
// ... = Filter, NestingLimit
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument& doc, TChar* input, size_t inputSize, Filter filter,
|
||||
@ -641,7 +647,9 @@ DeserializationError deserializeMsgPack(
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit,
|
||||
filter);
|
||||
}
|
||||
// ... = NestingLimit, Filter
|
||||
|
||||
// Parses a MessagePack input, filters, and puts the result in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/msgpack/deserializemsgpack/
|
||||
template <typename TChar>
|
||||
DeserializationError deserializeMsgPack(JsonDocument& doc, TChar* input,
|
||||
size_t inputSize,
|
||||
|
@ -197,16 +197,22 @@ class MsgPackSerializer : public Visitor<size_t> {
|
||||
CountingDecorator<TWriter> _writer;
|
||||
};
|
||||
|
||||
// Produces a MessagePack document.
|
||||
// https://arduinojson.org/v6/api/msgpack/serializemsgpack/
|
||||
template <typename TDestination>
|
||||
inline size_t serializeMsgPack(JsonVariantConst source, TDestination& output) {
|
||||
return serialize<MsgPackSerializer>(source, output);
|
||||
}
|
||||
|
||||
// Produces a MessagePack document.
|
||||
// https://arduinojson.org/v6/api/msgpack/serializemsgpack/
|
||||
inline size_t serializeMsgPack(JsonVariantConst source, void* output,
|
||||
size_t size) {
|
||||
return serialize<MsgPackSerializer>(source, output, size);
|
||||
}
|
||||
|
||||
// Computes the length of the document that serializeMsgPack() produces.
|
||||
// https://arduinojson.org/v6/api/msgpack/measuremsgpack/
|
||||
inline size_t measureMsgPack(JsonVariantConst source) {
|
||||
return measure<MsgPackSerializer>(source);
|
||||
}
|
||||
|
@ -11,13 +11,18 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class JsonArray;
|
||||
|
||||
// A reference to an object in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/jsonobject/
|
||||
class JsonObject : public VariantOperators<JsonObject> {
|
||||
friend class VariantAttorney;
|
||||
|
||||
public:
|
||||
typedef JsonObjectIterator iterator;
|
||||
|
||||
// Creates an unbound reference.
|
||||
FORCE_INLINE JsonObject() : _data(0), _pool(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
FORCE_INLINE JsonObject(MemoryPool* buf, CollectionData* data)
|
||||
: _data(data), _pool(buf) {}
|
||||
|
||||
@ -34,52 +39,74 @@ class JsonObject : public VariantOperators<JsonObject> {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns true if the reference is unbound.
|
||||
// https://arduinojson.org/v6/api/jsonobject/isnull/
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return _data == 0;
|
||||
}
|
||||
|
||||
// Returns true if the reference is bound.
|
||||
// https://arduinojson.org/v6/api/jsonobject/isnull/
|
||||
FORCE_INLINE operator bool() const {
|
||||
return _data != 0;
|
||||
}
|
||||
|
||||
// Returns the number of bytes occupied by the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/memoryusage/
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return _data ? _data->memoryUsage() : 0;
|
||||
}
|
||||
|
||||
// Returns the depth (nesting level) of the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/nesting/
|
||||
FORCE_INLINE size_t nesting() const {
|
||||
return variantNesting(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns the number of members in the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/size/
|
||||
FORCE_INLINE size_t size() const {
|
||||
return _data ? _data->size() : 0;
|
||||
}
|
||||
|
||||
// Returns an iterator to the first key-value pair of the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/begin/
|
||||
FORCE_INLINE iterator begin() const {
|
||||
if (!_data)
|
||||
return iterator();
|
||||
return iterator(_pool, _data->head());
|
||||
}
|
||||
|
||||
// Returns an iterator following the last key-value pair of the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/end/
|
||||
FORCE_INLINE iterator end() const {
|
||||
return iterator();
|
||||
}
|
||||
|
||||
// Removes all the members of the object.
|
||||
// ⚠️ Doesn't release the memory associated with the removed members.
|
||||
// https://arduinojson.org/v6/api/jsonobject/clear/
|
||||
void clear() const {
|
||||
if (!_data)
|
||||
return;
|
||||
_data->clear();
|
||||
}
|
||||
|
||||
// Copies an object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/set/
|
||||
FORCE_INLINE bool set(JsonObjectConst src) {
|
||||
if (!_data || !src._data)
|
||||
return false;
|
||||
return _data->copyFrom(*src._data, _pool);
|
||||
}
|
||||
|
||||
// Compares the content of two objects.
|
||||
FORCE_INLINE bool operator==(JsonObject rhs) const {
|
||||
return JsonObjectConst(_data) == JsonObjectConst(rhs._data);
|
||||
}
|
||||
|
||||
// Gets or sets the member with specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobject/subscript/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value,
|
||||
MemberProxy<JsonObject, TString> >::type
|
||||
@ -87,6 +114,8 @@ class JsonObject : public VariantOperators<JsonObject> {
|
||||
return MemberProxy<JsonObject, TString>(*this, key);
|
||||
}
|
||||
|
||||
// Gets or sets the member with specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobject/subscript/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value,
|
||||
MemberProxy<JsonObject, TChar*> >::type
|
||||
@ -94,50 +123,66 @@ class JsonObject : public VariantOperators<JsonObject> {
|
||||
return MemberProxy<JsonObject, TChar*>(*this, key);
|
||||
}
|
||||
|
||||
// Removes the member at the specified iterator.
|
||||
// ⚠️ Doesn't release the memory associated with the removed member.
|
||||
// https://arduinojson.org/v6/api/jsonobject/remove/
|
||||
FORCE_INLINE void remove(iterator it) const {
|
||||
if (!_data)
|
||||
return;
|
||||
_data->removeSlot(it._slot);
|
||||
}
|
||||
|
||||
// remove(const std::string&) const
|
||||
// remove(const String&) const
|
||||
// Removes the member with the specified key.
|
||||
// ⚠️ Doesn't release the memory associated with the removed member.
|
||||
// https://arduinojson.org/v6/api/jsonobject/remove/
|
||||
template <typename TString>
|
||||
FORCE_INLINE void remove(const TString& key) const {
|
||||
removeMember(adaptString(key));
|
||||
}
|
||||
|
||||
// remove(char*) const
|
||||
// remove(const char*) const
|
||||
// remove(const __FlashStringHelper*) const
|
||||
// Removes the member with the specified key.
|
||||
// ⚠️ Doesn't release the memory associated with the removed member.
|
||||
// https://arduinojson.org/v6/api/jsonobject/remove/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE void remove(TChar* key) const {
|
||||
removeMember(adaptString(key));
|
||||
}
|
||||
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobject/containskey/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value, bool>::type
|
||||
containsKey(const TString& key) const {
|
||||
return getMember(adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobject/containskey/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value, bool>::type
|
||||
containsKey(TChar* key) const {
|
||||
return getMember(adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// Creates an array and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/createnestedarray/
|
||||
template <typename TString>
|
||||
FORCE_INLINE JsonArray createNestedArray(const TString& key) const;
|
||||
|
||||
// Creates an array and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/createnestedarray/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE JsonArray createNestedArray(TChar* key) const;
|
||||
|
||||
// Creates an object and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/createnestedobject/
|
||||
template <typename TString>
|
||||
JsonObject createNestedObject(const TString& key) const {
|
||||
return operator[](key).template to<JsonObject>();
|
||||
}
|
||||
|
||||
// Creates an object and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/createnestedobject/
|
||||
template <typename TChar>
|
||||
JsonObject createNestedObject(TChar* key) const {
|
||||
return operator[](key).template to<JsonObject>();
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// A read-only reference to an object in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/
|
||||
class JsonObjectConst : public VariantOperators<JsonObjectConst> {
|
||||
friend class JsonObject;
|
||||
friend class VariantAttorney;
|
||||
@ -16,60 +18,76 @@ class JsonObjectConst : public VariantOperators<JsonObjectConst> {
|
||||
public:
|
||||
typedef JsonObjectConstIterator iterator;
|
||||
|
||||
// Creates an unbound reference.
|
||||
JsonObjectConst() : _data(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
JsonObjectConst(const CollectionData* data) : _data(data) {}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns true if the reference is unbound.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/isnull/
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return _data == 0;
|
||||
}
|
||||
|
||||
// Returns true if the reference is bound.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/isnull/
|
||||
FORCE_INLINE operator bool() const {
|
||||
return _data != 0;
|
||||
}
|
||||
|
||||
// Returns the number of bytes occupied by the object.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/memoryusage/
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return _data ? _data->memoryUsage() : 0;
|
||||
}
|
||||
|
||||
// Returns the depth (nesting level) of the object.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/nesting/
|
||||
FORCE_INLINE size_t nesting() const {
|
||||
return variantNesting(collectionToVariant(_data));
|
||||
}
|
||||
|
||||
// Returns the number of members in the object.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/size/
|
||||
FORCE_INLINE size_t size() const {
|
||||
return _data ? _data->size() : 0;
|
||||
}
|
||||
|
||||
// Returns an iterator to the first key-value pair of the object.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/begin/
|
||||
FORCE_INLINE iterator begin() const {
|
||||
if (!_data)
|
||||
return iterator();
|
||||
return iterator(_data->head());
|
||||
}
|
||||
|
||||
// Returns an iterator following the last key-value pair of the object.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/end/
|
||||
FORCE_INLINE iterator end() const {
|
||||
return iterator();
|
||||
}
|
||||
|
||||
// containsKey(const std::string&) const
|
||||
// containsKey(const String&) const
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/containskey/
|
||||
template <typename TString>
|
||||
FORCE_INLINE bool containsKey(const TString& key) const {
|
||||
return getMember(adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// containsKey(char*) const
|
||||
// containsKey(const char*) const
|
||||
// containsKey(const __FlashStringHelper*) const
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/containskey/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE bool containsKey(TChar* key) const {
|
||||
return getMember(adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// operator[](const std::string&) const
|
||||
// operator[](const String&) const
|
||||
// Gets the member with specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/subscript/
|
||||
template <typename TString>
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TString>::value, JsonVariantConst>::type
|
||||
@ -77,9 +95,8 @@ class JsonObjectConst : public VariantOperators<JsonObjectConst> {
|
||||
return JsonVariantConst(getMember(adaptString(key)));
|
||||
}
|
||||
|
||||
// operator[](char*) const
|
||||
// operator[](const char*) const
|
||||
// operator[](const __FlashStringHelper*) const
|
||||
// Gets the member with specified key.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/subscript/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TChar*>::value, JsonVariantConst>::type
|
||||
@ -87,6 +104,7 @@ class JsonObjectConst : public VariantOperators<JsonObjectConst> {
|
||||
return JsonVariantConst(getMember(adaptString(key)));
|
||||
}
|
||||
|
||||
// Compares objects.
|
||||
FORCE_INLINE bool operator==(JsonObjectConst rhs) const {
|
||||
if (_data == rhs._data)
|
||||
return true;
|
||||
|
@ -9,9 +9,12 @@
|
||||
#include <ArduinoJson/Variant/JsonVariantConst.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
// A key value pair for CollectionData.
|
||||
|
||||
// A key-value pair.
|
||||
// https://arduinojson.org/v6/api/jsonobject/begin_end/
|
||||
class JsonPair {
|
||||
public:
|
||||
// INTERNAL USE ONLY
|
||||
JsonPair(MemoryPool* pool, VariantSlot* slot) {
|
||||
if (slot) {
|
||||
_key = JsonString(slot->key(), slot->ownsKey() ? JsonString::Copied
|
||||
@ -20,10 +23,12 @@ class JsonPair {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the key.
|
||||
JsonString key() const {
|
||||
return _key;
|
||||
}
|
||||
|
||||
// Returns the value.
|
||||
JsonVariant value() const {
|
||||
return _value;
|
||||
}
|
||||
@ -33,6 +38,8 @@ class JsonPair {
|
||||
JsonVariant _value;
|
||||
};
|
||||
|
||||
// A read-only key-value pair.
|
||||
// https://arduinojson.org/v6/api/jsonobjectconst/begin_end/
|
||||
class JsonPairConst {
|
||||
public:
|
||||
JsonPairConst(const VariantSlot* slot) {
|
||||
@ -43,10 +50,12 @@ class JsonPairConst {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the key.
|
||||
JsonString key() const {
|
||||
return _key;
|
||||
}
|
||||
|
||||
// Returns the value.
|
||||
JsonVariantConst value() const {
|
||||
return _value;
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// A proxy class to get or set a member of an object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/subscript/
|
||||
template <typename TUpstream, typename TStringRef>
|
||||
class MemberProxy
|
||||
: public VariantRefBase<MemberProxy<TUpstream, TStringRef> >,
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// A string.
|
||||
// https://arduinojson.org/v6/api/jsonstring/
|
||||
class JsonString : public SafeBoolIdom<JsonString> {
|
||||
public:
|
||||
enum Ownership { Copied, Linked };
|
||||
@ -24,18 +26,23 @@ class JsonString : public SafeBoolIdom<JsonString> {
|
||||
JsonString(const char* data, size_t sz, Ownership ownership = Linked)
|
||||
: _data(data), _size(sz), _ownership(ownership) {}
|
||||
|
||||
// Returns a pointer to the characters.
|
||||
const char* c_str() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
// Returns true if the string is null.
|
||||
bool isNull() const {
|
||||
return !_data;
|
||||
}
|
||||
|
||||
// Returns true if the string is stored by address.
|
||||
// Returns false if the string is stored by copy.
|
||||
bool isLinked() const {
|
||||
return _ownership == Linked;
|
||||
}
|
||||
|
||||
// Returns length of the string.
|
||||
size_t size() const {
|
||||
return _size;
|
||||
}
|
||||
@ -45,6 +52,7 @@ class JsonString : public SafeBoolIdom<JsonString> {
|
||||
return _data ? safe_true() : safe_false();
|
||||
}
|
||||
|
||||
// Returns true if strings are equal.
|
||||
friend bool operator==(JsonString lhs, JsonString rhs) {
|
||||
if (lhs._size != rhs._size)
|
||||
return false;
|
||||
@ -57,6 +65,7 @@ class JsonString : public SafeBoolIdom<JsonString> {
|
||||
return memcmp(lhs._data, rhs._data, lhs._size) == 0;
|
||||
}
|
||||
|
||||
// Returns true if strings differs.
|
||||
friend bool operator!=(JsonString lhs, JsonString rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
@ -8,13 +8,17 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
// A reference to a value in a JsonDocument.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/
|
||||
class JsonVariant : public VariantRefBase<JsonVariant>,
|
||||
public VariantOperators<JsonVariant> {
|
||||
friend class VariantAttorney;
|
||||
|
||||
public:
|
||||
// Creates an unbound reference.
|
||||
JsonVariant() : _data(0), _pool(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
JsonVariant(MemoryPool* pool, VariantData* data) : _data(data), _pool(pool) {}
|
||||
|
||||
private:
|
||||
|
@ -22,34 +22,50 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
class JsonArray;
|
||||
class JsonObject;
|
||||
|
||||
// A read-only reference to a value in a JsonDocument
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/
|
||||
class JsonVariantConst : public VariantTag,
|
||||
public VariantOperators<JsonVariantConst> {
|
||||
friend class VariantAttorney;
|
||||
|
||||
public:
|
||||
// Creates an unbound reference.
|
||||
JsonVariantConst() : _data(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
explicit JsonVariantConst(const VariantData* data) : _data(data) {}
|
||||
|
||||
// Returns true if the value is null or the reference is unbound.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/isnull/
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return variantIsNull(_data);
|
||||
}
|
||||
|
||||
// Returns true if the reference is unbound.
|
||||
FORCE_INLINE bool isUnbound() const {
|
||||
return !_data;
|
||||
}
|
||||
|
||||
// Returns the number of bytes occupied by the value.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/memoryusage/
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return _data ? _data->memoryUsage() : 0;
|
||||
}
|
||||
|
||||
// Returns the depth (nesting level) of the value.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/nesting/
|
||||
FORCE_INLINE size_t nesting() const {
|
||||
return variantNesting(_data);
|
||||
}
|
||||
|
||||
// Returns the size of the array or object.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/size/
|
||||
size_t size() const {
|
||||
return variantSize(_data);
|
||||
}
|
||||
|
||||
// Casts the value to the specified type.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/as/
|
||||
template <typename T>
|
||||
FORCE_INLINE
|
||||
typename enable_if<!is_same<T, char*>::value && !is_same<T, char>::value,
|
||||
@ -58,6 +74,8 @@ class JsonVariantConst : public VariantTag,
|
||||
return Converter<T>::fromJson(*this);
|
||||
}
|
||||
|
||||
// Deprecated: use as<const char*>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/as/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char*>::value, const char*>::type
|
||||
ARDUINOJSON_DEPRECATED("Replace as<char*>() with as<const char*>()")
|
||||
@ -65,6 +83,8 @@ class JsonVariantConst : public VariantTag,
|
||||
return as<const char*>();
|
||||
}
|
||||
|
||||
// Deprecated: use as<int8_t>() or as<uint8_t>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/as/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char>::value, char>::type
|
||||
ARDUINOJSON_DEPRECATED(
|
||||
@ -73,6 +93,8 @@ class JsonVariantConst : public VariantTag,
|
||||
return static_cast<char>(as<signed char>());
|
||||
}
|
||||
|
||||
// Returns true if the value is of the specified type.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE
|
||||
typename enable_if<!is_same<T, char*>::value && !is_same<T, char>::value,
|
||||
@ -81,6 +103,8 @@ class JsonVariantConst : public VariantTag,
|
||||
return Converter<T>::checkJson(*this);
|
||||
}
|
||||
|
||||
// Deprecated: use is<const char*>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char*>::value, bool>::type
|
||||
ARDUINOJSON_DEPRECATED("Replace is<char*>() with is<const char*>()")
|
||||
@ -88,6 +112,8 @@ class JsonVariantConst : public VariantTag,
|
||||
return is<const char*>();
|
||||
}
|
||||
|
||||
// Deprecated: use is<int8_t>() or is<uint8_t>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char>::value, bool>::type
|
||||
ARDUINOJSON_DEPRECATED(
|
||||
@ -101,12 +127,14 @@ class JsonVariantConst : public VariantTag,
|
||||
return as<T>();
|
||||
}
|
||||
|
||||
// Gets array's element at specified index.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/subscript/
|
||||
FORCE_INLINE JsonVariantConst operator[](size_t index) const {
|
||||
return JsonVariantConst(variantGetElement(_data, index));
|
||||
}
|
||||
|
||||
// operator[](const std::string&) const
|
||||
// operator[](const String&) const
|
||||
// Gets object's member with specified key.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/subscript/
|
||||
template <typename TString>
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TString>::value, JsonVariantConst>::type
|
||||
@ -114,9 +142,8 @@ class JsonVariantConst : public VariantTag,
|
||||
return JsonVariantConst(variantGetMember(_data, adaptString(key)));
|
||||
}
|
||||
|
||||
// operator[](char*) const
|
||||
// operator[](const char*) const
|
||||
// operator[](const __FlashStringHelper*) const
|
||||
// Gets object's member with specified key.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/subscript/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE
|
||||
typename enable_if<IsString<TChar*>::value, JsonVariantConst>::type
|
||||
@ -124,17 +151,16 @@ class JsonVariantConst : public VariantTag,
|
||||
return JsonVariantConst(variantGetMember(_data, adaptString(key)));
|
||||
}
|
||||
|
||||
// containsKey(const std::string&) const
|
||||
// containsKey(const String&) const
|
||||
// Returns true if tge object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/containskey/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value, bool>::type
|
||||
containsKey(const TString& key) const {
|
||||
return variantGetMember(getData(), adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// containsKey(char*) const
|
||||
// containsKey(const char*) const
|
||||
// containsKey(const __FlashStringHelper*) const
|
||||
// Returns true if tge object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonvariantconst/containskey/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value, bool>::type
|
||||
containsKey(TChar* key) const {
|
||||
|
@ -25,18 +25,26 @@ class VariantRefBase : public VariantTag {
|
||||
friend class VariantAttorney;
|
||||
|
||||
public:
|
||||
// Sets the value to null.
|
||||
// ⚠️ Doesn't release the memory associated with the previous value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/clear/
|
||||
FORCE_INLINE void clear() const {
|
||||
variantSetNull(getData());
|
||||
}
|
||||
|
||||
// Returns true if the value is null or the reference is unbound.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/isnull/
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return variantIsNull(getData());
|
||||
}
|
||||
|
||||
// Returns true if the reference is unbound.
|
||||
FORCE_INLINE bool isUnbound() const {
|
||||
return !getData();
|
||||
}
|
||||
|
||||
// Casts the value to the specified type.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/as/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<!is_same<T, char*>::value &&
|
||||
!is_same<T, char>::value &&
|
||||
@ -46,12 +54,16 @@ class VariantRefBase : public VariantTag {
|
||||
return Converter<T>::fromJson(getVariantConst());
|
||||
}
|
||||
|
||||
// Casts the value to the specified type.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/as/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<ConverterNeedsWriteableRef<T>::value, T>::type
|
||||
as() const {
|
||||
return Converter<T>::fromJson(getVariant());
|
||||
}
|
||||
|
||||
// Deprecated: use as<const char*>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/as/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char*>::value, const char*>::type
|
||||
ARDUINOJSON_DEPRECATED("Replace as<char*>() with as<const char*>()")
|
||||
@ -59,6 +71,8 @@ class VariantRefBase : public VariantTag {
|
||||
return as<const char*>();
|
||||
}
|
||||
|
||||
// Deprecated: use as<int8_t>() or as<uint8_t>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/as/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char>::value, char>::type
|
||||
ARDUINOJSON_DEPRECATED(
|
||||
@ -72,22 +86,28 @@ class VariantRefBase : public VariantTag {
|
||||
return as<T>();
|
||||
}
|
||||
|
||||
// Change the type of the variant
|
||||
//
|
||||
// JsonArray to<JsonArray>()
|
||||
// Sets the value to an empty array.
|
||||
// ⚠️ Doesn't release the memory associated with the previous value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/to/
|
||||
template <typename T>
|
||||
typename enable_if<is_same<T, JsonArray>::value, JsonArray>::type to() const;
|
||||
//
|
||||
// JsonObject to<JsonObject>()
|
||||
|
||||
// Sets the value to an empty object.
|
||||
// ⚠️ Doesn't release the memory associated with the previous value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/to/
|
||||
template <typename T>
|
||||
typename enable_if<is_same<T, JsonObject>::value, JsonObject>::type to()
|
||||
const;
|
||||
//
|
||||
// JsonVariant to<JsonVariant>()
|
||||
|
||||
// Sets the value to null.
|
||||
// ⚠️ Doesn't release the memory associated with the previous value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/to/
|
||||
template <typename T>
|
||||
typename enable_if<is_same<T, JsonVariant>::value, JsonVariant>::type to()
|
||||
const;
|
||||
|
||||
// Returns true if the value is of the specified type.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE
|
||||
typename enable_if<ConverterNeedsWriteableRef<T>::value, bool>::type
|
||||
@ -95,6 +115,8 @@ class VariantRefBase : public VariantTag {
|
||||
return Converter<T>::checkJson(getVariant());
|
||||
}
|
||||
|
||||
// Returns true if the value is of the specified type.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<!ConverterNeedsWriteableRef<T>::value &&
|
||||
!is_same<T, char*>::value &&
|
||||
@ -104,6 +126,8 @@ class VariantRefBase : public VariantTag {
|
||||
return Converter<T>::checkJson(getVariantConst());
|
||||
}
|
||||
|
||||
// Deprecated: use is<const char*>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char*>::value, bool>::type
|
||||
ARDUINOJSON_DEPRECATED("Replace is<char*>() with is<const char*>()")
|
||||
@ -111,6 +135,8 @@ class VariantRefBase : public VariantTag {
|
||||
return is<const char*>();
|
||||
}
|
||||
|
||||
// Deprecated: use is<int8_t>() or is<uint8_t>() instead.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/is/
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, char>::value, bool>::type
|
||||
ARDUINOJSON_DEPRECATED(
|
||||
@ -119,6 +145,8 @@ class VariantRefBase : public VariantTag {
|
||||
return is<signed char>();
|
||||
}
|
||||
|
||||
// Shallow copies the specified value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/shallowcopy/
|
||||
FORCE_INLINE void shallowCopy(JsonVariantConst target) {
|
||||
VariantData* data = getOrCreateData();
|
||||
if (!data)
|
||||
@ -130,6 +158,8 @@ class VariantRefBase : public VariantTag {
|
||||
data->setNull();
|
||||
}
|
||||
|
||||
// Copies the specified value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/set/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(const T& value) const {
|
||||
Converter<T>::toJson(value, getOrCreateVariant());
|
||||
@ -137,6 +167,8 @@ class VariantRefBase : public VariantTag {
|
||||
return pool && !pool->overflowed();
|
||||
}
|
||||
|
||||
// Copies the specified value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/set/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(T* value) const {
|
||||
Converter<T*>::toJson(value, getOrCreateVariant());
|
||||
@ -144,45 +176,62 @@ class VariantRefBase : public VariantTag {
|
||||
return pool && !pool->overflowed();
|
||||
}
|
||||
|
||||
// Deprecated: use int8_t or uint8_t instead
|
||||
// https://arduinojson.org/v6/api/jsonvariant/set/
|
||||
bool ARDUINOJSON_DEPRECATED(
|
||||
"Support for char is deprecated, use int8_t or uint8_t instead")
|
||||
set(char value) const;
|
||||
|
||||
// Returns the size of the array or object.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/size/
|
||||
FORCE_INLINE size_t size() const {
|
||||
return variantSize(getData());
|
||||
}
|
||||
|
||||
// Returns the number of bytes occupied by the value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/memoryusage/
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
VariantData* data = getData();
|
||||
return data ? data->memoryUsage() : 0;
|
||||
}
|
||||
|
||||
// Returns the depth (nesting level) of the value.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/nesting/
|
||||
FORCE_INLINE size_t nesting() const {
|
||||
return variantNesting(getData());
|
||||
}
|
||||
|
||||
// Appends a new (null) element to the array.
|
||||
// Returns a reference to the new element.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/add/
|
||||
FORCE_INLINE JsonVariant add() const;
|
||||
|
||||
// Appends a value to the array.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/add/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool add(const T& value) const {
|
||||
return add().set(value);
|
||||
}
|
||||
//
|
||||
// bool add(TValue);
|
||||
// TValue = char*, const char*, const __FlashStringHelper*
|
||||
|
||||
// Appends a value to the array.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/add/
|
||||
template <typename T>
|
||||
FORCE_INLINE bool add(T* value) const {
|
||||
return add().set(value);
|
||||
}
|
||||
|
||||
// Removes an element of the array.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/remove/
|
||||
FORCE_INLINE void remove(size_t index) const {
|
||||
VariantData* data = getData();
|
||||
if (data)
|
||||
data->remove(index);
|
||||
}
|
||||
// remove(char*) const
|
||||
// remove(const char*) const
|
||||
// remove(const __FlashStringHelper*) const
|
||||
|
||||
// Removes a member of the object.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/remove/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value>::type remove(
|
||||
TChar* key) const {
|
||||
@ -190,8 +239,10 @@ class VariantRefBase : public VariantTag {
|
||||
if (data)
|
||||
data->remove(adaptString(key));
|
||||
}
|
||||
// remove(const std::string&) const
|
||||
// remove(const String&) const
|
||||
|
||||
// Removes a member of the object.
|
||||
// ⚠️ Doesn't release the memory associated with the removed element.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/remove/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value>::type remove(
|
||||
const TString& key) const {
|
||||
@ -200,37 +251,61 @@ class VariantRefBase : public VariantTag {
|
||||
data->remove(adaptString(key));
|
||||
}
|
||||
|
||||
// Creates an array and appends it to the array.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/createnestedarray/
|
||||
FORCE_INLINE JsonArray createNestedArray() const;
|
||||
|
||||
// Creates an object and appends it to the array.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/createnestedobject/
|
||||
FORCE_INLINE JsonObject createNestedObject() const;
|
||||
|
||||
// Gets or sets an array element.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/subscript/
|
||||
FORCE_INLINE ElementProxy<TDerived> operator[](size_t index) const;
|
||||
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/containskey/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value, bool>::type
|
||||
containsKey(const TString& key) const;
|
||||
|
||||
// Returns true if the object contains the specified key.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/containskey/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value, bool>::type
|
||||
containsKey(TChar* key) const;
|
||||
|
||||
// Gets or sets an object member.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/subscript/
|
||||
template <typename TString>
|
||||
FORCE_INLINE typename enable_if<IsString<TString>::value,
|
||||
MemberProxy<TDerived, TString> >::type
|
||||
operator[](const TString& key) const;
|
||||
|
||||
// Gets or sets an object member.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/subscript/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename enable_if<IsString<TChar*>::value,
|
||||
MemberProxy<TDerived, TChar*> >::type
|
||||
operator[](TChar* key) const;
|
||||
|
||||
// Creates an array and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/createnestedarray/
|
||||
template <typename TString>
|
||||
FORCE_INLINE JsonArray createNestedArray(const TString& key) const;
|
||||
|
||||
// Creates an array and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/createnestedarray/
|
||||
template <typename TChar>
|
||||
FORCE_INLINE JsonArray createNestedArray(TChar* key) const;
|
||||
|
||||
// Creates an object and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/createnestedobject/
|
||||
template <typename TString>
|
||||
JsonObject createNestedObject(const TString& key) const;
|
||||
|
||||
// Creates an object and adds it to the object.
|
||||
// https://arduinojson.org/v6/api/jsonvariant/createnestedobject/
|
||||
template <typename TChar>
|
||||
JsonObject createNestedObject(TChar* key) const;
|
||||
|
||||
|
Reference in New Issue
Block a user