From 39895a677e5d370824e702cfe90ebc67737b8482 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 12 May 2021 09:12:09 +0200 Subject: import ArduinoJson 6.18.0 --- include/lib/ArduinoJson.h | 73 ++ include/lib/ArduinoJson/Array/ArrayFunctions.hpp | 31 + include/lib/ArduinoJson/Array/ArrayImpl.hpp | 28 + include/lib/ArduinoJson/Array/ArrayIterator.hpp | 121 ++++ include/lib/ArduinoJson/Array/ArrayRef.hpp | 205 ++++++ include/lib/ArduinoJson/Array/ArrayShortcuts.hpp | 49 ++ include/lib/ArduinoJson/Array/ElementProxy.hpp | 193 ++++++ include/lib/ArduinoJson/Array/Utilities.hpp | 133 ++++ .../lib/ArduinoJson/Collection/CollectionData.hpp | 88 +++ .../lib/ArduinoJson/Collection/CollectionImpl.hpp | 234 +++++++ include/lib/ArduinoJson/Configuration.hpp | 255 +++++++ .../Deserialization/DeserializationError.hpp | 122 ++++ include/lib/ArduinoJson/Deserialization/Filter.hpp | 66 ++ .../ArduinoJson/Deserialization/NestingLimit.hpp | 29 + include/lib/ArduinoJson/Deserialization/Reader.hpp | 56 ++ .../Readers/ArduinoStreamReader.hpp | 31 + .../Readers/ArduinoStringReader.hpp | 17 + .../Deserialization/Readers/FlashReader.hpp | 53 ++ .../Deserialization/Readers/IteratorReader.hpp | 43 ++ .../Deserialization/Readers/RamReader.hpp | 50 ++ .../Deserialization/Readers/StdStreamReader.hpp | 29 + .../Deserialization/Readers/VariantReader.hpp | 34 + .../ArduinoJson/Deserialization/deserialize.hpp | 71 ++ .../lib/ArduinoJson/Document/BasicJsonDocument.hpp | 164 +++++ .../ArduinoJson/Document/DynamicJsonDocument.hpp | 29 + include/lib/ArduinoJson/Document/JsonDocument.hpp | 344 ++++++++++ .../ArduinoJson/Document/StaticJsonDocument.hpp | 56 ++ include/lib/ArduinoJson/Json/EscapeSequence.hpp | 39 ++ include/lib/ArduinoJson/Json/JsonDeserializer.hpp | 740 +++++++++++++++++++++ include/lib/ArduinoJson/Json/JsonSerializer.hpp | 137 ++++ include/lib/ArduinoJson/Json/Latch.hpp | 55 ++ .../lib/ArduinoJson/Json/PrettyJsonSerializer.hpp | 89 +++ include/lib/ArduinoJson/Json/TextFormatter.hpp | 163 +++++ include/lib/ArduinoJson/Json/Utf16.hpp | 67 ++ include/lib/ArduinoJson/Json/Utf8.hpp | 46 ++ include/lib/ArduinoJson/Memory/Alignment.hpp | 60 ++ include/lib/ArduinoJson/Memory/MemoryPool.hpp | 212 ++++++ include/lib/ArduinoJson/Misc/SerializedValue.hpp | 68 ++ include/lib/ArduinoJson/Misc/Visitable.hpp | 21 + .../ArduinoJson/MsgPack/MsgPackDeserializer.hpp | 599 +++++++++++++++++ .../lib/ArduinoJson/MsgPack/MsgPackSerializer.hpp | 212 ++++++ include/lib/ArduinoJson/MsgPack/endianess.hpp | 41 ++ include/lib/ArduinoJson/MsgPack/ieee754.hpp | 18 + include/lib/ArduinoJson/Namespace.hpp | 26 + include/lib/ArduinoJson/Numbers/Float.hpp | 17 + include/lib/ArduinoJson/Numbers/FloatParts.hpp | 87 +++ include/lib/ArduinoJson/Numbers/FloatTraits.hpp | 201 ++++++ include/lib/ArduinoJson/Numbers/Integer.hpp | 32 + .../lib/ArduinoJson/Numbers/arithmeticCompare.hpp | 121 ++++ include/lib/ArduinoJson/Numbers/convertNumber.hpp | 107 +++ include/lib/ArduinoJson/Numbers/parseNumber.hpp | 153 +++++ include/lib/ArduinoJson/Object/MemberProxy.hpp | 202 ++++++ include/lib/ArduinoJson/Object/ObjectFunctions.hpp | 51 ++ include/lib/ArduinoJson/Object/ObjectImpl.hpp | 69 ++ include/lib/ArduinoJson/Object/ObjectIterator.hpp | 123 ++++ include/lib/ArduinoJson/Object/ObjectRef.hpp | 277 ++++++++ include/lib/ArduinoJson/Object/ObjectShortcuts.hpp | 73 ++ include/lib/ArduinoJson/Object/Pair.hpp | 55 ++ include/lib/ArduinoJson/Polyfills/alias_cast.hpp | 29 + include/lib/ArduinoJson/Polyfills/assert.hpp | 14 + include/lib/ArduinoJson/Polyfills/attributes.hpp | 54 ++ include/lib/ArduinoJson/Polyfills/ctype.hpp | 20 + include/lib/ArduinoJson/Polyfills/integer.hpp | 30 + include/lib/ArduinoJson/Polyfills/limits.hpp | 45 ++ include/lib/ArduinoJson/Polyfills/math.hpp | 27 + include/lib/ArduinoJson/Polyfills/mpl/max.hpp | 26 + include/lib/ArduinoJson/Polyfills/pgmspace.hpp | 79 +++ .../lib/ArduinoJson/Polyfills/pgmspace_generic.hpp | 32 + include/lib/ArduinoJson/Polyfills/preprocessor.hpp | 35 + include/lib/ArduinoJson/Polyfills/safe_strcmp.hpp | 32 + include/lib/ArduinoJson/Polyfills/static_array.hpp | 34 + include/lib/ArduinoJson/Polyfills/type_traits.hpp | 24 + .../Polyfills/type_traits/conditional.hpp | 20 + .../ArduinoJson/Polyfills/type_traits/declval.hpp | 14 + .../Polyfills/type_traits/enable_if.hpp | 19 + .../Polyfills/type_traits/integral_constant.hpp | 19 + .../ArduinoJson/Polyfills/type_traits/is_array.hpp | 21 + .../Polyfills/type_traits/is_base_of.hpp | 26 + .../ArduinoJson/Polyfills/type_traits/is_class.hpp | 26 + .../ArduinoJson/Polyfills/type_traits/is_const.hpp | 17 + .../Polyfills/type_traits/is_convertible.hpp | 47 ++ .../ArduinoJson/Polyfills/type_traits/is_enum.hpp | 22 + .../Polyfills/type_traits/is_floating_point.hpp | 19 + .../Polyfills/type_traits/is_integral.hpp | 33 + .../Polyfills/type_traits/is_pointer.hpp | 16 + .../ArduinoJson/Polyfills/type_traits/is_same.hpp | 17 + .../Polyfills/type_traits/is_signed.hpp | 43 ++ .../Polyfills/type_traits/is_unsigned.hpp | 37 ++ .../Polyfills/type_traits/make_unsigned.hpp | 49 ++ .../Polyfills/type_traits/remove_const.hpp | 20 + .../Polyfills/type_traits/remove_reference.hpp | 20 + .../Polyfills/type_traits/type_identity.hpp | 15 + include/lib/ArduinoJson/Polyfills/utility.hpp | 28 + .../Serialization/CountingDecorator.hpp | 33 + include/lib/ArduinoJson/Serialization/Writer.hpp | 47 ++ .../Serialization/Writers/ArduinoStringWriter.hpp | 52 ++ .../Serialization/Writers/DummyWriter.hpp | 21 + .../Serialization/Writers/PrintWriter.hpp | 28 + .../Serialization/Writers/StaticStringWriter.hpp | 35 + .../Serialization/Writers/StdStreamWriter.hpp | 32 + .../Serialization/Writers/StdStringWriter.hpp | 40 ++ include/lib/ArduinoJson/Serialization/measure.hpp | 18 + .../lib/ArduinoJson/Serialization/serialize.hpp | 54 ++ .../lib/ArduinoJson/StringStorage/StringCopier.hpp | 62 ++ .../lib/ArduinoJson/StringStorage/StringMover.hpp | 42 ++ .../ArduinoJson/StringStorage/StringStorage.hpp | 23 + .../ArduinoJson/Strings/ArduinoStringAdapter.hpp | 62 ++ .../ArduinoJson/Strings/ConstRamStringAdapter.hpp | 62 ++ .../lib/ArduinoJson/Strings/FlashStringAdapter.hpp | 62 ++ .../ArduinoJson/Strings/FlashStringIterator.hpp | 44 ++ include/lib/ArduinoJson/Strings/IsString.hpp | 18 + .../lib/ArduinoJson/Strings/IsWriteableString.hpp | 37 ++ .../lib/ArduinoJson/Strings/RamStringAdapter.hpp | 43 ++ .../Strings/SizedFlashStringAdapter.hpp | 60 ++ .../ArduinoJson/Strings/SizedRamStringAdapter.hpp | 55 ++ .../lib/ArduinoJson/Strings/StdStringAdapter.hpp | 65 ++ include/lib/ArduinoJson/Strings/StoragePolicy.hpp | 15 + include/lib/ArduinoJson/Strings/String.hpp | 77 +++ include/lib/ArduinoJson/Strings/StringAdapters.hpp | 22 + include/lib/ArduinoJson/Variant/Converter.hpp | 12 + include/lib/ArduinoJson/Variant/ConverterImpl.hpp | 268 ++++++++ include/lib/ArduinoJson/Variant/SlotFunctions.hpp | 60 ++ include/lib/ArduinoJson/Variant/VariantCompare.hpp | 208 ++++++ include/lib/ArduinoJson/Variant/VariantContent.hpp | 59 ++ include/lib/ArduinoJson/Variant/VariantData.hpp | 368 ++++++++++ .../lib/ArduinoJson/Variant/VariantFunctions.hpp | 104 +++ include/lib/ArduinoJson/Variant/VariantImpl.hpp | 143 ++++ .../lib/ArduinoJson/Variant/VariantOperators.hpp | 180 +++++ include/lib/ArduinoJson/Variant/VariantRef.hpp | 375 +++++++++++ .../lib/ArduinoJson/Variant/VariantShortcuts.hpp | 23 + include/lib/ArduinoJson/Variant/VariantSlot.hpp | 116 ++++ include/lib/ArduinoJson/Variant/VariantTag.hpp | 16 + include/lib/ArduinoJson/Variant/VariantTo.hpp | 32 + include/lib/ArduinoJson/Variant/Visitor.hpp | 54 ++ include/lib/ArduinoJson/compatibility.hpp | 23 + include/lib/ArduinoJson/version.hpp | 10 + 136 files changed, 10934 insertions(+) create mode 100644 include/lib/ArduinoJson.h create mode 100644 include/lib/ArduinoJson/Array/ArrayFunctions.hpp create mode 100644 include/lib/ArduinoJson/Array/ArrayImpl.hpp create mode 100644 include/lib/ArduinoJson/Array/ArrayIterator.hpp create mode 100644 include/lib/ArduinoJson/Array/ArrayRef.hpp create mode 100644 include/lib/ArduinoJson/Array/ArrayShortcuts.hpp create mode 100644 include/lib/ArduinoJson/Array/ElementProxy.hpp create mode 100644 include/lib/ArduinoJson/Array/Utilities.hpp create mode 100644 include/lib/ArduinoJson/Collection/CollectionData.hpp create mode 100644 include/lib/ArduinoJson/Collection/CollectionImpl.hpp create mode 100644 include/lib/ArduinoJson/Configuration.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/DeserializationError.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Filter.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/NestingLimit.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Reader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Readers/FlashReader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Readers/IteratorReader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Readers/RamReader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/Readers/VariantReader.hpp create mode 100644 include/lib/ArduinoJson/Deserialization/deserialize.hpp create mode 100644 include/lib/ArduinoJson/Document/BasicJsonDocument.hpp create mode 100644 include/lib/ArduinoJson/Document/DynamicJsonDocument.hpp create mode 100644 include/lib/ArduinoJson/Document/JsonDocument.hpp create mode 100644 include/lib/ArduinoJson/Document/StaticJsonDocument.hpp create mode 100644 include/lib/ArduinoJson/Json/EscapeSequence.hpp create mode 100644 include/lib/ArduinoJson/Json/JsonDeserializer.hpp create mode 100644 include/lib/ArduinoJson/Json/JsonSerializer.hpp create mode 100644 include/lib/ArduinoJson/Json/Latch.hpp create mode 100644 include/lib/ArduinoJson/Json/PrettyJsonSerializer.hpp create mode 100644 include/lib/ArduinoJson/Json/TextFormatter.hpp create mode 100644 include/lib/ArduinoJson/Json/Utf16.hpp create mode 100644 include/lib/ArduinoJson/Json/Utf8.hpp create mode 100644 include/lib/ArduinoJson/Memory/Alignment.hpp create mode 100644 include/lib/ArduinoJson/Memory/MemoryPool.hpp create mode 100644 include/lib/ArduinoJson/Misc/SerializedValue.hpp create mode 100644 include/lib/ArduinoJson/Misc/Visitable.hpp create mode 100644 include/lib/ArduinoJson/MsgPack/MsgPackDeserializer.hpp create mode 100644 include/lib/ArduinoJson/MsgPack/MsgPackSerializer.hpp create mode 100644 include/lib/ArduinoJson/MsgPack/endianess.hpp create mode 100644 include/lib/ArduinoJson/MsgPack/ieee754.hpp create mode 100644 include/lib/ArduinoJson/Namespace.hpp create mode 100644 include/lib/ArduinoJson/Numbers/Float.hpp create mode 100644 include/lib/ArduinoJson/Numbers/FloatParts.hpp create mode 100644 include/lib/ArduinoJson/Numbers/FloatTraits.hpp create mode 100644 include/lib/ArduinoJson/Numbers/Integer.hpp create mode 100644 include/lib/ArduinoJson/Numbers/arithmeticCompare.hpp create mode 100644 include/lib/ArduinoJson/Numbers/convertNumber.hpp create mode 100644 include/lib/ArduinoJson/Numbers/parseNumber.hpp create mode 100644 include/lib/ArduinoJson/Object/MemberProxy.hpp create mode 100644 include/lib/ArduinoJson/Object/ObjectFunctions.hpp create mode 100644 include/lib/ArduinoJson/Object/ObjectImpl.hpp create mode 100644 include/lib/ArduinoJson/Object/ObjectIterator.hpp create mode 100644 include/lib/ArduinoJson/Object/ObjectRef.hpp create mode 100644 include/lib/ArduinoJson/Object/ObjectShortcuts.hpp create mode 100644 include/lib/ArduinoJson/Object/Pair.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/alias_cast.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/assert.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/attributes.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/ctype.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/integer.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/limits.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/math.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/mpl/max.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/pgmspace.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/pgmspace_generic.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/preprocessor.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/safe_strcmp.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/static_array.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/conditional.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/declval.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/enable_if.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/integral_constant.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_array.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_base_of.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_class.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_const.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_convertible.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_enum.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_integral.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_pointer.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_same.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_signed.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/make_unsigned.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/remove_const.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/remove_reference.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/type_traits/type_identity.hpp create mode 100644 include/lib/ArduinoJson/Polyfills/utility.hpp create mode 100644 include/lib/ArduinoJson/Serialization/CountingDecorator.hpp create mode 100644 include/lib/ArduinoJson/Serialization/Writer.hpp create mode 100644 include/lib/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp create mode 100644 include/lib/ArduinoJson/Serialization/Writers/DummyWriter.hpp create mode 100644 include/lib/ArduinoJson/Serialization/Writers/PrintWriter.hpp create mode 100644 include/lib/ArduinoJson/Serialization/Writers/StaticStringWriter.hpp create mode 100644 include/lib/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp create mode 100644 include/lib/ArduinoJson/Serialization/Writers/StdStringWriter.hpp create mode 100644 include/lib/ArduinoJson/Serialization/measure.hpp create mode 100644 include/lib/ArduinoJson/Serialization/serialize.hpp create mode 100644 include/lib/ArduinoJson/StringStorage/StringCopier.hpp create mode 100644 include/lib/ArduinoJson/StringStorage/StringMover.hpp create mode 100644 include/lib/ArduinoJson/StringStorage/StringStorage.hpp create mode 100644 include/lib/ArduinoJson/Strings/ArduinoStringAdapter.hpp create mode 100644 include/lib/ArduinoJson/Strings/ConstRamStringAdapter.hpp create mode 100644 include/lib/ArduinoJson/Strings/FlashStringAdapter.hpp create mode 100644 include/lib/ArduinoJson/Strings/FlashStringIterator.hpp create mode 100644 include/lib/ArduinoJson/Strings/IsString.hpp create mode 100644 include/lib/ArduinoJson/Strings/IsWriteableString.hpp create mode 100644 include/lib/ArduinoJson/Strings/RamStringAdapter.hpp create mode 100644 include/lib/ArduinoJson/Strings/SizedFlashStringAdapter.hpp create mode 100644 include/lib/ArduinoJson/Strings/SizedRamStringAdapter.hpp create mode 100644 include/lib/ArduinoJson/Strings/StdStringAdapter.hpp create mode 100644 include/lib/ArduinoJson/Strings/StoragePolicy.hpp create mode 100644 include/lib/ArduinoJson/Strings/String.hpp create mode 100644 include/lib/ArduinoJson/Strings/StringAdapters.hpp create mode 100644 include/lib/ArduinoJson/Variant/Converter.hpp create mode 100644 include/lib/ArduinoJson/Variant/ConverterImpl.hpp create mode 100644 include/lib/ArduinoJson/Variant/SlotFunctions.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantCompare.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantContent.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantData.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantFunctions.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantImpl.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantOperators.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantRef.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantShortcuts.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantSlot.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantTag.hpp create mode 100644 include/lib/ArduinoJson/Variant/VariantTo.hpp create mode 100644 include/lib/ArduinoJson/Variant/Visitor.hpp create mode 100644 include/lib/ArduinoJson/compatibility.hpp create mode 100644 include/lib/ArduinoJson/version.hpp (limited to 'include/lib') diff --git a/include/lib/ArduinoJson.h b/include/lib/ArduinoJson.h new file mode 100644 index 0000000..28d42ee --- /dev/null +++ b/include/lib/ArduinoJson.h @@ -0,0 +1,73 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include "ArduinoJson/Configuration.hpp" + +#if !ARDUINOJSON_DEBUG +#ifdef __clang__ +#pragma clang system_header +#elif defined __GNUC__ +#pragma GCC system_header +#endif +#endif + +#include "ArduinoJson/Array/ArrayRef.hpp" +#include "ArduinoJson/Object/ObjectRef.hpp" +#include "ArduinoJson/Variant/VariantRef.hpp" + +#include "ArduinoJson/Document/DynamicJsonDocument.hpp" +#include "ArduinoJson/Document/StaticJsonDocument.hpp" + +#include "ArduinoJson/Array/ArrayImpl.hpp" +#include "ArduinoJson/Array/ElementProxy.hpp" +#include "ArduinoJson/Array/Utilities.hpp" +#include "ArduinoJson/Collection/CollectionImpl.hpp" +#include "ArduinoJson/Object/MemberProxy.hpp" +#include "ArduinoJson/Object/ObjectImpl.hpp" +#include "ArduinoJson/Variant/ConverterImpl.hpp" +#include "ArduinoJson/Variant/VariantCompare.hpp" +#include "ArduinoJson/Variant/VariantImpl.hpp" + +#include "ArduinoJson/Json/JsonDeserializer.hpp" +#include "ArduinoJson/Json/JsonSerializer.hpp" +#include "ArduinoJson/Json/PrettyJsonSerializer.hpp" +#include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp" +#include "ArduinoJson/MsgPack/MsgPackSerializer.hpp" + +#include "ArduinoJson/compatibility.hpp" + +namespace ArduinoJson { +typedef ARDUINOJSON_NAMESPACE::ArrayConstRef JsonArrayConst; +typedef ARDUINOJSON_NAMESPACE::ArrayRef JsonArray; +typedef ARDUINOJSON_NAMESPACE::Float JsonFloat; +typedef ARDUINOJSON_NAMESPACE::Integer JsonInteger; +typedef ARDUINOJSON_NAMESPACE::ObjectConstRef JsonObjectConst; +typedef ARDUINOJSON_NAMESPACE::ObjectRef JsonObject; +typedef ARDUINOJSON_NAMESPACE::Pair JsonPair; +typedef ARDUINOJSON_NAMESPACE::PairConst JsonPairConst; +typedef ARDUINOJSON_NAMESPACE::String JsonString; +typedef ARDUINOJSON_NAMESPACE::UInt JsonUInt; +typedef ARDUINOJSON_NAMESPACE::VariantConstRef JsonVariantConst; +typedef ARDUINOJSON_NAMESPACE::VariantRef JsonVariant; +using ARDUINOJSON_NAMESPACE::BasicJsonDocument; +using ARDUINOJSON_NAMESPACE::copyArray; +using ARDUINOJSON_NAMESPACE::DeserializationError; +using ARDUINOJSON_NAMESPACE::deserializeJson; +using ARDUINOJSON_NAMESPACE::deserializeMsgPack; +using ARDUINOJSON_NAMESPACE::DynamicJsonDocument; +using ARDUINOJSON_NAMESPACE::JsonDocument; +using ARDUINOJSON_NAMESPACE::measureJson; +using ARDUINOJSON_NAMESPACE::serialized; +using ARDUINOJSON_NAMESPACE::serializeJson; +using ARDUINOJSON_NAMESPACE::serializeJsonPretty; +using ARDUINOJSON_NAMESPACE::serializeMsgPack; +using ARDUINOJSON_NAMESPACE::StaticJsonDocument; + +namespace DeserializationOption { +using ARDUINOJSON_NAMESPACE::Filter; +using ARDUINOJSON_NAMESPACE::NestingLimit; +} // namespace DeserializationOption +} // namespace ArduinoJson diff --git a/include/lib/ArduinoJson/Array/ArrayFunctions.hpp b/include/lib/ArduinoJson/Array/ArrayFunctions.hpp new file mode 100644 index 0000000..e7cdc4c --- /dev/null +++ b/include/lib/ArduinoJson/Array/ArrayFunctions.hpp @@ -0,0 +1,31 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +inline VariantData *arrayAdd(CollectionData *arr, MemoryPool *pool) { + return arr ? arr->addElement(pool) : 0; +} + +template +inline typename TVisitor::result_type arrayAccept(const CollectionData *arr, + TVisitor &visitor) { + if (arr) + return visitor.visitArray(*arr); + else + return visitor.visitNull(); +} + +inline bool arrayEquals(const CollectionData *lhs, const CollectionData *rhs) { + if (lhs == rhs) + return true; + if (!lhs || !rhs) + return false; + return lhs->equalsArray(*rhs); +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Array/ArrayImpl.hpp b/include/lib/ArduinoJson/Array/ArrayImpl.hpp new file mode 100644 index 0000000..ae06b20 --- /dev/null +++ b/include/lib/ArduinoJson/Array/ArrayImpl.hpp @@ -0,0 +1,28 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +inline ArrayRef ArrayShortcuts::createNestedArray() const { + return impl()->addElement().template to(); +} + +template +inline ObjectRef ArrayShortcuts::createNestedObject() const { + return impl()->addElement().template to(); +} + +template +inline ElementProxy ArrayShortcuts::operator[]( + size_t index) const { + return ElementProxy(*impl(), index); +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Array/ArrayIterator.hpp b/include/lib/ArduinoJson/Array/ArrayIterator.hpp new file mode 100644 index 0000000..fcacc6b --- /dev/null +++ b/include/lib/ArduinoJson/Array/ArrayIterator.hpp @@ -0,0 +1,121 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +class VariantPtr { + public: + VariantPtr(MemoryPool *pool, VariantData *data) : _variant(pool, data) {} + + VariantRef *operator->() { + return &_variant; + } + + VariantRef &operator*() { + return _variant; + } + + private: + VariantRef _variant; +}; + +class ArrayIterator { + public: + ArrayIterator() : _slot(0) {} + explicit ArrayIterator(MemoryPool *pool, VariantSlot *slot) + : _pool(pool), _slot(slot) {} + + VariantRef operator*() const { + return VariantRef(_pool, _slot->data()); + } + VariantPtr operator->() { + return VariantPtr(_pool, _slot->data()); + } + + bool operator==(const ArrayIterator &other) const { + return _slot == other._slot; + } + + bool operator!=(const ArrayIterator &other) const { + return _slot != other._slot; + } + + ArrayIterator &operator++() { + _slot = _slot->next(); + return *this; + } + + ArrayIterator &operator+=(size_t distance) { + _slot = _slot->next(distance); + return *this; + } + + VariantSlot *internal() { + return _slot; + } + + private: + MemoryPool *_pool; + VariantSlot *_slot; +}; + +class VariantConstPtr { + public: + VariantConstPtr(const VariantData *data) : _variant(data) {} + + VariantConstRef *operator->() { + return &_variant; + } + + VariantConstRef &operator*() { + return _variant; + } + + private: + VariantConstRef _variant; +}; + +class ArrayConstRefIterator { + public: + ArrayConstRefIterator() : _slot(0) {} + explicit ArrayConstRefIterator(const VariantSlot *slot) : _slot(slot) {} + + VariantConstRef operator*() const { + return VariantConstRef(_slot->data()); + } + VariantConstPtr operator->() { + return VariantConstPtr(_slot->data()); + } + + bool operator==(const ArrayConstRefIterator &other) const { + return _slot == other._slot; + } + + bool operator!=(const ArrayConstRefIterator &other) const { + return _slot != other._slot; + } + + ArrayConstRefIterator &operator++() { + _slot = _slot->next(); + return *this; + } + + ArrayConstRefIterator &operator+=(size_t distance) { + _slot = _slot->next(distance); + return *this; + } + + const VariantSlot *internal() { + return _slot; + } + + private: + const VariantSlot *_slot; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Array/ArrayRef.hpp b/include/lib/ArduinoJson/Array/ArrayRef.hpp new file mode 100644 index 0000000..a991db0 --- /dev/null +++ b/include/lib/ArduinoJson/Array/ArrayRef.hpp @@ -0,0 +1,205 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include + +// Returns the size (in bytes) of an array with n elements. +// Can be very handy to determine the size of a StaticMemoryPool. +#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \ + ((NUMBER_OF_ELEMENTS) * sizeof(ARDUINOJSON_NAMESPACE::VariantSlot)) + +namespace ARDUINOJSON_NAMESPACE { + +class ObjectRef; +template +class ElementProxy; + +template +class ArrayRefBase { + public: + operator VariantConstRef() const { + const void* data = _data; // prevent warning cast-align + return VariantConstRef(reinterpret_cast(data)); + } + + template + FORCE_INLINE typename TVisitor::result_type accept(TVisitor& visitor) const { + return arrayAccept(_data, visitor); + } + + FORCE_INLINE bool isNull() const { + return _data == 0; + } + + FORCE_INLINE operator bool() const { + return _data != 0; + } + + FORCE_INLINE size_t memoryUsage() const { + return _data ? _data->memoryUsage() : 0; + } + + FORCE_INLINE size_t nesting() const { + return _data ? _data->nesting() : 0; + } + + FORCE_INLINE size_t size() const { + return _data ? _data->size() : 0; + } + + protected: + ArrayRefBase(TData* data) : _data(data) {} + TData* _data; +}; + +class ArrayConstRef : public ArrayRefBase, + public Visitable { + friend class ArrayRef; + typedef ArrayRefBase base_type; + + public: + typedef ArrayConstRefIterator iterator; + + FORCE_INLINE iterator begin() const { + if (!_data) + return iterator(); + return iterator(_data->head()); + } + + FORCE_INLINE iterator end() const { + return iterator(); + } + + FORCE_INLINE ArrayConstRef() : base_type(0) {} + FORCE_INLINE ArrayConstRef(const CollectionData* data) : base_type(data) {} + + FORCE_INLINE bool operator==(ArrayConstRef rhs) const { + return arrayEquals(_data, rhs._data); + } + + FORCE_INLINE VariantConstRef operator[](size_t index) const { + return getElement(index); + } + + FORCE_INLINE VariantConstRef getElement(size_t index) const { + return VariantConstRef(_data ? _data->getElement(index) : 0); + } +}; + +class ArrayRef : public ArrayRefBase, + public ArrayShortcuts, + public Visitable { + typedef ArrayRefBase base_type; + + public: + typedef ArrayIterator iterator; + + FORCE_INLINE ArrayRef() : base_type(0), _pool(0) {} + FORCE_INLINE ArrayRef(MemoryPool* pool, CollectionData* data) + : base_type(data), _pool(pool) {} + + operator VariantRef() { + void* data = _data; // prevent warning cast-align + return VariantRef(_pool, reinterpret_cast(data)); + } + + operator ArrayConstRef() const { + return ArrayConstRef(_data); + } + + VariantRef addElement() const { + return VariantRef(_pool, arrayAdd(_data, _pool)); + } + + FORCE_INLINE iterator begin() const { + if (!_data) + return iterator(); + return iterator(_pool, _data->head()); + } + + FORCE_INLINE iterator end() const { + return iterator(); + } + + // Copy a ArrayRef + FORCE_INLINE bool set(ArrayConstRef src) const { + if (!_data || !src._data) + return false; + return _data->copyFrom(*src._data, _pool); + } + + FORCE_INLINE bool operator==(ArrayRef rhs) const { + return arrayEquals(_data, rhs._data); + } + + // Internal use + FORCE_INLINE VariantRef getOrAddElement(size_t index) const { + return VariantRef(_pool, _data ? _data->getOrAddElement(index, _pool) : 0); + } + + // Gets the value at the specified index. + FORCE_INLINE VariantRef getElement(size_t index) const { + return VariantRef(_pool, _data ? _data->getElement(index) : 0); + } + + // Removes element at specified position. + FORCE_INLINE void remove(iterator it) const { + if (!_data) + return; + _data->removeSlot(it.internal()); + } + + // Removes element at specified index. + FORCE_INLINE void remove(size_t index) const { + if (!_data) + return; + _data->removeElement(index); + } + + private: + MemoryPool* _pool; +}; + +template <> +struct Converter { + static bool toJson(VariantConstRef src, VariantRef dst) { + return variantCopyFrom(getData(dst), getData(src), getPool(dst)); + } + + static ArrayConstRef fromJson(VariantConstRef src) { + return ArrayConstRef(variantAsArray(getData(src))); + } + + static bool checkJson(VariantConstRef src) { + const VariantData* data = getData(src); + return data && data->isArray(); + } +}; + +template <> +struct Converter { + static bool toJson(VariantConstRef src, VariantRef dst) { + return variantCopyFrom(getData(dst), getData(src), getPool(dst)); + } + + static ArrayRef fromJson(VariantRef src) { + VariantData* data = getData(src); + MemoryPool* pool = getPool(src); + return ArrayRef(pool, data != 0 ? data->asArray() : 0); + } + + static bool checkJson(VariantConstRef) { + return false; + } + + static bool checkJson(VariantRef src) { + VariantData* data = getData(src); + return data && data->isArray(); + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Array/ArrayShortcuts.hpp b/include/lib/ArduinoJson/Array/ArrayShortcuts.hpp new file mode 100644 index 0000000..fd26d04 --- /dev/null +++ b/include/lib/ArduinoJson/Array/ArrayShortcuts.hpp @@ -0,0 +1,49 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { +// Forward declarations. +class ArrayRef; +class ObjectRef; +template +class ElementProxy; + +template +class ArrayShortcuts { + public: + // Returns the element at specified index if the variant is an array. + FORCE_INLINE ElementProxy operator[](size_t index) const; + + FORCE_INLINE ObjectRef createNestedObject() const; + + FORCE_INLINE ArrayRef createNestedArray() const; + + // Adds the specified value at the end of the array. + // + // bool add(TValue); + // TValue = bool, long, int, short, float, double, serialized, VariantRef, + // std::string, String, ObjectRef + template + FORCE_INLINE bool add(const T &value) const { + return impl()->addElement().set(value); + } + // + // bool add(TValue); + // TValue = char*, const char*, const __FlashStringHelper* + template + FORCE_INLINE bool add(T *value) const { + return impl()->addElement().set(value); + } + + private: + const TArray *impl() const { + return static_cast(this); + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Array/ElementProxy.hpp b/include/lib/ArduinoJson/Array/ElementProxy.hpp new file mode 100644 index 0000000..c6062e4 --- /dev/null +++ b/include/lib/ArduinoJson/Array/ElementProxy.hpp @@ -0,0 +1,193 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4522) +#endif + +namespace ARDUINOJSON_NAMESPACE { + +template +class ElementProxy : public VariantOperators >, + public VariantShortcuts >, + public Visitable, + public VariantTag { + typedef ElementProxy this_type; + + public: + typedef VariantRef variant_type; + + FORCE_INLINE ElementProxy(TArray array, size_t index) + : _array(array), _index(index) {} + + FORCE_INLINE ElementProxy(const ElementProxy& src) + : _array(src._array), _index(src._index) {} + + FORCE_INLINE this_type& operator=(const this_type& src) { + getOrAddUpstreamElement().set(src.as()); + return *this; + } + + // Replaces the value + // + // operator=(const TValue&) + // TValue = bool, long, int, short, float, double, serialized, VariantRef, + // std::string, String, ArrayRef, ObjectRef + template + FORCE_INLINE this_type& operator=(const T& src) { + getOrAddUpstreamElement().set(src); + return *this; + } + // + // operator=(TValue) + // TValue = char*, const char*, const __FlashStringHelper* + template + FORCE_INLINE this_type& operator=(T* src) { + getOrAddUpstreamElement().set(src); + return *this; + } + + FORCE_INLINE void clear() const { + getUpstreamElement().clear(); + } + + FORCE_INLINE bool isNull() const { + return getUpstreamElement().isNull(); + } + + template + FORCE_INLINE typename enable_if::value, T>::type as() + const { + return getUpstreamElement().template as(); + } + + template + FORCE_INLINE typename enable_if::value, const char*>::type + ARDUINOJSON_DEPRECATED("Replace as() with as()") + as() const { + return as(); + } + + template + FORCE_INLINE operator T() const { + return getUpstreamElement(); + } + + template + FORCE_INLINE bool is() const { + return getUpstreamElement().template is(); + } + + template + FORCE_INLINE typename VariantTo::type to() const { + return getOrAddUpstreamElement().template to(); + } + + // Replaces the value + // + // bool set(const TValue&) + // TValue = bool, long, int, short, float, double, serialized, VariantRef, + // std::string, String, ArrayRef, ObjectRef + template + FORCE_INLINE bool set(const TValue& value) const { + return getOrAddUpstreamElement().set(value); + } + // + // bool set(TValue) + // TValue = char*, const char*, const __FlashStringHelper* + template + FORCE_INLINE bool set(TValue* value) const { + return getOrAddUpstreamElement().set(value); + } + + template + typename TVisitor::result_type accept(TVisitor& visitor) const { + return getUpstreamElement().accept(visitor); + } + + FORCE_INLINE size_t size() const { + return getUpstreamElement().size(); + } + + template + VariantRef getMember(TNestedKey* key) const { + return getUpstreamElement().getMember(key); + } + + template + VariantRef getMember(const TNestedKey& key) const { + return getUpstreamElement().getMember(key); + } + + template + VariantRef getOrAddMember(TNestedKey* key) const { + return getOrAddUpstreamElement().getOrAddMember(key); + } + + template + VariantRef getOrAddMember(const TNestedKey& key) const { + return getOrAddUpstreamElement().getOrAddMember(key); + } + + VariantRef addElement() const { + return getOrAddUpstreamElement().addElement(); + } + + VariantRef getElement(size_t index) const { + return getOrAddUpstreamElement().getElement(index); + } + + VariantRef getOrAddElement(size_t index) const { + return getOrAddUpstreamElement().getOrAddElement(index); + } + + FORCE_INLINE void remove(size_t index) const { + getUpstreamElement().remove(index); + } + // remove(char*) const + // remove(const char*) const + // remove(const __FlashStringHelper*) const + template + FORCE_INLINE typename enable_if::value>::type remove( + TChar* key) const { + getUpstreamElement().remove(key); + } + // remove(const std::string&) const + // remove(const String&) const + template + FORCE_INLINE typename enable_if::value>::type remove( + const TString& key) const { + getUpstreamElement().remove(key); + } + + private: + FORCE_INLINE VariantRef getUpstreamElement() const { + return _array.getElement(_index); + } + + FORCE_INLINE VariantRef getOrAddUpstreamElement() const { + return _array.getOrAddElement(_index); + } + + friend bool convertToJson(const this_type& src, VariantRef dst) { + return dst.set(src.getUpstreamElement()); + } + + TArray _array; + const size_t _index; +}; + +} // namespace ARDUINOJSON_NAMESPACE + +#ifdef _MSC_VER +#pragma warning(pop) +#endif diff --git a/include/lib/ArduinoJson/Array/Utilities.hpp b/include/lib/ArduinoJson/Array/Utilities.hpp new file mode 100644 index 0000000..619b91d --- /dev/null +++ b/include/lib/ArduinoJson/Array/Utilities.hpp @@ -0,0 +1,133 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +// Copy a 1D array to a JsonArray +template +inline typename enable_if::value && + !is_base_of::value, + bool>::type +copyArray(T (&src)[N], const TDestination& dst) { + return copyArray(src, N, dst); +} + +// Copy a 1D array to a JsonDocument +template +inline bool copyArray(T (&src)[N], JsonDocument& dst) { + return copyArray(src, dst.to()); +} + +// Copy a 1D array to a JsonArray +template +inline typename enable_if::value && + !is_base_of::value, + bool>::type +copyArray(T* src, size_t len, const TDestination& dst) { + bool ok = true; + for (size_t i = 0; i < len; i++) { + ok &= dst.add(src[i]); + } + return ok; +} + +// Copy a 1D array to a JsonDocument +template +inline bool copyArray(T* src, size_t len, JsonDocument& dst) { + return copyArray(src, len, dst.to()); +} + +// Copy a 2D array to a JsonArray +template +inline typename enable_if::value, + bool>::type +copyArray(T (&src)[N1][N2], const TDestination& dst) { + bool ok = true; + for (size_t i = 0; i < N1; i++) { + ArrayRef nestedArray = dst.createNestedArray(); + for (size_t j = 0; j < N2; j++) { + ok &= nestedArray.add(src[i][j]); + } + } + return ok; +} + +// Copy a 2D array to a JsonDocument +template +inline bool copyArray(T (&src)[N1][N2], JsonDocument& dst) { + return copyArray(src, dst.to()); +} + +template +class ArrayCopier1D : public Visitor { + public: + ArrayCopier1D(T* destination, size_t capacity) + : _destination(destination), _capacity(capacity) {} + + size_t visitArray(const CollectionData& array) { + size_t size = 0; + VariantSlot* slot = array.head(); + + while (slot != 0 && size < _capacity) { + _destination[size++] = + Converter::fromJson(VariantConstRef(slot->data())); + slot = slot->next(); + } + return size; + } + + private: + T* _destination; + size_t _capacity; +}; + +template +class ArrayCopier2D : public Visitor { + public: + ArrayCopier2D(T (*destination)[N1][N2]) : _destination(destination) {} + + void visitArray(const CollectionData& array) { + VariantSlot* slot = array.head(); + size_t n = 0; + while (slot != 0 && n < N1) { + ArrayCopier1D copier((*_destination)[n++], N2); + variantAccept(slot->data(), copier); + slot = slot->next(); + } + } + + private: + T (*_destination)[N1][N2]; + size_t _capacity1, _capacity2; +}; + +// Copy a JsonArray to a 1D array +template +inline typename enable_if::value, size_t>::type copyArray( + const TSource& src, T (&dst)[N]) { + return copyArray(src, dst, N); +} + +// Copy a JsonArray to a 1D array +template +inline size_t copyArray(const TSource& src, T* dst, size_t len) { + ArrayCopier1D copier(dst, len); + + return src.accept(copier); +} + +// Copy a JsonArray to a 2D array +template +inline void copyArray(const TSource& src, T (&dst)[N1][N2]) { + ArrayCopier2D copier(&dst); + src.accept(copier); +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Collection/CollectionData.hpp b/include/lib/ArduinoJson/Collection/CollectionData.hpp new file mode 100644 index 0000000..d2bca45 --- /dev/null +++ b/include/lib/ArduinoJson/Collection/CollectionData.hpp @@ -0,0 +1,88 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +#include // size_t + +namespace ARDUINOJSON_NAMESPACE { + +class MemoryPool; +class VariantData; +class VariantSlot; + +class CollectionData { + VariantSlot *_head; + VariantSlot *_tail; + + public: + // Must be a POD! + // - no constructor + // - no destructor + // - no virtual + // - no inheritance + + // Array only + + VariantData *addElement(MemoryPool *pool); + + VariantData *getElement(size_t index) const; + + VariantData *getOrAddElement(size_t index, MemoryPool *pool); + + void removeElement(size_t index); + + bool equalsArray(const CollectionData &other) const; + + // Object only + + template + VariantData *addMember(TAdaptedString key, MemoryPool *pool); + + template + VariantData *getMember(TAdaptedString key) const; + + template + VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool); + + template + void removeMember(TAdaptedString key) { + removeSlot(getSlot(key)); + } + + template + bool containsKey(const TAdaptedString &key) const; + + bool equalsObject(const CollectionData &other) const; + + // Generic + + void clear(); + size_t memoryUsage() const; + size_t nesting() const; + size_t size() const; + + VariantSlot *addSlot(MemoryPool *); + void removeSlot(VariantSlot *slot); + + bool copyFrom(const CollectionData &src, MemoryPool *pool); + + VariantSlot *head() const { + return _head; + } + + void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance); + + private: + VariantSlot *getSlot(size_t index) const; + + template + VariantSlot *getSlot(TAdaptedString key) const; + + VariantSlot *getPreviousSlot(VariantSlot *) const; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Collection/CollectionImpl.hpp b/include/lib/ArduinoJson/Collection/CollectionImpl.hpp new file mode 100644 index 0000000..49a24be --- /dev/null +++ b/include/lib/ArduinoJson/Collection/CollectionImpl.hpp @@ -0,0 +1,234 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +inline bool variantEquals(const VariantData* a, const VariantData* b) { + return variantCompare(a, b) == COMPARE_RESULT_EQUAL; +} + +inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { + VariantSlot* slot = pool->allocVariant(); + if (!slot) + return 0; + + if (_tail) { + _tail->setNextNotNull(slot); + _tail = slot; + } else { + _head = slot; + _tail = slot; + } + + slot->clear(); + return slot; +} + +inline VariantData* CollectionData::addElement(MemoryPool* pool) { + return slotData(addSlot(pool)); +} + +template +inline VariantData* CollectionData::addMember(TAdaptedString key, + MemoryPool* pool) { + VariantSlot* slot = addSlot(pool); + if (!slotSetKey(slot, key, pool)) { + removeSlot(slot); + return 0; + } + return slot->data(); +} + +inline void CollectionData::clear() { + _head = 0; + _tail = 0; +} + +template +inline bool CollectionData::containsKey(const TAdaptedString& key) const { + return getSlot(key) != 0; +} + +inline bool CollectionData::copyFrom(const CollectionData& src, + MemoryPool* pool) { + clear(); + for (VariantSlot* s = src._head; s; s = s->next()) { + VariantData* var; + if (s->key() != 0) { + if (s->ownsKey()) + var = addMember(RamStringAdapter(s->key()), pool); + else + var = addMember(ConstRamStringAdapter(s->key()), pool); + } else { + var = addElement(pool); + } + if (!var) + return false; + if (!var->copyFrom(*s->data(), pool)) + return false; + } + return true; +} + +inline bool CollectionData::equalsObject(const CollectionData& other) const { + size_t count = 0; + for (VariantSlot* slot = _head; slot; slot = slot->next()) { + VariantData* v1 = slot->data(); + VariantData* v2 = other.getMember(adaptString(slot->key())); + if (!variantEquals(v1, v2)) + return false; + count++; + } + return count == other.size(); +} + +inline bool CollectionData::equalsArray(const CollectionData& other) const { + VariantSlot* s1 = _head; + VariantSlot* s2 = other._head; + for (;;) { + if (s1 == s2) + return true; + if (!s1 || !s2) + return false; + if (!variantEquals(s1->data(), s2->data())) + return false; + s1 = s1->next(); + s2 = s2->next(); + } +} + +template +inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { + VariantSlot* slot = _head; + while (slot) { + if (key.equals(slot->key())) + break; + slot = slot->next(); + } + return slot; +} + +inline VariantSlot* CollectionData::getSlot(size_t index) const { + if (!_head) + return 0; + return _head->next(index); +} + +inline VariantSlot* CollectionData::getPreviousSlot(VariantSlot* target) const { + VariantSlot* current = _head; + while (current) { + VariantSlot* next = current->next(); + if (next == target) + return current; + current = next; + } + return 0; +} + +template +inline VariantData* CollectionData::getMember(TAdaptedString key) const { + VariantSlot* slot = getSlot(key); + return slot ? slot->data() : 0; +} + +template +inline VariantData* CollectionData::getOrAddMember(TAdaptedString key, + MemoryPool* pool) { + // ignore null key + if (key.isNull()) + return 0; + + // search a matching key + VariantSlot* slot = getSlot(key); + if (slot) + return slot->data(); + + return addMember(key, pool); +} + +inline VariantData* CollectionData::getElement(size_t index) const { + VariantSlot* slot = getSlot(index); + return slot ? slot->data() : 0; +} + +inline VariantData* CollectionData::getOrAddElement(size_t index, + MemoryPool* pool) { + VariantSlot* slot = _head; + while (slot && index > 0) { + slot = slot->next(); + index--; + } + if (!slot) + index++; + while (index > 0) { + slot = addSlot(pool); + index--; + } + return slotData(slot); +} + +inline void CollectionData::removeSlot(VariantSlot* slot) { + if (!slot) + return; + VariantSlot* prev = getPreviousSlot(slot); + VariantSlot* next = slot->next(); + if (prev) + prev->setNext(next); + else + _head = next; + if (!next) + _tail = prev; +} + +inline void CollectionData::removeElement(size_t index) { + removeSlot(getSlot(index)); +} + +inline size_t CollectionData::memoryUsage() const { + size_t total = 0; + for (VariantSlot* s = _head; s; s = s->next()) { + total += sizeof(VariantSlot) + s->data()->memoryUsage(); + if (s->ownsKey()) + total += strlen(s->key()) + 1; + } + return total; +} + +inline size_t CollectionData::nesting() const { + size_t maxChildNesting = 0; + for (VariantSlot* s = _head; s; s = s->next()) { + size_t childNesting = s->data()->nesting(); + if (childNesting > maxChildNesting) + maxChildNesting = childNesting; + } + return maxChildNesting + 1; +} + +inline size_t CollectionData::size() const { + return slotSize(_head); +} + +template +inline void movePointer(T*& p, ptrdiff_t offset) { + if (!p) + return; + p = reinterpret_cast( + reinterpret_cast(reinterpret_cast(p) + offset)); + ARDUINOJSON_ASSERT(isAligned(p)); +} + +inline void CollectionData::movePointers(ptrdiff_t stringDistance, + ptrdiff_t variantDistance) { + movePointer(_head, variantDistance); + movePointer(_tail, variantDistance); + for (VariantSlot* slot = _head; slot; slot = slot->next()) + slot->movePointers(stringDistance, variantDistance); +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Configuration.hpp b/include/lib/ArduinoJson/Configuration.hpp new file mode 100644 index 0000000..0c0d4c4 --- /dev/null +++ b/include/lib/ArduinoJson/Configuration.hpp @@ -0,0 +1,255 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#if __cplusplus >= 201103L +#define ARDUINOJSON_HAS_LONG_LONG 1 +#define ARDUINOJSON_HAS_NULLPTR 1 +#define ARDUINOJSON_HAS_RVALUE_REFERENCES 1 +#else +#define ARDUINOJSON_HAS_LONG_LONG 0 +#define ARDUINOJSON_HAS_NULLPTR 0 +#define ARDUINOJSON_HAS_RVALUE_REFERENCES 0 +#endif + +#if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG +#define ARDUINOJSON_HAS_INT64 1 +#else +#define ARDUINOJSON_HAS_INT64 0 +#endif + +// Small or big machine? +#ifndef ARDUINOJSON_EMBEDDED_MODE +#if defined(ARDUINO) /* Arduino*/ \ + || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ + || defined(__XC) /* MPLAB XC compiler */ \ + || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ + || defined(__AVR) /* Atmel AVR8/GNU C Compiler */ +#define ARDUINOJSON_EMBEDDED_MODE 1 +#else +#define ARDUINOJSON_EMBEDDED_MODE 0 +#endif +#endif + +// Auto enable std::stream if the right headers are here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) +#if __has_include() && \ + __has_include() && \ + !defined(min) && \ + !defined(max) +#define ARDUINOJSON_ENABLE_STD_STREAM 1 +#else +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#endif +#endif + +// Auto enable std::string if the right header is here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) +#if __has_include() && !defined(min) && !defined(max) +#define ARDUINOJSON_ENABLE_STD_STRING 1 +#else +#define ARDUINOJSON_ENABLE_STD_STRING 0 +#endif +#endif + +#if ARDUINOJSON_EMBEDDED_MODE + +// Store floats by default to reduce the memory usage (issue #134) +#ifndef ARDUINOJSON_USE_DOUBLE +#define ARDUINOJSON_USE_DOUBLE 0 +#endif + +// Store longs by default, because they usually match the size of a float. +#ifndef ARDUINOJSON_USE_LONG_LONG +#define ARDUINOJSON_USE_LONG_LONG 0 +#endif + +// Embedded systems usually don't have std::string +#ifndef ARDUINOJSON_ENABLE_STD_STRING +#define ARDUINOJSON_ENABLE_STD_STRING 0 +#endif + +// Embedded systems usually don't have std::stream +#ifndef ARDUINOJSON_ENABLE_STD_STREAM +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#endif + +// Limit nesting as the stack is likely to be small +#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT +#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 +#endif + +// Number of bits to store the pointer to next node +// (saves RAM but limits the number of values in a document) +#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE +#if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2 +// Address space == 16-bit => max 127 values +#define ARDUINOJSON_SLOT_OFFSET_SIZE 1 +#else +// Address space > 16-bit => max 32767 values +#define ARDUINOJSON_SLOT_OFFSET_SIZE 2 +#endif +#endif + +#else // ARDUINOJSON_EMBEDDED_MODE + +// On a computer we have plenty of memory so we can use doubles +#ifndef ARDUINOJSON_USE_DOUBLE +#define ARDUINOJSON_USE_DOUBLE 1 +#endif + +// Use long long when available +#ifndef ARDUINOJSON_USE_LONG_LONG +#if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 +#define ARDUINOJSON_USE_LONG_LONG 1 +#else +#define ARDUINOJSON_USE_LONG_LONG 0 +#endif +#endif + +// On a computer, we can use std::string +#ifndef ARDUINOJSON_ENABLE_STD_STRING +#define ARDUINOJSON_ENABLE_STD_STRING 1 +#endif + +// On a computer, we can assume std::stream +#ifndef ARDUINOJSON_ENABLE_STD_STREAM +#define ARDUINOJSON_ENABLE_STD_STREAM 1 +#endif + +// On a computer, the stack is large so we can increase nesting limit +#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT +#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 +#endif + +// Number of bits to store the pointer to next node +#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE +#define ARDUINOJSON_SLOT_OFFSET_SIZE 4 +#endif + +#endif // ARDUINOJSON_EMBEDDED_MODE + +#ifdef ARDUINO + +#include + +// Enable support for Arduino's String class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING +#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +#endif + +// Enable support for Arduino's Stream class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM +#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 +#endif + +// Enable support for Arduino's Print class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT +#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1 +#endif + +#else // ARDUINO + +// Disable support for Arduino's String class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING +#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 +#endif + +// Disable support for Arduino's Stream class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM +#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 +#endif + +// Disable support for Arduino's Print class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT +#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0 +#endif + +#endif // ARDUINO + +#ifndef ARDUINOJSON_ENABLE_PROGMEM +#if defined(PROGMEM) && defined(pgm_read_byte) && defined(pgm_read_dword) && \ + defined(pgm_read_ptr) && defined(pgm_read_float) +#define ARDUINOJSON_ENABLE_PROGMEM 1 +#else +#define ARDUINOJSON_ENABLE_PROGMEM 0 +#endif +#endif + +// Convert unicode escape sequence (\u0123) to UTF-8 +#ifndef ARDUINOJSON_DECODE_UNICODE +#define ARDUINOJSON_DECODE_UNICODE 1 +#endif + +// Ignore comments in input +#ifndef ARDUINOJSON_ENABLE_COMMENTS +#define ARDUINOJSON_ENABLE_COMMENTS 0 +#endif + +// Support NaN in JSON +#ifndef ARDUINOJSON_ENABLE_NAN +#define ARDUINOJSON_ENABLE_NAN 0 +#endif + +// Support Infinity in JSON +#ifndef ARDUINOJSON_ENABLE_INFINITY +#define ARDUINOJSON_ENABLE_INFINITY 0 +#endif + +// Control the exponentiation threshold for big numbers +// CAUTION: cannot be more that 1e9 !!!! +#ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD +#define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 +#endif + +// Control the exponentiation threshold for small numbers +#ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD +#define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 +#endif + +#ifndef ARDUINOJSON_LITTLE_ENDIAN +#if defined(_MSC_VER) || \ + (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ + defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64) +#define ARDUINOJSON_LITTLE_ENDIAN 1 +#else +#define ARDUINOJSON_LITTLE_ENDIAN 0 +#endif +#endif + +#ifndef ARDUINOJSON_ENABLE_ALIGNMENT +#if defined(__AVR) +#define ARDUINOJSON_ENABLE_ALIGNMENT 0 +#else +#define ARDUINOJSON_ENABLE_ALIGNMENT 1 +#endif +#endif + +#ifndef ARDUINOJSON_TAB +#define ARDUINOJSON_TAB " " +#endif + +#ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION +#define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1 +#endif + +#ifndef ARDUINOJSON_STRING_BUFFER_SIZE +#define ARDUINOJSON_STRING_BUFFER_SIZE 32 +#endif + +#ifndef ARDUINOJSON_DEBUG +#ifdef __PLATFORMIO_BUILD_DEBUG__ +#define ARDUINOJSON_DEBUG 1 +#else +#define ARDUINOJSON_DEBUG 0 +#endif +#endif + +#if ARDUINOJSON_HAS_NULLPTR && defined(nullptr) +#error nullptr is defined as a macro. Remove the faulty #define or #undef nullptr +// See https://github.com/bblanchon/ArduinoJson/issues/1355 +#endif diff --git a/include/lib/ArduinoJson/Deserialization/DeserializationError.hpp b/include/lib/ArduinoJson/Deserialization/DeserializationError.hpp new file mode 100644 index 0000000..7b61711 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/DeserializationError.hpp @@ -0,0 +1,122 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include + +#if ARDUINOJSON_ENABLE_STD_STREAM +#include +#endif + +namespace ARDUINOJSON_NAMESPACE { + +class DeserializationError { + // safe bool idiom + typedef void (DeserializationError::*bool_type)() const; + void safeBoolHelper() const {} + + public: + enum Code { + Ok, + EmptyInput, + IncompleteInput, + InvalidInput, + NoMemory, + TooDeep + }; + + DeserializationError() {} + DeserializationError(Code c) : _code(c) {} + + // Compare with DeserializationError + friend bool operator==(const DeserializationError& lhs, + const DeserializationError& rhs) { + return lhs._code == rhs._code; + } + friend bool operator!=(const DeserializationError& lhs, + const DeserializationError& rhs) { + return lhs._code != rhs._code; + } + + // Compare with Code + friend bool operator==(const DeserializationError& lhs, Code rhs) { + return lhs._code == rhs; + } + friend bool operator==(Code lhs, const DeserializationError& rhs) { + return lhs == rhs._code; + } + friend bool operator!=(const DeserializationError& lhs, Code rhs) { + return lhs._code != rhs; + } + friend bool operator!=(Code lhs, const DeserializationError& rhs) { + return lhs != rhs._code; + } + + // Behaves like a bool + operator bool_type() const { + return _code != Ok ? &DeserializationError::safeBoolHelper : 0; + } + friend bool operator==(bool value, const DeserializationError& err) { + return static_cast(err) == value; + } + friend bool operator==(const DeserializationError& err, bool value) { + return static_cast(err) == value; + } + friend bool operator!=(bool value, const DeserializationError& err) { + return static_cast(err) != value; + } + friend bool operator!=(const DeserializationError& err, bool value) { + return static_cast(err) != value; + } + + // Returns internal enum, useful for switch statement + Code code() const { + return _code; + } + + const char* c_str() const { + static const char* messages[] = { + "Ok", "EmptyInput", "IncompleteInput", + "InvalidInput", "NoMemory", "TooDeep"}; + ARDUINOJSON_ASSERT(static_cast(_code) < + sizeof(messages) / sizeof(messages[0])); + return messages[_code]; + } + +#if ARDUINOJSON_ENABLE_PROGMEM + const __FlashStringHelper* f_str() const { + ARDUINOJSON_DEFINE_STATIC_ARRAY(char, s0, "Ok"); + ARDUINOJSON_DEFINE_STATIC_ARRAY(char, s1, "EmptyInput"); + ARDUINOJSON_DEFINE_STATIC_ARRAY(char, s2, "IncompleteInput"); + ARDUINOJSON_DEFINE_STATIC_ARRAY(char, s3, "InvalidInput"); + ARDUINOJSON_DEFINE_STATIC_ARRAY(char, s4, "NoMemory"); + ARDUINOJSON_DEFINE_STATIC_ARRAY(char, s5, "TooDeep"); + ARDUINOJSON_DEFINE_STATIC_ARRAY( + const char*, messages, ARDUINOJSON_EXPAND6({s0, s1, s2, s3, s4, s5})); + return ARDUINOJSON_READ_STATIC_ARRAY(const __FlashStringHelper*, messages, + _code); + } +#endif + + private: + Code _code; +}; + +#if ARDUINOJSON_ENABLE_STD_STREAM +inline std::ostream& operator<<(std::ostream& s, + const DeserializationError& e) { + s << e.c_str(); + return s; +} + +inline std::ostream& operator<<(std::ostream& s, DeserializationError::Code c) { + s << DeserializationError(c).c_str(); + return s; +} +#endif + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Filter.hpp b/include/lib/ArduinoJson/Deserialization/Filter.hpp new file mode 100644 index 0000000..7ea3078 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Filter.hpp @@ -0,0 +1,66 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +class Filter { + public: + explicit Filter(VariantConstRef v) : _variant(v) {} + + bool allow() const { + return _variant; + } + + bool allowArray() const { + return _variant == true || _variant.is(); + } + + bool allowObject() const { + return _variant == true || _variant.is(); + } + + bool allowValue() const { + return _variant == true; + } + + template + Filter operator[](const TKey& key) const { + if (_variant == true) // "true" means "allow recursively" + return *this; + else + return Filter(_variant[key] | _variant["*"]); + } + + private: + VariantConstRef _variant; +}; + +struct AllowAllFilter { + bool allow() const { + return true; + } + + bool allowArray() const { + return true; + } + + bool allowObject() const { + return true; + } + + bool allowValue() const { + return true; + } + + template + AllowAllFilter operator[](const TKey&) const { + return AllowAllFilter(); + } +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/NestingLimit.hpp b/include/lib/ArduinoJson/Deserialization/NestingLimit.hpp new file mode 100644 index 0000000..06964b4 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/NestingLimit.hpp @@ -0,0 +1,29 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +class NestingLimit { + public: + NestingLimit() : _value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {} + explicit NestingLimit(uint8_t n) : _value(n) {} + + NestingLimit decrement() const { + ARDUINOJSON_ASSERT(_value > 0); + return NestingLimit(static_cast(_value - 1)); + } + + bool reached() const { + return _value == 0; + } + + private: + uint8_t _value; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Reader.hpp b/include/lib/ArduinoJson/Deserialization/Reader.hpp new file mode 100644 index 0000000..e965c82 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Reader.hpp @@ -0,0 +1,56 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +#include // for size_t + +namespace ARDUINOJSON_NAMESPACE { + +// The default reader is a simple wrapper for Readers that are not copiable +template +struct Reader { + public: + Reader(TSource& source) : _source(&source) {} + + int read() { + return _source->read(); + } + + size_t readBytes(char* buffer, size_t length) { + return _source->readBytes(buffer, length); + } + + private: + TSource* _source; +}; + +template +struct BoundedReader { + // no default implementation because we need to pass the size to the + // constructor +}; +} // namespace ARDUINOJSON_NAMESPACE + +#include +#include +#include + +#if ARDUINOJSON_ENABLE_ARDUINO_STREAM +#include +#endif + +#if ARDUINOJSON_ENABLE_ARDUINO_STRING +#include +#endif + +#if ARDUINOJSON_ENABLE_PROGMEM +#include +#endif + +#if ARDUINOJSON_ENABLE_STD_STREAM +#include +#endif diff --git a/include/lib/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp b/include/lib/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp new file mode 100644 index 0000000..724638f --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp @@ -0,0 +1,31 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> { + public: + explicit Reader(Stream& stream) : _stream(&stream) {} + + int read() { + // don't use _stream.read() as it ignores the timeout + char c; + return _stream->readBytes(&c, 1) ? static_cast(c) : -1; + } + + size_t readBytes(char* buffer, size_t length) { + return _stream->readBytes(buffer, length); + } + + private: + Stream* _stream; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp b/include/lib/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp new file mode 100644 index 0000000..71571d4 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp @@ -0,0 +1,17 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> + : BoundedReader { + explicit Reader(const ::String& s) + : BoundedReader(s.c_str(), s.length()) {} +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/include/lib/ArduinoJson/Deserialization/Readers/FlashReader.hpp new file mode 100644 index 0000000..7eca134 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -0,0 +1,53 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template <> +struct Reader { + const char* _ptr; + + public: + explicit Reader(const __FlashStringHelper* ptr) + : _ptr(reinterpret_cast(ptr)) {} + + int read() { + return pgm_read_byte(_ptr++); + } + + size_t readBytes(char* buffer, size_t length) { + memcpy_P(buffer, _ptr, length); + _ptr += length; + return length; + } +}; + +template <> +struct BoundedReader { + const char* _ptr; + const char* _end; + + public: + explicit BoundedReader(const __FlashStringHelper* ptr, size_t size) + : _ptr(reinterpret_cast(ptr)), _end(_ptr + size) {} + + int read() { + if (_ptr < _end) + return pgm_read_byte(_ptr++); + else + return -1; + } + + size_t readBytes(char* buffer, size_t length) { + size_t available = static_cast(_end - _ptr); + if (available < length) + length = available; + memcpy_P(buffer, _ptr, length); + _ptr += length; + return length; + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Readers/IteratorReader.hpp b/include/lib/ArduinoJson/Deserialization/Readers/IteratorReader.hpp new file mode 100644 index 0000000..37c3c31 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Readers/IteratorReader.hpp @@ -0,0 +1,43 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template +class IteratorReader { + TIterator _ptr, _end; + + public: + explicit IteratorReader(TIterator begin, TIterator end) + : _ptr(begin), _end(end) {} + + int read() { + if (_ptr < _end) + return static_cast(*_ptr++); + else + return -1; + } + + size_t readBytes(char* buffer, size_t length) { + size_t i = 0; + while (i < length && _ptr < _end) buffer[i++] = *_ptr++; + return i; + } +}; + +template +struct void_ { + typedef void type; +}; + +template +struct Reader::type> + : IteratorReader { + explicit Reader(const TSource& source) + : IteratorReader(source.begin(), + source.end()) {} +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Readers/RamReader.hpp b/include/lib/ArduinoJson/Deserialization/Readers/RamReader.hpp new file mode 100644 index 0000000..67cf682 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Readers/RamReader.hpp @@ -0,0 +1,50 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct IsCharOrVoid { + static const bool value = + is_same::value || is_same::value || + is_same::value || is_same::value; +}; + +template +struct IsCharOrVoid : IsCharOrVoid {}; + +template +struct Reader::value>::type> { + const char* _ptr; + + public: + explicit Reader(const void* ptr) + : _ptr(ptr ? reinterpret_cast(ptr) : "") {} + + int read() { + return static_cast(*_ptr++); + } + + size_t readBytes(char* buffer, size_t length) { + for (size_t i = 0; i < length; i++) buffer[i] = *_ptr++; + return length; + } +}; + +template +struct BoundedReader::value>::type> + : public IteratorReader { + public: + explicit BoundedReader(const void* ptr, size_t len) + : IteratorReader(reinterpret_cast(ptr), + reinterpret_cast(ptr) + len) {} +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp b/include/lib/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp new file mode 100644 index 0000000..eebaa2c --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp @@ -0,0 +1,29 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> { + public: + explicit Reader(std::istream& stream) : _stream(&stream) {} + + int read() { + return _stream->get(); + } + + size_t readBytes(char* buffer, size_t length) { + _stream->read(buffer, static_cast(length)); + return static_cast(_stream->gcount()); + } + + private: + std::istream* _stream; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/Readers/VariantReader.hpp b/include/lib/ArduinoJson/Deserialization/Readers/VariantReader.hpp new file mode 100644 index 0000000..e56e262 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/Readers/VariantReader.hpp @@ -0,0 +1,34 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader, void> : Reader { + explicit Reader(const ElementProxy& x) + : Reader(x.template as()) {} +}; + +template +struct Reader, void> : Reader { + explicit Reader(const MemberProxy& x) + : Reader(x.template as()) {} +}; + +template <> +struct Reader : Reader { + explicit Reader(VariantRef x) : Reader(x.as()) {} +}; + +template <> +struct Reader : Reader { + explicit Reader(VariantConstRef x) + : Reader(x.as()) {} +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Deserialization/deserialize.hpp b/include/lib/ArduinoJson/Deserialization/deserialize.hpp new file mode 100644 index 0000000..2329542 --- /dev/null +++ b/include/lib/ArduinoJson/Deserialization/deserialize.hpp @@ -0,0 +1,71 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template