G.U.L.L.S/include/StreamEvent.h

57 lines
1.1 KiB
C++

#ifndef STREAMEVENT_H
#define STREAMEVENT_H
#include "Arduino.h"
class StreamEvent
{
public:
StreamEvent(Stream* _readFrom) {
handled = false;
code = _readFrom->read();
flags = _readFrom->read();
if (flags & 0x01 == 1) {
uint16_t payloadSizeMSB = _readFrom->read() << 8;
payloadSize == payloadSizeMSB | _readFrom->read();
payload = new byte[payloadSize];
_readFrom->readBytes(payload, payloadSize);
} else {
payloadSize = 0;
payload = NULL;
}
}
virtual ~StreamEvent() { delete[] payload; }
void markHandled() { handled = true; }
uint8_t getCode() { return code; }
uint16_t getPayloadSize() { return payloadSize; }
byte* getPayload() { return payload; }
bool isHandled() { return handled; }
bool isResponse() { return flags & 0x02 == 2; }
bool isDescribeRequest() { return flags & 0x04 == 4; }
virtual ~StreamEvent() { delete[] payload; }
private:
byte*
payload;
uint16_t
payloadSize;
uint8_t
code,
flags;
bool
handled;
};
#endif