/src/arduinojson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp
Line | Count | Source |
1 | | // ArduinoJson - https://arduinojson.org |
2 | | // Copyright © 2014-2025, Benoit BLANCHON |
3 | | // MIT License |
4 | | |
5 | | #pragma once |
6 | | |
7 | | #include <ArduinoJson/Polyfills/type_traits.hpp> |
8 | | |
9 | | ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE |
10 | | |
11 | | template <typename T> |
12 | | struct IsCharOrVoid { |
13 | | static const bool value = |
14 | | is_same<T, void>::value || is_same<T, char>::value || |
15 | | is_same<T, unsigned char>::value || is_same<T, signed char>::value; |
16 | | }; |
17 | | |
18 | | template <typename T> |
19 | | struct IsCharOrVoid<const T> : IsCharOrVoid<T> {}; |
20 | | |
21 | | template <typename TSource> |
22 | | struct Reader<TSource*, enable_if_t<IsCharOrVoid<TSource>::value>> { |
23 | | const char* ptr_; |
24 | | |
25 | | public: |
26 | | explicit Reader(const void* ptr) |
27 | | : ptr_(ptr ? reinterpret_cast<const char*>(ptr) : "") {} |
28 | | |
29 | | int read() { |
30 | | return static_cast<unsigned char>(*ptr_++); |
31 | | } |
32 | | |
33 | | size_t readBytes(char* buffer, size_t length) { |
34 | | for (size_t i = 0; i < length; i++) |
35 | | buffer[i] = *ptr_++; |
36 | | return length; |
37 | | } |
38 | | }; |
39 | | |
40 | | template <typename TSource> |
41 | | struct BoundedReader<TSource*, enable_if_t<IsCharOrVoid<TSource>::value>> |
42 | | : public IteratorReader<const char*> { |
43 | | public: |
44 | | explicit BoundedReader(const void* ptr, size_t len) |
45 | 4.44k | : IteratorReader<const char*>(reinterpret_cast<const char*>(ptr), |
46 | 4.44k | reinterpret_cast<const char*>(ptr) + len) {} |
47 | | }; |
48 | | |
49 | | ARDUINOJSON_END_PRIVATE_NAMESPACE |