FlashStringReader.hpp
Go to the documentation of this file.
1 // ArduinoJson - arduinojson.org
2 // Copyright Benoit Blanchon 2014-2019
3 // MIT License
4 //
5 // Sming FlashString reader mikee47 Nov 2019 <mike@sillyhouse.net>
6 
7 #pragma once
8 
10 {
11 template <> struct Reader<FlashString, void> {
12  explicit Reader(const FlashString& str) : str(str)
13  {
14  }
15 
16  int read()
17  {
18  if(index >= str.length()) {
19  return -1;
20  }
21  unsigned char c = str[index];
22  ++index;
23  return c;
24  }
25 
26  size_t readBytes(char* buffer, size_t length)
27  {
28  auto count = str.read(index, buffer, length);
29  index += count;
30  return count;
31  }
32 
33 private:
34  const FlashString& str;
35  unsigned index = 0;
36 };
37 
38 } // namespace ARDUINOJSON_NAMESPACE
describes a counted string stored in flash memory
Definition: String.hpp:173
#define str(s)
Definition: testrunner.h:124
size_t readBytes(char *buffer, size_t length)
Definition: FlashStringReader.hpp:26
Definition: FlashStringReader.hpp:9
Reader(const FlashString &str)
Definition: FlashStringReader.hpp:12
int read()
Definition: FlashStringReader.hpp:16