mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-26 08:47:31 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
b810833145 | |||
9d58e566fd | |||
6632fa8da1 | |||
5790f3c8f7 | |||
4073b52c00 | |||
f5c7a6478e | |||
ebf58320ca | |||
09ddb0f824 | |||
f02a699c26 | |||
67d0931c19 | |||
19d079c33c | |||
40723a4cc7 | |||
8a9a26588c |
@ -12,7 +12,8 @@
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools",
|
||||
"ms-vscode.cpptools"
|
||||
"ms-vscode.cpptools",
|
||||
"xaver.clang-format"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
|
23
.github/workflows/ci.yml
vendored
23
.github/workflows/ci.yml
vendored
@ -3,22 +3,24 @@ name: Continuous Integration
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
clang-format:
|
||||
name: Clang-Format
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y clang-format
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Format
|
||||
run: find src/ extras/ -name '*.[ch]pp' | xargs clang-format -i --verbose --style=file
|
||||
- name: Diff
|
||||
run: git diff --exit-code
|
||||
- name: Symlinks
|
||||
run: find * -type l -printf "::error::%p is a symlink. This is forbidden by the Arduino Library Specification." -exec false {} +
|
||||
- name: Clang-format
|
||||
run: |
|
||||
find src/ extras/ -name '*.[ch]pp' | xargs clang-format -i --verbose --style=file
|
||||
git diff --exit-code
|
||||
|
||||
gcc:
|
||||
name: GCC
|
||||
needs: clang-format
|
||||
needs: lint
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@ -66,7 +68,7 @@ jobs:
|
||||
|
||||
clang:
|
||||
name: Clang
|
||||
needs: clang-format
|
||||
needs: lint
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@ -470,6 +472,11 @@ jobs:
|
||||
submodules: true
|
||||
- name: Install ESP-IDF
|
||||
run: ./esp-idf/install.sh
|
||||
- name: Add component
|
||||
# NOTE: we cannot commit the symlink because the Arduino Library Specification forbids it.
|
||||
run: |
|
||||
mkdir -p extras/ci/espidf/components
|
||||
ln -s $PWD extras/ci/espidf/components/ArduinoJson
|
||||
- name: Build example
|
||||
run: |
|
||||
source esp-idf/export.sh
|
||||
|
51
.github/workflows/release.yml
vendored
Normal file
51
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*.*.*
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Create release
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Set variables
|
||||
id: init
|
||||
run: |
|
||||
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
|
||||
echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Write release body
|
||||
id: body
|
||||
run: |
|
||||
FILENAME=RELEASE.md
|
||||
extras/scripts/get-release-body.sh ${{ steps.init.outputs.tag }} CHANGELOG.md | tee $FILENAME
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Amalgamate ArduinoJson.h
|
||||
id: amalgamate_h
|
||||
run: |
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.h
|
||||
extras/scripts/build-single-header.sh src/ArduinoJson.h "$FILENAME"
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Amalgamate ArduinoJson.hpp
|
||||
id: amalgamate_hpp
|
||||
run: |
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.hpp
|
||||
extras/scripts/build-single-header.sh src/ArduinoJson.hpp "$FILENAME"
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Create Arduino package
|
||||
id: arduino
|
||||
run: |
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.zip
|
||||
extras/scripts/build-arduino-package.sh . "$FILENAME"
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Create release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
bodyFile: ${{ steps.body.outputs.filename }}
|
||||
draft: true
|
||||
name: ArduinoJson ${{ steps.init.outputs.version }}
|
||||
artifacts: ${{ steps.amalgamate_h.outputs.filename }},${{ steps.amalgamate_hpp.outputs.filename }},${{ steps.arduino.outputs.filename }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,6 +1,17 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v6.18.3 (2021-07-27)
|
||||
-------
|
||||
|
||||
* Changed return type of `convertToJson()` and `Converter<T>::toJson()` to `void`
|
||||
* Added `as<std::string_view>()` and `is<std::string_view>()`
|
||||
|
||||
v6.18.2 (2021-07-19)
|
||||
-------
|
||||
|
||||
* Removed a symlink because the Arduino Library Specification forbids it
|
||||
|
||||
v6.18.1 (2021-07-03)
|
||||
-------
|
||||
|
||||
|
@ -11,7 +11,7 @@ if(ESP_PLATFORM)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(ArduinoJson VERSION 6.18.1)
|
||||
project(ArduinoJson VERSION 6.18.3)
|
||||
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
include(CTest)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
---
|
||||
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.18.1)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.18.3)
|
||||
[](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 6.18.1.{build}
|
||||
version: 6.18.3.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
|
@ -1 +0,0 @@
|
||||
../../../..
|
@ -1,21 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
TAG=$(git describe)
|
||||
OUTPUT="ArduinoJson-$TAG.zip"
|
||||
set -eu
|
||||
|
||||
cd $(dirname $0)/../../..
|
||||
INPUT=$1
|
||||
OUTPUT=$2
|
||||
|
||||
cd "$INPUT"
|
||||
|
||||
# remove existing file
|
||||
rm -f $OUTPUT
|
||||
rm -f "$OUTPUT"
|
||||
|
||||
# create zip
|
||||
7z a $OUTPUT \
|
||||
-xr!.vs \
|
||||
ArduinoJson/CHANGELOG.md \
|
||||
ArduinoJson/examples \
|
||||
ArduinoJson/src \
|
||||
ArduinoJson/keywords.txt \
|
||||
ArduinoJson/library.properties \
|
||||
ArduinoJson/LICENSE.md \
|
||||
ArduinoJson/README.md \
|
||||
ArduinoJson/ArduinoJson.h
|
||||
7z a "$OUTPUT" \
|
||||
-xr!.vs \
|
||||
CHANGELOG.md \
|
||||
examples \
|
||||
src \
|
||||
keywords.txt \
|
||||
library.properties \
|
||||
LICENSE.md \
|
||||
README.md \
|
||||
ArduinoJson.h
|
||||
|
14
extras/scripts/get-release-body.sh
Executable file
14
extras/scripts/get-release-body.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
TAG="$1"
|
||||
CHANGELOG="$2"
|
||||
|
||||
cat << END
|
||||
## Changes
|
||||
|
||||
$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG")
|
||||
|
||||
[View version history](https://github.com/bblanchon/ArduinoJson/blob/$TAG/CHANGELOG.md)
|
||||
END
|
18
extras/scripts/get-release-page.sh
Executable file
18
extras/scripts/get-release-page.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
VERSION="$1"
|
||||
CHANGELOG="$2"
|
||||
FRONTMATTER="$3"
|
||||
|
||||
cat << END
|
||||
---
|
||||
branch: v6
|
||||
version: $VERSION
|
||||
date: '$(date +'%Y-%m-%d')'
|
||||
$(cat "$FRONTMATTER")
|
||||
---
|
||||
|
||||
$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG")
|
||||
END
|
@ -59,6 +59,10 @@ commit_new_version
|
||||
add_tag
|
||||
push
|
||||
|
||||
extras/scripts/build-arduino-package.sh
|
||||
extras/scripts/build-single-header.sh
|
||||
extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h"
|
||||
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"
|
||||
extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG-wandbox.txt" > "../ArduinoJson-$TAG.md"
|
||||
|
||||
echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md"
|
||||
|
@ -21,7 +21,7 @@ compile() {
|
||||
END
|
||||
URL=$(curl -sS -H "Content-type: application/json" -d @parameters.json https://wandbox.org/api/compile.json | jq --raw-output .url)
|
||||
rm parameters.json
|
||||
echo " $1: $URL"
|
||||
echo "$1: $URL"
|
||||
}
|
||||
|
||||
compile "JsonGeneratorExample"
|
||||
|
@ -58,6 +58,20 @@ TEST_CASE("string_view") {
|
||||
doc.add(std::string_view("example two", 7));
|
||||
REQUIRE(doc.memoryUsage() == JSON_ARRAY_SIZE(2) + 8);
|
||||
}
|
||||
|
||||
SECTION("as<std::string_view>()") {
|
||||
doc["s"] = "Hello World";
|
||||
doc["i"] = 42;
|
||||
REQUIRE(doc["s"].as<std::string_view>() == std::string_view("Hello World"));
|
||||
REQUIRE(doc["i"].as<std::string_view>() == std::string_view());
|
||||
}
|
||||
|
||||
SECTION("is<std::string_view>()") {
|
||||
doc["s"] = "Hello World";
|
||||
doc["i"] = 42;
|
||||
REQUIRE(doc["s"].is<std::string_view>() == true);
|
||||
REQUIRE(doc["i"].is<std::string_view>() == false);
|
||||
}
|
||||
}
|
||||
|
||||
using ARDUINOJSON_NAMESPACE::adaptString;
|
||||
@ -71,9 +85,5 @@ TEST_CASE("StringViewAdapter") {
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
CHECK_FALSE(adapter.equals(NULL));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
@ -13,11 +13,10 @@ struct Date {
|
||||
int year;
|
||||
};
|
||||
|
||||
bool convertToJson(const Date& src, JsonVariant dst) {
|
||||
void convertToJson(const Date& src, JsonVariant dst) {
|
||||
dst["day"] = src.day;
|
||||
dst["month"] = src.month;
|
||||
dst["year"] = src.year;
|
||||
return true;
|
||||
}
|
||||
|
||||
void convertFromJson(JsonVariantConst src, Date& dst) {
|
||||
@ -92,10 +91,9 @@ class Complex {
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
template <>
|
||||
struct Converter<Complex> {
|
||||
static bool toJson(const Complex& src, VariantRef dst) {
|
||||
static void toJson(const Complex& src, VariantRef dst) {
|
||||
dst["real"] = src.real();
|
||||
dst["imag"] = src.imag();
|
||||
return true;
|
||||
}
|
||||
|
||||
static Complex fromJson(VariantConstRef src) {
|
||||
|
@ -2,146 +2,118 @@
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_ENABLE_PROGMEM 1
|
||||
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
|
||||
|
||||
#include "custom_string.hpp"
|
||||
#include "progmem_emulation.hpp"
|
||||
#include "weird_strcmp.hpp"
|
||||
|
||||
#include <ArduinoJson/Strings/ArduinoStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/FlashStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/StdStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("ConstRamStringAdapter") {
|
||||
TEST_CASE("const char*") {
|
||||
SECTION("null") {
|
||||
ConstRamStringAdapter adapter(NULL);
|
||||
StringAdapter<const char*> adapter(NULL);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
ConstRamStringAdapter adapter("bravo");
|
||||
StringAdapter<const char*> adapter("bravo");
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SizedRamStringAdapter") {
|
||||
TEST_CASE("const char* + size") {
|
||||
SECTION("null") {
|
||||
SizedRamStringAdapter adapter(NULL, 10);
|
||||
StringAdapter<const char*, true> adapter(NULL, 10);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 10);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
SizedRamStringAdapter adapter("bravo", 5);
|
||||
StringAdapter<const char*, true> adapter("bravo", 5);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("FlashStringAdapter") {
|
||||
TEST_CASE("const __FlashStringHelper*") {
|
||||
SECTION("null") {
|
||||
FlashStringAdapter adapter(NULL);
|
||||
StringAdapter<const __FlashStringHelper*> adapter(NULL);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
FlashStringAdapter adapter = adaptString(F("bravo"));
|
||||
StringAdapter<const __FlashStringHelper*> adapter = adaptString(F("bravo"));
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("std::string") {
|
||||
std::string str("bravo");
|
||||
StdStringAdapter<std::string> adapter = adaptString(str);
|
||||
StringAdapter<std::string> adapter(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("Arduino String") {
|
||||
::String str("bravo");
|
||||
ArduinoStringAdapter adapter = adaptString(str);
|
||||
StringAdapter< ::String> adapter(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("custom_string") {
|
||||
custom_string str("bravo");
|
||||
StdStringAdapter<custom_string> adapter = adaptString(str);
|
||||
StringAdapter<custom_string> adapter(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "6.18.1",
|
||||
"version": "6.18.3",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "https://blog.benoitblanchon.fr"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ArduinoJson
|
||||
version=6.18.1
|
||||
version=6.18.3
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=A simple and efficient JSON library for embedded C++.
|
||||
|
@ -173,8 +173,8 @@ class ArrayRef : public ArrayRefBase<CollectionData>,
|
||||
|
||||
template <>
|
||||
struct Converter<ArrayConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ArrayConstRef fromJson(VariantConstRef src) {
|
||||
@ -189,8 +189,8 @@ struct Converter<ArrayConstRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<ArrayRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ArrayRef fromJson(VariantRef src) {
|
||||
|
@ -178,8 +178,8 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
||||
return _array.getOrAddElement(_index);
|
||||
}
|
||||
|
||||
friend bool convertToJson(const this_type& src, VariantRef dst) {
|
||||
return dst.set(src.getUpstreamElement());
|
||||
friend void convertToJson(const this_type& src, VariantRef dst) {
|
||||
dst.set(src.getUpstreamElement());
|
||||
}
|
||||
|
||||
TArray _array;
|
||||
|
@ -62,9 +62,9 @@ inline bool CollectionData::copyFrom(const CollectionData& src,
|
||||
VariantData* var;
|
||||
if (s->key() != 0) {
|
||||
if (s->ownsKey())
|
||||
var = addMember(RamStringAdapter(s->key()), pool);
|
||||
var = addMember(adaptString(const_cast<char*>(s->key())), pool);
|
||||
else
|
||||
var = addMember(ConstRamStringAdapter(s->key()), pool);
|
||||
var = addMember(adaptString(s->key()), pool);
|
||||
} else {
|
||||
var = addElement(pool);
|
||||
}
|
||||
@ -107,7 +107,7 @@ template <typename TAdaptedString>
|
||||
inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
|
||||
VariantSlot* slot = _head;
|
||||
while (slot) {
|
||||
if (key.equals(slot->key()))
|
||||
if (key.compare(slot->key()) == 0)
|
||||
break;
|
||||
slot = slot->next();
|
||||
}
|
||||
|
@ -337,8 +337,8 @@ class JsonDocument : public Visitable {
|
||||
JsonDocument& operator=(const JsonDocument&);
|
||||
};
|
||||
|
||||
inline bool convertToJson(const JsonDocument& src, VariantRef dst) {
|
||||
return dst.set(src.as<VariantConstRef>());
|
||||
inline void convertToJson(const JsonDocument& src, VariantRef dst) {
|
||||
dst.set(src.as<VariantConstRef>());
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -167,7 +167,7 @@ class MemoryPool {
|
||||
template <typename TAdaptedString>
|
||||
const char* findString(const TAdaptedString& str) {
|
||||
for (char* next = _begin; next < _left; ++next) {
|
||||
if (str.equals(next))
|
||||
if (str.compare(next) == 0)
|
||||
return next;
|
||||
|
||||
// jump to next terminator
|
||||
|
@ -187,8 +187,8 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return _object.getOrAddMember(_key);
|
||||
}
|
||||
|
||||
friend bool convertToJson(const this_type &src, VariantRef dst) {
|
||||
return dst.set(src.getUpstreamMember());
|
||||
friend void convertToJson(const this_type &src, VariantRef dst) {
|
||||
dst.set(src.getUpstreamMember());
|
||||
}
|
||||
|
||||
TObject _object;
|
||||
|
@ -239,8 +239,8 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
|
||||
|
||||
template <>
|
||||
struct Converter<ObjectConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ObjectConstRef fromJson(VariantConstRef src) {
|
||||
@ -255,8 +255,8 @@ struct Converter<ObjectConstRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<ObjectRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ObjectRef fromJson(VariantRef src) {
|
||||
|
@ -20,5 +20,6 @@
|
||||
#include "type_traits/is_signed.hpp"
|
||||
#include "type_traits/is_unsigned.hpp"
|
||||
#include "type_traits/make_unsigned.hpp"
|
||||
#include "type_traits/make_void.hpp"
|
||||
#include "type_traits/remove_const.hpp"
|
||||
#include "type_traits/remove_reference.hpp"
|
||||
|
14
src/ArduinoJson/Polyfills/type_traits/make_void.hpp
Normal file
14
src/ArduinoJson/Polyfills/type_traits/make_void.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <class = void>
|
||||
struct make_void {
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -7,14 +7,15 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class ArduinoStringAdapter {
|
||||
template <>
|
||||
class StringAdapter< ::String> {
|
||||
public:
|
||||
ArduinoStringAdapter(const ::String& str) : _str(&str) {}
|
||||
StringAdapter(const ::String& str) : _str(&str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str->c_str(), n);
|
||||
@ -31,10 +32,6 @@ class ArduinoStringAdapter {
|
||||
return safe_strcmp(me, other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str->length();
|
||||
}
|
||||
@ -46,13 +43,10 @@ class ArduinoStringAdapter {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString< ::String> : true_type {};
|
||||
|
||||
template <>
|
||||
struct IsString< ::StringSumHelper> : true_type {};
|
||||
|
||||
inline ArduinoStringAdapter adaptString(const ::String& str) {
|
||||
return ArduinoStringAdapter(str);
|
||||
}
|
||||
class StringAdapter< ::StringSumHelper> : public StringAdapter< ::String> {
|
||||
public:
|
||||
StringAdapter< ::StringSumHelper>(const ::String& s)
|
||||
: StringAdapter< ::String>(s) {}
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -8,23 +8,20 @@
|
||||
#include <string.h> // strcmp
|
||||
|
||||
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class ConstRamStringAdapter {
|
||||
template <>
|
||||
class StringAdapter<const char*> {
|
||||
public:
|
||||
ConstRamStringAdapter(const char* str = 0) : _str(str) {}
|
||||
StringAdapter(const char* str = 0) : _str(str) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
return safe_strcmp(_str, other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -45,14 +42,10 @@ class ConstRamStringAdapter {
|
||||
const char* _str;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<const char*> : true_type {};
|
||||
|
||||
template <int N>
|
||||
struct IsString<const char[N]> : true_type {};
|
||||
|
||||
inline ConstRamStringAdapter adaptString(const char* str) {
|
||||
return ConstRamStringAdapter(str);
|
||||
}
|
||||
class StringAdapter<const char[N]> : public StringAdapter<const char*> {
|
||||
public:
|
||||
StringAdapter<const char[N]>(const char* s) : StringAdapter<const char*>(s) {}
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,14 +5,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/pgmspace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class FlashStringAdapter {
|
||||
template <>
|
||||
class StringAdapter<const __FlashStringHelper*> {
|
||||
public:
|
||||
FlashStringAdapter(const __FlashStringHelper* str) : _str(str) {}
|
||||
StringAdapter(const __FlashStringHelper* str) : _str(str) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
if (!other && !_str)
|
||||
@ -24,10 +25,6 @@ class FlashStringAdapter {
|
||||
return -strcmp_P(other, reinterpret_cast<const char*>(_str));
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -48,10 +45,4 @@ class FlashStringAdapter {
|
||||
const __FlashStringHelper* _str;
|
||||
};
|
||||
|
||||
inline FlashStringAdapter adaptString(const __FlashStringHelper* str) {
|
||||
return FlashStringAdapter(str);
|
||||
}
|
||||
|
||||
template <>
|
||||
struct IsString<const __FlashStringHelper*> : true_type {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
27
src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
Normal file
27
src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/String.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <>
|
||||
class StringAdapter<String> : public StringAdapter<char*> {
|
||||
public:
|
||||
StringAdapter(const String& str)
|
||||
: StringAdapter<char*>(str.c_str()), _isStatic(str.isStatic()) {}
|
||||
|
||||
bool isStatic() const {
|
||||
return _isStatic;
|
||||
}
|
||||
|
||||
typedef storage_policies::decide_at_runtime storage_policy;
|
||||
|
||||
private:
|
||||
bool _isStatic;
|
||||
};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
29
src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp
Normal file
29
src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TChar>
|
||||
class StringAdapter<TChar*, false,
|
||||
typename enable_if<sizeof(TChar) == 1 &&
|
||||
!is_same<TChar, void>::value>::type>
|
||||
: public StringAdapter<const char*> {
|
||||
public:
|
||||
StringAdapter(const TChar* str)
|
||||
: StringAdapter<const char*>(reinterpret_cast<const char*>(str)) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str, n);
|
||||
}
|
||||
|
||||
typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,14 +5,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class SizedFlashStringAdapter {
|
||||
template <>
|
||||
class StringAdapter<const __FlashStringHelper*, true> {
|
||||
public:
|
||||
SizedFlashStringAdapter(const __FlashStringHelper* str, size_t sz)
|
||||
StringAdapter(const __FlashStringHelper* str, size_t sz)
|
||||
: _str(str), _size(sz) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
@ -25,10 +26,6 @@ class SizedFlashStringAdapter {
|
||||
return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -48,8 +45,4 @@ class SizedFlashStringAdapter {
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
inline SizedFlashStringAdapter adaptString(const __FlashStringHelper* str,
|
||||
size_t sz) {
|
||||
return SizedFlashStringAdapter(str, sz);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,25 +5,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
#include <string.h> // strcmp
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class SizedRamStringAdapter {
|
||||
template <typename TChar>
|
||||
class StringAdapter<TChar*, true> {
|
||||
public:
|
||||
SizedRamStringAdapter(const char* str, size_t n) : _str(str), _size(n) {}
|
||||
StringAdapter(const char* str, size_t n) : _str(str), _size(n) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
return safe_strncmp(_str, other, _size);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -43,9 +40,4 @@ class SizedRamStringAdapter {
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
inline SizedRamStringAdapter adaptString(const TChar* str, size_t size) {
|
||||
return SizedRamStringAdapter(reinterpret_cast<const char*>(str), size);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,17 +5,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TString>
|
||||
class StdStringAdapter {
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
class StringAdapter<std::basic_string<char, TCharTraits, TAllocator> > {
|
||||
public:
|
||||
StdStringAdapter(const TString& str) : _str(&str) {}
|
||||
typedef std::basic_string<char, TCharTraits, TAllocator> string_type;
|
||||
|
||||
StringAdapter(const string_type& str) : _str(&str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str->c_str(), n);
|
||||
@ -31,12 +33,6 @@ class StdStringAdapter {
|
||||
return _str->compare(other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
if (!expected)
|
||||
return false;
|
||||
return *_str == expected;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str->size();
|
||||
}
|
||||
@ -44,18 +40,7 @@ class StdStringAdapter {
|
||||
typedef storage_policies::store_by_copy storage_policy;
|
||||
|
||||
private:
|
||||
const TString* _str;
|
||||
const string_type* _str;
|
||||
};
|
||||
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
struct IsString<std::basic_string<char, TCharTraits, TAllocator> > : true_type {
|
||||
};
|
||||
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
inline StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >
|
||||
adaptString(const std::basic_string<char, TCharTraits, TAllocator>& str) {
|
||||
return StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >(
|
||||
str);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,16 +5,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class StringViewAdapter {
|
||||
template <>
|
||||
class StringAdapter<std::string_view> {
|
||||
public:
|
||||
StringViewAdapter(std::string_view str) : _str(str) {}
|
||||
StringAdapter(std::string_view str) : _str(str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str.data(), n);
|
||||
@ -30,12 +31,6 @@ class StringViewAdapter {
|
||||
return _str.compare(other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
if (!expected)
|
||||
return false;
|
||||
return _str == expected;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str.size();
|
||||
}
|
||||
@ -46,11 +41,4 @@ class StringViewAdapter {
|
||||
std::string_view _str;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<std::string_view> : true_type {};
|
||||
|
||||
inline StringViewAdapter adaptString(const std::string_view& str) {
|
||||
return StringViewAdapter(str);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -1,18 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
template <typename>
|
||||
struct IsString : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<const T> : IsString<T> {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<T&> : IsString<T> {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -1,43 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class RamStringAdapter : public ConstRamStringAdapter {
|
||||
public:
|
||||
RamStringAdapter(const char* str) : ConstRamStringAdapter(str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str, n);
|
||||
}
|
||||
|
||||
typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
inline RamStringAdapter adaptString(const TChar* str) {
|
||||
return RamStringAdapter(reinterpret_cast<const char*>(str));
|
||||
}
|
||||
|
||||
inline RamStringAdapter adaptString(char* str) {
|
||||
return RamStringAdapter(str);
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
struct IsString<TChar*> {
|
||||
static const bool value = sizeof(TChar) == 1;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<void*> {
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -4,10 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class String {
|
||||
@ -53,25 +49,4 @@ class String {
|
||||
bool _isStatic;
|
||||
};
|
||||
|
||||
class StringAdapter : public RamStringAdapter {
|
||||
public:
|
||||
StringAdapter(const String& str)
|
||||
: RamStringAdapter(str.c_str()), _isStatic(str.isStatic()) {}
|
||||
|
||||
bool isStatic() const {
|
||||
return _isStatic;
|
||||
}
|
||||
|
||||
typedef storage_policies::decide_at_runtime storage_policy;
|
||||
|
||||
private:
|
||||
bool _isStatic;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<String> : true_type {};
|
||||
|
||||
inline StringAdapter adaptString(const String& str) {
|
||||
return StringAdapter(str);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
32
src/ArduinoJson/Strings/StringAdapter.hpp
Normal file
32
src/ArduinoJson/Strings/StringAdapter.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename T, bool bounded = false, typename Enable = void>
|
||||
class StringAdapter;
|
||||
|
||||
template <typename T>
|
||||
inline StringAdapter<T, false> adaptString(const T& str) {
|
||||
return StringAdapter<T, false>(str);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline StringAdapter<T, true> adaptString(const T& str, size_t sz) {
|
||||
return StringAdapter<T, true>(str, sz);
|
||||
}
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct IsString : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<
|
||||
T, typename make_void<typename StringAdapter<T>::storage_policy>::type>
|
||||
: true_type {};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -4,23 +4,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp>
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STRING
|
||||
# include <ArduinoJson/Strings/StdStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/StdStringAdapter.hpp>
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STRING_VIEW
|
||||
# include <ArduinoJson/Strings/StringViewAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/StringViewAdapter.hpp>
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
|
||||
# include <ArduinoJson/Strings/ArduinoStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp>
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_PROGMEM
|
||||
# include <ArduinoJson/Strings/FlashStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/SizedFlashStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp>
|
||||
#endif
|
||||
|
@ -12,9 +12,9 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename T, typename Enable>
|
||||
struct Converter {
|
||||
static bool toJson(const T& src, VariantRef dst) {
|
||||
static void toJson(const T& src, VariantRef dst) {
|
||||
// clang-format off
|
||||
return convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/
|
||||
convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
@ -38,13 +38,11 @@ template <typename T>
|
||||
struct Converter<
|
||||
T, typename enable_if<is_integral<T>::value && !is_same<bool, T>::value &&
|
||||
!is_same<char, T>::value>::type> {
|
||||
static bool toJson(T src, VariantRef dst) {
|
||||
static void toJson(T src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setInteger(src);
|
||||
return true;
|
||||
if (data)
|
||||
data->setInteger(src);
|
||||
}
|
||||
|
||||
static T fromJson(VariantConstRef src) {
|
||||
@ -61,8 +59,8 @@ struct Converter<
|
||||
|
||||
template <typename T>
|
||||
struct Converter<T, typename enable_if<is_enum<T>::value>::type> {
|
||||
static bool toJson(T src, VariantRef dst) {
|
||||
return dst.set(static_cast<Integer>(src));
|
||||
static void toJson(T src, VariantRef dst) {
|
||||
dst.set(static_cast<Integer>(src));
|
||||
}
|
||||
|
||||
static T fromJson(VariantConstRef src) {
|
||||
@ -78,12 +76,10 @@ struct Converter<T, typename enable_if<is_enum<T>::value>::type> {
|
||||
|
||||
template <>
|
||||
struct Converter<bool> {
|
||||
static bool toJson(bool src, VariantRef dst) {
|
||||
static void toJson(bool src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setBoolean(src);
|
||||
return true;
|
||||
if (data)
|
||||
data->setBoolean(src);
|
||||
}
|
||||
|
||||
static bool fromJson(VariantConstRef src) {
|
||||
@ -99,12 +95,10 @@ struct Converter<bool> {
|
||||
|
||||
template <typename T>
|
||||
struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> {
|
||||
static bool toJson(T src, VariantRef dst) {
|
||||
static void toJson(T src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setFloat(static_cast<Float>(src));
|
||||
return true;
|
||||
if (data)
|
||||
data->setFloat(static_cast<Float>(src));
|
||||
}
|
||||
|
||||
static T fromJson(VariantConstRef src) {
|
||||
@ -120,8 +114,8 @@ struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> {
|
||||
|
||||
template <>
|
||||
struct Converter<const char*> {
|
||||
static bool toJson(const char* src, VariantRef dst) {
|
||||
return variantSetString(getData(dst), adaptString(src), getPool(dst));
|
||||
static void toJson(const char* src, VariantRef dst) {
|
||||
variantSetString(getData(dst), adaptString(src), getPool(dst));
|
||||
}
|
||||
|
||||
static const char* fromJson(VariantConstRef src) {
|
||||
@ -163,12 +157,10 @@ canConvertFromJson(VariantConstRef src, const T&) {
|
||||
|
||||
template <>
|
||||
struct Converter<SerializedValue<const char*> > {
|
||||
static bool toJson(SerializedValue<const char*> src, VariantRef dst) {
|
||||
static void toJson(SerializedValue<const char*> src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setLinkedRaw(src);
|
||||
return true;
|
||||
if (data)
|
||||
data->setLinkedRaw(src);
|
||||
}
|
||||
};
|
||||
|
||||
@ -178,10 +170,11 @@ struct Converter<SerializedValue<const char*> > {
|
||||
template <typename T>
|
||||
struct Converter<SerializedValue<T>,
|
||||
typename enable_if<!is_same<const char*, T>::value>::type> {
|
||||
static bool toJson(SerializedValue<T> src, VariantRef dst) {
|
||||
static void toJson(SerializedValue<T> src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
MemoryPool* pool = getPool(dst);
|
||||
return data != 0 && data->setOwnedRaw(src, pool);
|
||||
if (data)
|
||||
data->setOwnedRaw(src, pool);
|
||||
}
|
||||
};
|
||||
|
||||
@ -189,9 +182,8 @@ struct Converter<SerializedValue<T>,
|
||||
|
||||
template <>
|
||||
struct Converter<decltype(nullptr)> {
|
||||
static bool toJson(decltype(nullptr), VariantRef dst) {
|
||||
static void toJson(decltype(nullptr), VariantRef dst) {
|
||||
variantSetNull(getData(dst));
|
||||
return true;
|
||||
}
|
||||
static decltype(nullptr) fromJson(VariantConstRef) {
|
||||
return nullptr;
|
||||
@ -247,20 +239,33 @@ class MemoryPoolPrint : public Print {
|
||||
size_t _capacity;
|
||||
};
|
||||
|
||||
inline bool convertToJson(const ::Printable& src, VariantRef dst) {
|
||||
inline void convertToJson(const ::Printable& src, VariantRef dst) {
|
||||
MemoryPool* pool = getPool(dst);
|
||||
VariantData* data = getData(dst);
|
||||
if (!pool || !data)
|
||||
return false;
|
||||
return;
|
||||
MemoryPoolPrint print(pool);
|
||||
src.printTo(print);
|
||||
if (print.overflowed()) {
|
||||
pool->markAsOverflowed();
|
||||
data->setNull();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
data->setStringPointer(print.c_str(), storage_policies::store_by_copy());
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STRING_VIEW
|
||||
|
||||
inline void convertFromJson(VariantConstRef src, std::string_view& dst) {
|
||||
const char* str = src.as<const char*>();
|
||||
if (str) // the standard doesn't allow passing null to the constructor
|
||||
dst = std::string_view(str);
|
||||
}
|
||||
|
||||
inline bool canConvertFromJson(VariantConstRef src, const std::string_view&) {
|
||||
return src.is<const char*>();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <ArduinoJson/Misc/Visitable.hpp>
|
||||
#include <ArduinoJson/Numbers/arithmeticCompare.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
#include <ArduinoJson/Variant/Visitor.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Misc/SerializedValue.hpp>
|
||||
#include <ArduinoJson/Numbers/convertNumber.hpp>
|
||||
#include <ArduinoJson/Strings/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
#include <ArduinoJson/Variant/VariantContent.hpp>
|
||||
|
||||
// VariantData can't have a constructor (to be a POD), so we have no way to fix
|
||||
@ -103,7 +103,8 @@ class VariantData {
|
||||
case VALUE_IS_OBJECT:
|
||||
return toObject().copyFrom(src._content.asCollection, pool);
|
||||
case VALUE_IS_OWNED_STRING:
|
||||
return setString(RamStringAdapter(src._content.asString), pool);
|
||||
return setString(adaptString(const_cast<char *>(src._content.asString)),
|
||||
pool);
|
||||
case VALUE_IS_OWNED_RAW:
|
||||
return setOwnedRaw(
|
||||
serialized(src._content.asRaw.data, src._content.asRaw.size), pool);
|
||||
|
@ -85,7 +85,8 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(const T &value) const {
|
||||
return Converter<T>::toJson(value, *this);
|
||||
Converter<T>::toJson(value, *this);
|
||||
return _pool && !_pool->overflowed();
|
||||
}
|
||||
|
||||
bool ARDUINOJSON_DEPRECATED(
|
||||
@ -94,7 +95,8 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(T *value) const {
|
||||
return Converter<T *>::toJson(value, *this);
|
||||
Converter<T *>::toJson(value, *this);
|
||||
return _pool && !_pool->overflowed();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -339,8 +341,8 @@ class VariantConstRef : public VariantRefBase<const VariantData>,
|
||||
|
||||
template <>
|
||||
struct Converter<VariantRef> {
|
||||
static bool toJson(VariantRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static VariantRef fromJson(VariantRef src) {
|
||||
@ -362,8 +364,8 @@ struct Converter<VariantRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<VariantConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static VariantConstRef fromJson(VariantConstRef src) {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARDUINOJSON_VERSION "6.18.1"
|
||||
#define ARDUINOJSON_VERSION "6.18.3"
|
||||
#define ARDUINOJSON_VERSION_MAJOR 6
|
||||
#define ARDUINOJSON_VERSION_MINOR 18
|
||||
#define ARDUINOJSON_VERSION_REVISION 1
|
||||
#define ARDUINOJSON_VERSION_REVISION 3
|
||||
|
Reference in New Issue
Block a user