mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
upgrade ArduinoJson to 6.21.2
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v6.21.2 (2023-04-12)
|
||||
-------
|
||||
|
||||
* Fix compatibility with the Zephyr Project (issue #1905)
|
||||
* Allow using PROGMEM outside of Arduino (issue #1903)
|
||||
* Set default for `ARDUINOJSON_ENABLE_PROGMEM` to `1` on AVR
|
||||
|
||||
v6.21.1 (2023-03-27)
|
||||
-------
|
||||
|
||||
* Double speed of `DynamicJsonDocument::garbageCollect()`
|
||||
* Fix compatibility with GCC 5.2 (issue #1897)
|
||||
|
||||
v6.21.0 (2023-03-14)
|
||||
-------
|
||||
|
||||
|
||||
161
lib/ArduinoJson/README.md
Normal file
161
lib/ArduinoJson/README.md
Normal file
@@ -0,0 +1,161 @@
|
||||
<p align="center">
|
||||
<a href="https://arduinojson.org/"><img alt="ArduinoJson" src="https://arduinojson.org/images/logo.svg" width="200" /></a>
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
[](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.21.2)
|
||||
[](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.2)
|
||||
[](https://components.espressif.com/components/bblanchon/arduinojson)
|
||||
[](https://github.com/bblanchon/ArduinoJson/stargazers)
|
||||
[](https://github.com/sponsors/bblanchon)
|
||||
|
||||
ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
|
||||
## Features
|
||||
|
||||
* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/)
|
||||
* [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||
* [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/)
|
||||
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/#filtering)
|
||||
* Supports single quotes as a string delimiter
|
||||
* Compatible with [NDJSON](http://ndjson.org/) and [JSON Lines](https://jsonlines.org/)
|
||||
* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/)
|
||||
* [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/)
|
||||
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/)
|
||||
* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/)
|
||||
* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/)
|
||||
* Efficient
|
||||
* [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/)
|
||||
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/)
|
||||
* [Deduplicates strings](https://arduinojson.org/news/2020/08/01/version-6-16-0/)
|
||||
* Versatile
|
||||
* Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/)
|
||||
* Supports [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/)
|
||||
* Supports [`Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/)
|
||||
* Supports [Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/)
|
||||
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/#custom-writer)
|
||||
* Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/)
|
||||
* Portable
|
||||
* Usable on any C++ project (not limited to Arduino)
|
||||
* Compatible with C++11, C++14 and C++17
|
||||
* Support for C++98/C++03 available on [ArduinoJson 6.20.x](https://github.com/bblanchon/ArduinoJson/tree/6.20.x)
|
||||
* Zero warnings with `-Wall -Wextra -pedantic` and `/W4`
|
||||
* [Header-only library](https://en.wikipedia.org/wiki/Header-only)
|
||||
* Works with virtually any board
|
||||
* Arduino boards: [Uno](https://amzn.to/38aL2ik), [Due](https://amzn.to/36YkWi2), [Micro](https://amzn.to/35WkdwG), [Nano](https://amzn.to/2QTvwRX), [Mega](https://amzn.to/36XWhuf), [Yun](https://amzn.to/30odURc), [Leonardo](https://amzn.to/36XWjlR)...
|
||||
* Espressif chips: [ESP8266](https://amzn.to/36YluV8), [ESP32](https://amzn.to/2G4pRCB)
|
||||
* Lolin (WeMos) boards: [D1 mini](https://amzn.to/2QUpz7q), [D1 Mini Pro](https://amzn.to/36UsGSs)...
|
||||
* Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj)
|
||||
* Particle boards: [Argon](https://amzn.to/2FQHa9X), [Boron](https://amzn.to/36WgLUd), [Electron](https://amzn.to/30vEc4k), [Photon](https://amzn.to/387F9Cd)...
|
||||
* Texas Instruments boards: [MSP430](https://amzn.to/30nJWgg)...
|
||||
* Soft cores: [Nios II](https://en.wikipedia.org/wiki/Nios_II)...
|
||||
* Tested on all major development environments
|
||||
* [Arduino IDE](https://www.arduino.cc/en/Main/Software)
|
||||
* [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/)
|
||||
* [Atollic TrueSTUDIO](https://atollic.com/truestudio/)
|
||||
* [Energia](http://energia.nu/)
|
||||
* [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/)
|
||||
* [Keil uVision](http://www.keil.com/)
|
||||
* [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide)
|
||||
* [Particle](https://www.particle.io/)
|
||||
* [PlatformIO](http://platformio.org/)
|
||||
* [Sloeber plugin for Eclipse](https://eclipse.baeyens.it/)
|
||||
* [Visual Micro](http://www.visualmicro.com/)
|
||||
* [Visual Studio](https://www.visualstudio.com/)
|
||||
* [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/RlZSKy17DjJ6HcdN)
|
||||
* [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/)
|
||||
* Well designed
|
||||
* [Elegant API](http://arduinojson.org/v6/example/)
|
||||
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
|
||||
* Self-contained (no external dependency)
|
||||
* `const` friendly
|
||||
* [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/)
|
||||
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
|
||||
* Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/#integer-overflows)
|
||||
* Well tested
|
||||
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
* Continuously tested on
|
||||
* [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
* [GCC 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [Clang 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
* Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/)
|
||||
* Well documented
|
||||
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/)
|
||||
* [Examples](https://arduinojson.org/v6/example/)
|
||||
* [How-tos](https://arduinojson.org/v6/example/)
|
||||
* [FAQ](https://arduinojson.org/v6/faq/)
|
||||
* [Troubleshooter](https://arduinojson.org/v6/troubleshooter/)
|
||||
* [Book](https://arduinojson.org/book/)
|
||||
* [Changelog](CHANGELOG.md)
|
||||
* Vibrant user community
|
||||
* Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories)
|
||||
* [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson)
|
||||
* [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed)
|
||||
|
||||
## Quickstart
|
||||
|
||||
### Deserialization
|
||||
|
||||
Here is a program that parses a JSON document with ArduinoJson.
|
||||
|
||||
```c++
|
||||
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, json);
|
||||
|
||||
const char* sensor = doc["sensor"];
|
||||
long time = doc["time"];
|
||||
double latitude = doc["data"][0];
|
||||
double longitude = doc["data"][1];
|
||||
```
|
||||
|
||||
See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/deserialization/)
|
||||
|
||||
### Serialization
|
||||
|
||||
Here is a program that generates a JSON document with ArduinoJson:
|
||||
|
||||
```c++
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
doc["sensor"] = "gps";
|
||||
doc["time"] = 1351824120;
|
||||
doc["data"][0] = 48.756080;
|
||||
doc["data"][1] = 2.302038;
|
||||
|
||||
serializeJson(doc, Serial);
|
||||
// This prints:
|
||||
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
|
||||
```
|
||||
|
||||
See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/serialization/)
|
||||
|
||||
## Sponsors
|
||||
|
||||
ArduinoJson is thankful to its sponsors. Please give them a visit; they deserve it!
|
||||
|
||||
<p>
|
||||
<a href="https://www.programmingelectronics.com/" rel="sponsored">
|
||||
<img src="https://arduinojson.org/images/2021/10/programmingeleactronicsacademy.png" alt="Programming Electronics Academy" width="200">
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://github.com/1technophile" rel="sponsored">
|
||||
<img alt="1technophile" src="https://avatars.githubusercontent.com/u/12672732?s=40&v=4">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
If you run a commercial project that embeds ArduinoJson, think about [sponsoring the library's development](https://github.com/sponsors/bblanchon): it ensures the code that your products rely on stays actively maintained. It can also give your project some exposure to the makers' community.
|
||||
|
||||
If you are an individual user and want to support the development (or give a sign of appreciation), consider purchasing the book [Mastering ArduinoJson](https://arduinojson.org/book/) ❤, or simply [cast a star](https://github.com/bblanchon/ArduinoJson/stargazers) ⭐.
|
||||
40
lib/ArduinoJson/keywords.txt
Normal file
40
lib/ArduinoJson/keywords.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
# Macros
|
||||
JSON_ARRAY_SIZE KEYWORD2
|
||||
JSON_OBJECT_SIZE KEYWORD2
|
||||
JSON_STRING_SIZE KEYWORD2
|
||||
|
||||
# Free functions
|
||||
deserializeJson KEYWORD2
|
||||
deserializeMsgPack KEYWORD2
|
||||
serialized KEYWORD2
|
||||
serializeJson KEYWORD2
|
||||
serializeJsonPretty KEYWORD2
|
||||
serializeMsgPack KEYWORD2
|
||||
measureJson KEYWORD2
|
||||
measureJsonPretty KEYWORD2
|
||||
measureMsgPack KEYWORD2
|
||||
|
||||
# Methods
|
||||
add KEYWORD2
|
||||
as KEYWORD2
|
||||
createNestedArray KEYWORD2
|
||||
createNestedObject KEYWORD2
|
||||
get KEYWORD2
|
||||
set KEYWORD2
|
||||
to KEYWORD2
|
||||
|
||||
# Type names
|
||||
DeserializationError KEYWORD1 DATA_TYPE
|
||||
DynamicJsonDocument KEYWORD1 DATA_TYPE
|
||||
JsonArray KEYWORD1 DATA_TYPE
|
||||
JsonArrayConst KEYWORD1 DATA_TYPE
|
||||
JsonDocument KEYWORD1 DATA_TYPE
|
||||
JsonFloat KEYWORD1 DATA_TYPE
|
||||
JsonInteger KEYWORD1 DATA_TYPE
|
||||
JsonObject KEYWORD1 DATA_TYPE
|
||||
JsonObjectConst KEYWORD1 DATA_TYPE
|
||||
JsonString KEYWORD1 DATA_TYPE
|
||||
JsonUInt KEYWORD1 DATA_TYPE
|
||||
JsonVariant KEYWORD1 DATA_TYPE
|
||||
JsonVariantConst KEYWORD1 DATA_TYPE
|
||||
StaticJsonDocument KEYWORD1 DATA_TYPE
|
||||
11
lib/ArduinoJson/library.properties
Normal file
11
lib/ArduinoJson/library.properties
Normal file
@@ -0,0 +1,11 @@
|
||||
name=ArduinoJson
|
||||
version=6.21.2
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=A simple and efficient JSON library for embedded C++.
|
||||
paragraph=ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation.
|
||||
category=Data Processing
|
||||
url=https://arduinojson.org/?utm_source=meta&utm_medium=library.properties
|
||||
architectures=*
|
||||
repository=https://github.com/bblanchon/ArduinoJson.git
|
||||
license=MIT
|
||||
@@ -13,7 +13,8 @@
|
||||
// Include Arduino.h before stdlib.h to avoid conflict with atexit()
|
||||
// https://github.com/bblanchon/ArduinoJson/pull/1693#issuecomment-1001060240
|
||||
#if ARDUINOJSON_ENABLE_ARDUINO_STRING || ARDUINOJSON_ENABLE_ARDUINO_STREAM || \
|
||||
ARDUINOJSON_ENABLE_ARDUINO_PRINT || ARDUINOJSON_ENABLE_PROGMEM
|
||||
ARDUINOJSON_ENABLE_ARDUINO_PRINT || \
|
||||
(ARDUINOJSON_ENABLE_PROGMEM && defined(ARDUINO))
|
||||
# include <Arduino.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ class ElementProxy : public VariantRefBase<ElementProxy<TUpstream>>,
|
||||
|
||||
public:
|
||||
ElementProxy(TUpstream upstream, size_t index)
|
||||
: _upstream(upstream), _index(index) {}
|
||||
: upstream_(upstream), index_(index) {}
|
||||
|
||||
ElementProxy(const ElementProxy& src)
|
||||
: _upstream(src._upstream), _index(src._index) {}
|
||||
: upstream_(src.upstream_), index_(src.index_) {}
|
||||
|
||||
FORCE_INLINE ElementProxy& operator=(const ElementProxy& src) {
|
||||
this->set(src);
|
||||
@@ -41,20 +41,20 @@ class ElementProxy : public VariantRefBase<ElementProxy<TUpstream>>,
|
||||
|
||||
private:
|
||||
FORCE_INLINE MemoryPool* getPool() const {
|
||||
return VariantAttorney::getPool(_upstream);
|
||||
return VariantAttorney::getPool(upstream_);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantData* getData() const {
|
||||
return variantGetElement(VariantAttorney::getData(_upstream), _index);
|
||||
return variantGetElement(VariantAttorney::getData(upstream_), index_);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantData* getOrCreateData() const {
|
||||
return variantGetOrAddElement(VariantAttorney::getOrCreateData(_upstream),
|
||||
_index, VariantAttorney::getPool(_upstream));
|
||||
return variantGetOrAddElement(VariantAttorney::getOrCreateData(upstream_),
|
||||
index_, VariantAttorney::getPool(upstream_));
|
||||
}
|
||||
|
||||
TUpstream _upstream;
|
||||
size_t _index;
|
||||
TUpstream upstream_;
|
||||
size_t index_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -20,32 +20,32 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
typedef JsonArrayIterator iterator;
|
||||
|
||||
// Constructs an unbound reference.
|
||||
FORCE_INLINE JsonArray() : _data(0), _pool(0) {}
|
||||
FORCE_INLINE JsonArray() : data_(0), pool_(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
FORCE_INLINE JsonArray(detail::MemoryPool* pool, detail::CollectionData* data)
|
||||
: _data(data), _pool(pool) {}
|
||||
: 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<detail::VariantData*>(data));
|
||||
void* data = data_; // prevent warning cast-align
|
||||
return JsonVariant(pool_, reinterpret_cast<detail::VariantData*>(data));
|
||||
}
|
||||
|
||||
// Returns a read-only reference to the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/
|
||||
operator JsonArrayConst() const {
|
||||
return JsonArrayConst(_data);
|
||||
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)
|
||||
if (!data_)
|
||||
return JsonVariant();
|
||||
return JsonVariant(_pool, _data->addElement(_pool));
|
||||
return JsonVariant(pool_, data_->addElement(pool_));
|
||||
}
|
||||
|
||||
// Appends a value to the array.
|
||||
@@ -65,9 +65,9 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
// Returns an iterator to the first element of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/begin/
|
||||
FORCE_INLINE iterator begin() const {
|
||||
if (!_data)
|
||||
if (!data_)
|
||||
return iterator();
|
||||
return iterator(_pool, _data->head());
|
||||
return iterator(pool_, data_->head());
|
||||
}
|
||||
|
||||
// Returns an iterator following the last element of the array.
|
||||
@@ -79,41 +79,41 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
// Copies an array.
|
||||
// https://arduinojson.org/v6/api/jsonarray/set/
|
||||
FORCE_INLINE bool set(JsonArrayConst src) const {
|
||||
if (!_data || !src._data)
|
||||
if (!data_ || !src.data_)
|
||||
return false;
|
||||
return _data->copyFrom(*src._data, _pool);
|
||||
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);
|
||||
return JsonArrayConst(data_) == JsonArrayConst(rhs.data_);
|
||||
}
|
||||
|
||||
// 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)
|
||||
if (!data_)
|
||||
return;
|
||||
_data->removeSlot(it._slot);
|
||||
data_->removeSlot(it.slot_);
|
||||
}
|
||||
|
||||
// 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)
|
||||
if (!data_)
|
||||
return;
|
||||
_data->removeElement(index);
|
||||
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)
|
||||
if (!data_)
|
||||
return;
|
||||
_data->clear();
|
||||
data_->clear();
|
||||
}
|
||||
|
||||
// Gets or sets the element at the specified index.
|
||||
@@ -133,54 +133,54 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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));
|
||||
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;
|
||||
return data_ ? data_->size() : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
detail::MemoryPool* getPool() const {
|
||||
return _pool;
|
||||
return pool_;
|
||||
}
|
||||
|
||||
detail::VariantData* getData() const {
|
||||
return collectionToVariant(_data);
|
||||
return collectionToVariant(data_);
|
||||
}
|
||||
|
||||
detail::VariantData* getOrCreateData() const {
|
||||
return collectionToVariant(_data);
|
||||
return collectionToVariant(data_);
|
||||
}
|
||||
|
||||
detail::CollectionData* _data;
|
||||
detail::MemoryPool* _pool;
|
||||
detail::CollectionData* data_;
|
||||
detail::MemoryPool* pool_;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -24,9 +24,9 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
|
||||
// Returns an iterator to the first element of the array.
|
||||
// https://arduinojson.org/v6/api/jsonarrayconst/begin/
|
||||
FORCE_INLINE iterator begin() const {
|
||||
if (!_data)
|
||||
if (!data_)
|
||||
return iterator();
|
||||
return iterator(_data->head());
|
||||
return iterator(data_->head());
|
||||
}
|
||||
|
||||
// Returns an iterator to the element following the last element of the array.
|
||||
@@ -36,18 +36,18 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
|
||||
}
|
||||
|
||||
// Creates an unbound reference.
|
||||
FORCE_INLINE JsonArrayConst() : _data(0) {}
|
||||
FORCE_INLINE JsonArrayConst() : data_(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
FORCE_INLINE JsonArrayConst(const detail::CollectionData* data)
|
||||
: _data(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)
|
||||
if (data_ == rhs.data_)
|
||||
return true;
|
||||
if (!_data || !rhs._data)
|
||||
if (!data_ || !rhs.data_)
|
||||
return false;
|
||||
|
||||
iterator it1 = begin();
|
||||
@@ -70,49 +70,49 @@ class JsonArrayConst : public detail::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);
|
||||
return JsonVariantConst(data_ ? data_->getElement(index) : 0);
|
||||
}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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));
|
||||
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;
|
||||
return data_ ? data_->size() : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
const detail::VariantData* getData() const {
|
||||
return collectionToVariant(_data);
|
||||
return collectionToVariant(data_);
|
||||
}
|
||||
|
||||
const detail::CollectionData* _data;
|
||||
const detail::CollectionData* data_;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -12,110 +12,110 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
class VariantPtr {
|
||||
public:
|
||||
VariantPtr(detail::MemoryPool* pool, detail::VariantData* data)
|
||||
: _variant(pool, data) {}
|
||||
: variant_(pool, data) {}
|
||||
|
||||
JsonVariant* operator->() {
|
||||
return &_variant;
|
||||
return &variant_;
|
||||
}
|
||||
|
||||
JsonVariant& operator*() {
|
||||
return _variant;
|
||||
return variant_;
|
||||
}
|
||||
|
||||
private:
|
||||
JsonVariant _variant;
|
||||
JsonVariant variant_;
|
||||
};
|
||||
|
||||
class JsonArrayIterator {
|
||||
friend class JsonArray;
|
||||
|
||||
public:
|
||||
JsonArrayIterator() : _slot(0) {}
|
||||
JsonArrayIterator() : slot_(0) {}
|
||||
explicit JsonArrayIterator(detail::MemoryPool* pool,
|
||||
detail::VariantSlot* slot)
|
||||
: _pool(pool), _slot(slot) {}
|
||||
: pool_(pool), slot_(slot) {}
|
||||
|
||||
JsonVariant operator*() const {
|
||||
return JsonVariant(_pool, _slot->data());
|
||||
return JsonVariant(pool_, slot_->data());
|
||||
}
|
||||
VariantPtr operator->() {
|
||||
return VariantPtr(_pool, _slot->data());
|
||||
return VariantPtr(pool_, slot_->data());
|
||||
}
|
||||
|
||||
bool operator==(const JsonArrayIterator& other) const {
|
||||
return _slot == other._slot;
|
||||
return slot_ == other.slot_;
|
||||
}
|
||||
|
||||
bool operator!=(const JsonArrayIterator& other) const {
|
||||
return _slot != other._slot;
|
||||
return slot_ != other.slot_;
|
||||
}
|
||||
|
||||
JsonArrayIterator& operator++() {
|
||||
_slot = _slot->next();
|
||||
slot_ = slot_->next();
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonArrayIterator& operator+=(size_t distance) {
|
||||
_slot = _slot->next(distance);
|
||||
slot_ = slot_->next(distance);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
detail::MemoryPool* _pool;
|
||||
detail::VariantSlot* _slot;
|
||||
detail::MemoryPool* pool_;
|
||||
detail::VariantSlot* slot_;
|
||||
};
|
||||
|
||||
class VariantConstPtr {
|
||||
public:
|
||||
VariantConstPtr(const detail::VariantData* data) : _variant(data) {}
|
||||
VariantConstPtr(const detail::VariantData* data) : variant_(data) {}
|
||||
|
||||
JsonVariantConst* operator->() {
|
||||
return &_variant;
|
||||
return &variant_;
|
||||
}
|
||||
|
||||
JsonVariantConst& operator*() {
|
||||
return _variant;
|
||||
return variant_;
|
||||
}
|
||||
|
||||
private:
|
||||
JsonVariantConst _variant;
|
||||
JsonVariantConst variant_;
|
||||
};
|
||||
|
||||
class JsonArrayConstIterator {
|
||||
friend class JsonArray;
|
||||
|
||||
public:
|
||||
JsonArrayConstIterator() : _slot(0) {}
|
||||
JsonArrayConstIterator() : slot_(0) {}
|
||||
explicit JsonArrayConstIterator(const detail::VariantSlot* slot)
|
||||
: _slot(slot) {}
|
||||
: slot_(slot) {}
|
||||
|
||||
JsonVariantConst operator*() const {
|
||||
return JsonVariantConst(_slot->data());
|
||||
return JsonVariantConst(slot_->data());
|
||||
}
|
||||
VariantConstPtr operator->() {
|
||||
return VariantConstPtr(_slot->data());
|
||||
return VariantConstPtr(slot_->data());
|
||||
}
|
||||
|
||||
bool operator==(const JsonArrayConstIterator& other) const {
|
||||
return _slot == other._slot;
|
||||
return slot_ == other.slot_;
|
||||
}
|
||||
|
||||
bool operator!=(const JsonArrayConstIterator& other) const {
|
||||
return _slot != other._slot;
|
||||
return slot_ != other.slot_;
|
||||
}
|
||||
|
||||
JsonArrayConstIterator& operator++() {
|
||||
_slot = _slot->next();
|
||||
slot_ = slot_->next();
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonArrayConstIterator& operator+=(size_t distance) {
|
||||
_slot = _slot->next(distance);
|
||||
slot_ = slot_->next(distance);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
const detail::VariantSlot* _slot;
|
||||
const detail::VariantSlot* slot_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
||||
@@ -16,8 +16,8 @@ class VariantData;
|
||||
class VariantSlot;
|
||||
|
||||
class CollectionData {
|
||||
VariantSlot* _head;
|
||||
VariantSlot* _tail;
|
||||
VariantSlot* head_;
|
||||
VariantSlot* tail_;
|
||||
|
||||
public:
|
||||
// Must be a POD!
|
||||
@@ -67,7 +67,7 @@ class CollectionData {
|
||||
bool copyFrom(const CollectionData& src, MemoryPool* pool);
|
||||
|
||||
VariantSlot* head() const {
|
||||
return _head;
|
||||
return head_;
|
||||
}
|
||||
|
||||
void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance);
|
||||
|
||||
@@ -16,13 +16,13 @@ inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) {
|
||||
if (!slot)
|
||||
return 0;
|
||||
|
||||
if (_tail) {
|
||||
ARDUINOJSON_ASSERT(pool->owns(_tail)); // Can't alter a linked array/object
|
||||
_tail->setNextNotNull(slot);
|
||||
_tail = slot;
|
||||
if (tail_) {
|
||||
ARDUINOJSON_ASSERT(pool->owns(tail_)); // Can't alter a linked array/object
|
||||
tail_->setNextNotNull(slot);
|
||||
tail_ = slot;
|
||||
} else {
|
||||
_head = slot;
|
||||
_tail = slot;
|
||||
head_ = slot;
|
||||
tail_ = slot;
|
||||
}
|
||||
|
||||
slot->clear();
|
||||
@@ -45,8 +45,8 @@ inline VariantData* CollectionData::addMember(TAdaptedString key,
|
||||
}
|
||||
|
||||
inline void CollectionData::clear() {
|
||||
_head = 0;
|
||||
_tail = 0;
|
||||
head_ = 0;
|
||||
tail_ = 0;
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
@@ -57,7 +57,7 @@ inline bool CollectionData::containsKey(const TAdaptedString& key) const {
|
||||
inline bool CollectionData::copyFrom(const CollectionData& src,
|
||||
MemoryPool* pool) {
|
||||
clear();
|
||||
for (VariantSlot* s = src._head; s; s = s->next()) {
|
||||
for (VariantSlot* s = src.head_; s; s = s->next()) {
|
||||
VariantData* var;
|
||||
if (s->key() != 0) {
|
||||
JsonString key(s->key(),
|
||||
@@ -78,7 +78,7 @@ template <typename TAdaptedString>
|
||||
inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
|
||||
if (key.isNull())
|
||||
return 0;
|
||||
VariantSlot* slot = _head;
|
||||
VariantSlot* slot = head_;
|
||||
while (slot) {
|
||||
if (stringEquals(key, adaptString(slot->key())))
|
||||
break;
|
||||
@@ -88,13 +88,13 @@ inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
|
||||
}
|
||||
|
||||
inline VariantSlot* CollectionData::getSlot(size_t index) const {
|
||||
if (!_head)
|
||||
if (!head_)
|
||||
return 0;
|
||||
return _head->next(index);
|
||||
return head_->next(index);
|
||||
}
|
||||
|
||||
inline VariantSlot* CollectionData::getPreviousSlot(VariantSlot* target) const {
|
||||
VariantSlot* current = _head;
|
||||
VariantSlot* current = head_;
|
||||
while (current) {
|
||||
VariantSlot* next = current->next();
|
||||
if (next == target)
|
||||
@@ -132,7 +132,7 @@ inline VariantData* CollectionData::getElement(size_t index) const {
|
||||
|
||||
inline VariantData* CollectionData::getOrAddElement(size_t index,
|
||||
MemoryPool* pool) {
|
||||
VariantSlot* slot = _head;
|
||||
VariantSlot* slot = head_;
|
||||
while (slot && index > 0) {
|
||||
slot = slot->next();
|
||||
index--;
|
||||
@@ -154,9 +154,9 @@ inline void CollectionData::removeSlot(VariantSlot* slot) {
|
||||
if (prev)
|
||||
prev->setNext(next);
|
||||
else
|
||||
_head = next;
|
||||
head_ = next;
|
||||
if (!next)
|
||||
_tail = prev;
|
||||
tail_ = prev;
|
||||
}
|
||||
|
||||
inline void CollectionData::removeElement(size_t index) {
|
||||
@@ -165,7 +165,7 @@ inline void CollectionData::removeElement(size_t index) {
|
||||
|
||||
inline size_t CollectionData::memoryUsage() const {
|
||||
size_t total = 0;
|
||||
for (VariantSlot* s = _head; s; s = s->next()) {
|
||||
for (VariantSlot* s = head_; s; s = s->next()) {
|
||||
total += sizeof(VariantSlot) + s->data()->memoryUsage();
|
||||
if (s->ownsKey())
|
||||
total += strlen(s->key()) + 1;
|
||||
@@ -174,7 +174,7 @@ inline size_t CollectionData::memoryUsage() const {
|
||||
}
|
||||
|
||||
inline size_t CollectionData::size() const {
|
||||
return slotSize(_head);
|
||||
return slotSize(head_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -188,9 +188,9 @@ inline void movePointer(T*& p, ptrdiff_t offset) {
|
||||
|
||||
inline void CollectionData::movePointers(ptrdiff_t stringDistance,
|
||||
ptrdiff_t variantDistance) {
|
||||
movePointer(_head, variantDistance);
|
||||
movePointer(_tail, variantDistance);
|
||||
for (VariantSlot* slot = _head; slot; slot = slot->next())
|
||||
movePointer(head_, variantDistance);
|
||||
movePointer(tail_, variantDistance);
|
||||
for (VariantSlot* slot = head_; slot; slot = slot->next())
|
||||
slot->movePointers(stringDistance, variantDistance);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,9 +130,13 @@
|
||||
# define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0
|
||||
# endif
|
||||
|
||||
// Disable support for PROGMEM
|
||||
// Enable PROGMEM support on AVR only
|
||||
# ifndef ARDUINOJSON_ENABLE_PROGMEM
|
||||
# define ARDUINOJSON_ENABLE_PROGMEM 0
|
||||
# ifdef __AVR__
|
||||
# define ARDUINOJSON_ENABLE_PROGMEM 1
|
||||
# else
|
||||
# define ARDUINOJSON_ENABLE_PROGMEM 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif // ARDUINO
|
||||
|
||||
@@ -26,49 +26,49 @@ class DeserializationError {
|
||||
};
|
||||
|
||||
DeserializationError() {}
|
||||
DeserializationError(Code c) : _code(c) {}
|
||||
DeserializationError(Code c) : code_(c) {}
|
||||
|
||||
// Compare with DeserializationError
|
||||
friend bool operator==(const DeserializationError& lhs,
|
||||
const DeserializationError& rhs) {
|
||||
return lhs._code == rhs._code;
|
||||
return lhs.code_ == rhs.code_;
|
||||
}
|
||||
friend bool operator!=(const DeserializationError& lhs,
|
||||
const DeserializationError& rhs) {
|
||||
return lhs._code != rhs._code;
|
||||
return lhs.code_ != rhs.code_;
|
||||
}
|
||||
|
||||
// Compare with Code
|
||||
friend bool operator==(const DeserializationError& lhs, Code rhs) {
|
||||
return lhs._code == rhs;
|
||||
return lhs.code_ == rhs;
|
||||
}
|
||||
friend bool operator==(Code lhs, const DeserializationError& rhs) {
|
||||
return lhs == rhs._code;
|
||||
return lhs == rhs.code_;
|
||||
}
|
||||
friend bool operator!=(const DeserializationError& lhs, Code rhs) {
|
||||
return lhs._code != rhs;
|
||||
return lhs.code_ != rhs;
|
||||
}
|
||||
friend bool operator!=(Code lhs, const DeserializationError& rhs) {
|
||||
return lhs != rhs._code;
|
||||
return lhs != rhs.code_;
|
||||
}
|
||||
|
||||
// Returns true if there is an error
|
||||
explicit operator bool() const {
|
||||
return _code != Ok;
|
||||
return code_ != Ok;
|
||||
}
|
||||
|
||||
// Returns internal enum, useful for switch statement
|
||||
Code code() const {
|
||||
return _code;
|
||||
return code_;
|
||||
}
|
||||
|
||||
const char* c_str() const {
|
||||
static const char* messages[] = {
|
||||
"Ok", "EmptyInput", "IncompleteInput",
|
||||
"InvalidInput", "NoMemory", "TooDeep"};
|
||||
ARDUINOJSON_ASSERT(static_cast<size_t>(_code) <
|
||||
ARDUINOJSON_ASSERT(static_cast<size_t>(code_) <
|
||||
sizeof(messages) / sizeof(messages[0]));
|
||||
return messages[_code];
|
||||
return messages[code_];
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_ENABLE_PROGMEM
|
||||
@@ -82,12 +82,12 @@ class DeserializationError {
|
||||
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(const char*, messages,
|
||||
{s0, s1, s2, s3, s4, s5});
|
||||
return reinterpret_cast<const __FlashStringHelper*>(
|
||||
detail::pgm_read(messages + _code));
|
||||
detail::pgm_read(messages + code_));
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
Code _code;
|
||||
Code code_;
|
||||
};
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STREAM
|
||||
|
||||
@@ -11,34 +11,34 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
namespace DeserializationOption {
|
||||
class Filter {
|
||||
public:
|
||||
explicit Filter(JsonVariantConst v) : _variant(v) {}
|
||||
explicit Filter(JsonVariantConst v) : variant_(v) {}
|
||||
|
||||
bool allow() const {
|
||||
return _variant;
|
||||
return variant_;
|
||||
}
|
||||
|
||||
bool allowArray() const {
|
||||
return _variant == true || _variant.is<JsonArrayConst>();
|
||||
return variant_ == true || variant_.is<JsonArrayConst>();
|
||||
}
|
||||
|
||||
bool allowObject() const {
|
||||
return _variant == true || _variant.is<JsonObjectConst>();
|
||||
return variant_ == true || variant_.is<JsonObjectConst>();
|
||||
}
|
||||
|
||||
bool allowValue() const {
|
||||
return _variant == true;
|
||||
return variant_ == true;
|
||||
}
|
||||
|
||||
template <typename TKey>
|
||||
Filter operator[](const TKey& key) const {
|
||||
if (_variant == true) // "true" means "allow recursively"
|
||||
if (variant_ == true) // "true" means "allow recursively"
|
||||
return *this;
|
||||
JsonVariantConst member = _variant[key];
|
||||
return Filter(member.isNull() ? _variant["*"] : member);
|
||||
JsonVariantConst member = variant_[key];
|
||||
return Filter(member.isNull() ? variant_["*"] : member);
|
||||
}
|
||||
|
||||
private:
|
||||
JsonVariantConst _variant;
|
||||
JsonVariantConst variant_;
|
||||
};
|
||||
} // namespace DeserializationOption
|
||||
|
||||
|
||||
@@ -12,20 +12,20 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
namespace DeserializationOption {
|
||||
class NestingLimit {
|
||||
public:
|
||||
NestingLimit() : _value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {}
|
||||
explicit NestingLimit(uint8_t n) : _value(n) {}
|
||||
NestingLimit() : value_(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {}
|
||||
explicit NestingLimit(uint8_t n) : value_(n) {}
|
||||
|
||||
NestingLimit decrement() const {
|
||||
ARDUINOJSON_ASSERT(_value > 0);
|
||||
return NestingLimit(static_cast<uint8_t>(_value - 1));
|
||||
ARDUINOJSON_ASSERT(value_ > 0);
|
||||
return NestingLimit(static_cast<uint8_t>(value_ - 1));
|
||||
}
|
||||
|
||||
bool reached() const {
|
||||
return _value == 0;
|
||||
return value_ == 0;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t _value;
|
||||
uint8_t value_;
|
||||
};
|
||||
} // namespace DeserializationOption
|
||||
|
||||
|
||||
@@ -15,18 +15,18 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
template <typename TSource, typename Enable = void>
|
||||
struct Reader {
|
||||
public:
|
||||
Reader(TSource& source) : _source(&source) {}
|
||||
Reader(TSource& source) : source_(&source) {}
|
||||
|
||||
int read() {
|
||||
return _source->read(); // Error here? You passed an unsupported input type
|
||||
return source_->read(); // Error here? You passed an unsupported input type
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
return _source->readBytes(buffer, length);
|
||||
return source_->readBytes(buffer, length);
|
||||
}
|
||||
|
||||
private:
|
||||
TSource* _source;
|
||||
TSource* source_;
|
||||
};
|
||||
|
||||
template <typename TSource, typename Enable = void>
|
||||
|
||||
@@ -12,20 +12,20 @@ template <typename TSource>
|
||||
struct Reader<TSource,
|
||||
typename enable_if<is_base_of<Stream, TSource>::value>::type> {
|
||||
public:
|
||||
explicit Reader(Stream& stream) : _stream(&stream) {}
|
||||
explicit Reader(Stream& stream) : stream_(&stream) {}
|
||||
|
||||
int read() {
|
||||
// don't use _stream.read() as it ignores the timeout
|
||||
// don't use stream_.read() as it ignores the timeout
|
||||
char c;
|
||||
return _stream->readBytes(&c, 1) ? static_cast<unsigned char>(c) : -1;
|
||||
return stream_->readBytes(&c, 1) ? static_cast<unsigned char>(c) : -1;
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
return _stream->readBytes(buffer, length);
|
||||
return stream_->readBytes(buffer, length);
|
||||
}
|
||||
|
||||
private:
|
||||
Stream* _stream;
|
||||
Stream* stream_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -4,51 +4,51 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson/Polyfills/pgmspace.hpp>
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <>
|
||||
struct Reader<const __FlashStringHelper*, void> {
|
||||
const char* _ptr;
|
||||
const char* ptr_;
|
||||
|
||||
public:
|
||||
explicit Reader(const __FlashStringHelper* ptr)
|
||||
: _ptr(reinterpret_cast<const char*>(ptr)) {}
|
||||
: ptr_(reinterpret_cast<const char*>(ptr)) {}
|
||||
|
||||
int read() {
|
||||
return pgm_read_byte(_ptr++);
|
||||
return pgm_read_byte(ptr_++);
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
memcpy_P(buffer, _ptr, length);
|
||||
_ptr += length;
|
||||
memcpy_P(buffer, ptr_, length);
|
||||
ptr_ += length;
|
||||
return length;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct BoundedReader<const __FlashStringHelper*, void> {
|
||||
const char* _ptr;
|
||||
const char* _end;
|
||||
const char* ptr_;
|
||||
const char* end_;
|
||||
|
||||
public:
|
||||
explicit BoundedReader(const __FlashStringHelper* ptr, size_t size)
|
||||
: _ptr(reinterpret_cast<const char*>(ptr)), _end(_ptr + size) {}
|
||||
: ptr_(reinterpret_cast<const char*>(ptr)), end_(ptr_ + size) {}
|
||||
|
||||
int read() {
|
||||
if (_ptr < _end)
|
||||
return pgm_read_byte(_ptr++);
|
||||
if (ptr_ < end_)
|
||||
return pgm_read_byte(ptr_++);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
size_t available = static_cast<size_t>(_end - _ptr);
|
||||
size_t available = static_cast<size_t>(end_ - ptr_);
|
||||
if (available < length)
|
||||
length = available;
|
||||
memcpy_P(buffer, _ptr, length);
|
||||
_ptr += length;
|
||||
memcpy_P(buffer, ptr_, length);
|
||||
ptr_ += length;
|
||||
return length;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,23 +8,23 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename TIterator>
|
||||
class IteratorReader {
|
||||
TIterator _ptr, _end;
|
||||
TIterator ptr_, end_;
|
||||
|
||||
public:
|
||||
explicit IteratorReader(TIterator begin, TIterator end)
|
||||
: _ptr(begin), _end(end) {}
|
||||
: ptr_(begin), end_(end) {}
|
||||
|
||||
int read() {
|
||||
if (_ptr < _end)
|
||||
return static_cast<unsigned char>(*_ptr++);
|
||||
if (ptr_ < end_)
|
||||
return static_cast<unsigned char>(*ptr_++);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
size_t i = 0;
|
||||
while (i < length && _ptr < _end)
|
||||
buffer[i++] = *_ptr++;
|
||||
while (i < length && ptr_ < end_)
|
||||
buffer[i++] = *ptr_++;
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,19 +21,19 @@ struct IsCharOrVoid<const T> : IsCharOrVoid<T> {};
|
||||
template <typename TSource>
|
||||
struct Reader<TSource*,
|
||||
typename enable_if<IsCharOrVoid<TSource>::value>::type> {
|
||||
const char* _ptr;
|
||||
const char* ptr_;
|
||||
|
||||
public:
|
||||
explicit Reader(const void* ptr)
|
||||
: _ptr(ptr ? reinterpret_cast<const char*>(ptr) : "") {}
|
||||
: ptr_(ptr ? reinterpret_cast<const char*>(ptr) : "") {}
|
||||
|
||||
int read() {
|
||||
return static_cast<unsigned char>(*_ptr++);
|
||||
return static_cast<unsigned char>(*ptr_++);
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
for (size_t i = 0; i < length; i++)
|
||||
buffer[i] = *_ptr++;
|
||||
buffer[i] = *ptr_++;
|
||||
return length;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,19 +12,19 @@ template <typename TSource>
|
||||
struct Reader<TSource, typename enable_if<
|
||||
is_base_of<std::istream, TSource>::value>::type> {
|
||||
public:
|
||||
explicit Reader(std::istream& stream) : _stream(&stream) {}
|
||||
explicit Reader(std::istream& stream) : stream_(&stream) {}
|
||||
|
||||
int read() {
|
||||
return _stream->get();
|
||||
return stream_->get();
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
_stream->read(buffer, static_cast<std::streamsize>(length));
|
||||
return static_cast<size_t>(_stream->gcount());
|
||||
stream_->read(buffer, static_cast<std::streamsize>(length));
|
||||
return static_cast<size_t>(stream_->gcount());
|
||||
}
|
||||
|
||||
private:
|
||||
std::istream* _stream;
|
||||
std::istream* stream_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -12,6 +12,17 @@
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
// A meta-function that returns the first type of the parameter pack
|
||||
// or void if empty
|
||||
template <typename...>
|
||||
struct first_or_void {
|
||||
using type = void;
|
||||
};
|
||||
template <typename T, typename... Rest>
|
||||
struct first_or_void<T, Rest...> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <template <typename, typename> class TDeserializer, typename TReader,
|
||||
typename TWriter>
|
||||
TDeserializer<TReader, TWriter> makeDeserializer(MemoryPool* pool,
|
||||
@@ -22,7 +33,9 @@ TDeserializer<TReader, TWriter> makeDeserializer(MemoryPool* pool,
|
||||
}
|
||||
|
||||
template <template <typename, typename> class TDeserializer, typename TStream,
|
||||
typename... Args>
|
||||
typename... Args,
|
||||
typename = typename enable_if< // issue #1897
|
||||
!is_integral<typename first_or_void<Args...>::type>::value>::type>
|
||||
DeserializationError deserialize(JsonDocument& doc, TStream&& input,
|
||||
Args... args) {
|
||||
auto reader = makeReader(detail::forward<TStream>(input));
|
||||
|
||||
@@ -14,27 +14,27 @@ template <typename TAllocator>
|
||||
class AllocatorOwner {
|
||||
public:
|
||||
AllocatorOwner() {}
|
||||
AllocatorOwner(TAllocator a) : _allocator(a) {}
|
||||
AllocatorOwner(TAllocator a) : allocator_(a) {}
|
||||
|
||||
void* allocate(size_t size) {
|
||||
return _allocator.allocate(size);
|
||||
return allocator_.allocate(size);
|
||||
}
|
||||
|
||||
void deallocate(void* ptr) {
|
||||
if (ptr)
|
||||
_allocator.deallocate(ptr);
|
||||
allocator_.deallocate(ptr);
|
||||
}
|
||||
|
||||
void* reallocate(void* ptr, size_t new_size) {
|
||||
return _allocator.reallocate(ptr, new_size);
|
||||
return allocator_.reallocate(ptr, new_size);
|
||||
}
|
||||
|
||||
TAllocator& allocator() {
|
||||
return _allocator;
|
||||
return allocator_;
|
||||
}
|
||||
|
||||
private:
|
||||
TAllocator _allocator;
|
||||
TAllocator allocator_;
|
||||
};
|
||||
|
||||
// A JsonDocument that uses the provided allocator to allocate its memory pool.
|
||||
@@ -106,18 +106,18 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
|
||||
// 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();
|
||||
ptrdiff_t bytes_reclaimed = pool_.squash();
|
||||
if (bytes_reclaimed == 0)
|
||||
return;
|
||||
|
||||
void* old_ptr = _pool.buffer();
|
||||
void* new_ptr = this->reallocate(old_ptr, _pool.capacity());
|
||||
void* old_ptr = pool_.buffer();
|
||||
void* new_ptr = this->reallocate(old_ptr, pool_.capacity());
|
||||
|
||||
ptrdiff_t ptr_offset =
|
||||
static_cast<char*>(new_ptr) - static_cast<char*>(old_ptr);
|
||||
|
||||
_pool.movePointers(ptr_offset);
|
||||
_data.movePointers(ptr_offset, ptr_offset - bytes_reclaimed);
|
||||
pool_.movePointers(ptr_offset);
|
||||
data_.movePointers(ptr_offset, ptr_offset - bytes_reclaimed);
|
||||
}
|
||||
|
||||
// Reclaims the memory leaked when removing and replacing values.
|
||||
@@ -127,7 +127,6 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
|
||||
BasicJsonDocument tmp(*this);
|
||||
if (!tmp.capacity())
|
||||
return false;
|
||||
tmp.set(*this);
|
||||
moveAssignFrom(tmp);
|
||||
return true;
|
||||
}
|
||||
@@ -142,7 +141,7 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
|
||||
|
||||
void reallocPool(size_t requiredSize) {
|
||||
size_t capa = detail::addPadding(requiredSize);
|
||||
if (capa == _pool.capacity())
|
||||
if (capa == pool_.capacity())
|
||||
return;
|
||||
freePool();
|
||||
replacePool(allocPool(detail::addPadding(requiredSize)));
|
||||
@@ -159,10 +158,10 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
|
||||
|
||||
void moveAssignFrom(BasicJsonDocument& src) {
|
||||
freePool();
|
||||
_data = src._data;
|
||||
_pool = src._pool;
|
||||
src._data.setNull();
|
||||
src._pool = {0, 0};
|
||||
data_ = src.data_;
|
||||
pool_ = src.pool_;
|
||||
src.data_.setNull();
|
||||
src.pool_ = {0, 0};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// Empties the document and resets the memory pool
|
||||
// https://arduinojson.org/v6/api/jsondocument/clear/
|
||||
void clear() {
|
||||
_pool.clear();
|
||||
_data.init();
|
||||
pool_.clear();
|
||||
data_.setNull();
|
||||
}
|
||||
|
||||
// Returns true if the root is of the specified type.
|
||||
@@ -67,31 +67,31 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// Returns the number of used bytes in the memory pool.
|
||||
// https://arduinojson.org/v6/api/jsondocument/memoryusage/
|
||||
size_t memoryUsage() const {
|
||||
return _pool.size();
|
||||
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();
|
||||
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);
|
||||
return variantNesting(&data_);
|
||||
}
|
||||
|
||||
// Returns the capacity of the memory pool.
|
||||
// https://arduinojson.org/v6/api/jsondocument/capacity/
|
||||
size_t capacity() const {
|
||||
return _pool.capacity();
|
||||
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();
|
||||
return data_.size();
|
||||
}
|
||||
|
||||
// Copies the specified document.
|
||||
@@ -161,14 +161,14 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// https://arduinojson.org/v6/api/jsondocument/containskey/
|
||||
template <typename TChar>
|
||||
bool containsKey(TChar* key) const {
|
||||
return _data.getMember(detail::adaptString(key)) != 0;
|
||||
return data_.getMember(detail::adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// 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(detail::adaptString(key)) != 0;
|
||||
return data_.getMember(detail::adaptString(key)) != 0;
|
||||
}
|
||||
|
||||
// Gets or sets a root object's member.
|
||||
@@ -197,7 +197,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
FORCE_INLINE typename detail::enable_if<detail::IsString<TString>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](const TString& key) const {
|
||||
return JsonVariantConst(_data.getMember(detail::adaptString(key)));
|
||||
return JsonVariantConst(data_.getMember(detail::adaptString(key)));
|
||||
}
|
||||
|
||||
// Gets a root object's member.
|
||||
@@ -206,7 +206,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](TChar* key) const {
|
||||
return JsonVariantConst(_data.getMember(detail::adaptString(key)));
|
||||
return JsonVariantConst(data_.getMember(detail::adaptString(key)));
|
||||
}
|
||||
|
||||
// Gets or sets a root array's element.
|
||||
@@ -218,14 +218,14 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// 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));
|
||||
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));
|
||||
return JsonVariant(&pool_, data_.addElement(&pool_));
|
||||
}
|
||||
|
||||
// Appends a value to the root array.
|
||||
@@ -246,7 +246,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
// ⚠️ 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);
|
||||
data_.remove(index);
|
||||
}
|
||||
|
||||
// Removes a member of the root object.
|
||||
@@ -255,7 +255,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
template <typename TChar>
|
||||
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value>::type
|
||||
remove(TChar* key) {
|
||||
_data.remove(detail::adaptString(key));
|
||||
data_.remove(detail::adaptString(key));
|
||||
}
|
||||
|
||||
// Removes a member of the root object.
|
||||
@@ -265,7 +265,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
FORCE_INLINE
|
||||
typename detail::enable_if<detail::IsString<TString>::value>::type
|
||||
remove(const TString& key) {
|
||||
_data.remove(detail::adaptString(key));
|
||||
data_.remove(detail::adaptString(key));
|
||||
}
|
||||
|
||||
FORCE_INLINE operator JsonVariant() {
|
||||
@@ -277,50 +277,44 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
}
|
||||
|
||||
protected:
|
||||
JsonDocument() : _pool(0, 0) {
|
||||
_data.init();
|
||||
}
|
||||
JsonDocument() : pool_(0, 0) {}
|
||||
|
||||
JsonDocument(detail::MemoryPool pool) : _pool(pool) {
|
||||
_data.init();
|
||||
}
|
||||
JsonDocument(detail::MemoryPool pool) : pool_(pool) {}
|
||||
|
||||
JsonDocument(char* buf, size_t capa) : _pool(buf, capa) {
|
||||
_data.init();
|
||||
}
|
||||
JsonDocument(char* buf, size_t capa) : pool_(buf, capa) {}
|
||||
|
||||
~JsonDocument() {}
|
||||
|
||||
void replacePool(detail::MemoryPool pool) {
|
||||
_pool = pool;
|
||||
pool_ = pool;
|
||||
}
|
||||
|
||||
JsonVariant getVariant() {
|
||||
return JsonVariant(&_pool, &_data);
|
||||
return JsonVariant(&pool_, &data_);
|
||||
}
|
||||
|
||||
JsonVariantConst getVariant() const {
|
||||
return JsonVariantConst(&_data);
|
||||
return JsonVariantConst(&data_);
|
||||
}
|
||||
|
||||
detail::MemoryPool _pool;
|
||||
detail::VariantData _data;
|
||||
detail::MemoryPool pool_;
|
||||
detail::VariantData data_;
|
||||
|
||||
protected:
|
||||
detail::MemoryPool* getPool() {
|
||||
return &_pool;
|
||||
return &pool_;
|
||||
}
|
||||
|
||||
detail::VariantData* getData() {
|
||||
return &_data;
|
||||
return &data_;
|
||||
}
|
||||
|
||||
const detail::VariantData* getData() const {
|
||||
return &_data;
|
||||
return &data_;
|
||||
}
|
||||
|
||||
detail::VariantData* getOrCreateData() {
|
||||
return &_data;
|
||||
return &data_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
// A JsonDocument with a memory pool on the stack.
|
||||
template <size_t desiredCapacity>
|
||||
class StaticJsonDocument : public JsonDocument {
|
||||
static const size_t _capacity =
|
||||
static const size_t capacity_ =
|
||||
detail::AddPadding<detail::Max<1, desiredCapacity>::value>::value;
|
||||
|
||||
public:
|
||||
StaticJsonDocument() : JsonDocument(_buffer, _capacity) {}
|
||||
StaticJsonDocument() : JsonDocument(buffer_, capacity_) {}
|
||||
|
||||
StaticJsonDocument(const StaticJsonDocument& src)
|
||||
: JsonDocument(_buffer, _capacity) {
|
||||
: JsonDocument(buffer_, capacity_) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ class StaticJsonDocument : public JsonDocument {
|
||||
const T& src,
|
||||
typename detail::enable_if<
|
||||
detail::is_convertible<T, JsonVariantConst>::value>::type* = 0)
|
||||
: JsonDocument(_buffer, _capacity) {
|
||||
: JsonDocument(buffer_, capacity_) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
// disambiguate
|
||||
StaticJsonDocument(JsonVariant src) : JsonDocument(_buffer, _capacity) {
|
||||
StaticJsonDocument(JsonVariant src) : JsonDocument(buffer_, capacity_) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class StaticJsonDocument : public JsonDocument {
|
||||
}
|
||||
|
||||
private:
|
||||
char _buffer[_capacity];
|
||||
char buffer_[capacity_];
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
||||
@@ -23,10 +23,10 @@ class JsonDeserializer {
|
||||
public:
|
||||
JsonDeserializer(MemoryPool* pool, TReader reader,
|
||||
TStringStorage stringStorage)
|
||||
: _stringStorage(stringStorage),
|
||||
_foundSomething(false),
|
||||
_latch(reader),
|
||||
_pool(pool) {}
|
||||
: stringStorage_(stringStorage),
|
||||
foundSomething_(false),
|
||||
latch_(reader),
|
||||
pool_(pool) {}
|
||||
|
||||
template <typename TFilter>
|
||||
DeserializationError parse(VariantData& variant, TFilter filter,
|
||||
@@ -35,7 +35,7 @@ class JsonDeserializer {
|
||||
|
||||
err = parseVariant(variant, filter, nestingLimit);
|
||||
|
||||
if (!err && _latch.last() != 0 && !variant.isEnclosed()) {
|
||||
if (!err && latch_.last() != 0 && !variant.isEnclosed()) {
|
||||
// We don't detect trailing characters earlier, so we need to check now
|
||||
return DeserializationError::InvalidInput;
|
||||
}
|
||||
@@ -45,11 +45,11 @@ class JsonDeserializer {
|
||||
|
||||
private:
|
||||
char current() {
|
||||
return _latch.current();
|
||||
return latch_.current();
|
||||
}
|
||||
|
||||
void move() {
|
||||
_latch.clear();
|
||||
latch_.clear();
|
||||
}
|
||||
|
||||
bool eat(char charToSkip) {
|
||||
@@ -173,7 +173,7 @@ class JsonDeserializer {
|
||||
for (;;) {
|
||||
if (memberFilter.allow()) {
|
||||
// Allocate slot in array
|
||||
VariantData* value = array.addElement(_pool);
|
||||
VariantData* value = array.addElement(pool_);
|
||||
if (!value)
|
||||
return DeserializationError::NoMemory;
|
||||
|
||||
@@ -269,7 +269,7 @@ class JsonDeserializer {
|
||||
if (!eat(':'))
|
||||
return DeserializationError::InvalidInput;
|
||||
|
||||
JsonString key = _stringStorage.str();
|
||||
JsonString key = stringStorage_.str();
|
||||
|
||||
TFilter memberFilter = filter[key.c_str()];
|
||||
|
||||
@@ -278,10 +278,10 @@ class JsonDeserializer {
|
||||
if (!variant) {
|
||||
// Save key in memory pool.
|
||||
// This MUST be done before adding the slot.
|
||||
key = _stringStorage.save();
|
||||
key = stringStorage_.save();
|
||||
|
||||
// Allocate slot in object
|
||||
VariantSlot* slot = object.addSlot(_pool);
|
||||
VariantSlot* slot = object.addSlot(pool_);
|
||||
if (!slot)
|
||||
return DeserializationError::NoMemory;
|
||||
|
||||
@@ -377,7 +377,7 @@ class JsonDeserializer {
|
||||
}
|
||||
|
||||
DeserializationError::Code parseKey() {
|
||||
_stringStorage.startString();
|
||||
stringStorage_.startString();
|
||||
if (isQuote(current())) {
|
||||
return parseQuotedString();
|
||||
} else {
|
||||
@@ -388,13 +388,13 @@ class JsonDeserializer {
|
||||
DeserializationError::Code parseStringValue(VariantData& variant) {
|
||||
DeserializationError::Code err;
|
||||
|
||||
_stringStorage.startString();
|
||||
stringStorage_.startString();
|
||||
|
||||
err = parseQuotedString();
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
variant.setString(_stringStorage.save());
|
||||
variant.setString(stringStorage_.save());
|
||||
|
||||
return DeserializationError::Ok;
|
||||
}
|
||||
@@ -430,9 +430,9 @@ class JsonDeserializer {
|
||||
if (err)
|
||||
return err;
|
||||
if (codepoint.append(codeunit))
|
||||
Utf8::encodeCodepoint(codepoint.value(), _stringStorage);
|
||||
Utf8::encodeCodepoint(codepoint.value(), stringStorage_);
|
||||
#else
|
||||
_stringStorage.append('\\');
|
||||
stringStorage_.append('\\');
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
@@ -444,10 +444,10 @@ class JsonDeserializer {
|
||||
move();
|
||||
}
|
||||
|
||||
_stringStorage.append(c);
|
||||
stringStorage_.append(c);
|
||||
}
|
||||
|
||||
if (!_stringStorage.isValid())
|
||||
if (!stringStorage_.isValid())
|
||||
return DeserializationError::NoMemory;
|
||||
|
||||
return DeserializationError::Ok;
|
||||
@@ -460,14 +460,14 @@ class JsonDeserializer {
|
||||
if (canBeInNonQuotedString(c)) { // no quotes
|
||||
do {
|
||||
move();
|
||||
_stringStorage.append(c);
|
||||
stringStorage_.append(c);
|
||||
c = current();
|
||||
} while (canBeInNonQuotedString(c));
|
||||
} else {
|
||||
return DeserializationError::InvalidInput;
|
||||
}
|
||||
|
||||
if (!_stringStorage.isValid())
|
||||
if (!stringStorage_.isValid())
|
||||
return DeserializationError::NoMemory;
|
||||
|
||||
return DeserializationError::Ok;
|
||||
@@ -516,12 +516,12 @@ class JsonDeserializer {
|
||||
char c = current();
|
||||
while (canBeInNumber(c) && n < 63) {
|
||||
move();
|
||||
_buffer[n++] = c;
|
||||
buffer_[n++] = c;
|
||||
c = current();
|
||||
}
|
||||
_buffer[n] = 0;
|
||||
buffer_[n] = 0;
|
||||
|
||||
if (!parseNumber(_buffer, result))
|
||||
if (!parseNumber(buffer_, result))
|
||||
return DeserializationError::InvalidInput;
|
||||
|
||||
return DeserializationError::Ok;
|
||||
@@ -585,7 +585,7 @@ class JsonDeserializer {
|
||||
switch (current()) {
|
||||
// end of string
|
||||
case '\0':
|
||||
return _foundSomething ? DeserializationError::IncompleteInput
|
||||
return foundSomething_ ? DeserializationError::IncompleteInput
|
||||
: DeserializationError::EmptyInput;
|
||||
|
||||
// spaces
|
||||
@@ -640,7 +640,7 @@ class JsonDeserializer {
|
||||
#endif
|
||||
|
||||
default:
|
||||
_foundSomething = true;
|
||||
foundSomething_ = true;
|
||||
return DeserializationError::Ok;
|
||||
}
|
||||
}
|
||||
@@ -659,11 +659,11 @@ class JsonDeserializer {
|
||||
return DeserializationError::Ok;
|
||||
}
|
||||
|
||||
TStringStorage _stringStorage;
|
||||
bool _foundSomething;
|
||||
Latch<TReader> _latch;
|
||||
MemoryPool* _pool;
|
||||
char _buffer[64]; // using a member instead of a local variable because it
|
||||
TStringStorage stringStorage_;
|
||||
bool foundSomething_;
|
||||
Latch<TReader> latch_;
|
||||
MemoryPool* pool_;
|
||||
char buffer_[64]; // using a member instead of a local variable because it
|
||||
// ended in the recursive path after compiler inlined the
|
||||
// code
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ class JsonSerializer : public Visitor<size_t> {
|
||||
public:
|
||||
static const bool producesText = true;
|
||||
|
||||
JsonSerializer(TWriter writer) : _formatter(writer) {}
|
||||
JsonSerializer(TWriter writer) : formatter_(writer) {}
|
||||
|
||||
FORCE_INLINE size_t visitArray(const CollectionData& array) {
|
||||
write('[');
|
||||
@@ -43,7 +43,7 @@ class JsonSerializer : public Visitor<size_t> {
|
||||
const VariantSlot* slot = object.head();
|
||||
|
||||
while (slot != 0) {
|
||||
_formatter.writeString(slot->key());
|
||||
formatter_.writeString(slot->key());
|
||||
write(':');
|
||||
slot->data()->accept(*this);
|
||||
|
||||
@@ -59,60 +59,60 @@ class JsonSerializer : public Visitor<size_t> {
|
||||
}
|
||||
|
||||
size_t visitFloat(JsonFloat value) {
|
||||
_formatter.writeFloat(value);
|
||||
formatter_.writeFloat(value);
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
size_t visitString(const char* value) {
|
||||
_formatter.writeString(value);
|
||||
formatter_.writeString(value);
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
size_t visitString(const char* value, size_t n) {
|
||||
_formatter.writeString(value, n);
|
||||
formatter_.writeString(value, n);
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
size_t visitRawJson(const char* data, size_t n) {
|
||||
_formatter.writeRaw(data, n);
|
||||
formatter_.writeRaw(data, n);
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
size_t visitSignedInteger(JsonInteger value) {
|
||||
_formatter.writeInteger(value);
|
||||
formatter_.writeInteger(value);
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
size_t visitUnsignedInteger(JsonUInt value) {
|
||||
_formatter.writeInteger(value);
|
||||
formatter_.writeInteger(value);
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
size_t visitBoolean(bool value) {
|
||||
_formatter.writeBoolean(value);
|
||||
formatter_.writeBoolean(value);
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
size_t visitNull() {
|
||||
_formatter.writeRaw("null");
|
||||
formatter_.writeRaw("null");
|
||||
return bytesWritten();
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t bytesWritten() const {
|
||||
return _formatter.bytesWritten();
|
||||
return formatter_.bytesWritten();
|
||||
}
|
||||
|
||||
void write(char c) {
|
||||
_formatter.writeRaw(c);
|
||||
formatter_.writeRaw(c);
|
||||
}
|
||||
|
||||
void write(const char* s) {
|
||||
_formatter.writeRaw(s);
|
||||
formatter_.writeRaw(s);
|
||||
}
|
||||
|
||||
private:
|
||||
TextFormatter<TWriter> _formatter;
|
||||
TextFormatter<TWriter> formatter_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -11,45 +11,45 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
template <typename TReader>
|
||||
class Latch {
|
||||
public:
|
||||
Latch(TReader reader) : _reader(reader), _loaded(false) {
|
||||
Latch(TReader reader) : reader_(reader), loaded_(false) {
|
||||
#if ARDUINOJSON_DEBUG
|
||||
_ended = false;
|
||||
ended_ = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_loaded = false;
|
||||
loaded_ = false;
|
||||
}
|
||||
|
||||
int last() const {
|
||||
return _current;
|
||||
return current_;
|
||||
}
|
||||
|
||||
FORCE_INLINE char current() {
|
||||
if (!_loaded) {
|
||||
if (!loaded_) {
|
||||
load();
|
||||
}
|
||||
return _current;
|
||||
return current_;
|
||||
}
|
||||
|
||||
private:
|
||||
void load() {
|
||||
ARDUINOJSON_ASSERT(!_ended);
|
||||
int c = _reader.read();
|
||||
ARDUINOJSON_ASSERT(!ended_);
|
||||
int c = reader_.read();
|
||||
#if ARDUINOJSON_DEBUG
|
||||
if (c <= 0)
|
||||
_ended = true;
|
||||
ended_ = true;
|
||||
#endif
|
||||
_current = static_cast<char>(c > 0 ? c : 0);
|
||||
_loaded = true;
|
||||
current_ = static_cast<char>(c > 0 ? c : 0);
|
||||
loaded_ = true;
|
||||
}
|
||||
|
||||
TReader _reader;
|
||||
char _current; // NOLINT(clang-analyzer-optin.cplusplus.UninitializedObject)
|
||||
TReader reader_;
|
||||
char current_; // NOLINT(clang-analyzer-optin.cplusplus.UninitializedObject)
|
||||
// Not initialized in constructor (+10 bytes on AVR)
|
||||
bool _loaded;
|
||||
bool loaded_;
|
||||
#if ARDUINOJSON_DEBUG
|
||||
bool _ended;
|
||||
bool ended_;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
|
||||
typedef JsonSerializer<TWriter> base;
|
||||
|
||||
public:
|
||||
PrettyJsonSerializer(TWriter writer) : base(writer), _nesting(0) {}
|
||||
PrettyJsonSerializer(TWriter writer) : base(writer), nesting_(0) {}
|
||||
|
||||
size_t visitArray(const CollectionData& array) {
|
||||
const VariantSlot* slot = array.head();
|
||||
if (slot) {
|
||||
base::write("[\r\n");
|
||||
_nesting++;
|
||||
nesting_++;
|
||||
while (slot != 0) {
|
||||
indent();
|
||||
slot->data()->accept(*this);
|
||||
@@ -30,7 +30,7 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
|
||||
slot = slot->next();
|
||||
base::write(slot ? ",\r\n" : "\r\n");
|
||||
}
|
||||
_nesting--;
|
||||
nesting_--;
|
||||
indent();
|
||||
base::write("]");
|
||||
} else {
|
||||
@@ -43,7 +43,7 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
|
||||
const VariantSlot* slot = object.head();
|
||||
if (slot) {
|
||||
base::write("{\r\n");
|
||||
_nesting++;
|
||||
nesting_++;
|
||||
while (slot != 0) {
|
||||
indent();
|
||||
base::visitString(slot->key());
|
||||
@@ -53,7 +53,7 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
|
||||
slot = slot->next();
|
||||
base::write(slot ? ",\r\n" : "\r\n");
|
||||
}
|
||||
_nesting--;
|
||||
nesting_--;
|
||||
indent();
|
||||
base::write("}");
|
||||
} else {
|
||||
@@ -64,11 +64,11 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
|
||||
|
||||
private:
|
||||
void indent() {
|
||||
for (uint8_t i = 0; i < _nesting; i++)
|
||||
for (uint8_t i = 0; i < nesting_; i++)
|
||||
base::write(ARDUINOJSON_TAB);
|
||||
}
|
||||
|
||||
uint8_t _nesting;
|
||||
uint8_t nesting_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -20,13 +20,13 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
template <typename TWriter>
|
||||
class TextFormatter {
|
||||
public:
|
||||
explicit TextFormatter(TWriter writer) : _writer(writer) {}
|
||||
explicit TextFormatter(TWriter writer) : writer_(writer) {}
|
||||
|
||||
TextFormatter& operator=(const TextFormatter&) = delete;
|
||||
|
||||
// Returns the number of bytes sent to the TWriter implementation.
|
||||
size_t bytesWritten() const {
|
||||
return _writer.count();
|
||||
return writer_.count();
|
||||
}
|
||||
|
||||
void writeBoolean(bool value) {
|
||||
@@ -146,28 +146,28 @@ class TextFormatter {
|
||||
}
|
||||
|
||||
void writeRaw(const char* s) {
|
||||
_writer.write(reinterpret_cast<const uint8_t*>(s), strlen(s));
|
||||
writer_.write(reinterpret_cast<const uint8_t*>(s), strlen(s));
|
||||
}
|
||||
|
||||
void writeRaw(const char* s, size_t n) {
|
||||
_writer.write(reinterpret_cast<const uint8_t*>(s), n);
|
||||
writer_.write(reinterpret_cast<const uint8_t*>(s), n);
|
||||
}
|
||||
|
||||
void writeRaw(const char* begin, const char* end) {
|
||||
_writer.write(reinterpret_cast<const uint8_t*>(begin),
|
||||
writer_.write(reinterpret_cast<const uint8_t*>(begin),
|
||||
static_cast<size_t>(end - begin));
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
void writeRaw(const char (&s)[N]) {
|
||||
_writer.write(reinterpret_cast<const uint8_t*>(s), N - 1);
|
||||
writer_.write(reinterpret_cast<const uint8_t*>(s), N - 1);
|
||||
}
|
||||
void writeRaw(char c) {
|
||||
_writer.write(static_cast<uint8_t>(c));
|
||||
writer_.write(static_cast<uint8_t>(c));
|
||||
}
|
||||
|
||||
protected:
|
||||
CountingDecorator<TWriter> _writer;
|
||||
CountingDecorator<TWriter> writer_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -31,31 +31,31 @@ inline bool isLowSurrogate(uint16_t codeunit) {
|
||||
|
||||
class Codepoint {
|
||||
public:
|
||||
Codepoint() : _highSurrogate(0), _codepoint(0) {}
|
||||
Codepoint() : highSurrogate_(0), codepoint_(0) {}
|
||||
|
||||
bool append(uint16_t codeunit) {
|
||||
if (isHighSurrogate(codeunit)) {
|
||||
_highSurrogate = codeunit & 0x3FF;
|
||||
highSurrogate_ = codeunit & 0x3FF;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isLowSurrogate(codeunit)) {
|
||||
_codepoint =
|
||||
uint32_t(0x10000 + ((_highSurrogate << 10) | (codeunit & 0x3FF)));
|
||||
codepoint_ =
|
||||
uint32_t(0x10000 + ((highSurrogate_ << 10) | (codeunit & 0x3FF)));
|
||||
return true;
|
||||
}
|
||||
|
||||
_codepoint = codeunit;
|
||||
codepoint_ = codeunit;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t value() const {
|
||||
return _codepoint;
|
||||
return codepoint_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t _highSurrogate;
|
||||
uint32_t _codepoint;
|
||||
uint16_t highSurrogate_;
|
||||
uint32_t codepoint_;
|
||||
};
|
||||
} // namespace Utf16
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -26,43 +26,43 @@
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
// _begin _end
|
||||
// begin_ end_
|
||||
// v v
|
||||
// +-------------+--------------+--------------+
|
||||
// | strings... | (free) | ...variants |
|
||||
// +-------------+--------------+--------------+
|
||||
// ^ ^
|
||||
// _left _right
|
||||
// left_ right_
|
||||
|
||||
class MemoryPool {
|
||||
public:
|
||||
MemoryPool(char* buf, size_t capa)
|
||||
: _begin(buf),
|
||||
_left(buf),
|
||||
_right(buf ? buf + capa : 0),
|
||||
_end(buf ? buf + capa : 0),
|
||||
_overflowed(false) {
|
||||
ARDUINOJSON_ASSERT(isAligned(_begin));
|
||||
ARDUINOJSON_ASSERT(isAligned(_right));
|
||||
ARDUINOJSON_ASSERT(isAligned(_end));
|
||||
: begin_(buf),
|
||||
left_(buf),
|
||||
right_(buf ? buf + capa : 0),
|
||||
end_(buf ? buf + capa : 0),
|
||||
overflowed_(false) {
|
||||
ARDUINOJSON_ASSERT(isAligned(begin_));
|
||||
ARDUINOJSON_ASSERT(isAligned(right_));
|
||||
ARDUINOJSON_ASSERT(isAligned(end_));
|
||||
}
|
||||
|
||||
void* buffer() {
|
||||
return _begin; // NOLINT(clang-analyzer-unix.Malloc)
|
||||
return begin_; // NOLINT(clang-analyzer-unix.Malloc)
|
||||
// movePointers() alters this pointer
|
||||
}
|
||||
|
||||
// Gets the capacity of the memoryPool in bytes
|
||||
size_t capacity() const {
|
||||
return size_t(_end - _begin);
|
||||
return size_t(end_ - begin_);
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return size_t(_left - _begin + _end - _right);
|
||||
return size_t(left_ - begin_ + end_ - right_);
|
||||
}
|
||||
|
||||
bool overflowed() const {
|
||||
return _overflowed;
|
||||
return overflowed_;
|
||||
}
|
||||
|
||||
VariantSlot* allocVariant() {
|
||||
@@ -91,40 +91,40 @@ class MemoryPool {
|
||||
}
|
||||
|
||||
void getFreeZone(char** zoneStart, size_t* zoneSize) const {
|
||||
*zoneStart = _left;
|
||||
*zoneSize = size_t(_right - _left);
|
||||
*zoneStart = left_;
|
||||
*zoneSize = size_t(right_ - left_);
|
||||
}
|
||||
|
||||
const char* saveStringFromFreeZone(size_t len) {
|
||||
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
|
||||
const char* dup = findString(adaptString(_left, len));
|
||||
const char* dup = findString(adaptString(left_, len));
|
||||
if (dup)
|
||||
return dup;
|
||||
#endif
|
||||
|
||||
const char* str = _left;
|
||||
_left += len;
|
||||
*_left++ = 0;
|
||||
const char* str = left_;
|
||||
left_ += len;
|
||||
*left_++ = 0;
|
||||
checkInvariants();
|
||||
return str;
|
||||
}
|
||||
|
||||
void markAsOverflowed() {
|
||||
_overflowed = true;
|
||||
overflowed_ = true;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_left = _begin;
|
||||
_right = _end;
|
||||
_overflowed = false;
|
||||
left_ = begin_;
|
||||
right_ = end_;
|
||||
overflowed_ = false;
|
||||
}
|
||||
|
||||
bool canAlloc(size_t bytes) const {
|
||||
return _left + bytes <= _right;
|
||||
return left_ + bytes <= right_;
|
||||
}
|
||||
|
||||
bool owns(void* p) const {
|
||||
return _begin <= p && p < _end;
|
||||
return begin_ <= p && p < end_;
|
||||
}
|
||||
|
||||
// Workaround for missing placement new
|
||||
@@ -134,51 +134,51 @@ class MemoryPool {
|
||||
|
||||
// Squash the free space between strings and variants
|
||||
//
|
||||
// _begin _end
|
||||
// begin_ end_
|
||||
// v v
|
||||
// +-------------+--------------+
|
||||
// | strings... | ...variants |
|
||||
// +-------------+--------------+
|
||||
// ^
|
||||
// _left _right
|
||||
// left_ right_
|
||||
//
|
||||
// This funcion is called before a realloc.
|
||||
ptrdiff_t squash() {
|
||||
char* new_right = addPadding(_left);
|
||||
if (new_right >= _right)
|
||||
char* new_right = addPadding(left_);
|
||||
if (new_right >= right_)
|
||||
return 0;
|
||||
|
||||
size_t right_size = static_cast<size_t>(_end - _right);
|
||||
memmove(new_right, _right, right_size);
|
||||
size_t right_size = static_cast<size_t>(end_ - right_);
|
||||
memmove(new_right, right_, right_size);
|
||||
|
||||
ptrdiff_t bytes_reclaimed = _right - new_right;
|
||||
_right = new_right;
|
||||
_end = new_right + right_size;
|
||||
ptrdiff_t bytes_reclaimed = right_ - new_right;
|
||||
right_ = new_right;
|
||||
end_ = new_right + right_size;
|
||||
return bytes_reclaimed;
|
||||
}
|
||||
|
||||
// Move all pointers together
|
||||
// This funcion is called after a realloc.
|
||||
void movePointers(ptrdiff_t offset) {
|
||||
_begin += offset;
|
||||
_left += offset;
|
||||
_right += offset;
|
||||
_end += offset;
|
||||
begin_ += offset;
|
||||
left_ += offset;
|
||||
right_ += offset;
|
||||
end_ += offset;
|
||||
}
|
||||
|
||||
private:
|
||||
void checkInvariants() {
|
||||
ARDUINOJSON_ASSERT(_begin <= _left);
|
||||
ARDUINOJSON_ASSERT(_left <= _right);
|
||||
ARDUINOJSON_ASSERT(_right <= _end);
|
||||
ARDUINOJSON_ASSERT(isAligned(_right));
|
||||
ARDUINOJSON_ASSERT(begin_ <= left_);
|
||||
ARDUINOJSON_ASSERT(left_ <= right_);
|
||||
ARDUINOJSON_ASSERT(right_ <= end_);
|
||||
ARDUINOJSON_ASSERT(isAligned(right_));
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
|
||||
template <typename TAdaptedString>
|
||||
const char* findString(const TAdaptedString& str) const {
|
||||
size_t n = str.size();
|
||||
for (char* next = _begin; next + n < _left; ++next) {
|
||||
for (char* next = begin_; next + n < left_; ++next) {
|
||||
if (next[n] == '\0' && stringEquals(str, adaptString(next, n)))
|
||||
return next;
|
||||
|
||||
@@ -192,11 +192,11 @@ class MemoryPool {
|
||||
|
||||
char* allocString(size_t n) {
|
||||
if (!canAlloc(n)) {
|
||||
_overflowed = true;
|
||||
overflowed_ = true;
|
||||
return 0;
|
||||
}
|
||||
char* s = _left;
|
||||
_left += n;
|
||||
char* s = left_;
|
||||
left_ += n;
|
||||
checkInvariants();
|
||||
return s;
|
||||
}
|
||||
@@ -208,15 +208,15 @@ class MemoryPool {
|
||||
|
||||
void* allocRight(size_t bytes) {
|
||||
if (!canAlloc(bytes)) {
|
||||
_overflowed = true;
|
||||
overflowed_ = true;
|
||||
return 0;
|
||||
}
|
||||
_right -= bytes;
|
||||
return _right;
|
||||
right_ -= bytes;
|
||||
return right_;
|
||||
}
|
||||
|
||||
char *_begin, *_left, *_right, *_end;
|
||||
bool _overflowed;
|
||||
char *begin_, *left_, *right_, *end_;
|
||||
bool overflowed_;
|
||||
};
|
||||
|
||||
template <typename TAdaptedString, typename TCallback>
|
||||
|
||||
@@ -12,43 +12,43 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
template <typename T>
|
||||
class SerializedValue {
|
||||
public:
|
||||
explicit SerializedValue(T str) : _str(str) {}
|
||||
explicit SerializedValue(T str) : str_(str) {}
|
||||
operator T() const {
|
||||
return _str;
|
||||
return str_;
|
||||
}
|
||||
|
||||
const char* data() const {
|
||||
return _str.c_str();
|
||||
return str_.c_str();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
// CAUTION: the old Arduino String doesn't have size()
|
||||
return _str.length();
|
||||
return str_.length();
|
||||
}
|
||||
|
||||
private:
|
||||
T _str;
|
||||
T str_;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
class SerializedValue<TChar*> {
|
||||
public:
|
||||
explicit SerializedValue(TChar* p, size_t n) : _data(p), _size(n) {}
|
||||
explicit SerializedValue(TChar* p, size_t n) : data_(p), size_(n) {}
|
||||
operator TChar*() const {
|
||||
return _data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
TChar* data() const {
|
||||
return _data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _size;
|
||||
return size_;
|
||||
}
|
||||
|
||||
private:
|
||||
TChar* _data;
|
||||
size_t _size;
|
||||
TChar* data_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@ class MsgPackSerializer : public Visitor<size_t> {
|
||||
public:
|
||||
static const bool producesText = false;
|
||||
|
||||
MsgPackSerializer(TWriter writer) : _writer(writer) {}
|
||||
MsgPackSerializer(TWriter writer) : writer_(writer) {}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<sizeof(T) == 4, size_t>::type visitFloat(T value32) {
|
||||
@@ -177,15 +177,15 @@ class MsgPackSerializer : public Visitor<size_t> {
|
||||
|
||||
private:
|
||||
size_t bytesWritten() const {
|
||||
return _writer.count();
|
||||
return writer_.count();
|
||||
}
|
||||
|
||||
void writeByte(uint8_t c) {
|
||||
_writer.write(c);
|
||||
writer_.write(c);
|
||||
}
|
||||
|
||||
void writeBytes(const uint8_t* p, size_t n) {
|
||||
_writer.write(p, n);
|
||||
writer_.write(p, n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -194,7 +194,7 @@ class MsgPackSerializer : public Visitor<size_t> {
|
||||
writeBytes(reinterpret_cast<uint8_t*>(&value), sizeof(value));
|
||||
}
|
||||
|
||||
CountingDecorator<TWriter> _writer;
|
||||
CountingDecorator<TWriter> writer_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -146,7 +146,6 @@ inline bool parseNumber(const char* s, VariantData& result) {
|
||||
template <typename T>
|
||||
inline T parseNumber(const char* s) {
|
||||
VariantData value;
|
||||
value.init(); // VariantData is a POD, so it has no constructor
|
||||
parseNumber(s, value);
|
||||
return Converter<T>::fromJson(JsonVariantConst(&value));
|
||||
}
|
||||
|
||||
@@ -20,61 +20,61 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
typedef JsonObjectIterator iterator;
|
||||
|
||||
// Creates an unbound reference.
|
||||
FORCE_INLINE JsonObject() : _data(0), _pool(0) {}
|
||||
FORCE_INLINE JsonObject() : data_(0), pool_(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
FORCE_INLINE JsonObject(detail::MemoryPool* buf, detail::CollectionData* data)
|
||||
: _data(data), _pool(buf) {}
|
||||
: data_(data), pool_(buf) {}
|
||||
|
||||
operator JsonVariant() const {
|
||||
void* data = _data; // prevent warning cast-align
|
||||
return JsonVariant(_pool, reinterpret_cast<detail::VariantData*>(data));
|
||||
void* data = data_; // prevent warning cast-align
|
||||
return JsonVariant(pool_, reinterpret_cast<detail::VariantData*>(data));
|
||||
}
|
||||
|
||||
operator JsonObjectConst() const {
|
||||
return JsonObjectConst(_data);
|
||||
return JsonObjectConst(data_);
|
||||
}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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));
|
||||
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;
|
||||
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)
|
||||
if (!data_)
|
||||
return iterator();
|
||||
return iterator(_pool, _data->head());
|
||||
return iterator(pool_, data_->head());
|
||||
}
|
||||
|
||||
// Returns an iterator following the last key-value pair of the object.
|
||||
@@ -87,22 +87,22 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// ⚠️ Doesn't release the memory associated with the removed members.
|
||||
// https://arduinojson.org/v6/api/jsonobject/clear/
|
||||
void clear() const {
|
||||
if (!_data)
|
||||
if (!data_)
|
||||
return;
|
||||
_data->clear();
|
||||
data_->clear();
|
||||
}
|
||||
|
||||
// Copies an object.
|
||||
// https://arduinojson.org/v6/api/jsonobject/set/
|
||||
FORCE_INLINE bool set(JsonObjectConst src) {
|
||||
if (!_data || !src._data)
|
||||
if (!data_ || !src.data_)
|
||||
return false;
|
||||
return _data->copyFrom(*src._data, _pool);
|
||||
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);
|
||||
return JsonObjectConst(data_) == JsonObjectConst(rhs.data_);
|
||||
}
|
||||
|
||||
// Gets or sets the member with specified key.
|
||||
@@ -129,9 +129,9 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// ⚠️ 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)
|
||||
if (!data_)
|
||||
return;
|
||||
_data->removeSlot(it._slot);
|
||||
data_->removeSlot(it.slot_);
|
||||
}
|
||||
|
||||
// Removes the member with the specified key.
|
||||
@@ -194,33 +194,33 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
|
||||
private:
|
||||
detail::MemoryPool* getPool() const {
|
||||
return _pool;
|
||||
return pool_;
|
||||
}
|
||||
|
||||
detail::VariantData* getData() const {
|
||||
return detail::collectionToVariant(_data);
|
||||
return detail::collectionToVariant(data_);
|
||||
}
|
||||
|
||||
detail::VariantData* getOrCreateData() const {
|
||||
return detail::collectionToVariant(_data);
|
||||
return detail::collectionToVariant(data_);
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
inline detail::VariantData* getMember(TAdaptedString key) const {
|
||||
if (!_data)
|
||||
if (!data_)
|
||||
return 0;
|
||||
return _data->getMember(key);
|
||||
return data_->getMember(key);
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
void removeMember(TAdaptedString key) const {
|
||||
if (!_data)
|
||||
if (!data_)
|
||||
return;
|
||||
_data->removeMember(key);
|
||||
data_->removeMember(key);
|
||||
}
|
||||
|
||||
detail::CollectionData* _data;
|
||||
detail::MemoryPool* _pool;
|
||||
detail::CollectionData* data_;
|
||||
detail::MemoryPool* pool_;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -19,51 +19,51 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
typedef JsonObjectConstIterator iterator;
|
||||
|
||||
// Creates an unbound reference.
|
||||
JsonObjectConst() : _data(0) {}
|
||||
JsonObjectConst() : data_(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
JsonObjectConst(const detail::CollectionData* data) : _data(data) {}
|
||||
JsonObjectConst(const detail::CollectionData* data) : data_(data) {}
|
||||
|
||||
operator JsonVariantConst() const {
|
||||
return JsonVariantConst(collectionToVariant(_data));
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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));
|
||||
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;
|
||||
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)
|
||||
if (!data_)
|
||||
return iterator();
|
||||
return iterator(_data->head());
|
||||
return iterator(data_->head());
|
||||
}
|
||||
|
||||
// Returns an iterator following the last key-value pair of the object.
|
||||
@@ -106,10 +106,10 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
|
||||
// Compares objects.
|
||||
FORCE_INLINE bool operator==(JsonObjectConst rhs) const {
|
||||
if (_data == rhs._data)
|
||||
if (data_ == rhs.data_)
|
||||
return true;
|
||||
|
||||
if (!_data || !rhs._data)
|
||||
if (!data_ || !rhs.data_)
|
||||
return false;
|
||||
|
||||
size_t count = 0;
|
||||
@@ -123,17 +123,17 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
|
||||
private:
|
||||
const detail::VariantData* getData() const {
|
||||
return collectionToVariant(_data);
|
||||
return collectionToVariant(data_);
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
const detail::VariantData* getMember(TAdaptedString key) const {
|
||||
if (!_data)
|
||||
if (!data_)
|
||||
return 0;
|
||||
return _data->getMember(key);
|
||||
return data_->getMember(key);
|
||||
}
|
||||
|
||||
const detail::CollectionData* _data;
|
||||
const detail::CollectionData* data_;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -12,112 +12,112 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
class JsonPairPtr {
|
||||
public:
|
||||
JsonPairPtr(detail::MemoryPool* pool, detail::VariantSlot* slot)
|
||||
: _pair(pool, slot) {}
|
||||
: pair_(pool, slot) {}
|
||||
|
||||
const JsonPair* operator->() const {
|
||||
return &_pair;
|
||||
return &pair_;
|
||||
}
|
||||
|
||||
const JsonPair& operator*() const {
|
||||
return _pair;
|
||||
return pair_;
|
||||
}
|
||||
|
||||
private:
|
||||
JsonPair _pair;
|
||||
JsonPair pair_;
|
||||
};
|
||||
|
||||
class JsonObjectIterator {
|
||||
friend class JsonObject;
|
||||
|
||||
public:
|
||||
JsonObjectIterator() : _slot(0) {}
|
||||
JsonObjectIterator() : slot_(0) {}
|
||||
|
||||
explicit JsonObjectIterator(detail::MemoryPool* pool,
|
||||
detail::VariantSlot* slot)
|
||||
: _pool(pool), _slot(slot) {}
|
||||
: pool_(pool), slot_(slot) {}
|
||||
|
||||
JsonPair operator*() const {
|
||||
return JsonPair(_pool, _slot);
|
||||
return JsonPair(pool_, slot_);
|
||||
}
|
||||
JsonPairPtr operator->() {
|
||||
return JsonPairPtr(_pool, _slot);
|
||||
return JsonPairPtr(pool_, slot_);
|
||||
}
|
||||
|
||||
bool operator==(const JsonObjectIterator& other) const {
|
||||
return _slot == other._slot;
|
||||
return slot_ == other.slot_;
|
||||
}
|
||||
|
||||
bool operator!=(const JsonObjectIterator& other) const {
|
||||
return _slot != other._slot;
|
||||
return slot_ != other.slot_;
|
||||
}
|
||||
|
||||
JsonObjectIterator& operator++() {
|
||||
_slot = _slot->next();
|
||||
slot_ = slot_->next();
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonObjectIterator& operator+=(size_t distance) {
|
||||
_slot = _slot->next(distance);
|
||||
slot_ = slot_->next(distance);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
detail::MemoryPool* _pool;
|
||||
detail::VariantSlot* _slot;
|
||||
detail::MemoryPool* pool_;
|
||||
detail::VariantSlot* slot_;
|
||||
};
|
||||
|
||||
class JsonPairConstPtr {
|
||||
public:
|
||||
JsonPairConstPtr(const detail::VariantSlot* slot) : _pair(slot) {}
|
||||
JsonPairConstPtr(const detail::VariantSlot* slot) : pair_(slot) {}
|
||||
|
||||
const JsonPairConst* operator->() const {
|
||||
return &_pair;
|
||||
return &pair_;
|
||||
}
|
||||
|
||||
const JsonPairConst& operator*() const {
|
||||
return _pair;
|
||||
return pair_;
|
||||
}
|
||||
|
||||
private:
|
||||
JsonPairConst _pair;
|
||||
JsonPairConst pair_;
|
||||
};
|
||||
|
||||
class JsonObjectConstIterator {
|
||||
friend class JsonObject;
|
||||
|
||||
public:
|
||||
JsonObjectConstIterator() : _slot(0) {}
|
||||
JsonObjectConstIterator() : slot_(0) {}
|
||||
|
||||
explicit JsonObjectConstIterator(const detail::VariantSlot* slot)
|
||||
: _slot(slot) {}
|
||||
: slot_(slot) {}
|
||||
|
||||
JsonPairConst operator*() const {
|
||||
return JsonPairConst(_slot);
|
||||
return JsonPairConst(slot_);
|
||||
}
|
||||
JsonPairConstPtr operator->() {
|
||||
return JsonPairConstPtr(_slot);
|
||||
return JsonPairConstPtr(slot_);
|
||||
}
|
||||
|
||||
bool operator==(const JsonObjectConstIterator& other) const {
|
||||
return _slot == other._slot;
|
||||
return slot_ == other.slot_;
|
||||
}
|
||||
|
||||
bool operator!=(const JsonObjectConstIterator& other) const {
|
||||
return _slot != other._slot;
|
||||
return slot_ != other.slot_;
|
||||
}
|
||||
|
||||
JsonObjectConstIterator& operator++() {
|
||||
_slot = _slot->next();
|
||||
slot_ = slot_->next();
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonObjectConstIterator& operator+=(size_t distance) {
|
||||
_slot = _slot->next(distance);
|
||||
slot_ = slot_->next(distance);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
const detail::VariantSlot* _slot;
|
||||
const detail::VariantSlot* slot_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
||||
@@ -17,25 +17,25 @@ class JsonPair {
|
||||
// INTERNAL USE ONLY
|
||||
JsonPair(detail::MemoryPool* pool, detail::VariantSlot* slot) {
|
||||
if (slot) {
|
||||
_key = JsonString(slot->key(), slot->ownsKey() ? JsonString::Copied
|
||||
key_ = JsonString(slot->key(), slot->ownsKey() ? JsonString::Copied
|
||||
: JsonString::Linked);
|
||||
_value = JsonVariant(pool, slot->data());
|
||||
value_ = JsonVariant(pool, slot->data());
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the key.
|
||||
JsonString key() const {
|
||||
return _key;
|
||||
return key_;
|
||||
}
|
||||
|
||||
// Returns the value.
|
||||
JsonVariant value() const {
|
||||
return _value;
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
JsonString _key;
|
||||
JsonVariant _value;
|
||||
JsonString key_;
|
||||
JsonVariant value_;
|
||||
};
|
||||
|
||||
// A read-only key-value pair.
|
||||
@@ -44,25 +44,25 @@ class JsonPairConst {
|
||||
public:
|
||||
JsonPairConst(const detail::VariantSlot* slot) {
|
||||
if (slot) {
|
||||
_key = JsonString(slot->key(), slot->ownsKey() ? JsonString::Copied
|
||||
key_ = JsonString(slot->key(), slot->ownsKey() ? JsonString::Copied
|
||||
: JsonString::Linked);
|
||||
_value = JsonVariantConst(slot->data());
|
||||
value_ = JsonVariantConst(slot->data());
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the key.
|
||||
JsonString key() const {
|
||||
return _key;
|
||||
return key_;
|
||||
}
|
||||
|
||||
// Returns the value.
|
||||
JsonVariantConst value() const {
|
||||
return _value;
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
JsonString _key;
|
||||
JsonVariantConst _value;
|
||||
JsonString key_;
|
||||
JsonVariantConst value_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
||||
@@ -18,10 +18,10 @@ class MemberProxy
|
||||
|
||||
public:
|
||||
FORCE_INLINE MemberProxy(TUpstream upstream, TStringRef key)
|
||||
: _upstream(upstream), _key(key) {}
|
||||
: upstream_(upstream), key_(key) {}
|
||||
|
||||
MemberProxy(const MemberProxy& src)
|
||||
: _upstream(src._upstream), _key(src._key) {}
|
||||
: upstream_(src.upstream_), key_(src.key_) {}
|
||||
|
||||
FORCE_INLINE MemberProxy& operator=(const MemberProxy& src) {
|
||||
this->set(src);
|
||||
@@ -42,23 +42,23 @@ class MemberProxy
|
||||
|
||||
private:
|
||||
FORCE_INLINE MemoryPool* getPool() const {
|
||||
return VariantAttorney::getPool(_upstream);
|
||||
return VariantAttorney::getPool(upstream_);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantData* getData() const {
|
||||
return variantGetMember(VariantAttorney::getData(_upstream),
|
||||
adaptString(_key));
|
||||
return variantGetMember(VariantAttorney::getData(upstream_),
|
||||
adaptString(key_));
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantData* getOrCreateData() const {
|
||||
return variantGetOrAddMember(VariantAttorney::getOrCreateData(_upstream),
|
||||
adaptString(_key),
|
||||
VariantAttorney::getPool(_upstream));
|
||||
return variantGetOrAddMember(VariantAttorney::getOrCreateData(upstream_),
|
||||
adaptString(key_),
|
||||
VariantAttorney::getPool(upstream_));
|
||||
}
|
||||
|
||||
private:
|
||||
TUpstream _upstream;
|
||||
TStringRef _key;
|
||||
TUpstream upstream_;
|
||||
TStringRef key_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -4,7 +4,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef ARDUINO
|
||||
# include <Arduino.h>
|
||||
#else
|
||||
// Allow using PROGMEM outside of Arduino (issue #1903)
|
||||
class __FlashStringHelper;
|
||||
# include <avr/pgmspace.h>
|
||||
#endif
|
||||
|
||||
#include <ArduinoJson/Configuration.hpp>
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
|
||||
@@ -54,14 +54,14 @@ inline T pgm_read(const T* p) {
|
||||
template <typename T>
|
||||
class pgm_ptr {
|
||||
public:
|
||||
explicit pgm_ptr(const T* ptr) : _ptr(ptr) {}
|
||||
explicit pgm_ptr(const T* ptr) : ptr_(ptr) {}
|
||||
|
||||
T operator[](intptr_t index) const {
|
||||
return pgm_read(_ptr + index);
|
||||
return pgm_read(ptr_ + index);
|
||||
}
|
||||
|
||||
private:
|
||||
const T* _ptr;
|
||||
const T* ptr_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -27,10 +27,10 @@ struct is_convertible {
|
||||
static int probe(To);
|
||||
static char probe(...);
|
||||
|
||||
static From& _from;
|
||||
static From& from_;
|
||||
|
||||
public:
|
||||
static const bool value = sizeof(probe(_from)) == sizeof(int);
|
||||
static const bool value = sizeof(probe(from_)) == sizeof(int);
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -11,23 +11,23 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
template <typename TWriter>
|
||||
class CountingDecorator {
|
||||
public:
|
||||
explicit CountingDecorator(TWriter& writer) : _writer(writer), _count(0) {}
|
||||
explicit CountingDecorator(TWriter& writer) : writer_(writer), count_(0) {}
|
||||
|
||||
void write(uint8_t c) {
|
||||
_count += _writer.write(c);
|
||||
count_ += writer_.write(c);
|
||||
}
|
||||
|
||||
void write(const uint8_t* s, size_t n) {
|
||||
_count += _writer.write(s, n);
|
||||
count_ += writer_.write(s, n);
|
||||
}
|
||||
|
||||
size_t count() const {
|
||||
return _count;
|
||||
return count_;
|
||||
}
|
||||
|
||||
private:
|
||||
TWriter _writer;
|
||||
size_t _count;
|
||||
TWriter writer_;
|
||||
size_t count_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -12,18 +12,18 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
template <typename TDestination, typename Enable = void>
|
||||
class Writer {
|
||||
public:
|
||||
explicit Writer(TDestination& dest) : _dest(&dest) {}
|
||||
explicit Writer(TDestination& dest) : dest_(&dest) {}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
return _dest->write(c);
|
||||
return dest_->write(c);
|
||||
}
|
||||
|
||||
size_t write(const uint8_t* s, size_t n) {
|
||||
return _dest->write(s, n);
|
||||
return dest_->write(s, n);
|
||||
}
|
||||
|
||||
private:
|
||||
TDestination* _dest;
|
||||
TDestination* dest_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -13,8 +13,8 @@ class Writer<::String, void> {
|
||||
static const size_t bufferCapacity = ARDUINOJSON_STRING_BUFFER_SIZE;
|
||||
|
||||
public:
|
||||
explicit Writer(::String& str) : _destination(&str) {
|
||||
_size = 0;
|
||||
explicit Writer(::String& str) : destination_(&str) {
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
~Writer() {
|
||||
@@ -22,10 +22,10 @@ class Writer<::String, void> {
|
||||
}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
if (_size + 1 >= bufferCapacity)
|
||||
if (size_ + 1 >= bufferCapacity)
|
||||
if (flush() != 0)
|
||||
return 0;
|
||||
_buffer[_size++] = static_cast<char>(c);
|
||||
buffer_[size_++] = static_cast<char>(c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -37,17 +37,17 @@ class Writer<::String, void> {
|
||||
}
|
||||
|
||||
size_t flush() {
|
||||
ARDUINOJSON_ASSERT(_size < bufferCapacity);
|
||||
_buffer[_size] = 0;
|
||||
if (_destination->concat(_buffer))
|
||||
_size = 0;
|
||||
return _size;
|
||||
ARDUINOJSON_ASSERT(size_ < bufferCapacity);
|
||||
buffer_[size_] = 0;
|
||||
if (destination_->concat(buffer_))
|
||||
size_ = 0;
|
||||
return size_;
|
||||
}
|
||||
|
||||
private:
|
||||
::String* _destination;
|
||||
char _buffer[bufferCapacity];
|
||||
size_t _size;
|
||||
::String* destination_;
|
||||
char buffer_[bufferCapacity];
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -13,18 +13,18 @@ class Writer<
|
||||
TDestination,
|
||||
typename enable_if<is_base_of<::Print, TDestination>::value>::type> {
|
||||
public:
|
||||
explicit Writer(::Print& print) : _print(&print) {}
|
||||
explicit Writer(::Print& print) : print_(&print) {}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
return _print->write(c);
|
||||
return print_->write(c);
|
||||
}
|
||||
|
||||
size_t write(const uint8_t* s, size_t n) {
|
||||
return _print->write(s, n);
|
||||
return print_->write(s, n);
|
||||
}
|
||||
|
||||
private:
|
||||
::Print* _print;
|
||||
::Print* print_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -13,21 +13,21 @@ class Writer<
|
||||
TDestination,
|
||||
typename enable_if<is_base_of<std::ostream, TDestination>::value>::type> {
|
||||
public:
|
||||
explicit Writer(std::ostream& os) : _os(&os) {}
|
||||
explicit Writer(std::ostream& os) : os_(&os) {}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
_os->put(static_cast<char>(c));
|
||||
os_->put(static_cast<char>(c));
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t write(const uint8_t* s, size_t n) {
|
||||
_os->write(reinterpret_cast<const char*>(s),
|
||||
os_->write(reinterpret_cast<const char*>(s),
|
||||
static_cast<std::streamsize>(n));
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
std::ostream* _os;
|
||||
std::ostream* os_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -24,20 +24,20 @@ template <typename TDestination>
|
||||
class Writer<TDestination,
|
||||
typename enable_if<is_std_string<TDestination>::value>::type> {
|
||||
public:
|
||||
Writer(TDestination& str) : _str(&str) {}
|
||||
Writer(TDestination& str) : str_(&str) {}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
_str->push_back(static_cast<char>(c));
|
||||
str_->push_back(static_cast<char>(c));
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t write(const uint8_t* s, size_t n) {
|
||||
_str->append(reinterpret_cast<const char*>(s), n);
|
||||
str_->append(reinterpret_cast<const char*>(s), n);
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
TDestination* _str;
|
||||
TDestination* str_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -10,19 +10,19 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
class StringCopier {
|
||||
public:
|
||||
StringCopier(MemoryPool* pool) : _pool(pool) {}
|
||||
StringCopier(MemoryPool* pool) : pool_(pool) {}
|
||||
|
||||
void startString() {
|
||||
_pool->getFreeZone(&_ptr, &_capacity);
|
||||
_size = 0;
|
||||
if (_capacity == 0)
|
||||
_pool->markAsOverflowed();
|
||||
pool_->getFreeZone(&ptr_, &capacity_);
|
||||
size_ = 0;
|
||||
if (capacity_ == 0)
|
||||
pool_->markAsOverflowed();
|
||||
}
|
||||
|
||||
JsonString save() {
|
||||
ARDUINOJSON_ASSERT(_ptr);
|
||||
ARDUINOJSON_ASSERT(_size < _capacity); // needs room for the terminator
|
||||
return JsonString(_pool->saveStringFromFreeZone(_size), _size,
|
||||
ARDUINOJSON_ASSERT(ptr_);
|
||||
ARDUINOJSON_ASSERT(size_ < capacity_); // needs room for the terminator
|
||||
return JsonString(pool_->saveStringFromFreeZone(size_), size_,
|
||||
JsonString::Copied);
|
||||
}
|
||||
|
||||
@@ -37,36 +37,36 @@ class StringCopier {
|
||||
}
|
||||
|
||||
void append(char c) {
|
||||
if (_size + 1 < _capacity)
|
||||
_ptr[_size++] = c;
|
||||
if (size_ + 1 < capacity_)
|
||||
ptr_[size_++] = c;
|
||||
else
|
||||
_pool->markAsOverflowed();
|
||||
pool_->markAsOverflowed();
|
||||
}
|
||||
|
||||
bool isValid() const {
|
||||
return !_pool->overflowed();
|
||||
return !pool_->overflowed();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _size;
|
||||
return size_;
|
||||
}
|
||||
|
||||
JsonString str() const {
|
||||
ARDUINOJSON_ASSERT(_ptr);
|
||||
ARDUINOJSON_ASSERT(_size < _capacity);
|
||||
_ptr[_size] = 0;
|
||||
return JsonString(_ptr, _size, JsonString::Copied);
|
||||
ARDUINOJSON_ASSERT(ptr_);
|
||||
ARDUINOJSON_ASSERT(size_ < capacity_);
|
||||
ptr_[size_] = 0;
|
||||
return JsonString(ptr_, size_, JsonString::Copied);
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryPool* _pool;
|
||||
MemoryPool* pool_;
|
||||
|
||||
// These fields aren't initialized by the constructor but startString()
|
||||
//
|
||||
// NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
|
||||
char* _ptr;
|
||||
char* ptr_;
|
||||
// NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
|
||||
size_t _size, _capacity;
|
||||
size_t size_, capacity_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -11,20 +11,20 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
class StringMover {
|
||||
public:
|
||||
StringMover(char* ptr) : _writePtr(ptr) {}
|
||||
StringMover(char* ptr) : writePtr_(ptr) {}
|
||||
|
||||
void startString() {
|
||||
_startPtr = _writePtr;
|
||||
startPtr_ = writePtr_;
|
||||
}
|
||||
|
||||
FORCE_INLINE JsonString save() {
|
||||
JsonString s = str();
|
||||
_writePtr++;
|
||||
writePtr_++;
|
||||
return s;
|
||||
}
|
||||
|
||||
void append(char c) {
|
||||
*_writePtr++ = c;
|
||||
*writePtr_++ = c;
|
||||
}
|
||||
|
||||
bool isValid() const {
|
||||
@@ -32,17 +32,17 @@ class StringMover {
|
||||
}
|
||||
|
||||
JsonString str() const {
|
||||
_writePtr[0] = 0; // terminator
|
||||
return JsonString(_startPtr, size(), JsonString::Linked);
|
||||
writePtr_[0] = 0; // terminator
|
||||
return JsonString(startPtr_, size(), JsonString::Linked);
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return size_t(_writePtr - _startPtr);
|
||||
return size_t(writePtr_ - startPtr_);
|
||||
}
|
||||
|
||||
private:
|
||||
char* _writePtr;
|
||||
char* _startPtr;
|
||||
char* writePtr_;
|
||||
char* startPtr_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ArduinoJson/Polyfills/pgmspace.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
@@ -16,20 +14,20 @@ class FlashString {
|
||||
static const size_t typeSortKey = 1;
|
||||
|
||||
FlashString(const __FlashStringHelper* str, size_t sz)
|
||||
: _str(reinterpret_cast<const char*>(str)), _size(sz) {}
|
||||
: str_(reinterpret_cast<const char*>(str)), size_(sz) {}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
return !str_;
|
||||
}
|
||||
|
||||
char operator[](size_t i) const {
|
||||
ARDUINOJSON_ASSERT(_str != 0);
|
||||
ARDUINOJSON_ASSERT(i <= _size);
|
||||
return static_cast<char>(pgm_read_byte(_str + i));
|
||||
ARDUINOJSON_ASSERT(str_ != 0);
|
||||
ARDUINOJSON_ASSERT(i <= size_);
|
||||
return static_cast<char>(pgm_read_byte(str_ + i));
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _size;
|
||||
return size_;
|
||||
}
|
||||
|
||||
friend bool stringEquals(FlashString a, SizedRamString b) {
|
||||
@@ -38,7 +36,7 @@ class FlashString {
|
||||
ARDUINOJSON_ASSERT(!b.isNull());
|
||||
if (a.size() != b.size())
|
||||
return false;
|
||||
return ::memcmp_P(b.data(), a._str, a._size) == 0;
|
||||
return ::memcmp_P(b.data(), a.str_, a.size_) == 0;
|
||||
}
|
||||
|
||||
friend int stringCompare(FlashString a, SizedRamString b) {
|
||||
@@ -46,7 +44,7 @@ class FlashString {
|
||||
ARDUINOJSON_ASSERT(!a.isNull());
|
||||
ARDUINOJSON_ASSERT(!b.isNull());
|
||||
size_t minsize = a.size() < b.size() ? a.size() : b.size();
|
||||
int res = ::memcmp_P(b.data(), a._str, minsize);
|
||||
int res = ::memcmp_P(b.data(), a.str_, minsize);
|
||||
if (res)
|
||||
return -res;
|
||||
if (a.size() < b.size())
|
||||
@@ -58,7 +56,7 @@ class FlashString {
|
||||
|
||||
friend void stringGetChars(FlashString s, char* p, size_t n) {
|
||||
ARDUINOJSON_ASSERT(s.size() <= n);
|
||||
::memcpy_P(p, s._str, n);
|
||||
::memcpy_P(p, s.str_, n);
|
||||
}
|
||||
|
||||
StringStoragePolicy::Copy storagePolicy() const {
|
||||
@@ -66,8 +64,8 @@ class FlashString {
|
||||
}
|
||||
|
||||
private:
|
||||
const char* _str;
|
||||
size_t _size;
|
||||
const char* str_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -13,15 +13,15 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
class JsonStringAdapter : public SizedRamString {
|
||||
public:
|
||||
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 {
|
||||
StringStoragePolicy::LinkOrCopy policy = {_linked};
|
||||
StringStoragePolicy::LinkOrCopy policy = {linked_};
|
||||
return policy;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _linked;
|
||||
bool linked_;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -21,31 +21,31 @@ class ZeroTerminatedRamString {
|
||||
public:
|
||||
static const size_t typeSortKey = 3;
|
||||
|
||||
ZeroTerminatedRamString(const char* str) : _str(str) {}
|
||||
ZeroTerminatedRamString(const char* str) : str_(str) {}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
return !str_;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str ? ::strlen(_str) : 0;
|
||||
return str_ ? ::strlen(str_) : 0;
|
||||
}
|
||||
|
||||
char operator[](size_t i) const {
|
||||
ARDUINOJSON_ASSERT(_str != 0);
|
||||
ARDUINOJSON_ASSERT(str_ != 0);
|
||||
ARDUINOJSON_ASSERT(i <= size());
|
||||
return _str[i];
|
||||
return str_[i];
|
||||
}
|
||||
|
||||
const char* data() const {
|
||||
return _str;
|
||||
return str_;
|
||||
}
|
||||
|
||||
friend int stringCompare(ZeroTerminatedRamString a,
|
||||
ZeroTerminatedRamString b) {
|
||||
ARDUINOJSON_ASSERT(!a.isNull());
|
||||
ARDUINOJSON_ASSERT(!b.isNull());
|
||||
return ::strcmp(a._str, b._str);
|
||||
return ::strcmp(a.str_, b.str_);
|
||||
}
|
||||
|
||||
friend bool stringEquals(ZeroTerminatedRamString a,
|
||||
@@ -58,7 +58,7 @@ class ZeroTerminatedRamString {
|
||||
}
|
||||
|
||||
protected:
|
||||
const char* _str;
|
||||
const char* str_;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
@@ -101,24 +101,24 @@ class SizedRamString {
|
||||
public:
|
||||
static const size_t typeSortKey = 2;
|
||||
|
||||
SizedRamString(const char* str, size_t sz) : _str(str), _size(sz) {}
|
||||
SizedRamString(const char* str, size_t sz) : str_(str), size_(sz) {}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
return !str_;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _size;
|
||||
return size_;
|
||||
}
|
||||
|
||||
char operator[](size_t i) const {
|
||||
ARDUINOJSON_ASSERT(_str != 0);
|
||||
ARDUINOJSON_ASSERT(str_ != 0);
|
||||
ARDUINOJSON_ASSERT(i <= size());
|
||||
return _str[i];
|
||||
return str_[i];
|
||||
}
|
||||
|
||||
const char* data() const {
|
||||
return _str;
|
||||
return str_;
|
||||
}
|
||||
|
||||
StringStoragePolicy::Copy storagePolicy() const {
|
||||
@@ -126,8 +126,8 @@ class SizedRamString {
|
||||
}
|
||||
|
||||
protected:
|
||||
const char* _str;
|
||||
size_t _size;
|
||||
const char* str_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
|
||||
@@ -16,51 +16,51 @@ class JsonString {
|
||||
public:
|
||||
enum Ownership { Copied, Linked };
|
||||
|
||||
JsonString() : _data(0), _size(0), _ownership(Linked) {}
|
||||
JsonString() : data_(0), size_(0), ownership_(Linked) {}
|
||||
|
||||
JsonString(const char* data, Ownership ownership = Linked)
|
||||
: _data(data), _size(data ? ::strlen(data) : 0), _ownership(ownership) {}
|
||||
: data_(data), size_(data ? ::strlen(data) : 0), ownership_(ownership) {}
|
||||
|
||||
JsonString(const char* data, size_t sz, Ownership ownership = Linked)
|
||||
: _data(data), _size(sz), _ownership(ownership) {}
|
||||
: data_(data), size_(sz), ownership_(ownership) {}
|
||||
|
||||
// Returns a pointer to the characters.
|
||||
const char* c_str() const {
|
||||
return _data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
// Returns true if the string is null.
|
||||
bool isNull() const {
|
||||
return !_data;
|
||||
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;
|
||||
return ownership_ == Linked;
|
||||
}
|
||||
|
||||
// Returns length of the string.
|
||||
size_t size() const {
|
||||
return _size;
|
||||
return size_;
|
||||
}
|
||||
|
||||
// Returns true if the string is non-null
|
||||
explicit operator bool() const {
|
||||
return _data != 0;
|
||||
return data_ != 0;
|
||||
}
|
||||
|
||||
// Returns true if strings are equal.
|
||||
friend bool operator==(JsonString lhs, JsonString rhs) {
|
||||
if (lhs._size != rhs._size)
|
||||
if (lhs.size_ != rhs.size_)
|
||||
return false;
|
||||
if (lhs._data == rhs._data)
|
||||
if (lhs.data_ == rhs.data_)
|
||||
return true;
|
||||
if (!lhs._data)
|
||||
if (!lhs.data_)
|
||||
return false;
|
||||
if (!rhs._data)
|
||||
if (!rhs.data_)
|
||||
return false;
|
||||
return memcmp(lhs._data, rhs._data, lhs._size) == 0;
|
||||
return memcmp(lhs.data_, rhs.data_, lhs.size_) == 0;
|
||||
}
|
||||
|
||||
// Returns true if strings differs.
|
||||
@@ -76,9 +76,9 @@ class JsonString {
|
||||
#endif
|
||||
|
||||
private:
|
||||
const char* _data;
|
||||
size_t _size;
|
||||
Ownership _ownership;
|
||||
const char* data_;
|
||||
size_t size_;
|
||||
Ownership ownership_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
||||
@@ -205,43 +205,43 @@ struct Converter<decltype(nullptr)> : private detail::VariantAttorney {
|
||||
namespace detail {
|
||||
class MemoryPoolPrint : public Print {
|
||||
public:
|
||||
MemoryPoolPrint(MemoryPool* pool) : _pool(pool), _size(0) {
|
||||
pool->getFreeZone(&_string, &_capacity);
|
||||
MemoryPoolPrint(MemoryPool* pool) : pool_(pool), size_(0) {
|
||||
pool->getFreeZone(&string_, &capacity_);
|
||||
}
|
||||
|
||||
JsonString str() {
|
||||
ARDUINOJSON_ASSERT(_size < _capacity);
|
||||
return JsonString(_pool->saveStringFromFreeZone(_size), _size,
|
||||
ARDUINOJSON_ASSERT(size_ < capacity_);
|
||||
return JsonString(pool_->saveStringFromFreeZone(size_), size_,
|
||||
JsonString::Copied);
|
||||
}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
if (_size >= _capacity)
|
||||
if (size_ >= capacity_)
|
||||
return 0;
|
||||
|
||||
_string[_size++] = char(c);
|
||||
string_[size_++] = char(c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t write(const uint8_t* buffer, size_t size) {
|
||||
if (_size + size >= _capacity) {
|
||||
_size = _capacity; // mark as overflowed
|
||||
if (size_ + size >= capacity_) {
|
||||
size_ = capacity_; // mark as overflowed
|
||||
return 0;
|
||||
}
|
||||
memcpy(&_string[_size], buffer, size);
|
||||
_size += size;
|
||||
memcpy(&string_[size_], buffer, size);
|
||||
size_ += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
bool overflowed() const {
|
||||
return _size >= _capacity;
|
||||
return size_ >= capacity_;
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryPool* _pool;
|
||||
size_t _size;
|
||||
char* _string;
|
||||
size_t _capacity;
|
||||
MemoryPool* pool_;
|
||||
size_t size_;
|
||||
char* string_;
|
||||
size_t capacity_;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
|
||||
@@ -16,27 +16,27 @@ class JsonVariant : public detail::VariantRefBase<JsonVariant>,
|
||||
|
||||
public:
|
||||
// Creates an unbound reference.
|
||||
JsonVariant() : _data(0), _pool(0) {}
|
||||
JsonVariant() : data_(0), pool_(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
JsonVariant(detail::MemoryPool* pool, detail::VariantData* data)
|
||||
: _data(data), _pool(pool) {}
|
||||
: data_(data), pool_(pool) {}
|
||||
|
||||
private:
|
||||
FORCE_INLINE detail::MemoryPool* getPool() const {
|
||||
return _pool;
|
||||
return pool_;
|
||||
}
|
||||
|
||||
FORCE_INLINE detail::VariantData* getData() const {
|
||||
return _data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
FORCE_INLINE detail::VariantData* getOrCreateData() const {
|
||||
return _data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
detail::VariantData* _data;
|
||||
detail::MemoryPool* _pool;
|
||||
detail::VariantData* data_;
|
||||
detail::MemoryPool* pool_;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -30,39 +30,39 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
|
||||
public:
|
||||
// Creates an unbound reference.
|
||||
JsonVariantConst() : _data(0) {}
|
||||
JsonVariantConst() : data_(0) {}
|
||||
|
||||
// INTERNAL USE ONLY
|
||||
explicit JsonVariantConst(const detail::VariantData* data) : _data(data) {}
|
||||
explicit JsonVariantConst(const detail::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 {
|
||||
using namespace detail;
|
||||
return variantIsNull(_data);
|
||||
return variantIsNull(data_);
|
||||
}
|
||||
|
||||
// Returns true if the reference is unbound.
|
||||
FORCE_INLINE bool isUnbound() const {
|
||||
return !_data;
|
||||
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;
|
||||
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);
|
||||
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);
|
||||
return variantSize(data_);
|
||||
}
|
||||
|
||||
// Casts the value to the specified type.
|
||||
@@ -93,7 +93,7 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
// 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));
|
||||
return JsonVariantConst(variantGetElement(data_, index));
|
||||
}
|
||||
|
||||
// Gets object's member with specified key.
|
||||
@@ -102,7 +102,7 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
FORCE_INLINE typename detail::enable_if<detail::IsString<TString>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](const TString& key) const {
|
||||
return JsonVariantConst(variantGetMember(_data, detail::adaptString(key)));
|
||||
return JsonVariantConst(variantGetMember(data_, detail::adaptString(key)));
|
||||
}
|
||||
|
||||
// Gets object's member with specified key.
|
||||
@@ -111,7 +111,7 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
|
||||
JsonVariantConst>::type
|
||||
operator[](TChar* key) const {
|
||||
return JsonVariantConst(variantGetMember(_data, detail::adaptString(key)));
|
||||
return JsonVariantConst(variantGetMember(data_, detail::adaptString(key)));
|
||||
}
|
||||
|
||||
// Returns true if tge object contains the specified key.
|
||||
@@ -134,11 +134,11 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
|
||||
protected:
|
||||
const detail::VariantData* getData() const {
|
||||
return _data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
private:
|
||||
const detail::VariantData* _data;
|
||||
const detail::VariantData* data_;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
||||
@@ -10,17 +10,17 @@
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
struct SlotKeySetter {
|
||||
SlotKeySetter(VariantSlot* instance) : _instance(instance) {}
|
||||
SlotKeySetter(VariantSlot* instance) : instance_(instance) {}
|
||||
|
||||
template <typename TStoredString>
|
||||
void operator()(TStoredString s) {
|
||||
if (!s)
|
||||
return;
|
||||
ARDUINOJSON_ASSERT(_instance != 0);
|
||||
_instance->setKey(s);
|
||||
ARDUINOJSON_ASSERT(instance_ != 0);
|
||||
instance_->setKey(s);
|
||||
}
|
||||
|
||||
VariantSlot* _instance;
|
||||
VariantSlot* instance_;
|
||||
};
|
||||
|
||||
template <typename TAdaptedString>
|
||||
|
||||
@@ -20,198 +20,188 @@ template <typename T, typename Enable = void>
|
||||
struct Comparer;
|
||||
|
||||
template <typename T>
|
||||
struct Comparer<T, typename enable_if<IsString<T>::value>::type> : ComparerBase {
|
||||
T rhs;
|
||||
struct Comparer<T, typename enable_if<IsString<T>::value>::type>
|
||||
: ComparerBase {
|
||||
T rhs; // TODO: store adapted string?
|
||||
|
||||
explicit Comparer(T value)
|
||||
: rhs(value) {
|
||||
}
|
||||
explicit Comparer(T value) : rhs(value) {}
|
||||
|
||||
CompareResult visitString(const char * lhs, size_t n) {
|
||||
int i = stringCompare(adaptString(rhs), adaptString(lhs, n));
|
||||
if (i < 0)
|
||||
return COMPARE_RESULT_GREATER;
|
||||
else if (i > 0)
|
||||
return COMPARE_RESULT_LESS;
|
||||
else
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
}
|
||||
CompareResult visitString(const char* lhs, size_t n) {
|
||||
int i = stringCompare(adaptString(rhs), adaptString(lhs, n));
|
||||
if (i < 0)
|
||||
return COMPARE_RESULT_GREATER;
|
||||
else if (i > 0)
|
||||
return COMPARE_RESULT_LESS;
|
||||
else
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
}
|
||||
|
||||
CompareResult visitNull() {
|
||||
if (adaptString(rhs).isNull())
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
else
|
||||
return COMPARE_RESULT_DIFFER;
|
||||
}
|
||||
CompareResult visitNull() {
|
||||
if (adaptString(rhs).isNull())
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
else
|
||||
return COMPARE_RESULT_DIFFER;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Comparer<T, typename enable_if<is_integral<T>::value || is_floating_point<T>::value>::type> : ComparerBase {
|
||||
T rhs;
|
||||
struct Comparer<T, typename enable_if<is_integral<T>::value ||
|
||||
is_floating_point<T>::value>::type>
|
||||
: ComparerBase {
|
||||
T rhs;
|
||||
|
||||
explicit Comparer(T value)
|
||||
: rhs(value) {
|
||||
}
|
||||
explicit Comparer(T value) : rhs(value) {}
|
||||
|
||||
CompareResult visitFloat(JsonFloat lhs) {
|
||||
return arithmeticCompare(lhs, rhs);
|
||||
}
|
||||
CompareResult visitFloat(JsonFloat lhs) {
|
||||
return arithmeticCompare(lhs, rhs);
|
||||
}
|
||||
|
||||
CompareResult visitSignedInteger(JsonInteger lhs) {
|
||||
return arithmeticCompare(lhs, rhs);
|
||||
}
|
||||
CompareResult visitSignedInteger(JsonInteger lhs) {
|
||||
return arithmeticCompare(lhs, rhs);
|
||||
}
|
||||
|
||||
CompareResult visitUnsignedInteger(JsonUInt lhs) {
|
||||
return arithmeticCompare(lhs, rhs);
|
||||
}
|
||||
CompareResult visitUnsignedInteger(JsonUInt lhs) {
|
||||
return arithmeticCompare(lhs, rhs);
|
||||
}
|
||||
|
||||
CompareResult visitBoolean(bool lhs) {
|
||||
return visitUnsignedInteger(static_cast<JsonUInt>(lhs));
|
||||
}
|
||||
CompareResult visitBoolean(bool lhs) {
|
||||
return visitUnsignedInteger(static_cast<JsonUInt>(lhs));
|
||||
}
|
||||
};
|
||||
|
||||
struct NullComparer : ComparerBase {
|
||||
CompareResult visitNull() {
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
}
|
||||
CompareResult visitNull() {
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Comparer<decltype(nullptr), void> : NullComparer {
|
||||
explicit Comparer(decltype(nullptr))
|
||||
: NullComparer() {
|
||||
}
|
||||
explicit Comparer(decltype(nullptr)) : NullComparer() {}
|
||||
};
|
||||
|
||||
struct ArrayComparer : ComparerBase {
|
||||
const CollectionData * _rhs;
|
||||
const CollectionData* rhs_;
|
||||
|
||||
explicit ArrayComparer(const CollectionData & rhs)
|
||||
: _rhs(&rhs) {
|
||||
}
|
||||
explicit ArrayComparer(const CollectionData& rhs) : rhs_(&rhs) {}
|
||||
|
||||
CompareResult visitArray(const CollectionData & lhs) {
|
||||
if (JsonArrayConst(&lhs) == JsonArrayConst(_rhs))
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
else
|
||||
return COMPARE_RESULT_DIFFER;
|
||||
}
|
||||
CompareResult visitArray(const CollectionData& lhs) {
|
||||
if (JsonArrayConst(&lhs) == JsonArrayConst(rhs_))
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
else
|
||||
return COMPARE_RESULT_DIFFER;
|
||||
}
|
||||
};
|
||||
|
||||
struct ObjectComparer : ComparerBase {
|
||||
const CollectionData * _rhs;
|
||||
const CollectionData* rhs_;
|
||||
|
||||
explicit ObjectComparer(const CollectionData & rhs)
|
||||
: _rhs(&rhs) {
|
||||
}
|
||||
explicit ObjectComparer(const CollectionData& rhs) : rhs_(&rhs) {}
|
||||
|
||||
CompareResult visitObject(const CollectionData & lhs) {
|
||||
if (JsonObjectConst(&lhs) == JsonObjectConst(_rhs))
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
else
|
||||
return COMPARE_RESULT_DIFFER;
|
||||
}
|
||||
CompareResult visitObject(const CollectionData& lhs) {
|
||||
if (JsonObjectConst(&lhs) == JsonObjectConst(rhs_))
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
else
|
||||
return COMPARE_RESULT_DIFFER;
|
||||
}
|
||||
};
|
||||
|
||||
struct RawComparer : ComparerBase {
|
||||
const char * _rhsData;
|
||||
size_t _rhsSize;
|
||||
const char* rhsData_;
|
||||
size_t rhsSize_;
|
||||
|
||||
explicit RawComparer(const char * rhsData, size_t rhsSize)
|
||||
: _rhsData(rhsData)
|
||||
, _rhsSize(rhsSize) {
|
||||
}
|
||||
explicit RawComparer(const char* rhsData, size_t rhsSize)
|
||||
: rhsData_(rhsData), rhsSize_(rhsSize) {}
|
||||
|
||||
CompareResult visitRawJson(const char * lhsData, size_t lhsSize) {
|
||||
size_t size = _rhsSize < lhsSize ? _rhsSize : lhsSize;
|
||||
int n = memcmp(lhsData, _rhsData, size);
|
||||
if (n < 0)
|
||||
return COMPARE_RESULT_LESS;
|
||||
else if (n > 0)
|
||||
return COMPARE_RESULT_GREATER;
|
||||
else
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
}
|
||||
CompareResult visitRawJson(const char* lhsData, size_t lhsSize) {
|
||||
size_t size = rhsSize_ < lhsSize ? rhsSize_ : lhsSize;
|
||||
int n = memcmp(lhsData, rhsData_, size);
|
||||
if (n < 0)
|
||||
return COMPARE_RESULT_LESS;
|
||||
else if (n > 0)
|
||||
return COMPARE_RESULT_GREATER;
|
||||
else
|
||||
return COMPARE_RESULT_EQUAL;
|
||||
}
|
||||
};
|
||||
|
||||
struct VariantComparer : ComparerBase {
|
||||
const VariantData * rhs;
|
||||
const VariantData* rhs;
|
||||
|
||||
explicit VariantComparer(const VariantData * value)
|
||||
: rhs(value) {
|
||||
}
|
||||
explicit VariantComparer(const VariantData* value) : rhs(value) {}
|
||||
|
||||
CompareResult visitArray(const CollectionData & lhs) {
|
||||
ArrayComparer comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitArray(const CollectionData& lhs) {
|
||||
ArrayComparer comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitObject(const CollectionData & lhs) {
|
||||
ObjectComparer comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitObject(const CollectionData& lhs) {
|
||||
ObjectComparer comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitFloat(JsonFloat lhs) {
|
||||
Comparer<JsonFloat> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitFloat(JsonFloat lhs) {
|
||||
Comparer<JsonFloat> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitString(const char * lhs, size_t) {
|
||||
Comparer<const char *> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitString(const char* lhs, size_t) {
|
||||
Comparer<const char*> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitRawJson(const char * lhsData, size_t lhsSize) {
|
||||
RawComparer comparer(lhsData, lhsSize);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitRawJson(const char* lhsData, size_t lhsSize) {
|
||||
RawComparer comparer(lhsData, lhsSize);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitSignedInteger(JsonInteger lhs) {
|
||||
Comparer<JsonInteger> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitSignedInteger(JsonInteger lhs) {
|
||||
Comparer<JsonInteger> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitUnsignedInteger(JsonUInt lhs) {
|
||||
Comparer<JsonUInt> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitUnsignedInteger(JsonUInt lhs) {
|
||||
Comparer<JsonUInt> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitBoolean(bool lhs) {
|
||||
Comparer<bool> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitBoolean(bool lhs) {
|
||||
Comparer<bool> comparer(lhs);
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
CompareResult visitNull() {
|
||||
NullComparer comparer;
|
||||
return accept(comparer);
|
||||
}
|
||||
CompareResult visitNull() {
|
||||
NullComparer comparer;
|
||||
return accept(comparer);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename TComparer>
|
||||
CompareResult accept(TComparer & comparer) {
|
||||
CompareResult reversedResult = variantAccept(rhs, comparer);
|
||||
switch (reversedResult) {
|
||||
case COMPARE_RESULT_GREATER:
|
||||
return COMPARE_RESULT_LESS;
|
||||
case COMPARE_RESULT_LESS:
|
||||
return COMPARE_RESULT_GREATER;
|
||||
default:
|
||||
return reversedResult;
|
||||
}
|
||||
private:
|
||||
template <typename TComparer>
|
||||
CompareResult accept(TComparer& comparer) {
|
||||
CompareResult reversedResult = variantAccept(rhs, comparer);
|
||||
switch (reversedResult) {
|
||||
case COMPARE_RESULT_GREATER:
|
||||
return COMPARE_RESULT_LESS;
|
||||
case COMPARE_RESULT_LESS:
|
||||
return COMPARE_RESULT_GREATER;
|
||||
default:
|
||||
return reversedResult;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Comparer<T, typename enable_if<is_convertible<T, ArduinoJson::JsonVariantConst>::value>::type> : VariantComparer {
|
||||
explicit Comparer(const T & value)
|
||||
: VariantComparer(VariantAttorney::getData(value)) {
|
||||
}
|
||||
struct Comparer<T, typename enable_if<is_convertible<
|
||||
T, ArduinoJson::JsonVariantConst>::value>::type>
|
||||
: VariantComparer {
|
||||
explicit Comparer(const T& value)
|
||||
: VariantComparer(VariantAttorney::getData(value)) {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
CompareResult compare(ArduinoJson::JsonVariantConst lhs, const T & rhs) {
|
||||
Comparer<T> comparer(rhs);
|
||||
return variantAccept(VariantAttorney::getData(lhs), comparer);
|
||||
CompareResult compare(ArduinoJson::JsonVariantConst lhs, const T& rhs) {
|
||||
Comparer<T> comparer(rhs);
|
||||
return variantAccept(VariantAttorney::getData(lhs), comparer);
|
||||
}
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
@@ -11,67 +11,50 @@
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
#include <ArduinoJson/Variant/VariantContent.hpp>
|
||||
|
||||
// VariantData can't have a constructor (to be a POD), so we have no way to fix
|
||||
// this warning
|
||||
#if defined(__GNUC__)
|
||||
# if __GNUC__ >= 7
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
# pragma GCC diagnostic ignored "-Wuninitialized"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
class VariantData {
|
||||
VariantContent _content; // must be first to allow cast from array to variant
|
||||
uint8_t _flags;
|
||||
VariantContent content_; // must be first to allow cast from array to variant
|
||||
uint8_t flags_;
|
||||
|
||||
public:
|
||||
// Must be a POD!
|
||||
// - no constructor
|
||||
// - no destructor
|
||||
// - no virtual
|
||||
// - no inheritance
|
||||
void init() {
|
||||
_flags = VALUE_IS_NULL;
|
||||
}
|
||||
VariantData() : flags_(VALUE_IS_NULL) {}
|
||||
|
||||
void operator=(const VariantData& src) {
|
||||
_content = src._content;
|
||||
_flags = uint8_t((_flags & OWNED_KEY_BIT) | (src._flags & ~OWNED_KEY_BIT));
|
||||
content_ = src.content_;
|
||||
flags_ = uint8_t((flags_ & OWNED_KEY_BIT) | (src.flags_ & ~OWNED_KEY_BIT));
|
||||
}
|
||||
|
||||
template <typename TVisitor>
|
||||
typename TVisitor::result_type accept(TVisitor& visitor) const {
|
||||
switch (type()) {
|
||||
case VALUE_IS_FLOAT:
|
||||
return visitor.visitFloat(_content.asFloat);
|
||||
return visitor.visitFloat(content_.asFloat);
|
||||
|
||||
case VALUE_IS_ARRAY:
|
||||
return visitor.visitArray(_content.asCollection);
|
||||
return visitor.visitArray(content_.asCollection);
|
||||
|
||||
case VALUE_IS_OBJECT:
|
||||
return visitor.visitObject(_content.asCollection);
|
||||
return visitor.visitObject(content_.asCollection);
|
||||
|
||||
case VALUE_IS_LINKED_STRING:
|
||||
case VALUE_IS_OWNED_STRING:
|
||||
return visitor.visitString(_content.asString.data,
|
||||
_content.asString.size);
|
||||
return visitor.visitString(content_.asString.data,
|
||||
content_.asString.size);
|
||||
|
||||
case VALUE_IS_OWNED_RAW:
|
||||
case VALUE_IS_LINKED_RAW:
|
||||
return visitor.visitRawJson(_content.asString.data,
|
||||
_content.asString.size);
|
||||
return visitor.visitRawJson(content_.asString.data,
|
||||
content_.asString.size);
|
||||
|
||||
case VALUE_IS_SIGNED_INTEGER:
|
||||
return visitor.visitSignedInteger(_content.asSignedInteger);
|
||||
return visitor.visitSignedInteger(content_.asSignedInteger);
|
||||
|
||||
case VALUE_IS_UNSIGNED_INTEGER:
|
||||
return visitor.visitUnsignedInteger(_content.asUnsignedInteger);
|
||||
return visitor.visitUnsignedInteger(content_.asUnsignedInteger);
|
||||
|
||||
case VALUE_IS_BOOLEAN:
|
||||
return visitor.visitBoolean(_content.asBoolean != 0);
|
||||
return visitor.visitBoolean(content_.asBoolean != 0);
|
||||
|
||||
default:
|
||||
return visitor.visitNull();
|
||||
@@ -89,7 +72,7 @@ class VariantData {
|
||||
bool asBoolean() const;
|
||||
|
||||
CollectionData* asArray() {
|
||||
return isArray() ? &_content.asCollection : 0;
|
||||
return isArray() ? &content_.asCollection : 0;
|
||||
}
|
||||
|
||||
const CollectionData* asArray() const {
|
||||
@@ -97,11 +80,11 @@ class VariantData {
|
||||
}
|
||||
|
||||
const CollectionData* asCollection() const {
|
||||
return isCollection() ? &_content.asCollection : 0;
|
||||
return isCollection() ? &content_.asCollection : 0;
|
||||
}
|
||||
|
||||
CollectionData* asObject() {
|
||||
return isObject() ? &_content.asCollection : 0;
|
||||
return isObject() ? &content_.asCollection : 0;
|
||||
}
|
||||
|
||||
const CollectionData* asObject() const {
|
||||
@@ -111,7 +94,7 @@ class VariantData {
|
||||
bool copyFrom(const VariantData& src, MemoryPool* pool);
|
||||
|
||||
bool isArray() const {
|
||||
return (_flags & VALUE_IS_ARRAY) != 0;
|
||||
return (flags_ & VALUE_IS_ARRAY) != 0;
|
||||
}
|
||||
|
||||
bool isBoolean() const {
|
||||
@@ -119,17 +102,17 @@ class VariantData {
|
||||
}
|
||||
|
||||
bool isCollection() const {
|
||||
return (_flags & COLLECTION_MASK) != 0;
|
||||
return (flags_ & COLLECTION_MASK) != 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool isInteger() const {
|
||||
switch (type()) {
|
||||
case VALUE_IS_UNSIGNED_INTEGER:
|
||||
return canConvertNumber<T>(_content.asUnsignedInteger);
|
||||
return canConvertNumber<T>(content_.asUnsignedInteger);
|
||||
|
||||
case VALUE_IS_SIGNED_INTEGER:
|
||||
return canConvertNumber<T>(_content.asSignedInteger);
|
||||
return canConvertNumber<T>(content_.asSignedInteger);
|
||||
|
||||
default:
|
||||
return false;
|
||||
@@ -137,7 +120,7 @@ class VariantData {
|
||||
}
|
||||
|
||||
bool isFloat() const {
|
||||
return (_flags & NUMBER_BIT) != 0;
|
||||
return (flags_ & NUMBER_BIT) != 0;
|
||||
}
|
||||
|
||||
bool isString() const {
|
||||
@@ -145,7 +128,7 @@ class VariantData {
|
||||
}
|
||||
|
||||
bool isObject() const {
|
||||
return (_flags & VALUE_IS_OBJECT) != 0;
|
||||
return (flags_ & VALUE_IS_OBJECT) != 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
@@ -158,30 +141,30 @@ class VariantData {
|
||||
|
||||
void remove(size_t index) {
|
||||
if (isArray())
|
||||
_content.asCollection.removeElement(index);
|
||||
content_.asCollection.removeElement(index);
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
void remove(TAdaptedString key) {
|
||||
if (isObject())
|
||||
_content.asCollection.removeMember(key);
|
||||
content_.asCollection.removeMember(key);
|
||||
}
|
||||
|
||||
void setBoolean(bool value) {
|
||||
setType(VALUE_IS_BOOLEAN);
|
||||
_content.asBoolean = value;
|
||||
content_.asBoolean = value;
|
||||
}
|
||||
|
||||
void setFloat(JsonFloat value) {
|
||||
setType(VALUE_IS_FLOAT);
|
||||
_content.asFloat = value;
|
||||
content_.asFloat = value;
|
||||
}
|
||||
|
||||
void setLinkedRaw(SerializedValue<const char*> value) {
|
||||
if (value.data()) {
|
||||
setType(VALUE_IS_LINKED_RAW);
|
||||
_content.asString.data = value.data();
|
||||
_content.asString.size = value.size();
|
||||
content_.asString.data = value.data();
|
||||
content_.asString.size = value.size();
|
||||
} else {
|
||||
setType(VALUE_IS_NULL);
|
||||
}
|
||||
@@ -192,8 +175,8 @@ class VariantData {
|
||||
const char* dup = pool->saveString(adaptString(value.data(), value.size()));
|
||||
if (dup) {
|
||||
setType(VALUE_IS_OWNED_RAW);
|
||||
_content.asString.data = dup;
|
||||
_content.asString.size = value.size();
|
||||
content_.asString.data = dup;
|
||||
content_.asString.size = value.size();
|
||||
return true;
|
||||
} else {
|
||||
setType(VALUE_IS_NULL);
|
||||
@@ -204,13 +187,13 @@ class VariantData {
|
||||
template <typename T>
|
||||
typename enable_if<is_unsigned<T>::value>::type setInteger(T value) {
|
||||
setType(VALUE_IS_UNSIGNED_INTEGER);
|
||||
_content.asUnsignedInteger = static_cast<JsonUInt>(value);
|
||||
content_.asUnsignedInteger = static_cast<JsonUInt>(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<is_signed<T>::value>::type setInteger(T value) {
|
||||
setType(VALUE_IS_SIGNED_INTEGER);
|
||||
_content.asSignedInteger = value;
|
||||
content_.asSignedInteger = value;
|
||||
}
|
||||
|
||||
void setNull() {
|
||||
@@ -223,20 +206,20 @@ class VariantData {
|
||||
setType(VALUE_IS_LINKED_STRING);
|
||||
else
|
||||
setType(VALUE_IS_OWNED_STRING);
|
||||
_content.asString.data = s.c_str();
|
||||
_content.asString.size = s.size();
|
||||
content_.asString.data = s.c_str();
|
||||
content_.asString.size = s.size();
|
||||
}
|
||||
|
||||
CollectionData& toArray() {
|
||||
setType(VALUE_IS_ARRAY);
|
||||
_content.asCollection.clear();
|
||||
return _content.asCollection;
|
||||
content_.asCollection.clear();
|
||||
return content_.asCollection;
|
||||
}
|
||||
|
||||
CollectionData& toObject() {
|
||||
setType(VALUE_IS_OBJECT);
|
||||
_content.asCollection.clear();
|
||||
return _content.asCollection;
|
||||
content_.asCollection.clear();
|
||||
return content_.asCollection;
|
||||
}
|
||||
|
||||
size_t memoryUsage() const {
|
||||
@@ -245,17 +228,17 @@ class VariantData {
|
||||
case VALUE_IS_OWNED_RAW:
|
||||
// We always add a zero at the end: the deduplication function uses it
|
||||
// to detect the beginning of the next string.
|
||||
return _content.asString.size + 1;
|
||||
return content_.asString.size + 1;
|
||||
case VALUE_IS_OBJECT:
|
||||
case VALUE_IS_ARRAY:
|
||||
return _content.asCollection.memoryUsage();
|
||||
return content_.asCollection.memoryUsage();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return isCollection() ? _content.asCollection.size() : 0;
|
||||
return isCollection() ? content_.asCollection.size() : 0;
|
||||
}
|
||||
|
||||
VariantData* addElement(MemoryPool* pool) {
|
||||
@@ -263,7 +246,7 @@ class VariantData {
|
||||
toArray();
|
||||
if (!isArray())
|
||||
return 0;
|
||||
return _content.asCollection.addElement(pool);
|
||||
return content_.asCollection.addElement(pool);
|
||||
}
|
||||
|
||||
VariantData* getElement(size_t index) const {
|
||||
@@ -276,7 +259,7 @@ class VariantData {
|
||||
toArray();
|
||||
if (!isArray())
|
||||
return 0;
|
||||
return _content.asCollection.getOrAddElement(index, pool);
|
||||
return content_.asCollection.getOrAddElement(index, pool);
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
@@ -291,18 +274,18 @@ class VariantData {
|
||||
toObject();
|
||||
if (!isObject())
|
||||
return 0;
|
||||
return _content.asCollection.getOrAddMember(key, pool);
|
||||
return content_.asCollection.getOrAddMember(key, pool);
|
||||
}
|
||||
|
||||
void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) {
|
||||
if (_flags & OWNED_VALUE_BIT)
|
||||
_content.asString.data += stringDistance;
|
||||
if (_flags & COLLECTION_MASK)
|
||||
_content.asCollection.movePointers(stringDistance, variantDistance);
|
||||
if (flags_ & OWNED_VALUE_BIT)
|
||||
content_.asString.data += stringDistance;
|
||||
if (flags_ & COLLECTION_MASK)
|
||||
content_.asCollection.movePointers(stringDistance, variantDistance);
|
||||
}
|
||||
|
||||
uint8_t type() const {
|
||||
return _flags & VALUE_MASK;
|
||||
return flags_ & VALUE_MASK;
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
@@ -317,29 +300,23 @@ class VariantData {
|
||||
|
||||
private:
|
||||
void setType(uint8_t t) {
|
||||
_flags &= OWNED_KEY_BIT;
|
||||
_flags |= t;
|
||||
flags_ &= OWNED_KEY_BIT;
|
||||
flags_ |= t;
|
||||
}
|
||||
|
||||
struct VariantStringSetter {
|
||||
VariantStringSetter(VariantData* instance) : _instance(instance) {}
|
||||
VariantStringSetter(VariantData* instance) : instance_(instance) {}
|
||||
|
||||
template <typename TStoredString>
|
||||
void operator()(TStoredString s) {
|
||||
if (s)
|
||||
_instance->setString(s);
|
||||
instance_->setString(s);
|
||||
else
|
||||
_instance->setNull();
|
||||
instance_->setNull();
|
||||
}
|
||||
|
||||
VariantData* _instance;
|
||||
VariantData* instance_;
|
||||
};
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# if __GNUC__ >= 8
|
||||
# pragma GCC diagnostic pop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -19,16 +19,16 @@ template <typename T>
|
||||
inline T VariantData::asIntegral() const {
|
||||
switch (type()) {
|
||||
case VALUE_IS_BOOLEAN:
|
||||
return _content.asBoolean;
|
||||
return content_.asBoolean;
|
||||
case VALUE_IS_UNSIGNED_INTEGER:
|
||||
return convertNumber<T>(_content.asUnsignedInteger);
|
||||
return convertNumber<T>(content_.asUnsignedInteger);
|
||||
case VALUE_IS_SIGNED_INTEGER:
|
||||
return convertNumber<T>(_content.asSignedInteger);
|
||||
return convertNumber<T>(content_.asSignedInteger);
|
||||
case VALUE_IS_LINKED_STRING:
|
||||
case VALUE_IS_OWNED_STRING:
|
||||
return parseNumber<T>(_content.asString.data);
|
||||
return parseNumber<T>(content_.asString.data);
|
||||
case VALUE_IS_FLOAT:
|
||||
return convertNumber<T>(_content.asFloat);
|
||||
return convertNumber<T>(content_.asFloat);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -37,12 +37,12 @@ inline T VariantData::asIntegral() const {
|
||||
inline bool VariantData::asBoolean() const {
|
||||
switch (type()) {
|
||||
case VALUE_IS_BOOLEAN:
|
||||
return _content.asBoolean;
|
||||
return content_.asBoolean;
|
||||
case VALUE_IS_SIGNED_INTEGER:
|
||||
case VALUE_IS_UNSIGNED_INTEGER:
|
||||
return _content.asUnsignedInteger != 0;
|
||||
return content_.asUnsignedInteger != 0;
|
||||
case VALUE_IS_FLOAT:
|
||||
return _content.asFloat != 0;
|
||||
return content_.asFloat != 0;
|
||||
case VALUE_IS_NULL:
|
||||
return false;
|
||||
default:
|
||||
@@ -55,16 +55,16 @@ template <typename T>
|
||||
inline T VariantData::asFloat() const {
|
||||
switch (type()) {
|
||||
case VALUE_IS_BOOLEAN:
|
||||
return static_cast<T>(_content.asBoolean);
|
||||
return static_cast<T>(content_.asBoolean);
|
||||
case VALUE_IS_UNSIGNED_INTEGER:
|
||||
return static_cast<T>(_content.asUnsignedInteger);
|
||||
return static_cast<T>(content_.asUnsignedInteger);
|
||||
case VALUE_IS_SIGNED_INTEGER:
|
||||
return static_cast<T>(_content.asSignedInteger);
|
||||
return static_cast<T>(content_.asSignedInteger);
|
||||
case VALUE_IS_LINKED_STRING:
|
||||
case VALUE_IS_OWNED_STRING:
|
||||
return parseNumber<T>(_content.asString.data);
|
||||
return parseNumber<T>(content_.asString.data);
|
||||
case VALUE_IS_FLOAT:
|
||||
return static_cast<T>(_content.asFloat);
|
||||
return static_cast<T>(content_.asFloat);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -73,10 +73,10 @@ inline T VariantData::asFloat() const {
|
||||
inline JsonString VariantData::asString() const {
|
||||
switch (type()) {
|
||||
case VALUE_IS_LINKED_STRING:
|
||||
return JsonString(_content.asString.data, _content.asString.size,
|
||||
return JsonString(content_.asString.data, content_.asString.size,
|
||||
JsonString::Linked);
|
||||
case VALUE_IS_OWNED_STRING:
|
||||
return JsonString(_content.asString.data, _content.asString.size,
|
||||
return JsonString(content_.asString.data, content_.asString.size,
|
||||
JsonString::Copied);
|
||||
default:
|
||||
return JsonString();
|
||||
@@ -86,20 +86,20 @@ inline JsonString VariantData::asString() const {
|
||||
inline bool VariantData::copyFrom(const VariantData& src, MemoryPool* pool) {
|
||||
switch (src.type()) {
|
||||
case VALUE_IS_ARRAY:
|
||||
return toArray().copyFrom(src._content.asCollection, pool);
|
||||
return toArray().copyFrom(src.content_.asCollection, pool);
|
||||
case VALUE_IS_OBJECT:
|
||||
return toObject().copyFrom(src._content.asCollection, pool);
|
||||
return toObject().copyFrom(src.content_.asCollection, pool);
|
||||
case VALUE_IS_OWNED_STRING: {
|
||||
JsonString value = src.asString();
|
||||
return setString(adaptString(value), pool);
|
||||
}
|
||||
case VALUE_IS_OWNED_RAW:
|
||||
return storeOwnedRaw(
|
||||
serialized(src._content.asString.data, src._content.asString.size),
|
||||
serialized(src.content_.asString.data, src.content_.asString.size),
|
||||
pool);
|
||||
default:
|
||||
setType(src.type());
|
||||
_content = src._content;
|
||||
content_ = src.content_;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ class VariantSlot {
|
||||
// CAUTION: same layout as VariantData
|
||||
// we cannot use composition because it adds padding
|
||||
// (+20% on ESP8266 for example)
|
||||
VariantContent _content;
|
||||
uint8_t _flags;
|
||||
VariantSlotDiff _next;
|
||||
const char* _key;
|
||||
VariantContent content_;
|
||||
uint8_t flags_;
|
||||
VariantSlotDiff next_;
|
||||
const char* key_;
|
||||
|
||||
public:
|
||||
// Must be a POD!
|
||||
@@ -30,15 +30,15 @@ class VariantSlot {
|
||||
// - no inheritance
|
||||
|
||||
VariantData* data() {
|
||||
return reinterpret_cast<VariantData*>(&_content);
|
||||
return reinterpret_cast<VariantData*>(&content_);
|
||||
}
|
||||
|
||||
const VariantData* data() const {
|
||||
return reinterpret_cast<const VariantData*>(&_content);
|
||||
return reinterpret_cast<const VariantData*>(&content_);
|
||||
}
|
||||
|
||||
VariantSlot* next() {
|
||||
return _next ? this + _next : 0;
|
||||
return next_ ? this + next_ : 0;
|
||||
}
|
||||
|
||||
const VariantSlot* next() const {
|
||||
@@ -48,9 +48,9 @@ class VariantSlot {
|
||||
VariantSlot* next(size_t distance) {
|
||||
VariantSlot* slot = this;
|
||||
while (distance--) {
|
||||
if (!slot->_next)
|
||||
if (!slot->next_)
|
||||
return 0;
|
||||
slot += slot->_next;
|
||||
slot += slot->next_;
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class VariantSlot {
|
||||
numeric_limits<VariantSlotDiff>::lowest());
|
||||
ARDUINOJSON_ASSERT(!slot || slot - this <=
|
||||
numeric_limits<VariantSlotDiff>::highest());
|
||||
_next = VariantSlotDiff(slot ? slot - this : 0);
|
||||
next_ = VariantSlotDiff(slot ? slot - this : 0);
|
||||
}
|
||||
|
||||
void setNextNotNull(VariantSlot* slot) {
|
||||
@@ -73,39 +73,39 @@ class VariantSlot {
|
||||
numeric_limits<VariantSlotDiff>::lowest());
|
||||
ARDUINOJSON_ASSERT(slot - this <=
|
||||
numeric_limits<VariantSlotDiff>::highest());
|
||||
_next = VariantSlotDiff(slot - this);
|
||||
next_ = VariantSlotDiff(slot - this);
|
||||
}
|
||||
|
||||
void setKey(JsonString k) {
|
||||
ARDUINOJSON_ASSERT(k);
|
||||
if (k.isLinked())
|
||||
_flags &= VALUE_MASK;
|
||||
flags_ &= VALUE_MASK;
|
||||
else
|
||||
_flags |= OWNED_KEY_BIT;
|
||||
_key = k.c_str();
|
||||
flags_ |= OWNED_KEY_BIT;
|
||||
key_ = k.c_str();
|
||||
}
|
||||
|
||||
const char* key() const {
|
||||
return _key;
|
||||
return key_;
|
||||
}
|
||||
|
||||
bool ownsKey() const {
|
||||
return (_flags & OWNED_KEY_BIT) != 0;
|
||||
return (flags_ & OWNED_KEY_BIT) != 0;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_next = 0;
|
||||
_flags = 0;
|
||||
_key = 0;
|
||||
next_ = 0;
|
||||
flags_ = 0;
|
||||
key_ = 0;
|
||||
}
|
||||
|
||||
void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) {
|
||||
if (_flags & OWNED_KEY_BIT)
|
||||
_key += stringDistance;
|
||||
if (_flags & OWNED_VALUE_BIT)
|
||||
_content.asString.data += stringDistance;
|
||||
if (_flags & COLLECTION_MASK)
|
||||
_content.asCollection.movePointers(stringDistance, variantDistance);
|
||||
if (flags_ & OWNED_KEY_BIT)
|
||||
key_ += stringDistance;
|
||||
if (flags_ & OWNED_VALUE_BIT)
|
||||
content_.asString.data += stringDistance;
|
||||
if (flags_ & COLLECTION_MASK)
|
||||
content_.asCollection.movePointers(stringDistance, variantDistance);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARDUINOJSON_VERSION "6.21.0"
|
||||
#define ARDUINOJSON_VERSION "6.21.2"
|
||||
#define ARDUINOJSON_VERSION_MAJOR 6
|
||||
#define ARDUINOJSON_VERSION_MINOR 21
|
||||
#define ARDUINOJSON_VERSION_REVISION 0
|
||||
#define ARDUINOJSON_VERSION_REVISION 2
|
||||
|
||||
91
lib/ArduinoJson/src/CMakeLists.txt
Normal file
91
lib/ArduinoJson/src/CMakeLists.txt
Normal file
@@ -0,0 +1,91 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
# I have no idea what this is about, I simply followed the instructions from:
|
||||
# https://dominikberner.ch/cmake-interface-lib/
|
||||
|
||||
add_library(ArduinoJson INTERFACE)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Adding the install interface generator expression makes sure that the include
|
||||
# files are installed to the proper location (provided by GNUInstallDirs)
|
||||
target_include_directories(ArduinoJson
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
target_compile_definitions(ArduinoJson
|
||||
INTERFACE
|
||||
ARDUINOJSON_DEBUG=$<CONFIG:Debug>
|
||||
)
|
||||
|
||||
# locations are provided by GNUInstallDirs
|
||||
install(
|
||||
TARGETS
|
||||
ArduinoJson
|
||||
EXPORT
|
||||
ArduinoJson_Targets
|
||||
ARCHIVE DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION
|
||||
${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_GREATER "3.14.0")
|
||||
set(ARCH_INDEPENDENT "ARCH_INDEPENDENT")
|
||||
endif()
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${PROJECT_BINARY_DIR}/ArduinoJsonConfigVersion.cmake"
|
||||
VERSION
|
||||
${PROJECT_VERSION}
|
||||
COMPATIBILITY
|
||||
SameMajorVersion
|
||||
${ARCH_INDEPENDENT}
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
"${PROJECT_SOURCE_DIR}/extras/ArduinoJsonConfig.cmake.in"
|
||||
"${PROJECT_BINARY_DIR}/ArduinoJsonConfig.cmake"
|
||||
INSTALL_DESTINATION
|
||||
${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT
|
||||
ArduinoJson_Targets
|
||||
FILE
|
||||
ArduinoJsonTargets.cmake
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
"${PROJECT_BINARY_DIR}/ArduinoJsonConfig.cmake"
|
||||
"${PROJECT_BINARY_DIR}/ArduinoJsonConfigVersion.cmake"
|
||||
DESTINATION
|
||||
"${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
ArduinoJson.h
|
||||
ArduinoJson.hpp
|
||||
DESTINATION
|
||||
include
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ArduinoJson"
|
||||
DESTINATION
|
||||
include
|
||||
)
|
||||
Reference in New Issue
Block a user