Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
DataSourceStream.h
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/anakod/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * DataSourceStream.h
8  *
9  ****/
10 
11 #ifndef _SMING_CORE_DATA_STREAM_DATA_SOURCE_STREAM_H_
12 #define _SMING_CORE_DATA_STREAM_DATA_SOURCE_STREAM_H_
13 
14 #include <user_config.h>
15 #include "Stream.h"
16 #include "WString.h"
17 
22 enum StreamType {
30 };
38 class IDataSourceStream : public Stream
40 {
41 public:
45  virtual StreamType getStreamType() const
46  {
47  return eSST_Unknown;
48  }
49 
55  virtual bool isValid() const
56  {
57  return getStreamType() != eSST_Invalid;
58  }
59 
66  virtual uint16_t readMemoryBlock(char* data, int bufSize) = 0;
67 
72  int read() override;
73 
78  int peek() override;
79 
84  virtual bool seek(int len) = 0;
85 
89  virtual bool isFinished() = 0;
90 
95  virtual int available()
96  {
97  return -1;
98  }
99 
100  /*
101  * From Stream class: We don't write using this stream
102  */
103  size_t write(uint8_t charToWrite) override
104  {
105  return 0;
106  }
107 
114  int length() SMING_DEPRECATED
115  {
116  return available();
117  }
118 
119  /*
120  * @brief Flushes the stream
121  */
122  void flush() override
123  {
124  }
125 
130  virtual String id() const
131  {
132  return nullptr;
133  }
134 
140  virtual String getName() const
141  {
142  return nullptr;
143  }
144 };
145 
147 #endif /* _SMING_CORE_DATA_STREAM_DATA_SOURCE_STREAM_H_ */
virtual bool isValid() const
Determine if the stream object contains valid data.
Definition: DataSourceStream.h:55
Memory data stream.
Definition: DataSourceStream.h:24
Base class for data source stream.
Definition: DataSourceStream.h:39
int read() override
Read one character and moves the stream pointer.
virtual bool isFinished()=0
Check if all data has been read.
virtual uint16_t readMemoryBlock(char *data, int bufSize)=0
Read a block of memory.
The string class.
Definition: WString.h:104
JSON object data stream.
Definition: DataSourceStream.h:27
virtual bool seek(int len)=0
Move read cursor.
Unknown data stream type.
Definition: DataSourceStream.h:29
virtual String id() const
Returns unique id of the resource.
Definition: DataSourceStream.h:130
virtual StreamType getStreamType() const
Get the stream type.
Definition: DataSourceStream.h:45
StreamType
Data stream type.
Definition: DataSourceStream.h:22
File data stream.
Definition: DataSourceStream.h:25
Template data stream.
Definition: DataSourceStream.h:26
Stream content not valid.
Definition: DataSourceStream.h:23
int peek() override
Read a character without advancing the stream pointer.
size_t write(uint8_t charToWrite) override
Writes a single character to output stream.
Definition: DataSourceStream.h:103
User defined data stream.
Definition: DataSourceStream.h:28
virtual int available()
Return the total length of the stream.
Definition: DataSourceStream.h:95
int length() SMING_DEPRECATED
Return the total length of the stream.
Definition: DataSourceStream.h:114
virtual String getName() const
Returns name of the resource.
Definition: DataSourceStream.h:140
Definition: Stream.h:30