summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/Misc/SerializedValue.hpp
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-05-12 09:12:09 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2021-05-12 09:12:09 +0200
commit39895a677e5d370824e702cfe90ebc67737b8482 (patch)
treeff5b4cc9e373d33a795d50d9333e05549bd9f2b8 /include/lib/ArduinoJson/Misc/SerializedValue.hpp
parent42e7fdf01c3a5701bb51e93ad6c650c3dbbc5450 (diff)
import ArduinoJson 6.18.0
Diffstat (limited to 'include/lib/ArduinoJson/Misc/SerializedValue.hpp')
-rw-r--r--include/lib/ArduinoJson/Misc/SerializedValue.hpp68
1 files changed, 68 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