summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/Deserialization/Readers/IteratorReader.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/lib/ArduinoJson/Deserialization/Readers/IteratorReader.hpp')
-rw-r--r--include/lib/ArduinoJson/Deserialization/Readers/IteratorReader.hpp43
1 files changed, 43 insertions, 0 deletions
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 <typename TIterator>
+class IteratorReader {
+ TIterator _ptr, _end;
+
+ public:
+ explicit IteratorReader(TIterator begin, TIterator end)
+ : _ptr(begin), _end(end) {}
+
+ int read() {
+ if (_ptr < _end)
+ return static_cast<unsigned char>(*_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 <typename T>
+struct void_ {
+ typedef void type;
+};
+
+template <typename TSource>
+struct Reader<TSource, typename void_<typename TSource::const_iterator>::type>
+ : IteratorReader<typename TSource::const_iterator> {
+ explicit Reader(const TSource& source)
+ : IteratorReader<typename TSource::const_iterator>(source.begin(),
+ source.end()) {}
+};
+} // namespace ARDUINOJSON_NAMESPACE