Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
LimitedMemoryStream.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  * LimitedMemoryStream.h
8  *
9  ****/
10 
11 #ifndef _SMING_CORE_DATA_STREAM_LIMITED_MEMORY_STREAM_H_
12 #define _SMING_CORE_DATA_STREAM_LIMITED_MEMORY_STREAM_H_
13 
14 #include "ReadWriteStream.h"
15 
25 {
26 public:
27  LimitedMemoryStream(size_t length) : buffer(new uint8_t[length]), length(length)
28  {
29  }
30 
32  {
33  delete[] buffer;
34  }
35 
36  //Use base class documentation
37  StreamType getStreamType() const override
38  {
39  return eSST_Memory;
40  }
41 
46  int available() override
47  {
48  return writePos - readPos;
49  }
50 
51  uint16_t readMemoryBlock(char* data, int bufSize) override;
52 
53  //Use base class documentation
54  bool seek(int len) override;
55 
61  size_t write(const uint8_t* buffer, size_t size) override;
62 
63  bool isFinished() override
64  {
65  return (readPos >= length);
66  }
67 
68 private:
69  uint8_t* buffer = nullptr;
70  size_t writePos = 0;
71  size_t readPos = 0;
72  size_t length = 0;
73 };
74 
76 #endif /* _SMING_CORE_DATA_STREAM_LIMITED_MEMORY_STREAM_H_ */
StreamType getStreamType() const override
Get the stream type.
Definition: LimitedMemoryStream.h:37
Memory data stream.
Definition: DataSourceStream.h:24
uint16_t readMemoryBlock(char *data, int bufSize) override
Read a block of memory.
int available() override
Return the total length of the stream.
Definition: LimitedMemoryStream.h:46
bool seek(int len) override
Move read cursor.
size_t write(const uint8_t *buffer, size_t size) override
Write chars to stream.
StreamType
Data stream type.
Definition: DataSourceStream.h:22
bool isFinished() override
Check if all data has been read.
Definition: LimitedMemoryStream.h:63
Memory stream that stores limited number of bytes Once the limit is reached the stream will discard i...
Definition: LimitedMemoryStream.h:24
Base class for read/write stream.
Definition: ReadWriteStream.h:23
int length() SMING_DEPRECATED
Return the total length of the stream.
Definition: DataSourceStream.h:114