Compare commits

...

35 Commits

Author SHA1 Message Date
40ee05c065 Set version to 6.21.5 2024-01-10 21:27:06 +01:00
632cb279f1 CI: publish package to PlatformIO registry
Ported from 44d2d47863
2024-01-10 21:24:35 +01:00
6e641ae0b0 Remove unused files in the PlatformIO package
Ported from 3571db6290
2024-01-10 21:23:38 +01:00
5d1d2721d1 Fix volatile bool serialized as 1 or 0
Fixes #2029
2024-01-10 13:30:26 +01:00
3e1be980d9 Fix function returns incomplete class type on IAR (issue #2001) 2023-12-07 14:43:53 +01:00
38441691cd Set version to 6.21.4 2023-12-07 10:10:23 +01:00
6ed87029e2 Fix no instance of overloaded function... on IAR (fixes #2001) 2023-12-06 17:36:39 +01:00
7517ecb91b Force inline ZeroTerminatedRamString::size()
Resolves #1990
2023-11-06 09:50:11 +01:00
49e2a8d421 Fix 'std::string_view' has not been declared (issue #1967) 2023-09-13 18:13:19 +02:00
259855a87b Fix 'std::string' has not been declared (issue #1967) 2023-09-13 18:13:18 +02:00
aebf042bae Test custom converter for char (#1963) 2023-08-24 09:43:23 +02:00
9794ba24b2 Remove duplicate comment block in wandbox's JsonGeneratorExample.cpp 2023-07-23 17:59:27 +02:00
4b00783345 Set version to 6.21.3 2023-07-23 17:49:42 +02:00
371fa4667e Scripts: call wandbox/publish.sh from get-release-page.sh 2023-07-23 17:47:32 +02:00
7eec01cdd6 Show a link to the doc when user passes an unsupported input type 2023-07-23 16:39:24 +02:00
6c5fde2a55 Fix ARDUINOJSON_BIN2ALPHA_0110() 2023-07-12 14:54:58 +02:00
433fb4b961 Include ARDUINOJSON_SLOT_OFFSET_SIZE in the namespace name 2023-07-12 14:54:19 +02:00
afbcc2106e Fix double call to size() in serializeMsgPack() 2023-07-12 11:54:20 +02:00
7b1c012f80 Fix double lookup in to<JsonVariant>()
Ported from 23b01a89b1
2023-07-05 21:10:47 +02:00
ecbc8e85d4 Wandbox: upgrade to GCC 5.5.0 2023-06-19 09:03:28 +02:00
4d00ed9efc Fix build on ESP32 (caused by espressif/arduino-esp32#7941)
Ported from 6b4dd3ff2f
2023-05-06 10:42:17 +02:00
cd5566cd40 Add a test for #1922 2023-05-06 10:32:33 +02:00
52d8a65cbc Fix compatibility with the Blynk libary (fixes #1914) 2023-04-18 15:13:41 +02:00
420221f078 Set version to 6.21.2 2023-04-12 14:35:25 +02:00
082ae69e86 Set default for ARDUINOJSON_ENABLE_PROGMEM to 1 on AVR 2023-04-12 11:42:02 +02:00
976a6d7594 CI: check build configuration on AVR 2023-04-12 11:22:50 +02:00
40daf56b5a Allow using PROGMEM outside of Arduino (fixes #1903) 2023-04-07 18:19:33 +02:00
31ce648e63 Change naming convention from _member to member_ (fixes #1905) 2023-04-07 09:02:23 +02:00
4ba9c1b0c0 Add Dev Container configs 2023-03-27 18:59:21 +02:00
19c5bb7f15 Pass -v to particle command line 2023-03-27 14:22:15 +02:00
cb850bc1b1 Set version to 6.21.1 2023-03-27 14:05:53 +02:00
481e4d2ffb Add timeouts for particle commands 2023-03-27 14:05:10 +02:00
9e9015f4b9 Fix compatibility with GCC 5.2 (fixes #1897) 2023-03-27 11:00:20 +02:00
74601b2585 CI: restore build on GCC 5 2023-03-27 08:48:44 +02:00
9bb3f4051d Double speed of DynamicJsonDocument::garbageCollect() 2023-03-20 12:32:52 +01:00
117 changed files with 1305 additions and 883 deletions

View File

@ -0,0 +1,18 @@
{
"name": "Clang 10",
"image": "conanio/clang10",
"runArgs": [
"--name=ArduinoJson-clang10"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "Clang 5",
"image": "conanio/clang50",
"runArgs": [
"--name=ArduinoJson-clang5"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "Clang 6",
"image": "conanio/clang60",
"runArgs": [
"--name=ArduinoJson-clang6"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "Clang 7",
"image": "conanio/clang7",
"runArgs": [
"--name=ArduinoJson-clang7"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "Clang 8",
"image": "conanio/clang8",
"runArgs": [
"--name=ArduinoJson-clang8"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "Clang 9",
"image": "conanio/clang9",
"runArgs": [
"--name=ArduinoJson-clang9"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "GCC 10",
"image": "conanio/gcc10",
"runArgs": [
"--name=ArduinoJson-gcc10"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "GCC 11",
"image": "conanio/gcc11",
"runArgs": [
"--name=ArduinoJson-gcc11"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "GCC 5",
"image": "conanio/gcc5",
"runArgs": [
"--name=ArduinoJson-gcc5"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "GCC 6",
"image": "conanio/gcc6",
"runArgs": [
"--name=ArduinoJson-gcc6"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "GCC 7",
"image": "conanio/gcc7",
"runArgs": [
"--name=ArduinoJson-gcc7"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "GCC 8",
"image": "conanio/gcc8",
"runArgs": [
"--name=ArduinoJson-gcc8"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "GCC 9",
"image": "conanio/gcc9",
"runArgs": [
"--name=ArduinoJson-gcc9"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools"
],
"settings": {
"cmake.generator": "Unix Makefiles",
"cmake.buildDirectory": "/tmp/build"
}
}
}
}

3
.gitattributes vendored
View File

@ -1 +1,2 @@
*.sh text eol=lf
* text=auto
*.sh text eol=lf

View File

@ -33,6 +33,7 @@ jobs:
fail-fast: false
matrix:
include:
- gcc: "5"
- gcc: "6"
- gcc: "7"
cxxflags: -fsanitize=leak -fno-sanitize-recover=all
@ -131,9 +132,11 @@ jobs:
- name: Install
run: |
sudo apt-get update
sudo apt-get install -y g++-multilib
sudo apt-get install -y g++-multilib gcc-avr avr-libc
- name: Checkout
uses: actions/checkout@v3
- name: AVR
run: avr-g++ -std=c++11 -Isrc extras/conf_test/avr.cpp
- name: GCC 32-bit
run: g++ -std=c++11 -m32 -Isrc extras/conf_test/x86.cpp
- name: GCC 64-bit

View File

@ -72,5 +72,24 @@ jobs:
uses: actions/checkout@v3
- name: Login
run: particle login --token ${{ secrets.PARTICLE_TOKEN }}
timeout-minutes: 1
- name: Publish
run: bash -eux extras/scripts/publish-particle-library.sh
timeout-minutes: 5
platformio:
name: PlatformIO
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install PlatformIO
run: pip install platformio
- name: Checkout
uses: actions/checkout@v3
- name: Publish
run: pio pkg publish --no-interactive --no-notify
env:
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}

View File

@ -1,3 +1,4 @@
.devcontainer/
.github/
examples/
extras/
extras/

View File

@ -1,6 +1,5 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.generator": "Ninja",
"git.inputValidationLength": 80,
"git.inputValidationSubjectLength": 72,
"files.insertFinalNewline": true,

View File

@ -1,6 +1,42 @@
ArduinoJson: change log
=======================
v6.21.5 (2024-01-10)
-------
* Fix warning `function returns incomplete class type` on IAR (issue #2001)
* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029)
* Remove unused files in the PlatformIO package
v6.21.4 (2023-12-07)
-------
* Fix error `'std::string' has not been declared` (issue #1967)
* Fix error `'std::string_view' has not been declared` (issue #1967)
* Fix error `no instance of overloaded function...` on recent IAR compilers (issue #2001)
v6.21.3 (2023-07-23)
-------
* Fix compatibility with the Blynk libary (issue #1914)
* Fix double lookup in `to<JsonVariant>()`
* Fix double call to `size()` in `serializeMsgPack()`
* Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name
* Show a link to the documentation when user passes an unsupported input type
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)
-------

View File

@ -10,7 +10,7 @@ if(ESP_PLATFORM)
return()
endif()
project(ArduinoJson VERSION 6.21.0)
project(ArduinoJson VERSION 6.21.5)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)

View File

@ -8,9 +8,9 @@
[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
[![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/6.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.21.0&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.0)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.0)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.0)
[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.0&logo=cpu&logoColor=white&color=blue)](https://components.espressif.com/components/bblanchon/arduinojson)
[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.21.5&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.5)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.5)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.5)
[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.5&logo=cpu&logoColor=white&color=blue)](https://components.espressif.com/components/bblanchon/arduinojson)
[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat&logo=github&color=orange)](https://github.com/bblanchon/ArduinoJson/stargazers)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/bblanchon?logo=github&color=orange)](https://github.com/sponsors/bblanchon)
@ -85,7 +85,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [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 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
* [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/)

View File

@ -1,4 +1,4 @@
version: 6.21.0.{build}
version: 6.21.5.{build}
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022

View File

@ -14,7 +14,7 @@ void setup() {
while (!Serial) continue;
// The huge input: an extract from OpenWeatherMap response
const __FlashStringHelper* input_json = F(
auto input_json = F(
"{\"cod\":\"200\",\"message\":0,\"list\":[{\"dt\":1581498000,\"main\":{"
"\"temp\":3.23,\"feels_like\":-3.63,\"temp_min\":3.23,\"temp_max\":4.62,"
"\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":"

View File

@ -1,5 +1,7 @@
#include <ArduinoJson.h>
static_assert(ARDUINOJSON_ENABLE_PROGMEM == 1, "ARDUINOJSON_ENABLE_PROGMEM");
static_assert(ARDUINOJSON_USE_LONG_LONG == 0, "ARDUINOJSON_USE_LONG_LONG");
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 1,

View File

@ -4,14 +4,14 @@ set -eu
VERSION="$1"
CHANGELOG="$2"
FRONTMATTER="$3"
ARDUINOJSON_H="$3"
cat << END
---
branch: v6
version: $VERSION
date: '$(date +'%Y-%m-%d')'
$(cat "$FRONTMATTER")
$(extras/scripts/wandbox/publish.sh "$ARDUINOJSON_H")
---
$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG")

View File

@ -14,5 +14,5 @@ cp -r "$SOURCE_DIR/src" "$WORK_DIR/"
cp -r "$SOURCE_DIR/examples" "$WORK_DIR/"
cd "$WORK_DIR"
particle library upload
particle library publish
particle library upload -v
particle library publish -v

View File

@ -46,6 +46,7 @@ update_version_in_source () {
-e "s/ARDUINOJSON_VERSION_MAJOR .*$/ARDUINOJSON_VERSION_MAJOR $MAJOR/" \
-e "s/ARDUINOJSON_VERSION_MINOR .*$/ARDUINOJSON_VERSION_MINOR $MINOR/" \
-e "s/ARDUINOJSON_VERSION_REVISION .*$/ARDUINOJSON_VERSION_REVISION $REVISION/" \
-e "s/ARDUINOJSON_VERSION_MACRO .*$/ARDUINOJSON_VERSION_MACRO V$MAJOR$MINOR$REVISION/" \
src/ArduinoJson/version.hpp
rm src/ArduinoJson/version.hpp*~
}
@ -72,7 +73,6 @@ push
extras/scripts/build-arduino-package.sh . "../ArduinoJson-$TAG.zip"
extras/scripts/build-single-header.sh "src/ArduinoJson.h" "../ArduinoJson-$TAG.h"
extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "../ArduinoJson-$TAG.hpp"
extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG-wandbox.txt" || echo "Wandbox failed!"
extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG-wandbox.txt" > "../ArduinoJson-$TAG.md"
extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG.md"
echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md"

View File

@ -20,11 +20,6 @@ int main() {
//
// DynamicJsonDocument doc(200);
// StaticJsonObject allocates memory on the stack, it can be
// replaced by DynamicJsonDocument which allocates in the heap.
//
// DynamicJsonDocument doc(200);
// Add values in the document
//
doc["sensor"] = "gps";

View File

@ -14,8 +14,8 @@ compile() {
{
"code":$(read_string "$FILE_PATH"),
"codes": [{"file":"ArduinoJson.h","code":$(read_string "$ARDUINOJSON_H")}],
"options": "warning",
"compiler": "gcc-4.9.4",
"options": "warning,c++11",
"compiler": "gcc-5.5.0",
"save": true
}
END

View File

@ -1,8 +1,16 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
// we expect ArduinoJson.h to include <string_view>
// but we don't want it to included accidentally
#undef ARDUINO
#define ARDUINOJSON_ENABLE_STD_STREAM 0
#define ARDUINOJSON_ENABLE_STD_STRING 0
#include <ArduinoJson.h>
#include <catch.hpp>
#include <string_view>
#if !ARDUINOJSON_ENABLE_STRING_VIEW
# error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1
#endif
@ -19,7 +27,7 @@ TEST_CASE("string_view") {
SECTION("JsonDocument::set()") {
doc.set(std::string_view("123", 2));
REQUIRE(doc.as<std::string>() == "12");
REQUIRE(doc.as<std::string_view>() == "12");
}
SECTION("JsonDocument::operator[]() const") {

View File

@ -7,5 +7,7 @@
#include "api/Print.h"
#include "api/Stream.h"
#include "api/String.h"
#include "avr/pgmspace.h"
#define ARDUINO
#define ARDUINO_H_INCLUDED 1

View File

@ -7,18 +7,18 @@
#include <sstream>
class CustomReader {
std::stringstream _stream;
std::stringstream stream_;
public:
CustomReader(const char* input) : _stream(input) {}
CustomReader(const char* input) : stream_(input) {}
CustomReader(const CustomReader&) = delete;
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());
}
};

View File

@ -2,6 +2,8 @@
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#pragma once
#include <stdint.h> // uint8_t
#define PROGMEM

View File

@ -9,7 +9,7 @@ add_executable(IntegrationTests
openweathermap.cpp
)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6)
target_compile_options(IntegrationTests
PUBLIC
-fsingle-precision-constant # issue 544

View File

@ -24,6 +24,30 @@ TEST_CASE("deserializeJson(char*)") {
}
}
TEST_CASE("deserializeJson(unsigned char*, unsigned int)") { // issue #1897
StaticJsonDocument<1024> doc;
unsigned char input[] = "{\"hello\":\"world\"}";
unsigned char* input_ptr = input;
unsigned int size = sizeof(input);
DeserializationError err = deserializeJson(doc, input_ptr, size);
REQUIRE(err == DeserializationError::Ok);
}
TEST_CASE("deserializeJson(uint8_t*, size_t)") { // issue #1898
StaticJsonDocument<1024> doc;
uint8_t input[] = "{\"hello\":\"world\"}";
uint8_t* input_ptr = input;
size_t size = sizeof(input);
DeserializationError err = deserializeJson(doc, input_ptr, size);
REQUIRE(err == DeserializationError::Ok);
}
TEST_CASE("deserializeJson(const std::string&)") {
DynamicJsonDocument doc(4096);

View File

@ -10,29 +10,29 @@
class SpyingAllocator {
public:
SpyingAllocator(const SpyingAllocator& src) : _log(src._log) {}
SpyingAllocator(std::ostream& log) : _log(log) {}
SpyingAllocator(const SpyingAllocator& src) : log_(src.log_) {}
SpyingAllocator(std::ostream& log) : log_(log) {}
SpyingAllocator& operator=(const SpyingAllocator& src) = delete;
void* allocate(size_t n) {
_log << "A" << n;
log_ << "A" << n;
return malloc(n);
}
void deallocate(void* p) {
_log << "F";
log_ << "F";
free(p);
}
private:
std::ostream& _log;
std::ostream& log_;
};
class ControllableAllocator {
public:
ControllableAllocator() : _enabled(true) {}
ControllableAllocator() : enabled_(true) {}
void* allocate(size_t n) {
return _enabled ? malloc(n) : 0;
return enabled_ ? malloc(n) : 0;
}
void deallocate(void* p) {
@ -40,11 +40,11 @@ class ControllableAllocator {
}
void disable() {
_enabled = false;
enabled_ = false;
}
private:
bool _enabled;
bool enabled_;
};
TEST_CASE("BasicJsonDocument") {

View File

@ -10,36 +10,36 @@
class ArmoredAllocator {
public:
ArmoredAllocator() : _ptr(0), _size(0) {}
ArmoredAllocator() : ptr_(0), size_(0) {}
void* allocate(size_t size) {
_ptr = malloc(size);
_size = size;
return _ptr;
ptr_ = malloc(size);
size_ = size;
return ptr_;
}
void deallocate(void* ptr) {
REQUIRE(ptr == _ptr);
REQUIRE(ptr == ptr_);
free(ptr);
_ptr = 0;
_size = 0;
ptr_ = 0;
size_ = 0;
}
void* reallocate(void* ptr, size_t new_size) {
REQUIRE(ptr == _ptr);
REQUIRE(ptr == ptr_);
// don't call realloc, instead alloc a new buffer and erase the old one
// this way we make sure we support relocation
void* new_ptr = malloc(new_size);
memcpy(new_ptr, _ptr, std::min(new_size, _size));
memset(_ptr, '#', _size); // erase
free(_ptr);
_ptr = new_ptr;
memcpy(new_ptr, ptr_, std::min(new_size, size_));
memset(ptr_, '#', size_); // erase
free(ptr_);
ptr_ = new_ptr;
return new_ptr;
}
private:
void* _ptr;
size_t _size;
void* ptr_;
size_t size_;
};
typedef BasicJsonDocument<ArmoredAllocator> ShrinkToFitTestDocument;

View File

@ -12,21 +12,21 @@ class CustomWriter {
CustomWriter& operator=(const CustomWriter&) = delete;
size_t write(uint8_t c) {
_str.append(1, static_cast<char>(c));
str_.append(1, 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;
}
const std::string& str() const {
return _str;
return str_;
}
private:
std::string _str;
std::string str_;
};
TEST_CASE("CustomWriter") {

View File

@ -74,18 +74,18 @@ TEST_CASE("Custom converter with overloading") {
class Complex {
public:
explicit Complex(double r, double i) : _real(r), _imag(i) {}
explicit Complex(double r, double i) : real_(r), imag_(i) {}
double real() const {
return _real;
return real_;
}
double imag() const {
return _imag;
return imag_;
}
private:
double _real, _imag;
double real_, imag_;
};
namespace ArduinoJson {
@ -152,3 +152,27 @@ TEST_CASE("ConverterNeedsWriteableRef") {
CHECK(ConverterNeedsWriteableRef<JsonArray>::value == true);
CHECK(ConverterNeedsWriteableRef<JsonArrayConst>::value == false);
}
namespace ArduinoJson {
void convertToJson(char c, JsonVariant var) {
char buf[] = {c, 0};
var.set(buf);
}
void convertFromJson(JsonVariantConst src, char& dst) {
auto p = src.as<const char*>();
dst = p ? p[0] : 0;
}
} // namespace ArduinoJson
TEST_CASE("Convert char to string") { // issue #1922
StaticJsonDocument<64> doc;
doc.set('a');
REQUIRE(doc.as<std::string>() == "a");
}
TEST_CASE("Convert string to char") { // issue #1963
StaticJsonDocument<64> doc;
doc.set("a");
REQUIRE(doc.as<char>() == 'a');
}

View File

@ -140,6 +140,13 @@ TEST_CASE("volatile") {
DynamicJsonDocument doc(4096);
JsonVariant variant = doc.to<JsonVariant>();
SECTION("volatile bool") { // issue #2029
volatile bool f = true;
variant.set(f);
CHECK(variant.is<bool>() == true);
CHECK(variant.as<bool>() == true);
}
SECTION("volatile int") {
volatile int f = 42;
variant.set(f);

View File

@ -6,6 +6,7 @@ add_executable(MiscTests
arithmeticCompare.cpp
conflicts.cpp
FloatParts.cpp
issue1967.cpp
JsonString.cpp
NoArduinoHeader.cpp
printable.cpp

View File

@ -170,19 +170,19 @@ TEST_CASE("IteratorReader") {
class StreamStub : public Stream {
public:
StreamStub(const char* s) : _stream(s) {}
StreamStub(const char* s) : stream_(s) {}
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::istringstream _stream;
std::istringstream stream_;
};
TEST_CASE("Reader<Stream>") {

View File

@ -2,17 +2,16 @@
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_ENABLE_PROGMEM 1
#include "custom_string.hpp"
#include "progmem_emulation.hpp"
#include "weird_strcmp.hpp"
#include <Arduino.h>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <catch.hpp>
#include "custom_string.hpp"
#include "weird_strcmp.hpp"
using namespace ArduinoJson::detail;
TEST_CASE("ZeroTerminatedRamString") {

View File

@ -2,10 +2,13 @@
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
#include <Arduino.h>
#define ARDUINOJSON_STRING_BUFFER_SIZE 5
#include <ArduinoJson.h>
#include <catch.hpp>
#include "custom_string.hpp"
using namespace ArduinoJson::detail;

View File

@ -52,5 +52,11 @@
#define BLOCKSIZE
#define CAPACITY
// issue #1905
#define _current
// issue #1914
#define V6 6
// catch.hpp mutes several warnings, this file also allows to detect them
#include "ArduinoJson.h"

View File

@ -0,0 +1,13 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
// we expect ArduinoJson.h to include <string>
#define ARDUINOJSON_ENABLE_STD_STRING 1
// but we don't want it to included accidentally
#undef ARDUINO
#define ARDUINOJSON_ENABLE_STD_STREAM 0
#define ARDUINOJSON_ENABLE_STRING_VIEW 0
#include <ArduinoJson.h>

View File

@ -29,21 +29,21 @@ struct PrintAllAtOnce {
template <typename PrintPolicy>
struct PrintableString : public Printable {
PrintableString(const char* s) : _str(s), _total(0) {}
PrintableString(const char* s) : str_(s), total_(0) {}
virtual size_t printTo(Print& p) const {
size_t result = PrintPolicy::printStringTo(_str, p);
_total += result;
size_t result = PrintPolicy::printStringTo(str_, p);
total_ += result;
return result;
}
size_t totalBytesWritten() const {
return _total;
return total_;
}
private:
std::string _str;
mutable size_t _total;
std::string str_;
mutable size_t total_;
};
TEST_CASE("Printable") {

View File

@ -2,8 +2,6 @@
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include "progmem_emulation.hpp"
#define ARDUINOJSON_ENABLE_PROGMEM 1
#include <ArduinoJson.h>

View File

@ -2,8 +2,6 @@
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include "progmem_emulation.hpp"
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
#define ARDUINOJSON_ENABLE_PROGMEM 1
#define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 0

View File

@ -2,8 +2,6 @@
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include "progmem_emulation.hpp"
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
#define ARDUINOJSON_ENABLE_PROGMEM 1
#define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1

View File

@ -5,8 +5,6 @@
#define ARDUINO
#define memcpy_P(dest, src, n) memcpy((dest), (src), (n))
#include "progmem_emulation.hpp"
#include <ArduinoJson.h>
#include <catch.hpp>

View File

@ -1,4 +1,4 @@
version: "6.21.0"
version: "6.21.5"
description: >-
A simple and efficient JSON library for embedded C++.
ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more.
@ -8,5 +8,6 @@ url: https://arduinojson.org/
files:
exclude:
- "**/.vs/**/*"
- ".devcontainer/**/*"
- "examples/**/*"
- "extras/**/*"

View File

@ -7,15 +7,14 @@
"type": "git",
"url": "https://github.com/bblanchon/ArduinoJson.git"
},
"version": "6.21.0",
"version": "6.21.5",
"authors": {
"name": "Benoit Blanchon",
"url": "https://blog.benoitblanchon.fr"
},
"exclude": [
".github",
"extras"
],
"export": {
"include": ["src", "examples", "LICENSE.txt", "ArduinoJson.h"]
},
"frameworks": "*",
"platforms": "*",
"build": {

View File

@ -1,5 +1,5 @@
name=ArduinoJson
version=6.21.0
version=6.21.5
author=Benoit Blanchon <blog.benoitblanchon.fr>
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
sentence=A simple and efficient JSON library for embedded C++.

View File

@ -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

View File

@ -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

View File

@ -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 <>

View File

@ -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 <>

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -15,18 +15,20 @@ 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
// clang-format off
return source_->read(); // Error here? See https://arduinojson.org/v6/invalid-input/
// clang-format on
}
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>

View File

@ -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

View File

@ -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;
}
};

View File

@ -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;
}
};

View File

@ -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;
}
};

View File

@ -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

View File

@ -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));

View File

@ -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};
}
};

View File

@ -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.setNull();
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,44 +277,44 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
}
protected:
JsonDocument() : _pool(0, 0) {}
JsonDocument() : pool_(0, 0) {}
JsonDocument(detail::MemoryPool pool) : _pool(pool) {}
JsonDocument(detail::MemoryPool pool) : pool_(pool) {}
JsonDocument(char* buf, size_t capa) : _pool(buf, capa) {}
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_;
}
};

View File

@ -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

View File

@ -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
};

View File

@ -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

View File

@ -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
};

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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>

View File

@ -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>

View File

@ -18,17 +18,17 @@ class MsgPackDeserializer {
public:
MsgPackDeserializer(MemoryPool* pool, TReader reader,
TStringStorage stringStorage)
: _pool(pool),
_reader(reader),
_stringStorage(stringStorage),
_foundSomething(false) {}
: pool_(pool),
reader_(reader),
stringStorage_(stringStorage),
foundSomething_(false) {}
template <typename TFilter>
DeserializationError parse(VariantData& variant, TFilter filter,
DeserializationOption::NestingLimit nestingLimit) {
DeserializationError::Code err;
err = parseVariant(&variant, filter, nestingLimit);
return _foundSomething ? err : DeserializationError::EmptyInput;
return foundSomething_ ? err : DeserializationError::EmptyInput;
}
private:
@ -43,7 +43,7 @@ class MsgPackDeserializer {
if (err)
return err;
_foundSomething = true;
foundSomething_ = true;
bool allowValue = filter.allowValue();
@ -224,7 +224,7 @@ class MsgPackDeserializer {
}
DeserializationError::Code readByte(uint8_t& value) {
int c = _reader.read();
int c = reader_.read();
if (c < 0)
return DeserializationError::IncompleteInput;
value = static_cast<uint8_t>(c);
@ -232,7 +232,7 @@ class MsgPackDeserializer {
}
DeserializationError::Code readBytes(uint8_t* p, size_t n) {
if (_reader.readBytes(reinterpret_cast<char*>(p), n) == n)
if (reader_.readBytes(reinterpret_cast<char*>(p), n) == n)
return DeserializationError::Ok;
return DeserializationError::IncompleteInput;
}
@ -244,7 +244,7 @@ class MsgPackDeserializer {
DeserializationError::Code skipBytes(size_t n) {
for (; n; --n) {
if (_reader.read() < 0)
if (reader_.read() < 0)
return DeserializationError::IncompleteInput;
}
return DeserializationError::Ok;
@ -371,14 +371,14 @@ class MsgPackDeserializer {
if (err)
return err;
variant->setString(_stringStorage.save());
variant->setString(stringStorage_.save());
return DeserializationError::Ok;
}
DeserializationError::Code readString(size_t n) {
DeserializationError::Code err;
_stringStorage.startString();
stringStorage_.startString();
for (; n; --n) {
uint8_t c;
@ -386,10 +386,10 @@ class MsgPackDeserializer {
if (err)
return err;
_stringStorage.append(static_cast<char>(c));
stringStorage_.append(static_cast<char>(c));
}
if (!_stringStorage.isValid())
if (!stringStorage_.isValid())
return DeserializationError::NoMemory;
return DeserializationError::Ok;
@ -435,7 +435,7 @@ class MsgPackDeserializer {
if (memberFilter.allow()) {
ARDUINOJSON_ASSERT(array != 0);
value = array->addElement(_pool);
value = array->addElement(pool_);
if (!value)
return DeserializationError::NoMemory;
} else {
@ -486,7 +486,7 @@ class MsgPackDeserializer {
if (err)
return err;
JsonString key = _stringStorage.str();
JsonString key = stringStorage_.str();
TFilter memberFilter = filter[key.c_str()];
VariantData* member;
@ -495,9 +495,9 @@ class MsgPackDeserializer {
// Save key in memory pool.
// This MUST be done before adding the slot.
key = _stringStorage.save();
key = stringStorage_.save();
VariantSlot* slot = object->addSlot(_pool);
VariantSlot* slot = object->addSlot(pool_);
if (!slot)
return DeserializationError::NoMemory;
@ -554,10 +554,10 @@ class MsgPackDeserializer {
return skipBytes(size + 1U);
}
MemoryPool* _pool;
TReader _reader;
TStringStorage _stringStorage;
bool _foundSomething;
MemoryPool* pool_;
TReader reader_;
TStringStorage stringStorage_;
bool foundSomething_;
};
ARDUINOJSON_END_PRIVATE_NAMESPACE

View File

@ -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) {
@ -47,7 +47,7 @@ class MsgPackSerializer : public Visitor<size_t> {
size_t visitArray(const CollectionData& array) {
size_t n = array.size();
if (n < 0x10) {
writeByte(uint8_t(0x90 + array.size()));
writeByte(uint8_t(0x90 + n));
} else if (n < 0x10000) {
writeByte(0xDC);
writeInteger(uint16_t(n));
@ -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

View File

@ -11,16 +11,15 @@
#ifndef ARDUINOJSON_VERSION_NAMESPACE
# define ARDUINOJSON_VERSION_NAMESPACE \
ARDUINOJSON_CONCAT3( \
ARDUINOJSON_CONCAT4(V, ARDUINOJSON_VERSION_MAJOR, \
ARDUINOJSON_VERSION_MINOR, \
ARDUINOJSON_VERSION_REVISION), \
ARDUINOJSON_CONCAT4( \
ARDUINOJSON_VERSION_MACRO, \
ARDUINOJSON_BIN2ALPHA( \
ARDUINOJSON_ENABLE_PROGMEM, ARDUINOJSON_USE_LONG_LONG, \
ARDUINOJSON_USE_DOUBLE, ARDUINOJSON_ENABLE_STRING_DEDUPLICATION), \
ARDUINOJSON_BIN2ALPHA( \
ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \
ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE))
ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE), \
ARDUINOJSON_SLOT_OFFSET_SIZE)
#endif

View File

@ -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 <>

View File

@ -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 <>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -6,8 +6,6 @@
#define ARDUINOJSON_CONCAT_(A, B) A##B
#define ARDUINOJSON_CONCAT2(A, B) ARDUINOJSON_CONCAT_(A, B)
#define ARDUINOJSON_CONCAT3(A, B, C) \
ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT2(A, B), C)
#define ARDUINOJSON_CONCAT4(A, B, C, D) \
ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT2(A, B), ARDUINOJSON_CONCAT2(C, D))
@ -17,7 +15,7 @@
#define ARDUINOJSON_BIN2ALPHA_0011() D
#define ARDUINOJSON_BIN2ALPHA_0100() E
#define ARDUINOJSON_BIN2ALPHA_0101() F
#define ARDUINOJSON_BIN2ALPHA_0110() F
#define ARDUINOJSON_BIN2ALPHA_0110() G
#define ARDUINOJSON_BIN2ALPHA_0111() H
#define ARDUINOJSON_BIN2ALPHA_1000() I
#define ARDUINOJSON_BIN2ALPHA_1001() J

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

Some files were not shown because too many files have changed in this diff Show More