forked from bblanchon/ArduinoJson
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
6fb52c3638 | |||
b72ef09451 | |||
f7de027617 | |||
bc4c2dde33 | |||
95f05dad66 | |||
3bb0a7aa8e | |||
dcf7eeef28 | |||
3b923b6e4e | |||
8050f7404b | |||
959b1d9e4c | |||
daa279d57b | |||
ae9b7926a2 | |||
1f7a5e6943 | |||
9e354803de | |||
3ea5eb3f3a | |||
ec43bf4fe9 | |||
2097ffaabf | |||
67e78f0751 | |||
1791dccbf2 | |||
40d1cfe7af | |||
4627f851ca | |||
fc9e609ab5 | |||
8b3d861a9d | |||
9ef864b27c | |||
275b80a462 |
23
CHANGELOG.md
23
CHANGELOG.md
@ -1,6 +1,27 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v6.15.2 (2020-05-15)
|
||||
-------
|
||||
|
||||
* CMake: don't build tests when imported in another project
|
||||
* CMake: made project arch-independent
|
||||
* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250)
|
||||
* Added support for `JsonDocument` to `copyArray()` (issue #1255)
|
||||
* Added support for `enum`s in `as<T>()` and `is<T>()` (issue #1256)
|
||||
* Added `JsonVariant` as an input type for `deserializeXxx()`
|
||||
For example, you can do: `deserializeJson(doc2, doc1["payload"])`
|
||||
* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0
|
||||
|
||||
v6.15.1 (2020-04-08)
|
||||
-------
|
||||
|
||||
* Fixed "maybe-uninitialized" warning (issue #1217)
|
||||
* Fixed "statement is unreachable" warning on IAR (issue #1233)
|
||||
* Fixed "pointless integer comparison" warning on IAR (issue #1233)
|
||||
* Added CMake "install" target (issue #1209)
|
||||
* Disabled alignment on AVR (issue #1231)
|
||||
|
||||
v6.15.0 (2020-03-22)
|
||||
-------
|
||||
|
||||
@ -32,7 +53,7 @@ v6.15.0 (2020-03-22)
|
||||
>
|
||||
> DynamicJsonDocument doc2 = doc1;
|
||||
> Serial.print(doc2.capacity()); // 8 with ArduinoJson 6.14
|
||||
// 64 with ArduinoJson 6.15
|
||||
> // 64 with ArduinoJson 6.15
|
||||
> ```
|
||||
>
|
||||
> I made this change to get consistent results between copy-constructor and move-constructor, and whether RVO applies or not.
|
||||
|
@ -3,19 +3,17 @@
|
||||
# MIT License
|
||||
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(ArduinoJson)
|
||||
|
||||
enable_testing()
|
||||
project(ArduinoJson VERSION 6.15.1)
|
||||
|
||||
add_definitions(-DARDUINOJSON_DEBUG=1)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
add_compile_options(-g -O0)
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
include(CTest)
|
||||
endif()
|
||||
|
||||
if(${COVERAGE})
|
||||
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
add_subdirectory(src)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
|
||||
add_subdirectory(extras/tests)
|
||||
add_subdirectory(extras/fuzzing)
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
|
||||
include(extras/CompileOptions.cmake)
|
||||
add_subdirectory(extras/tests)
|
||||
add_subdirectory(extras/fuzzing)
|
||||
endif()
|
||||
|
67
README.md
67
README.md
@ -2,7 +2,7 @@
|
||||
|
||||
---
|
||||
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.15.0)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.15.2)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
[](https://travis-ci.org/bblanchon/ArduinoJson)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
@ -13,29 +13,30 @@ 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
|
||||
* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme)
|
||||
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/?utm_source=github&utm_medium=readme)
|
||||
* [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme)
|
||||
* [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/?utm_source=github&utm_medium=readme)
|
||||
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#filtering)
|
||||
* Supports single quotes as a string delimiter
|
||||
* Compatible with NDJSON and JSON Lines
|
||||
* [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/)
|
||||
* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme)
|
||||
* [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme)
|
||||
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/?utm_source=github&utm_medium=readme)
|
||||
* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/?utm_source=github&utm_medium=readme)
|
||||
* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/?utm_source=github&utm_medium=readme)
|
||||
* 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/)
|
||||
* [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
|
||||
* [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
|
||||
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
|
||||
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/?utm_source=github&utm_medium=readme)
|
||||
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme)
|
||||
* Versatile
|
||||
* [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/)
|
||||
* Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/)
|
||||
* Supports Arduino's `Stream` and [STL's `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 allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme)
|
||||
* Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme)
|
||||
* Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme)
|
||||
* [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme)
|
||||
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer)
|
||||
* Portable
|
||||
* Usable on any C++ project (not limited to Arduino)
|
||||
* Compatible with C++98
|
||||
@ -61,13 +62,15 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
* [Visual Micro](http://www.visualmicro.com/)
|
||||
* [Visual Studio](https://www.visualstudio.com/)
|
||||
* [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/t7KP7I6dVuLhqzDl)
|
||||
* [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/?utm_source=github&utm_medium=readme)
|
||||
* Well designed
|
||||
* [Elegant API](http://127.0.0.1:4000/v6/example/)
|
||||
* [Elegant API](http://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
|
||||
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
|
||||
* Self-contained (no external dependency)
|
||||
* `const` friendly
|
||||
* `for` friendly
|
||||
* [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/?utm_source=github&utm_medium=readme)
|
||||
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
|
||||
* Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/?utm_source=github&utm_medium=readme#integer-overflows)
|
||||
* Well tested
|
||||
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
* Continuously tested on
|
||||
@ -76,11 +79,11 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
* [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson)
|
||||
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
* 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/)
|
||||
* [Book](https://arduinojson.org/book/)
|
||||
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme)
|
||||
* [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
|
||||
* [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
|
||||
* [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme)
|
||||
* [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme)
|
||||
* Vibrant user community
|
||||
* Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search)
|
||||
* [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson)
|
||||
@ -115,10 +118,8 @@ DynamicJsonDocument doc(1024);
|
||||
|
||||
doc["sensor"] = "gps";
|
||||
doc["time"] = 1351824120;
|
||||
|
||||
JsonArray data = doc.createNestedArray("data");
|
||||
data.add(48.756080);
|
||||
data.add(2.302038);
|
||||
doc["data"][0] = 48.756080;
|
||||
doc["data"][1] = 2.302038;
|
||||
|
||||
serializeJson(doc, Serial);
|
||||
// This prints:
|
||||
@ -131,5 +132,5 @@ See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_
|
||||
|
||||
Do you like this library? Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)!
|
||||
|
||||
What? You don't like it but you *love* it?
|
||||
We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time!
|
||||
What? You don't like it but you *love* it?
|
||||
We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time.
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 6.15.0.{build}
|
||||
version: 6.15.2.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
|
4
extras/ArduinoJsonConfig.cmake.in
Normal file
4
extras/ArduinoJsonConfig.cmake.in
Normal file
@ -0,0 +1,4 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
check_required_components("@PROJECT_NAME@")
|
100
extras/CompileOptions.cmake
Normal file
100
extras/CompileOptions.cmake
Normal file
@ -0,0 +1,100 @@
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
add_compile_options(
|
||||
-pedantic
|
||||
-Wall
|
||||
-Wcast-align
|
||||
-Wcast-qual
|
||||
-Wconversion
|
||||
-Wctor-dtor-privacy
|
||||
-Wdisabled-optimization
|
||||
-Werror
|
||||
-Wextra
|
||||
-Wformat=2
|
||||
-Winit-self
|
||||
-Wmissing-include-dirs
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Woverloaded-virtual
|
||||
-Wparentheses
|
||||
-Wredundant-decls
|
||||
-Wshadow
|
||||
-Wsign-promo
|
||||
-Wstrict-aliasing
|
||||
-Wundef
|
||||
)
|
||||
|
||||
if(NOT MINGW)
|
||||
add_compile_options(
|
||||
-std=c++98
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${COVERAGE})
|
||||
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8)
|
||||
add_compile_options(-g -Og)
|
||||
else()
|
||||
add_compile_options(-g -O0)
|
||||
endif()
|
||||
|
||||
add_compile_options(
|
||||
-Wstrict-null-sentinel
|
||||
-Wno-vla # Allow VLA in tests
|
||||
)
|
||||
add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
|
||||
add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
|
||||
add_compile_options(-Wnoexcept)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(
|
||||
-Wc++11-compat
|
||||
-Wdeprecated-register
|
||||
-Wno-vla-extension # Allow VLA in tests
|
||||
)
|
||||
add_definitions(
|
||||
-DHAS_VARIABLE_LENGTH_ARRAY
|
||||
-DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0)
|
||||
add_compile_options(-g -Og)
|
||||
else()
|
||||
add_compile_options(-g -O0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
|
||||
add_compile_options(-g -Og)
|
||||
else()
|
||||
add_compile_options(-g -O0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_compile_options(
|
||||
/W4 # Set warning level
|
||||
/WX # Treats all compiler warnings as errors.
|
||||
)
|
||||
|
||||
if (NOT MSVC_VERSION LESS 1910) # >= Visual Studio 2017
|
||||
add_compile_options(
|
||||
/Zc:__cplusplus # Enable updated __cplusplus macro
|
||||
)
|
||||
endif()
|
||||
endif()
|
@ -3,12 +3,5 @@
|
||||
export CC="$_CC"
|
||||
export CXX="$_CXX"
|
||||
|
||||
if [ -n "$SANITIZE" ]; then
|
||||
export CXXFLAGS="-fsanitize=$SANITIZE"
|
||||
BUILD_TYPE="Debug"
|
||||
else
|
||||
BUILD_TYPE="Release"
|
||||
fi
|
||||
|
||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .
|
||||
cmake -DCMAKE_BUILD_TYPE=Release .
|
||||
cmake --build .
|
||||
|
@ -1,4 +1,10 @@
|
||||
#!/bin/sh -ex
|
||||
|
||||
"$(dirname "$0")/build.sh"
|
||||
export CC="$_CC"
|
||||
export CXX="$_CXX"
|
||||
|
||||
[ -n "$SANITIZE" ] && export CXXFLAGS="-fsanitize=$SANITIZE"
|
||||
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug .
|
||||
cmake --build .
|
||||
ctest --output-on-failure .
|
||||
|
@ -10,8 +10,14 @@ add_executable(msgpack_fuzzer
|
||||
msgpack_fuzzer.cpp
|
||||
fuzzer_main.cpp
|
||||
)
|
||||
target_link_libraries(msgpack_fuzzer
|
||||
ArduinoJson
|
||||
)
|
||||
|
||||
add_executable(json_fuzzer
|
||||
json_fuzzer.cpp
|
||||
fuzzer_main.cpp
|
||||
)
|
||||
target_link_libraries(json_fuzzer
|
||||
ArduinoJson
|
||||
)
|
||||
|
@ -21,7 +21,7 @@ std::vector<uint8_t> read(const char* path) {
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t size = ftell(f);
|
||||
size_t size = static_cast<size_t>(ftell(f));
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
std::vector<uint8_t> buffer(size);
|
||||
|
@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export PATH="$PATH:/Applications/CMake.app/Contents/bin/"
|
||||
|
||||
cd $(dirname $0)/../..
|
||||
ROOT=$(pwd)
|
||||
|
||||
mkdir "build"
|
||||
cd build
|
||||
BUILD=$(pwd)
|
||||
|
||||
build-env()
|
||||
{
|
||||
cd $BUILD
|
||||
mkdir "$1"
|
||||
cd "$1"
|
||||
cmake "$ROOT" -G "$2"
|
||||
}
|
||||
|
||||
if [[ $(uname) == MINGW* ]]
|
||||
then
|
||||
build-env "Make" "MinGW Makefiles"
|
||||
build-env "SublimeText" "Sublime Text 2 - Ninja"
|
||||
build-env "VisualStudio" "Visual Studio 14 2015"
|
||||
else
|
||||
build-env "SublimeText" "Sublime Text 2 - Ninja"
|
||||
build-env "Make" "Unix Makefiles"
|
||||
build-env "Xcode" "Xcode"
|
||||
fi
|
@ -14,19 +14,22 @@ update_version_in_source () {
|
||||
UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG}))
|
||||
|
||||
sed -i~ -bE "s/version=$VERSION_REGEX/version=$VERSION/; s|ardu-badge.com/ArduinoJson/$VERSION_REGEX|ardu-badge.com/ArduinoJson/$VERSION|; " README.md
|
||||
rm README.md*~
|
||||
rm README.md~
|
||||
|
||||
sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md
|
||||
rm CHANGELOG.md*~
|
||||
rm CHANGELOG.md~
|
||||
|
||||
sed -i~ -bE "s/(project\\s*\\(ArduinoJson\\s+VERSION\\s+).*?\\)/\\1$MAJOR.$MINOR.$REVISION)/" CMakeLists.txt
|
||||
rm CMakeLists.txt~
|
||||
|
||||
sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json
|
||||
rm library.json*~
|
||||
rm library.json~
|
||||
|
||||
sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties
|
||||
rm library.properties*~
|
||||
rm library.properties~
|
||||
|
||||
sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml
|
||||
rm appveyor.yml*~
|
||||
rm appveyor.yml~
|
||||
|
||||
sed -i~ -bE \
|
||||
-e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \
|
||||
|
@ -4,76 +4,11 @@
|
||||
|
||||
add_subdirectory(catch)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
add_compile_options(
|
||||
-pedantic
|
||||
-Wall
|
||||
-Wcast-align
|
||||
-Wcast-qual
|
||||
-Wconversion
|
||||
-Wctor-dtor-privacy
|
||||
-Wdisabled-optimization
|
||||
-Werror
|
||||
-Wextra
|
||||
-Wformat=2
|
||||
-Winit-self
|
||||
-Wmissing-include-dirs
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Woverloaded-virtual
|
||||
-Wparentheses
|
||||
-Wredundant-decls
|
||||
-Wshadow
|
||||
-Wsign-promo
|
||||
-Wstrict-aliasing
|
||||
-Wundef
|
||||
)
|
||||
|
||||
if(NOT MINGW)
|
||||
add_compile_options(
|
||||
-std=c++98
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
add_compile_options(
|
||||
-Wstrict-null-sentinel
|
||||
-Wno-vla # Allow VLA in tests
|
||||
)
|
||||
add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
|
||||
add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
|
||||
add_compile_options(-Wnoexcept)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(
|
||||
-Wc++11-compat
|
||||
-Wdeprecated-register
|
||||
-Wno-vla-extension # Allow VLA in tests
|
||||
)
|
||||
add_definitions(
|
||||
-DHAS_VARIABLE_LENGTH_ARRAY
|
||||
-DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_compile_options(
|
||||
/W4 # Set warning level
|
||||
/WX # Treats all compiler warnings as errors.
|
||||
)
|
||||
endif()
|
||||
link_libraries(ArduinoJson catch)
|
||||
|
||||
include_directories(Helpers)
|
||||
add_subdirectory(ElementProxy)
|
||||
add_subdirectory(FailingBuilds)
|
||||
add_subdirectory(IntegrationTests)
|
||||
add_subdirectory(JsonArray)
|
||||
add_subdirectory(JsonDeserializer)
|
||||
|
@ -11,5 +11,4 @@ add_executable(ElementProxyTests
|
||||
size.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(ElementProxyTests catch)
|
||||
add_test(ElementProxy ElementProxyTests)
|
||||
|
38
extras/tests/FailingBuilds/CMakeLists.txt
Normal file
38
extras/tests/FailingBuilds/CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
macro(build_should_fail target)
|
||||
set_target_properties(${target}
|
||||
PROPERTIES
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
EXCLUDE_FROM_DEFAULT_BUILD TRUE
|
||||
)
|
||||
add_test(
|
||||
NAME
|
||||
${target}
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
|
||||
WORKING_DIRECTORY
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
set_tests_properties(${target}
|
||||
PROPERTIES
|
||||
WILL_FAIL TRUE
|
||||
)
|
||||
endmacro()
|
||||
|
||||
|
||||
add_executable(Issue978 Issue978.cpp)
|
||||
build_should_fail(Issue978)
|
||||
|
||||
add_executable(Issue1189 Issue1189.cpp)
|
||||
build_should_fail(Issue1189)
|
||||
|
||||
add_executable(read_long_long read_long_long.cpp)
|
||||
set_property(TARGET read_long_long PROPERTY CXX_STANDARD 11)
|
||||
build_should_fail(read_long_long)
|
||||
|
||||
add_executable(write_long_long write_long_long.cpp)
|
||||
set_property(TARGET write_long_long PROPERTY CXX_STANDARD 11)
|
||||
build_should_fail(write_long_long)
|
20
extras/tests/FailingBuilds/read_long_long.cpp
Normal file
20
extras/tests/FailingBuilds/read_long_long.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8
|
||||
#error This test requires sizeof(long) < 8
|
||||
#endif
|
||||
|
||||
#if !ARDUINOJSON_HAS_LONG_LONG
|
||||
#error This test requires C++11
|
||||
#endif
|
||||
|
||||
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(long long)
|
||||
int main() {
|
||||
DynamicJsonDocument doc(1024);
|
||||
doc["dummy"].as<long long>();
|
||||
}
|
19
extras/tests/FailingBuilds/write_long_long.cpp
Normal file
19
extras/tests/FailingBuilds/write_long_long.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8
|
||||
#error This test requires sizeof(long) < 8
|
||||
#endif
|
||||
|
||||
#if !ARDUINOJSON_HAS_LONG_LONG
|
||||
#error This test requires C++11
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
DynamicJsonDocument doc(1024);
|
||||
doc["dummy"] = static_cast<long long>(42);
|
||||
}
|
@ -16,5 +16,4 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(IntegrationTests catch)
|
||||
add_test(IntegrationTests IntegrationTests)
|
||||
|
@ -19,5 +19,4 @@ add_executable(JsonArrayTests
|
||||
undefined.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(JsonArrayTests catch)
|
||||
add_test(JsonArray JsonArrayTests)
|
||||
|
@ -19,6 +19,18 @@ TEST_CASE("copyArray()") {
|
||||
REQUIRE(std::string("[1,2,3]") == json);
|
||||
}
|
||||
|
||||
SECTION("1D -> JsonDocument") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
int source[] = {1, 2, 3};
|
||||
|
||||
bool ok = copyArray(source, doc);
|
||||
REQUIRE(ok);
|
||||
|
||||
serializeJson(doc, json, sizeof(json));
|
||||
REQUIRE(std::string("[1,2,3]") == json);
|
||||
}
|
||||
|
||||
SECTION("1D -> JsonArray, but not enough memory") {
|
||||
const size_t SIZE = JSON_ARRAY_SIZE(2);
|
||||
StaticJsonDocument<SIZE> doc;
|
||||
@ -46,6 +58,18 @@ TEST_CASE("copyArray()") {
|
||||
REQUIRE(std::string("[[1,2,3],[4,5,6]]") == json);
|
||||
}
|
||||
|
||||
SECTION("2D -> JsonDocument") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
|
||||
bool ok = copyArray(source, doc);
|
||||
REQUIRE(ok);
|
||||
|
||||
serializeJson(doc, json, sizeof(json));
|
||||
REQUIRE(std::string("[[1,2,3],[4,5,6]]") == json);
|
||||
}
|
||||
|
||||
SECTION("2D -> JsonArray, but not enough memory") {
|
||||
const size_t SIZE =
|
||||
JSON_ARRAY_SIZE(2) + JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(2);
|
||||
@ -96,6 +120,22 @@ TEST_CASE("copyArray()") {
|
||||
REQUIRE(2 == destination[1]);
|
||||
}
|
||||
|
||||
SECTION("JsonDocument -> 1D") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[1,2,3]";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
|
||||
int destination[4] = {0};
|
||||
size_t result = copyArray(doc, destination);
|
||||
|
||||
REQUIRE(3 == result);
|
||||
REQUIRE(1 == destination[0]);
|
||||
REQUIRE(2 == destination[1]);
|
||||
REQUIRE(3 == destination[2]);
|
||||
REQUIRE(0 == destination[3]);
|
||||
}
|
||||
|
||||
SECTION("JsonArray -> 2D") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[[1,2],[3],[4]]";
|
||||
@ -114,4 +154,22 @@ TEST_CASE("copyArray()") {
|
||||
REQUIRE(4 == destination[2][0]);
|
||||
REQUIRE(0 == destination[2][1]);
|
||||
}
|
||||
|
||||
SECTION("JsonDocument -> 2D") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[[1,2],[3],[4]]";
|
||||
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
|
||||
int destination[3][2] = {{0}};
|
||||
copyArray(doc, destination);
|
||||
|
||||
REQUIRE(1 == destination[0][0]);
|
||||
REQUIRE(2 == destination[0][1]);
|
||||
REQUIRE(3 == destination[1][0]);
|
||||
REQUIRE(0 == destination[1][1]);
|
||||
REQUIRE(4 == destination[2][0]);
|
||||
REQUIRE(0 == destination[2][1]);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ add_executable(JsonDeserializerTests
|
||||
string.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(JsonDeserializerTests catch)
|
||||
set_target_properties(JsonDeserializerTests PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
add_test(JsonDeserializer JsonDeserializerTests)
|
||||
|
@ -126,3 +126,57 @@ TEST_CASE("deserializeJson(CustomReader)") {
|
||||
REQUIRE(doc[0] == 4);
|
||||
REQUIRE(doc[1] == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("deserializeJson(JsonDocument&, MemberProxy)") {
|
||||
DynamicJsonDocument doc1(4096);
|
||||
doc1["payload"] = "[4,2]";
|
||||
|
||||
DynamicJsonDocument doc2(4096);
|
||||
DeserializationError err = deserializeJson(doc2, doc1["payload"]);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc2.size() == 2);
|
||||
REQUIRE(doc2[0] == 4);
|
||||
REQUIRE(doc2[1] == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("deserializeJson(JsonDocument&, JsonVariant)") {
|
||||
DynamicJsonDocument doc1(4096);
|
||||
doc1["payload"] = "[4,2]";
|
||||
|
||||
DynamicJsonDocument doc2(4096);
|
||||
DeserializationError err =
|
||||
deserializeJson(doc2, doc1["payload"].as<JsonVariant>());
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc2.size() == 2);
|
||||
REQUIRE(doc2[0] == 4);
|
||||
REQUIRE(doc2[1] == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("deserializeJson(JsonDocument&, JsonVariantConst)") {
|
||||
DynamicJsonDocument doc1(4096);
|
||||
doc1["payload"] = "[4,2]";
|
||||
|
||||
DynamicJsonDocument doc2(4096);
|
||||
DeserializationError err =
|
||||
deserializeJson(doc2, doc1["payload"].as<JsonVariantConst>());
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc2.size() == 2);
|
||||
REQUIRE(doc2[0] == 4);
|
||||
REQUIRE(doc2[1] == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("deserializeJson(JsonDocument&, ElementProxy)") {
|
||||
DynamicJsonDocument doc1(4096);
|
||||
doc1[0] = "[4,2]";
|
||||
|
||||
DynamicJsonDocument doc2(4096);
|
||||
DeserializationError err = deserializeJson(doc2, doc1[0]);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc2.size() == 2);
|
||||
REQUIRE(doc2[0] == 4);
|
||||
REQUIRE(doc2[1] == 2);
|
||||
}
|
||||
|
@ -18,5 +18,4 @@ add_executable(JsonDocumentTests
|
||||
subscript.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(JsonDocumentTests catch)
|
||||
add_test(JsonDocument JsonDocumentTests)
|
||||
|
@ -19,5 +19,4 @@ add_executable(JsonObjectTests
|
||||
subscript.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(JsonObjectTests catch)
|
||||
add_test(JsonObject JsonObjectTests)
|
||||
|
@ -14,5 +14,4 @@ add_executable(JsonSerializerTests
|
||||
std_string.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(JsonSerializerTests catch)
|
||||
add_test(JsonSerializer JsonSerializerTests)
|
||||
|
@ -24,5 +24,4 @@ add_executable(JsonVariantTests
|
||||
undefined.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(JsonVariantTests catch)
|
||||
add_test(JsonVariant JsonVariantTests)
|
||||
|
@ -10,6 +10,8 @@ namespace my {
|
||||
using ARDUINOJSON_NAMESPACE::isinf;
|
||||
} // namespace my
|
||||
|
||||
enum MY_ENUM { ONE = 1, TWO = 2 };
|
||||
|
||||
TEST_CASE("JsonVariant::as()") {
|
||||
static const char* null = 0;
|
||||
|
||||
@ -212,4 +214,10 @@ TEST_CASE("JsonVariant::as()") {
|
||||
REQUIRE(cvar.as<char*>() == std::string("hello"));
|
||||
// REQUIRE(cvar.as<std::string>() == std::string("hello"));
|
||||
}
|
||||
|
||||
SECTION("as<enum>()") {
|
||||
variant.set(1);
|
||||
|
||||
REQUIRE(variant.as<MY_ENUM>() == ONE);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
enum MYENUM2 { ONE = 1, TWO = 2 };
|
||||
|
||||
template <typename TVariant>
|
||||
void checkIsArray(TVariant var) {
|
||||
REQUIRE(var.template is<JsonArray>());
|
||||
@ -80,6 +82,7 @@ void checkIsInteger(TVariant var) {
|
||||
REQUIRE(var.template is<int>());
|
||||
REQUIRE(var.template is<float>());
|
||||
REQUIRE(var.template is<double>());
|
||||
REQUIRE(var.template is<MYENUM2>());
|
||||
|
||||
REQUIRE_FALSE(var.template is<bool>());
|
||||
REQUIRE_FALSE(var.template is<const char *>());
|
||||
@ -107,6 +110,7 @@ void checkIsString(TVariant var) {
|
||||
REQUIRE_FALSE(var.template is<double>());
|
||||
REQUIRE_FALSE(var.template is<float>());
|
||||
REQUIRE_FALSE(var.template is<long>());
|
||||
REQUIRE_FALSE(var.template is<MYENUM2>());
|
||||
REQUIRE_FALSE(var.template is<JsonArray>());
|
||||
REQUIRE_FALSE(var.template is<JsonObject>());
|
||||
}
|
||||
|
@ -13,5 +13,4 @@ add_executable(MemberProxyTests
|
||||
subscript.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MemberProxyTests catch)
|
||||
add_test(MemberProxy MemberProxyTests)
|
||||
|
@ -10,5 +10,4 @@ add_executable(MemoryPoolTests
|
||||
StringBuilder.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MemoryPoolTests catch)
|
||||
add_test(MemoryPool MemoryPoolTests)
|
||||
|
@ -15,40 +15,6 @@ add_executable(MiscTests
|
||||
version.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MiscTests catch)
|
||||
set_target_properties(MiscTests PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
add_test(Misc MiscTests)
|
||||
|
||||
macro(build_should_fail target)
|
||||
set_target_properties(${target}
|
||||
PROPERTIES
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
EXCLUDE_FROM_DEFAULT_BUILD TRUE
|
||||
)
|
||||
add_test(
|
||||
NAME
|
||||
${target}
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
|
||||
WORKING_DIRECTORY
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
set_tests_properties(${target}
|
||||
|
||||
|
||||
|
||||
PROPERTIES
|
||||
WILL_FAIL TRUE)
|
||||
endmacro()
|
||||
|
||||
|
||||
add_executable(Issue978
|
||||
Issue978.cpp
|
||||
)
|
||||
build_should_fail(Issue978)
|
||||
|
||||
add_executable(Issue1189
|
||||
Issue1189.cpp
|
||||
)
|
||||
build_should_fail(Issue1189)
|
||||
|
@ -9,20 +9,21 @@ add_executable(MixedConfigurationTests
|
||||
cpp11.cpp
|
||||
decode_unicode_0.cpp
|
||||
decode_unicode_1.cpp
|
||||
enable_alignment_0.cpp
|
||||
enable_alignment_1.cpp
|
||||
enable_comments_0.cpp
|
||||
enable_comments_1.cpp
|
||||
enable_infinity_0.cpp
|
||||
enable_infinity_1.cpp
|
||||
enable_nan_0.cpp
|
||||
enable_nan_1.cpp
|
||||
enable_progmem_1.cpp
|
||||
use_double_0.cpp
|
||||
use_double_1.cpp
|
||||
use_long_long_0.cpp
|
||||
use_long_long_1.cpp
|
||||
enable_progmem_1.cpp
|
||||
enable_comments_1.cpp
|
||||
enable_comments_0.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MixedConfigurationTests catch)
|
||||
set_target_properties(MixedConfigurationTests PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
add_test(MixedConfiguration MixedConfigurationTests)
|
||||
|
41
extras/tests/MixedConfiguration/enable_alignment_0.cpp
Normal file
41
extras/tests/MixedConfiguration/enable_alignment_0.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#define ARDUINOJSON_NAMESPACE ArduinoJson_NoAlignment
|
||||
#define ARDUINOJSON_ENABLE_ALIGNMENT 0
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 0") {
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
const size_t N = sizeof(void*);
|
||||
|
||||
SECTION("isAligned()") {
|
||||
CHECK(isAligned(0) == true);
|
||||
CHECK(isAligned(1) == true);
|
||||
CHECK(isAligned(N) == true);
|
||||
CHECK(isAligned(N + 1) == true);
|
||||
CHECK(isAligned(2 * N) == true);
|
||||
CHECK(isAligned(2 * N + 1) == true);
|
||||
}
|
||||
|
||||
SECTION("addPadding()") {
|
||||
CHECK(addPadding(0) == 0);
|
||||
CHECK(addPadding(1) == 1);
|
||||
CHECK(addPadding(N) == N);
|
||||
CHECK(addPadding(N + 1) == N + 1);
|
||||
}
|
||||
|
||||
SECTION("AddPadding<>") {
|
||||
const size_t a = AddPadding<0>::value;
|
||||
CHECK(a == 0);
|
||||
|
||||
const size_t b = AddPadding<1>::value;
|
||||
CHECK(b == 1);
|
||||
|
||||
const size_t c = AddPadding<N>::value;
|
||||
CHECK(c == N);
|
||||
|
||||
const size_t d = AddPadding<N + 1>::value;
|
||||
CHECK(d == N + 1);
|
||||
}
|
||||
}
|
40
extras/tests/MixedConfiguration/enable_alignment_1.cpp
Normal file
40
extras/tests/MixedConfiguration/enable_alignment_1.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#define ARDUINOJSON_ENABLE_ALIGNMENT 1
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 1") {
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
const size_t N = sizeof(void*);
|
||||
|
||||
SECTION("isAligned()") {
|
||||
CHECK(isAligned(0) == true);
|
||||
CHECK(isAligned(1) == false);
|
||||
CHECK(isAligned(N) == true);
|
||||
CHECK(isAligned(N + 1) == false);
|
||||
CHECK(isAligned(2 * N) == true);
|
||||
CHECK(isAligned(2 * N + 1) == false);
|
||||
}
|
||||
|
||||
SECTION("addPadding()") {
|
||||
CHECK(addPadding(0) == 0);
|
||||
CHECK(addPadding(1) == N);
|
||||
CHECK(addPadding(N) == N);
|
||||
CHECK(addPadding(N + 1) == 2 * N);
|
||||
}
|
||||
|
||||
SECTION("AddPadding<>") {
|
||||
const size_t a = AddPadding<0>::value;
|
||||
CHECK(a == 0);
|
||||
|
||||
const size_t b = AddPadding<1>::value;
|
||||
CHECK(b == N);
|
||||
|
||||
const size_t c = AddPadding<N>::value;
|
||||
CHECK(c == N);
|
||||
|
||||
const size_t d = AddPadding<N + 1>::value;
|
||||
CHECK(d == 2 * N);
|
||||
}
|
||||
}
|
@ -3,28 +3,14 @@
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
template <size_t size_of_long>
|
||||
std::string get_expected_json();
|
||||
|
||||
template <>
|
||||
std::string get_expected_json<4>() {
|
||||
return "{\"A\":2899336981,\"B\":2129924785}";
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string get_expected_json<8>() {
|
||||
return "{\"A\":123456789123456789,\"B\":987654321987654321}";
|
||||
}
|
||||
|
||||
TEST_CASE("ARDUINOJSON_USE_LONG_LONG == 0") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
|
||||
root["A"] = 123456789123456789;
|
||||
root["B"] = 987654321987654321;
|
||||
doc["A"] = 42;
|
||||
doc["B"] = 84;
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
|
||||
REQUIRE(json == get_expected_json<sizeof(long)>());
|
||||
REQUIRE(json == "{\"A\":42,\"B\":84}");
|
||||
}
|
||||
|
@ -14,5 +14,4 @@ add_executable(MsgPackDeserializerTests
|
||||
notSupported.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MsgPackDeserializerTests catch)
|
||||
add_test(MsgPackDeserializer MsgPackDeserializerTests)
|
||||
|
@ -11,5 +11,4 @@ add_executable(MsgPackSerializerTests
|
||||
serializeVariant.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MsgPackSerializerTests catch)
|
||||
add_test(MsgPackSerializer MsgPackSerializerTests)
|
||||
|
@ -8,6 +8,5 @@ add_executable(NumbersTests
|
||||
parseNumber.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(NumbersTests catch)
|
||||
|
||||
add_test(Numbers NumbersTests)
|
||||
|
@ -7,7 +7,6 @@ add_executable(TextFormatterTests
|
||||
writeString.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(TextFormatterTests catch)
|
||||
set_target_properties(TextFormatterTests PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
add_test(TextFormatter TextFormatterTests)
|
||||
|
10
library.json
10
library.json
@ -1,22 +1,20 @@
|
||||
{
|
||||
"name": "ArduinoJson",
|
||||
"keywords": "json, rest, http, web",
|
||||
"description": "An elegant and efficient JSON library for embedded systems",
|
||||
"description": "A simple and efficient JSON library for embedded C++. 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.",
|
||||
"homepage": "https://arduinojson.org/?utm_source=meta&utm_medium=library.json",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "6.15.0",
|
||||
"version": "6.15.2",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "https://blog.benoitblanchon.fr"
|
||||
},
|
||||
"exclude": [
|
||||
"fuzzing",
|
||||
"scripts",
|
||||
"test",
|
||||
"third-party"
|
||||
".github",
|
||||
"extras"
|
||||
],
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=ArduinoJson
|
||||
version=6.15.0
|
||||
version=6.15.2
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=An efficient and elegant JSON library for Arduino.
|
||||
paragraph=ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation.
|
||||
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=*
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "ArduinoJson/Configuration.hpp"
|
||||
|
||||
#if ARDUINOJSON_DEBUG
|
||||
#if !ARDUINOJSON_DEBUG
|
||||
#ifdef __clang__
|
||||
#pragma clang system_header
|
||||
#elif defined __GNUC__
|
||||
|
@ -72,6 +72,11 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
||||
return getUpstreamElement().template as<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE operator T() const {
|
||||
return getUpstreamElement();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE bool is() const {
|
||||
return getUpstreamElement().template is<T>();
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Array/ArrayRef.hpp>
|
||||
#include <ArduinoJson/Document/JsonDocument.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
@ -14,6 +15,12 @@ inline bool copyArray(T (&src)[N], ArrayRef dst) {
|
||||
return copyArray(src, N, dst);
|
||||
}
|
||||
|
||||
// Copy a 1D array to a JsonDocument
|
||||
template <typename T, size_t N>
|
||||
inline bool copyArray(T (&src)[N], JsonDocument& dst) {
|
||||
return copyArray(src, dst.to<ArrayRef>());
|
||||
}
|
||||
|
||||
// Copy a 1D array to a JsonArray
|
||||
template <typename T>
|
||||
inline bool copyArray(T* src, size_t len, ArrayRef dst) {
|
||||
@ -24,6 +31,12 @@ inline bool copyArray(T* src, size_t len, ArrayRef dst) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Copy a 1D array to a JsonDocument
|
||||
template <typename T>
|
||||
inline bool copyArray(T* src, size_t len, JsonDocument& dst) {
|
||||
return copyArray(src, len, dst.to<ArrayRef>());
|
||||
}
|
||||
|
||||
// Copy a 2D array to a JsonArray
|
||||
template <typename T, size_t N1, size_t N2>
|
||||
inline bool copyArray(T (&src)[N1][N2], ArrayRef dst) {
|
||||
@ -37,12 +50,24 @@ inline bool copyArray(T (&src)[N1][N2], ArrayRef dst) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Copy a 2D array to a JsonDocument
|
||||
template <typename T, size_t N1, size_t N2>
|
||||
inline bool copyArray(T (&src)[N1][N2], JsonDocument& dst) {
|
||||
return copyArray(src, dst.to<ArrayRef>());
|
||||
}
|
||||
|
||||
// Copy a JsonArray to a 1D array
|
||||
template <typename T, size_t N>
|
||||
inline size_t copyArray(ArrayConstRef src, T (&dst)[N]) {
|
||||
return copyArray(src, dst, N);
|
||||
}
|
||||
|
||||
// Copy a JsonDocument to a 1D array
|
||||
template <typename T, size_t N>
|
||||
inline size_t copyArray(const JsonDocument& src, T (&dst)[N]) {
|
||||
return copyArray(src.as<ArrayConstRef>(), dst, N);
|
||||
}
|
||||
|
||||
// Copy a JsonArray to a 1D array
|
||||
template <typename T>
|
||||
inline size_t copyArray(ArrayConstRef src, T* dst, size_t len) {
|
||||
@ -63,4 +88,10 @@ inline void copyArray(ArrayConstRef src, T (&dst)[N1][N2]) {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy a JsonDocument to a 2D array
|
||||
template <typename T, size_t N1, size_t N2>
|
||||
inline void copyArray(const JsonDocument& src, T (&dst)[N1][N2]) {
|
||||
copyArray(src.as<ArrayConstRef>(), dst);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -4,12 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define ARDUINOJSON_HAS_INT64 1
|
||||
#else
|
||||
#define ARDUINOJSON_HAS_INT64 0
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#define ARDUINOJSON_HAS_LONG_LONG 1
|
||||
#define ARDUINOJSON_HAS_NULLPTR 1
|
||||
@ -20,6 +14,12 @@
|
||||
#define ARDUINOJSON_HAS_RVALUE_REFERENCES 0
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG
|
||||
#define ARDUINOJSON_HAS_INT64 1
|
||||
#else
|
||||
#define ARDUINOJSON_HAS_INT64 0
|
||||
#endif
|
||||
|
||||
// Small or big machine?
|
||||
#ifndef ARDUINOJSON_EMBEDDED_MODE
|
||||
#if defined(ARDUINO) /* Arduino*/ \
|
||||
@ -203,6 +203,14 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ARDUINOJSON_ENABLE_ALIGNMENT
|
||||
#if defined(__AVR)
|
||||
#define ARDUINOJSON_ENABLE_ALIGNMENT 0
|
||||
#else
|
||||
#define ARDUINOJSON_ENABLE_ALIGNMENT 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ARDUINOJSON_TAB
|
||||
#define ARDUINOJSON_TAB " "
|
||||
#endif
|
||||
|
@ -37,6 +37,7 @@ struct BoundedReader {
|
||||
|
||||
#include <ArduinoJson/Deserialization/Readers/IteratorReader.hpp>
|
||||
#include <ArduinoJson/Deserialization/Readers/RamReader.hpp>
|
||||
#include <ArduinoJson/Deserialization/Readers/VariantReader.hpp>
|
||||
|
||||
#if ARDUINOJSON_ENABLE_ARDUINO_STREAM
|
||||
#include <ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp>
|
||||
|
34
src/ArduinoJson/Deserialization/Readers/VariantReader.hpp
Normal file
34
src/ArduinoJson/Deserialization/Readers/VariantReader.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Object/MemberProxy.hpp>
|
||||
#include <ArduinoJson/Variant/VariantRef.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TArray>
|
||||
struct Reader<ElementProxy<TArray>, void> : Reader<char*, void> {
|
||||
explicit Reader(const ElementProxy<TArray>& x)
|
||||
: Reader<char*, void>(x.template as<const char*>()) {}
|
||||
};
|
||||
|
||||
template <typename TObject, typename TStringRef>
|
||||
struct Reader<MemberProxy<TObject, TStringRef>, void> : Reader<char*, void> {
|
||||
explicit Reader(const MemberProxy<TObject, TStringRef>& x)
|
||||
: Reader<char*, void>(x.template as<const char*>()) {}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Reader<VariantRef, void> : Reader<char*, void> {
|
||||
explicit Reader(VariantRef x) : Reader<char*, void>(x.as<const char*>()) {}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Reader<VariantConstRef, void> : Reader<char*, void> {
|
||||
explicit Reader(VariantConstRef x)
|
||||
: Reader<char*, void>(x.as<const char*>()) {}
|
||||
};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -22,6 +22,15 @@ class JsonDeserializer {
|
||||
typedef typename remove_reference<TStringStorage>::type::StringBuilder
|
||||
StringBuilder;
|
||||
|
||||
struct StringOrError {
|
||||
DeserializationError err;
|
||||
const char *value;
|
||||
|
||||
StringOrError(DeserializationError e) : err(e) {}
|
||||
StringOrError(DeserializationError::Code c) : err(c) {}
|
||||
StringOrError(const char *s) : err(DeserializationError::Ok), value(s) {}
|
||||
};
|
||||
|
||||
public:
|
||||
JsonDeserializer(MemoryPool &pool, TReader reader,
|
||||
TStringStorage stringStorage)
|
||||
@ -216,8 +225,8 @@ class JsonDeserializer {
|
||||
// Read each key value pair
|
||||
for (;;) {
|
||||
// Parse key
|
||||
const char *key;
|
||||
err = parseKey(key);
|
||||
StringOrError key = parseKey();
|
||||
err = key.err; // <- this trick saves 62 bytes on AVR
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@ -228,17 +237,17 @@ class JsonDeserializer {
|
||||
if (!eat(':'))
|
||||
return DeserializationError::InvalidInput;
|
||||
|
||||
TFilter memberFilter = filter[key];
|
||||
TFilter memberFilter = filter[key.value];
|
||||
|
||||
if (memberFilter.allow()) {
|
||||
VariantData *variant = object.getMember(adaptString(key));
|
||||
VariantData *variant = object.getMember(adaptString(key.value));
|
||||
if (!variant) {
|
||||
// Allocate slot in object
|
||||
VariantSlot *slot = object.addSlot(_pool);
|
||||
if (!slot)
|
||||
return DeserializationError::NoMemory;
|
||||
|
||||
slot->setOwnedKey(make_not_null(key));
|
||||
slot->setOwnedKey(make_not_null(key.value));
|
||||
|
||||
variant = slot->data();
|
||||
}
|
||||
@ -248,7 +257,7 @@ class JsonDeserializer {
|
||||
if (err)
|
||||
return err;
|
||||
} else {
|
||||
_stringStorage.reclaim(key);
|
||||
_stringStorage.reclaim(key.value);
|
||||
err = skipVariant(nestingLimit.decrement());
|
||||
if (err)
|
||||
return err;
|
||||
@ -323,24 +332,23 @@ class JsonDeserializer {
|
||||
}
|
||||
}
|
||||
|
||||
DeserializationError parseKey(const char *&key) {
|
||||
StringOrError parseKey() {
|
||||
if (isQuote(current())) {
|
||||
return parseQuotedString(key);
|
||||
return parseQuotedString();
|
||||
} else {
|
||||
return parseNonQuotedString(key);
|
||||
return parseNonQuotedString();
|
||||
}
|
||||
}
|
||||
|
||||
DeserializationError parseStringValue(VariantData &variant) {
|
||||
const char *value;
|
||||
DeserializationError err = parseQuotedString(value);
|
||||
if (err)
|
||||
return err;
|
||||
variant.setOwnedString(make_not_null(value));
|
||||
StringOrError result = parseQuotedString();
|
||||
if (result.err)
|
||||
return result.err;
|
||||
variant.setOwnedString(make_not_null(result.value));
|
||||
return DeserializationError::Ok;
|
||||
}
|
||||
|
||||
DeserializationError parseQuotedString(const char *&result) {
|
||||
StringOrError parseQuotedString() {
|
||||
StringBuilder builder = _stringStorage.startString();
|
||||
#if ARDUINOJSON_DECODE_UNICODE
|
||||
Utf16::Codepoint codepoint;
|
||||
@ -385,13 +393,13 @@ class JsonDeserializer {
|
||||
builder.append(c);
|
||||
}
|
||||
|
||||
result = builder.complete();
|
||||
const char *result = builder.complete();
|
||||
if (!result)
|
||||
return DeserializationError::NoMemory;
|
||||
return DeserializationError::Ok;
|
||||
return result;
|
||||
}
|
||||
|
||||
DeserializationError parseNonQuotedString(const char *&result) {
|
||||
StringOrError parseNonQuotedString() {
|
||||
StringBuilder builder = _stringStorage.startString();
|
||||
|
||||
char c = current();
|
||||
@ -407,10 +415,10 @@ class JsonDeserializer {
|
||||
return DeserializationError::InvalidInput;
|
||||
}
|
||||
|
||||
result = builder.complete();
|
||||
const char *result = builder.complete();
|
||||
if (!result)
|
||||
return DeserializationError::NoMemory;
|
||||
return DeserializationError::Ok;
|
||||
return result;
|
||||
}
|
||||
|
||||
DeserializationError skipString() {
|
||||
|
@ -8,6 +8,16 @@
|
||||
|
||||
#include <stdint.h> // uint16_t, uint32_t
|
||||
|
||||
// The high surrogate may be uninitialized if the pair is invalid,
|
||||
// we choose to ignore the problem to reduce the size of the code
|
||||
// Garbage in => Garbage out
|
||||
#if defined(__GNUC__)
|
||||
#if __GNUC__ >= 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
namespace Utf16 {
|
||||
@ -47,3 +57,9 @@ class Codepoint {
|
||||
};
|
||||
} // namespace Utf16
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if __GNUC__ >= 8
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif
|
||||
|
@ -10,9 +10,11 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
inline bool isAligned(void *ptr) {
|
||||
#if ARDUINOJSON_ENABLE_ALIGNMENT
|
||||
|
||||
inline bool isAligned(size_t value) {
|
||||
const size_t mask = sizeof(void *) - 1;
|
||||
size_t addr = reinterpret_cast<size_t>(ptr);
|
||||
size_t addr = value;
|
||||
return (addr & mask) == 0;
|
||||
}
|
||||
|
||||
@ -21,16 +23,38 @@ inline size_t addPadding(size_t bytes) {
|
||||
return (bytes + mask) & ~mask;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T *addPadding(T *p) {
|
||||
size_t address = addPadding(reinterpret_cast<size_t>(p));
|
||||
return reinterpret_cast<T *>(address);
|
||||
}
|
||||
|
||||
template <size_t bytes>
|
||||
struct AddPadding {
|
||||
static const size_t mask = sizeof(void *) - 1;
|
||||
static const size_t value = (bytes + mask) & ~mask;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
inline bool isAligned(size_t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline size_t addPadding(size_t bytes) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
template <size_t bytes>
|
||||
struct AddPadding {
|
||||
static const size_t value = bytes;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
inline bool isAligned(T *ptr) {
|
||||
return isAligned(reinterpret_cast<size_t>(ptr));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T *addPadding(T *p) {
|
||||
size_t address = addPadding(reinterpret_cast<size_t>(p));
|
||||
return reinterpret_cast<T *>(address);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -233,7 +233,7 @@ class MsgPackDeserializer {
|
||||
}
|
||||
|
||||
DeserializationError readString(VariantData &variant, size_t n) {
|
||||
const char *s;
|
||||
const char *s = 0; // <- mute "maybe-uninitialized" (+4 bytes on AVR)
|
||||
DeserializationError err = readString(s, n);
|
||||
if (!err)
|
||||
variant.setOwnedString(make_not_null(s));
|
||||
@ -300,7 +300,7 @@ class MsgPackDeserializer {
|
||||
if (!slot)
|
||||
return DeserializationError::NoMemory;
|
||||
|
||||
const char *key;
|
||||
const char *key = 0; // <- mute "maybe-uninitialized" (+4 bytes on AVR)
|
||||
DeserializationError err = parseKey(key);
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -125,7 +125,13 @@ class MsgPackSerializer {
|
||||
} else if (value <= 0xFFFF) {
|
||||
writeByte(0xCD);
|
||||
writeInteger(uint16_t(value));
|
||||
} else if (value <= 0xFFFFFFFF) {
|
||||
}
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
else if (value <= 0xFFFFFFFF)
|
||||
#else
|
||||
else
|
||||
#endif
|
||||
{
|
||||
writeByte(0xCE);
|
||||
writeInteger(uint32_t(value));
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <ArduinoJson/Configuration.hpp>
|
||||
#include <ArduinoJson/version.hpp>
|
||||
|
||||
#ifndef ARDUINOJSON_NAMESPACE
|
||||
|
||||
#define ARDUINOJSON_DO_CONCAT(A, B) A##B
|
||||
#define ARDUINOJSON_CONCAT2(A, B) ARDUINOJSON_DO_CONCAT(A, B)
|
||||
#define ARDUINOJSON_CONCAT4(A, B, C, D) \
|
||||
@ -25,3 +27,5 @@
|
||||
ARDUINOJSON_USE_DOUBLE, ARDUINOJSON_DECODE_UNICODE, \
|
||||
ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \
|
||||
ARDUINOJSON_ENABLE_PROGMEM, ARDUINOJSON_ENABLE_COMMENTS)
|
||||
|
||||
#endif
|
||||
|
@ -18,4 +18,15 @@ typedef uint64_t UInt;
|
||||
typedef long Integer;
|
||||
typedef unsigned long UInt;
|
||||
#endif
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
#if ARDUINOJSON_HAS_LONG_LONG && !ARDUINOJSON_USE_LONG_LONG
|
||||
#define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) \
|
||||
static_assert(sizeof(T) <= sizeof(ARDUINOJSON_NAMESPACE::Integer), \
|
||||
"To use 64-bit integers with ArduinoJson, you must set " \
|
||||
"ARDUINOJSON_USE_LONG_LONG to 1. See " \
|
||||
"https://arduinojson.org/v6/api/config/use_long_long/");
|
||||
#else
|
||||
#define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T)
|
||||
#endif
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <ArduinoJson/Configuration.hpp>
|
||||
#include <ArduinoJson/Operators/VariantOperators.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Variant/VariantRef.hpp>
|
||||
#include <ArduinoJson/Variant/VariantTo.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
@ -73,6 +75,11 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return getUpstreamMember().template as<TValue>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE operator T() const {
|
||||
return getUpstreamMember();
|
||||
}
|
||||
|
||||
template <typename TValue>
|
||||
FORCE_INLINE bool is() const {
|
||||
return getUpstreamMember().template is<TValue>();
|
||||
|
@ -1,24 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/attributes.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TImpl>
|
||||
class VariantCasts {
|
||||
public:
|
||||
template <typename T>
|
||||
FORCE_INLINE operator T() const {
|
||||
return impl()->template as<T>();
|
||||
}
|
||||
|
||||
private:
|
||||
const TImpl *impl() const {
|
||||
return static_cast<const TImpl *>(this);
|
||||
}
|
||||
};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -4,10 +4,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Variant/VariantRef.hpp>
|
||||
#include <ArduinoJson/Configuration.hpp>
|
||||
#include <ArduinoJson/Misc/Visitable.hpp>
|
||||
#include <ArduinoJson/Numbers/Float.hpp>
|
||||
#include <ArduinoJson/Numbers/Integer.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class CollectionData;
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct Comparer;
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Operators/VariantCasts.hpp>
|
||||
#include <ArduinoJson/Operators/VariantComparisons.hpp>
|
||||
#include <ArduinoJson/Operators/VariantOr.hpp>
|
||||
#include <ArduinoJson/Operators/VariantShortcuts.hpp>
|
||||
@ -12,8 +11,7 @@
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TImpl>
|
||||
class VariantOperators : public VariantCasts<TImpl>,
|
||||
public VariantComparisons<TImpl>,
|
||||
class VariantOperators : public VariantComparisons<TImpl>,
|
||||
public VariantOr<TImpl>,
|
||||
public VariantShortcuts<TImpl> {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -24,7 +24,6 @@ inline bool slotSetKey(VariantSlot* var, TAdaptedString key, MemoryPool* pool,
|
||||
} else {
|
||||
return slotSetKey(var, key, pool, storage_policy::store_by_copy());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename TAdaptedString>
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/IsWriteableString.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
@ -53,44 +54,59 @@ struct VariantConstAs<ArrayRef> {
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_integral<T>::value, T>::type variantAs(
|
||||
const VariantData* _data) {
|
||||
return _data != 0 ? _data->asIntegral<T>() : T(0);
|
||||
const VariantData* data) {
|
||||
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T);
|
||||
return data != 0 ? data->asIntegral<T>() : T(0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_enum<T>::value, T>::type variantAs(
|
||||
const VariantData* data) {
|
||||
return data != 0 ? static_cast<T>(data->asIntegral<int>()) : T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<T, bool>::value, T>::type variantAs(
|
||||
const VariantData* _data) {
|
||||
return _data != 0 ? _data->asBoolean() : false;
|
||||
const VariantData* data) {
|
||||
return data != 0 ? data->asBoolean() : false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_floating_point<T>::value, T>::type variantAs(
|
||||
const VariantData* _data) {
|
||||
return _data != 0 ? _data->asFloat<T>() : T(0);
|
||||
const VariantData* data) {
|
||||
return data != 0 ? data->asFloat<T>() : T(0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<T, const char*>::value ||
|
||||
is_same<T, char*>::value,
|
||||
const char*>::type
|
||||
variantAs(const VariantData* _data) {
|
||||
return _data != 0 ? _data->asString() : 0;
|
||||
variantAs(const VariantData* data) {
|
||||
return data != 0 ? data->asString() : 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T variantAs(VariantData* data, MemoryPool*) {
|
||||
// By default use the read-only conversion.
|
||||
// There are specializations for
|
||||
// - ArrayRef
|
||||
return variantAs<T>(data);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<ArrayConstRef, T>::value, T>::type variantAs(
|
||||
const VariantData* _data);
|
||||
const VariantData* data);
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<ObjectConstRef, T>::value, T>::type variantAs(
|
||||
const VariantData* _data);
|
||||
const VariantData* data);
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<VariantConstRef, T>::value, T>::type
|
||||
variantAs(const VariantData* _data);
|
||||
variantAs(const VariantData* data);
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<IsWriteableString<T>::value, T>::type variantAs(
|
||||
const VariantData* _data);
|
||||
const VariantData* data);
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -39,4 +39,19 @@ inline typename enable_if<IsWriteableString<T>::value, T>::type variantAs(
|
||||
return s;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline ArrayRef variantAs<ArrayRef>(VariantData* data, MemoryPool* pool) {
|
||||
return ArrayRef(pool, data != 0 ? data->asArray() : 0);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline ObjectRef variantAs<ObjectRef>(VariantData* data, MemoryPool* pool) {
|
||||
return ObjectRef(pool, data != 0 ? data->asObject() : 0);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline VariantRef variantAs<VariantRef>(VariantData* data, MemoryPool* pool) {
|
||||
return VariantRef(pool, data);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -10,6 +10,16 @@
|
||||
#include <ArduinoJson/Strings/RamStringAdapter.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
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class VariantData {
|
||||
@ -248,6 +258,11 @@ class VariantData {
|
||||
}
|
||||
}
|
||||
|
||||
void setUnsignedInteger(UInt value) {
|
||||
setType(VALUE_IS_POSITIVE_INTEGER);
|
||||
_content.asInteger = static_cast<UInt>(value);
|
||||
}
|
||||
|
||||
void setPositiveInteger(UInt value) {
|
||||
setType(VALUE_IS_POSITIVE_INTEGER);
|
||||
_content.asInteger = value;
|
||||
@ -291,11 +306,6 @@ class VariantData {
|
||||
return setOwnedString(value.save(pool));
|
||||
}
|
||||
|
||||
void setUnsignedInteger(UInt value) {
|
||||
setType(VALUE_IS_POSITIVE_INTEGER);
|
||||
_content.asInteger = static_cast<UInt>(value);
|
||||
}
|
||||
|
||||
CollectionData &toArray() {
|
||||
setType(VALUE_IS_ARRAY);
|
||||
_content.asCollection.clear();
|
||||
@ -383,3 +393,9 @@ class VariantData {
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if __GNUC__ >= 8
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/attributes.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
@ -104,14 +105,6 @@ inline bool variantSetOwnedRaw(VariantData *var, SerializedValue<T> value,
|
||||
return var != 0 && var->setOwnedRaw(value, pool);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool variantSetSignedInteger(VariantData *var, T value) {
|
||||
if (!var)
|
||||
return false;
|
||||
var->setSignedInteger(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool variantSetLinkedString(VariantData *var, const char *value) {
|
||||
if (!var)
|
||||
return false;
|
||||
@ -137,10 +130,12 @@ inline bool variantSetOwnedString(VariantData *var, T value, MemoryPool *pool) {
|
||||
return var != 0 && var->setOwnedString(value, pool);
|
||||
}
|
||||
|
||||
inline bool variantSetUnsignedInteger(VariantData *var, UInt value) {
|
||||
template <typename T>
|
||||
inline bool variantSetInteger(VariantData *var, T value) {
|
||||
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T);
|
||||
if (!var)
|
||||
return false;
|
||||
var->setUnsignedInteger(value);
|
||||
var->setInteger(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -83,18 +83,6 @@ typename enable_if<IsVisitable<TVariant>::value, bool>::type VariantRef::set(
|
||||
return variantCopyFrom(_data, v._data, _pool);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<T, ArrayRef>::value, T>::type VariantRef::as()
|
||||
const {
|
||||
return ArrayRef(_pool, _data != 0 ? _data->asArray() : 0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<T, ObjectRef>::value, T>::type
|
||||
VariantRef::as() const {
|
||||
return ObjectRef(_pool, variantAsObject(_data));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename enable_if<is_same<T, ArrayRef>::value, ArrayRef>::type
|
||||
VariantRef::to() const {
|
||||
|
@ -101,6 +101,11 @@ class VariantRefBase {
|
||||
return variantIsNull(_data);
|
||||
}
|
||||
#endif
|
||||
// bool is<enum>() const;
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_enum<T>::value, bool>::type is() const {
|
||||
return variantIsInteger<int>(_data);
|
||||
}
|
||||
|
||||
FORCE_INLINE bool isNull() const {
|
||||
return variantIsNull(_data);
|
||||
@ -173,22 +178,13 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
// set(signed int)
|
||||
// set(signed long)
|
||||
// set(signed char)
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(
|
||||
T value,
|
||||
typename enable_if<is_integral<T>::value && is_signed<T>::value>::type * =
|
||||
0) const {
|
||||
return variantSetSignedInteger(_data, value);
|
||||
}
|
||||
|
||||
// set(unsigned short)
|
||||
// set(unsigned int)
|
||||
// set(unsigned long)
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(
|
||||
T value, typename enable_if<is_integral<T>::value &&
|
||||
is_unsigned<T>::value>::type * = 0) const {
|
||||
return variantSetUnsignedInteger(_data, static_cast<UInt>(value));
|
||||
T value, typename enable_if<is_integral<T>::value>::type * = 0) const {
|
||||
return variantSetInteger<T>(_data, value);
|
||||
}
|
||||
|
||||
// set(SerializedValue<const char *>)
|
||||
@ -243,39 +239,17 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(
|
||||
T value, typename enable_if<is_enum<T>::value>::type * = 0) const {
|
||||
return variantSetSignedInteger(_data, static_cast<Integer>(value));
|
||||
return variantSetInteger(_data, static_cast<Integer>(value));
|
||||
}
|
||||
|
||||
// Get the variant as the specified type.
|
||||
//
|
||||
// std::string as<std::string>() const;
|
||||
// String as<String>() const;
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<!is_same<T, ArrayRef>::value &&
|
||||
!is_same<T, ObjectRef>::value &&
|
||||
!is_same<T, VariantRef>::value,
|
||||
typename VariantAs<T>::type>::type
|
||||
as() const {
|
||||
return variantAs<T>(_data);
|
||||
FORCE_INLINE typename VariantAs<T>::type as() const {
|
||||
return variantAs<typename VariantAs<T>::type>(_data, _pool);
|
||||
}
|
||||
//
|
||||
// ArrayRef as<ArrayRef>() const;
|
||||
// const ArrayRef as<const ArrayRef>() const;
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, ArrayRef>::value, T>::type as()
|
||||
const;
|
||||
//
|
||||
// ObjectRef as<ObjectRef>() const;
|
||||
// const ObjectRef as<const ObjectRef>() const;
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, ObjectRef>::value, T>::type as()
|
||||
const;
|
||||
//
|
||||
// VariantRef as<VariantRef> const;
|
||||
template <typename T>
|
||||
FORCE_INLINE typename enable_if<is_same<T, VariantRef>::value, T>::type as()
|
||||
const {
|
||||
return *this;
|
||||
FORCE_INLINE operator T() const {
|
||||
return variantAs<T>(_data, _pool);
|
||||
}
|
||||
|
||||
template <typename Visitor>
|
||||
@ -376,13 +350,16 @@ class VariantConstRef : public VariantRefBase<const VariantData>,
|
||||
variantAccept(_data, visitor);
|
||||
}
|
||||
|
||||
// Get the variant as the specified type.
|
||||
//
|
||||
template <typename T>
|
||||
FORCE_INLINE typename VariantConstAs<T>::type as() const {
|
||||
return variantAs<typename VariantConstAs<T>::type>(_data);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE operator T() const {
|
||||
return variantAs<T>(_data);
|
||||
}
|
||||
|
||||
FORCE_INLINE VariantConstRef getElement(size_t) const;
|
||||
|
||||
FORCE_INLINE VariantConstRef operator[](size_t index) const {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARDUINOJSON_VERSION "6.15.0"
|
||||
#define ARDUINOJSON_VERSION "6.15.2"
|
||||
#define ARDUINOJSON_VERSION_MAJOR 6
|
||||
#define ARDUINOJSON_VERSION_MINOR 15
|
||||
#define ARDUINOJSON_VERSION_REVISION 0
|
||||
#define ARDUINOJSON_VERSION_REVISION 2
|
||||
|
90
src/CMakeLists.txt
Normal file
90
src/CMakeLists.txt
Normal file
@ -0,0 +1,90 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# 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