diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2021-05-12 09:12:09 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2021-05-12 09:12:09 +0200 |
commit | 39895a677e5d370824e702cfe90ebc67737b8482 (patch) | |
tree | ff5b4cc9e373d33a795d50d9333e05549bd9f2b8 /include/lib/ArduinoJson/Misc | |
parent | 42e7fdf01c3a5701bb51e93ad6c650c3dbbc5450 (diff) |
import ArduinoJson 6.18.0
Diffstat (limited to 'include/lib/ArduinoJson/Misc')
-rw-r--r-- | include/lib/ArduinoJson/Misc/SerializedValue.hpp | 68 | ||||
-rw-r--r-- | include/lib/ArduinoJson/Misc/Visitable.hpp | 21 |
2 files changed, 89 insertions, 0 deletions
diff --git a/include/lib/ArduinoJson/Misc/SerializedValue.hpp b/include/lib/ArduinoJson/Misc/SerializedValue.hpp new file mode 100644 index 0000000..30173bf --- /dev/null +++ b/include/lib/ArduinoJson/Misc/SerializedValue.hpp @@ -0,0 +1,68 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Strings/StringAdapters.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +// A special type of data that can be used to insert pregenerated JSON portions. +template <typename T> +class SerializedValue { + public: + explicit SerializedValue(T str) : _str(str) {} + operator T() const { + return _str; + } + + const char* data() const { + return _str.c_str(); + } + + size_t size() const { + // CAUTION: the old Arduino String doesn't have size() + return _str.length(); + } + + private: + T _str; +}; + +template <typename TChar> +class SerializedValue<TChar*> { + public: + explicit SerializedValue(TChar* p, size_t n) : _data(p), _size(n) {} + operator TChar*() const { + return _data; + } + + TChar* data() const { + return _data; + } + + size_t size() const { + return _size; + } + + private: + TChar* _data; + size_t _size; +}; + +template <typename T> +inline SerializedValue<T> serialized(T str) { + return SerializedValue<T>(str); +} + +template <typename TChar> +inline SerializedValue<TChar*> serialized(TChar* p) { + return SerializedValue<TChar*>(p, adaptString(p).size()); +} + +template <typename TChar> +inline SerializedValue<TChar*> serialized(TChar* p, size_t n) { + return SerializedValue<TChar*>(p, n); +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/include/lib/ArduinoJson/Misc/Visitable.hpp b/include/lib/ArduinoJson/Misc/Visitable.hpp new file mode 100644 index 0000000..f25d12f --- /dev/null +++ b/include/lib/ArduinoJson/Misc/Visitable.hpp @@ -0,0 +1,21 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include <ArduinoJson/Polyfills/type_traits.hpp> + +namespace ARDUINOJSON_NAMESPACE { + +struct Visitable { + // template<Visitor> + // void accept(Visitor&) const; +}; + +template <typename T> +struct IsVisitable : is_base_of<Visitable, T> {}; + +template <typename T> +struct IsVisitable<T &> : IsVisitable<T> {}; +} // namespace ARDUINOJSON_NAMESPACE |