diff --git a/Sming/Libraries/ArduinoJson6/ArduinoJson b/Sming/Libraries/ArduinoJson6/ArduinoJson index 6fb52c3638..7517ecb91b 160000 --- a/Sming/Libraries/ArduinoJson6/ArduinoJson +++ b/Sming/Libraries/ArduinoJson6/ArduinoJson @@ -1 +1 @@ -Subproject commit 6fb52c363849557c69485f97110371d0a4454432 +Subproject commit 7517ecb91b50b8ed4b6c94a4b83031ef86a01a26 diff --git a/Sming/Libraries/ArduinoJson6/ArduinoJson.patch b/Sming/Libraries/ArduinoJson6/ArduinoJson.patch new file mode 100644 index 0000000000..34595bfae4 --- /dev/null +++ b/Sming/Libraries/ArduinoJson6/ArduinoJson.patch @@ -0,0 +1,48 @@ +diff --git a/src/ArduinoJson/Document/JsonDocument.hpp b/src/ArduinoJson/Document/JsonDocument.hpp +index 39c1536f..1b129120 100644 +--- a/src/ArduinoJson/Document/JsonDocument.hpp ++++ b/src/ArduinoJson/Document/JsonDocument.hpp +@@ -181,6 +181,11 @@ class JsonDocument : public detail::VariantOperators { + return {*this, key}; + } + ++ inline detail::MemberProxy ++ operator[](const FSTR::String& key) { ++ return {*this, ::String(key)}; ++ } ++ + // Gets or sets a root object's member. + // https://arduinojson.org/v6/api/jsondocument/subscript/ + template +diff --git a/src/ArduinoJson/Object/JsonObject.hpp b/src/ArduinoJson/Object/JsonObject.hpp +index 7cdc1c76..2e006b1e 100644 +--- a/src/ArduinoJson/Object/JsonObject.hpp ++++ b/src/ArduinoJson/Object/JsonObject.hpp +@@ -115,6 +115,11 @@ class JsonObject : public detail::VariantOperators { + return {*this, key}; + } + ++ inline detail::MemberProxy ++ operator[](const FSTR::String& key) const { ++ return {*this, ::String(key)}; ++ } ++ + // Gets or sets the member with specified key. + // https://arduinojson.org/v6/api/jsonobject/subscript/ + template +diff --git a/src/ArduinoJson/Variant/VariantRefBase.hpp b/src/ArduinoJson/Variant/VariantRefBase.hpp +index 2afdda6a..6b48e102 100644 +--- a/src/ArduinoJson/Variant/VariantRefBase.hpp ++++ b/src/ArduinoJson/Variant/VariantRefBase.hpp +@@ -244,6 +244,11 @@ class VariantRefBase : public VariantTag { + MemberProxy>::type + operator[](TChar* key) const; + ++ inline MemberProxy ++ operator[](const FSTR::String& key) const { ++ return MemberProxy(derived(), ::String(key)); ++ } ++ + // Creates an array and adds it to the object. + // https://arduinojson.org/v6/api/jsonvariant/createnestedarray/ + template diff --git a/Sming/Libraries/ArduinoJson6/include/FlashStringReader.hpp b/Sming/Libraries/ArduinoJson6/include/FlashStringReader.hpp index 18058249cc..156454c9a6 100644 --- a/Sming/Libraries/ArduinoJson6/include/FlashStringReader.hpp +++ b/Sming/Libraries/ArduinoJson6/include/FlashStringReader.hpp @@ -6,33 +6,15 @@ #pragma once -namespace ARDUINOJSON_NAMESPACE -{ -template <> struct Reader { - explicit Reader(const FlashString& str) : str(str) - { - } +#include +#include - int read() - { - if(index >= str.length()) { - return -1; - } - unsigned char c = str[index]; - ++index; - return c; - } +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE - size_t readBytes(char* buffer, size_t length) +template <> struct Reader : public BoundedReader { + explicit Reader(const FSTR::String& str) : BoundedReader(str.data(), str.length()) { - auto count = str.read(index, buffer, length); - index += count; - return count; } - -private: - const FlashString& str; - unsigned index = 0; }; -} // namespace ARDUINOJSON_NAMESPACE +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/Sming/Libraries/ArduinoJson6/include/FlashStringRefAdapter.hpp b/Sming/Libraries/ArduinoJson6/include/FlashStringRefAdapter.hpp index 5f55ae6591..b4e287d559 100644 --- a/Sming/Libraries/ArduinoJson6/include/FlashStringRefAdapter.hpp +++ b/Sming/Libraries/ArduinoJson6/include/FlashStringRefAdapter.hpp @@ -6,67 +6,23 @@ #pragma once -#include +#include +#include -namespace ARDUINOJSON_NAMESPACE -{ -class FlashStringRefAdapter -{ -public: - explicit FlashStringRefAdapter(const FlashString& str) : str(str) - { - } - - bool equals(const char* expected) const - { - return str.equals(expected); - } - - bool isNull() const - { - return str.isNull(); - } +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE - char* save(MemoryPool* pool) const - { - size_t n = str.size(); - char* dup = pool->allocFrozenString(n); - if(dup) { - str.read(0, dup, n); - } - return dup; - } +template <> struct StringAdapter { + typedef FlashString AdaptedString; - const char* data() const + static AdaptedString adapt(const FSTR::String& str) { - // Cannot access directly using a char* - return nullptr; + return FlashString(str.data(), str.length()); } - - size_t size() const - { - return str.length(); - } - - bool isStatic() const - { - // Whilst our value won't change, it cannot be accessed using a regular char* - return false; - } - -private: - const FlashString& str; }; -inline FlashStringRefAdapter adaptString(const FlashString& str) +inline CompareResult compare(JsonVariantConst lhs, const FSTR::String& rhs) { - return FlashStringRefAdapter(str); + return compare(lhs, String(rhs)); } -template <> struct IsString : true_type { -}; - -template <> struct IsWriteableString : false_type { -}; - -} // namespace ARDUINOJSON_NAMESPACE +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/tests/HostTests/modules/ArduinoJson6.cpp b/tests/HostTests/modules/ArduinoJson6.cpp index e56d813818..302b5f603c 100644 --- a/tests/HostTests/modules/ArduinoJson6.cpp +++ b/tests/HostTests/modules/ArduinoJson6.cpp @@ -80,7 +80,7 @@ class JsonTest6 : public TestGroup } // Keep a reference copy for when doc gets messed up - StaticJsonDocument<512> sourceDoc = doc; + auto sourceDoc = doc; TEST_CASE("Json::serialize(doc, String), then save to file") { @@ -248,6 +248,12 @@ class JsonTest6 : public TestGroup REQUIRE(root["longtest"] == testnum); } + TEST_CASE("FSTR comparison") + { + doc[FS_number2] = FS_number2; + REQUIRE(doc[FS_number2] == FS_number2); + } + /* * Dangling reference https://github.com/bblanchon/ArduinoJson/issues/1120 * Fixed in ArduinoJson 6.13.0