forked from xively/xively_arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXivelyDatastream.h
52 lines (45 loc) · 1.42 KB
/
XivelyDatastream.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
#ifndef XIVELY_DATASTREAM_H
#define XIVELY_DATASTREAM_H
#include <Stream.h>
#include <Printable.h>
#define DATASTREAM_STRING 0
#define DATASTREAM_BUFFER 1
#define DATASTREAM_INT 2
#define DATASTREAM_FLOAT 3
class XivelyDatastream : public Printable {
friend class XivelyClient;
typedef struct {
char* _buffer;
int _bufferSize;
} tBuffer;
public:
XivelyDatastream(String& aId, int aType);
XivelyDatastream(char* aIdBuffer, int aIdBufferLength, int aType);
XivelyDatastream(char* aIdBuffer, int aIdBufferLength, int aType, char* aValueBuffer, int aValueBufferLength);
int updateValue(Stream& aStream);
void setInt(int aValue);
void setFloat(float aValue);
void setString(String& aValue);
void setBuffer(const char* aValue);
String& getString();
int getInt();
float getFloat();
char* getBuffer();
virtual size_t printTo(Print&) const;
protected:
int idLength() { return (_idType == DATASTREAM_STRING ? _idString.length() : strlen(_idBuffer._buffer)); };
char idChar(int idx) { return (_idType == DATASTREAM_STRING ? _idString[idx] : (idx > strlen(_idBuffer._buffer) ? '\0' : _idBuffer._buffer[idx])); };
// FIXME Only needed until readStringUntil is available in core
int timedRead(Stream& aStream);
int _idType;
String _idString;
tBuffer _idBuffer;
int _valueType;
String _valueString;
union {
tBuffer _valueBuffer;
int _valueInt;
float _valueFloat;
} _value;
};
#endif