summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/Misc
diff options
context:
space:
mode:
Diffstat (limited to 'include/lib/ArduinoJson/Misc')
-rw-r--r--include/lib/ArduinoJson/Misc/SerializedValue.hpp68
-rw-r--r--include/lib/ArduinoJson/Misc/Visitable.hpp21
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