-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathTestDirectClient.h
80 lines (64 loc) · 1.32 KB
/
TestDirectClient.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <Arduino.h>
#include <Client.h>
#include <string>
class TestDirectClient : public Client
{
private:
std::string toSend;
public:
TestDirectClient(std::string RESPtoSend) : toSend(RESPtoSend) {}
int connect(IPAddress ip, uint16_t port)
{
(void)ip;
(void)port;
return 42;
}
int connect(const char *host, uint16_t port)
{
(void)host;
(void)port;
return 42;
}
size_t write(uint8_t val)
{
(void)val;
return 0;
}
size_t write(const uint8_t *buf, size_t size)
{
(void)buf;
(void)size;
return 0;
}
int available() { return toSend.size(); }
int read()
{
auto retval = toSend.at(0);
toSend = toSend.substr(1, std::string::npos);
return retval;
}
int read(uint8_t *buf, size_t size)
{
if (size > toSend.size())
{
size = toSend.size();
}
::memcpy(buf, toSend.c_str(), size);
toSend = toSend.substr(size, std::string::npos);
return size;
}
int peek()
{
return toSend.size() ? toSend.at(0) : -1;
}
void flush() {}
void stop() {}
uint8_t connected()
{
return operator bool();
}
virtual operator bool()
{
return 1;
}
};