-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferedInputStream.cpp
More file actions
60 lines (47 loc) · 1.12 KB
/
Copy pathBufferedInputStream.cpp
File metadata and controls
60 lines (47 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
BufferedStream
Philippe Rochat, 2017, Philippe.Rochat'at'gmail.com
*/
#include "BufferedInputStream.h"
BufferedInputStream::BufferedInputStream(uint8_t *buffer, const uint16_t size) {
this->size = size;
this->buffer = buffer;
pos = 0;
buffer_overflow = (size > 0 ? true: false);
}
int BufferedInputStream::read() {
if (pos >= size) {
buffer_overflow = true;
return -1;
}
return buffer[pos++];
}
size_t BufferedInputStream::readBytes(char * buf, size_t length) {
int i;
for(i=0; i<length && pos<size; i++, pos++) {
buf[i] = buffer[pos];
}
if(pos>=size) buffer_overflow = true;
return i-1;
}
size_t BufferedInputStream::readBytesUntil( char terminator, char *buf, size_t length) {
int i;
for(i=0; i<length && pos<size; i++, pos++) {
buf[i] = buffer[pos];
if(buf[i] == terminator) {
i++; pos++;
break;
}
}
if(pos>=size) buffer_overflow = true;
return i-1;
}
String BufferedInputStream::readString() {
int strl = strlen(&buffer[pos]);
if(pos+strl>size) {
return String("");
}
pos+=strlen+1;
if(pos>=size) buffer_overflow = true;
return String((char *)&buffer[pos]);
}