Compare commits

...

26 Commits

Author SHA1 Message Date
617c0329df Replace problematic symbols in idf_component.yml
Fixes #2131
2024-09-26 09:21:51 +02:00
57354de831 Make string support even more generic
Closes #2084
2024-05-01 14:04:04 +02:00
c99af48e97 CI: update runner for the lint job
Ported from ece4d030a8
2024-05-01 14:04:00 +02:00
0741bd9e68 Fix typo in "endianness"
Ported from 0d43e51d48
Closes #2071
2024-03-26 13:46:27 +01:00
8d3d9c718d Remove final from JsonArray, JsonObject, and JsonVariant
`final` breaks ThingsBoard ಠ_ಠ
https://github.com/thingsboard/thingsboard-client-sdk/blob/v0.12.2/src/RPC_Response.h#L10

See #2056.
This reverts commit 5ed9daae91.
2024-02-18 20:01:04 +01:00
5ed9daae91 Mark JsonArray, JsonObject, and JsonVariant as final
See #2056
Ported from 483a2c9
2024-02-18 11:25:49 +01:00
0e7262a77b Improve error messages when using char or char*
See #2043
Ported from 650d537b5d
2024-01-26 18:45:12 +01:00
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
30 changed files with 202 additions and 86 deletions

View File

@ -5,7 +5,7 @@ on: [push, pull_request]
jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install
run: sudo apt-get install -y clang-format

View File

@ -76,3 +76,20 @@ jobs:
- 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

@ -4,7 +4,31 @@ ArduinoJson: change log
HEAD
----
* Improve error messages when using `char` or `char*` (issue #2043)
* Make string support even more generic (PR #2084 by @d-a-v)
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)
-------

View File

@ -10,7 +10,7 @@ if(ESP_PLATFORM)
return()
endif()
project(ArduinoJson VERSION 6.21.2)
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.2&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.2)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.2)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.2)
[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.2&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)

View File

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

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

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

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

@ -154,10 +154,18 @@ TEST_CASE("ConverterNeedsWriteableRef") {
}
namespace ArduinoJson {
void convertToJson(char c, JsonVariant var) {
char buf[] = {c, 0};
var.set(buf);
}
template <>
struct Converter<char> {
static void toJson(char c, JsonVariant var) {
char buf[] = {c, 0};
var.set(buf);
}
static char fromJson(JsonVariantConst src) {
auto p = src.as<const char*>();
return p ? p[0] : 0;
}
};
} // namespace ArduinoJson
TEST_CASE("Convert char to string") { // issue #1922
@ -165,3 +173,9 @@ TEST_CASE("Convert char to string") { // issue #1922
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

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

@ -13,7 +13,7 @@ static void check(const char* input, T expected) {
uint8_t* f = reinterpret_cast<uint8_t*>(&actual);
const uint8_t* d = reinterpret_cast<const uint8_t*>(input);
doubleToFloat(d, f);
fixEndianess(actual);
fixEndianness(actual);
CHECK(actual == expected);
}

View File

@ -1,8 +1,8 @@
version: "6.21.2"
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.
It is the most popular Arduino library on GitHub ❤❤❤❤❤.
It is the most popular Arduino library on GitHub .
Check out arduinojson.org for a comprehensive documentation.
url: https://arduinojson.org/
files:

View File

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

View File

@ -1,5 +1,5 @@
name=ArduinoJson
version=6.21.2
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

@ -18,7 +18,9 @@ struct Reader {
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) {

View File

@ -6,7 +6,7 @@
#include <ArduinoJson/Deserialization/deserialize.hpp>
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/MsgPack/endianess.hpp>
#include <ArduinoJson/MsgPack/endianness.hpp>
#include <ArduinoJson/MsgPack/ieee754.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Variant/VariantData.hpp>
@ -258,7 +258,7 @@ class MsgPackDeserializer {
if (err)
return err;
fixEndianess(value);
fixEndianness(value);
return DeserializationError::Ok;
}
@ -287,7 +287,7 @@ class MsgPackDeserializer {
if (err)
return err;
fixEndianess(value);
fixEndianness(value);
variant->setFloat(value);
return DeserializationError::Ok;
@ -303,7 +303,7 @@ class MsgPackDeserializer {
if (err)
return err;
fixEndianess(value);
fixEndianness(value);
variant->setFloat(value);
return DeserializationError::Ok;
@ -322,7 +322,7 @@ class MsgPackDeserializer {
return err;
doubleToFloat(i, o);
fixEndianess(value);
fixEndianness(value);
variant->setFloat(value);
return DeserializationError::Ok;

View File

@ -4,7 +4,7 @@
#pragma once
#include <ArduinoJson/MsgPack/endianess.hpp>
#include <ArduinoJson/MsgPack/endianness.hpp>
#include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Serialization/CountingDecorator.hpp>
@ -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));
@ -190,7 +190,7 @@ class MsgPackSerializer : public Visitor<size_t> {
template <typename T>
void writeInteger(T value) {
fixEndianess(value);
fixEndianness(value);
writeBytes(reinterpret_cast<uint8_t*>(&value), sizeof(value));
}

View File

@ -15,32 +15,32 @@ inline void swapBytes(uint8_t& a, uint8_t& b) {
b = t;
}
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 8>) {
inline void fixEndianness(uint8_t* p, integral_constant<size_t, 8>) {
swapBytes(p[0], p[7]);
swapBytes(p[1], p[6]);
swapBytes(p[2], p[5]);
swapBytes(p[3], p[4]);
}
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 4>) {
inline void fixEndianness(uint8_t* p, integral_constant<size_t, 4>) {
swapBytes(p[0], p[3]);
swapBytes(p[1], p[2]);
}
inline void fixEndianess(uint8_t* p, integral_constant<size_t, 2>) {
inline void fixEndianness(uint8_t* p, integral_constant<size_t, 2>) {
swapBytes(p[0], p[1]);
}
inline void fixEndianess(uint8_t*, integral_constant<size_t, 1>) {}
inline void fixEndianness(uint8_t*, integral_constant<size_t, 1>) {}
template <typename T>
inline void fixEndianess(T& value) {
fixEndianess(reinterpret_cast<uint8_t*>(&value),
integral_constant<size_t, sizeof(T)>());
inline void fixEndianness(T& value) {
fixEndianness(reinterpret_cast<uint8_t*>(&value),
integral_constant<size_t, sizeof(T)>());
}
#else
template <typename T>
inline void fixEndianess(T&) {}
inline void fixEndianness(T&) {}
#endif
ARDUINOJSON_END_PRIVATE_NAMESPACE

View File

@ -11,14 +11,15 @@
#ifndef ARDUINOJSON_VERSION_NAMESPACE
# define ARDUINOJSON_VERSION_NAMESPACE \
ARDUINOJSON_CONCAT3( \
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

@ -6,8 +6,8 @@
#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))
#define ARDUINOJSON_BIN2ALPHA_0000() A
#define ARDUINOJSON_BIN2ALPHA_0001() B
@ -15,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

@ -8,6 +8,7 @@
#include <string.h> // strcmp
#include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Polyfills/attributes.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
@ -27,7 +28,7 @@ class ZeroTerminatedRamString {
return !str_;
}
size_t size() const {
FORCE_INLINE size_t size() const {
return str_ ? ::strlen(str_) : 0;
}

View File

@ -38,16 +38,15 @@ struct has_data<T,
const char*>::value>::type>
: true_type {};
// size_t length() const
// unsigned int length() const
// - String
template <class T, class = void>
struct has_length : false_type {};
template <class T>
struct has_length<
T, typename enable_if<
is_same<decltype(declval<const T>().length()), size_t>::value>::type>
struct has_length<T, typename enable_if<is_unsigned<
decltype(declval<const T>().length())>::value>::type>
: true_type {};
// size_t size() const

View File

@ -8,10 +8,22 @@
#include <ArduinoJson/Variant/JsonVariantConst.hpp>
#include <ArduinoJson/Variant/VariantFunctions.hpp>
#if ARDUINOJSON_ENABLE_STD_STRING
# include <string>
#endif
#if ARDUINOJSON_ENABLE_STRING_VIEW
# include <string_view>
#endif
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
template <typename T, typename Enable>
struct Converter {
static_assert(!detail::is_same<T, char>::value,
"type 'char' is not supported, use 'signed char', 'unsigned "
"char' or another integer type instead");
static void toJson(const T& src, JsonVariant dst) {
// clang-format off
convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/
@ -19,6 +31,9 @@ struct Converter {
}
static T fromJson(JsonVariantConst src) {
static_assert(!detail::is_same<T, char*>::value,
"type 'char*' is not supported, use 'const char*' instead");
// clang-format off
T result; // Error here? See https://arduinojson.org/v6/non-default-constructible/
convertFromJson(src, result); // Error here? See https://arduinojson.org/v6/unsupported-as/
@ -27,6 +42,9 @@ struct Converter {
}
static bool checkJson(JsonVariantConst src) {
static_assert(!detail::is_same<T, char*>::value,
"type 'char*' is not supported, use 'const char*' instead");
T dummy = T();
// clang-format off
return canConvertFromJson(src, dummy); // Error here? See https://arduinojson.org/v6/unsupported-is/

View File

@ -110,6 +110,13 @@ inline JsonVariant VariantRefBase<TDerived>::add() const {
variantAddElement(getOrCreateData(), getPool()));
}
template <typename TDerived>
template <typename T>
inline typename enable_if<ConverterNeedsWriteableRef<T>::value, T>::type
VariantRefBase<TDerived>::as() const {
return Converter<T>::fromJson(getVariant());
}
template <typename TDerived>
inline JsonVariant VariantRefBase<TDerived>::getVariant() const {
return JsonVariant(getPool(), getData());
@ -120,6 +127,30 @@ inline JsonVariant VariantRefBase<TDerived>::getOrCreateVariant() const {
return JsonVariant(getPool(), getOrCreateData());
}
template <typename TDerived>
template <typename T>
inline typename enable_if<ConverterNeedsWriteableRef<T>::value, bool>::type
VariantRefBase<TDerived>::is() const {
return Converter<T>::checkJson(getVariant());
}
template <typename TDerived>
template <typename T>
inline bool VariantRefBase<TDerived>::set(const T& value) const {
Converter<typename detail::remove_cv<T>::type>::toJson(value,
getOrCreateVariant());
MemoryPool* pool = getPool();
return pool && !pool->overflowed();
}
template <typename TDerived>
template <typename T>
inline bool VariantRefBase<TDerived>::set(T* value) const {
Converter<T*>::toJson(value, getOrCreateVariant());
MemoryPool* pool = getPool();
return pool && !pool->overflowed();
}
template <typename TDerived>
template <typename T>
inline typename enable_if<is_same<T, JsonArray>::value, JsonArray>::type
@ -138,8 +169,9 @@ template <typename TDerived>
template <typename T>
typename enable_if<is_same<T, JsonVariant>::value, JsonVariant>::type
VariantRefBase<TDerived>::to() const {
variantSetNull(getOrCreateData());
return *this;
auto data = getOrCreateData();
variantSetNull(data);
return JsonVariant(getPool(), data);
}
template <typename TDerived>

View File

@ -57,11 +57,10 @@ class VariantRefBase : public VariantTag {
// https://arduinojson.org/v6/api/jsonvariant/as/
template <typename T>
FORCE_INLINE typename enable_if<ConverterNeedsWriteableRef<T>::value, T>::type
as() const {
return Converter<T>::fromJson(getVariant());
}
as() const;
template <typename T>
template <typename T,
typename = typename enable_if<!is_same<T, TDerived>::value>::type>
FORCE_INLINE operator T() const {
return as<T>();
}
@ -91,18 +90,14 @@ class VariantRefBase : public VariantTag {
template <typename T>
FORCE_INLINE
typename enable_if<ConverterNeedsWriteableRef<T>::value, bool>::type
is() const {
return Converter<T>::checkJson(getVariant());
}
is() const;
// Returns true if the value is of the specified type.
// https://arduinojson.org/v6/api/jsonvariant/is/
template <typename T>
FORCE_INLINE typename enable_if<!ConverterNeedsWriteableRef<T>::value &&
!is_same<T, char*>::value &&
!is_same<T, char>::value,
bool>::type
is() const {
FORCE_INLINE
typename enable_if<!ConverterNeedsWriteableRef<T>::value, bool>::type
is() const {
return Converter<T>::checkJson(getVariantConst());
}
@ -122,20 +117,12 @@ class VariantRefBase : public VariantTag {
// Copies the specified value.
// https://arduinojson.org/v6/api/jsonvariant/set/
template <typename T>
FORCE_INLINE bool set(const T& value) const {
Converter<T>::toJson(value, getOrCreateVariant());
MemoryPool* pool = getPool();
return pool && !pool->overflowed();
}
FORCE_INLINE bool set(const T& value) const;
// Copies the specified value.
// https://arduinojson.org/v6/api/jsonvariant/set/
template <typename T>
FORCE_INLINE bool set(T* value) const {
Converter<T*>::toJson(value, getOrCreateVariant());
MemoryPool* pool = getPool();
return pool && !pool->overflowed();
}
FORCE_INLINE bool set(T* value) const;
// Returns the size of the array or object.
// https://arduinojson.org/v6/api/jsonvariant/size/

View File

@ -4,8 +4,8 @@
#pragma once
#define ARDUINOJSON_VERSION "6.21.2"
#define ARDUINOJSON_VERSION "6.21.5"
#define ARDUINOJSON_VERSION_MAJOR 6
#define ARDUINOJSON_VERSION_MINOR 21
#define ARDUINOJSON_VERSION_REVISION 2
#define ARDUINOJSON_VERSION_MACRO V6212
#define ARDUINOJSON_VERSION_REVISION 5
#define ARDUINOJSON_VERSION_MACRO V6215