#include "BinaryMsg.h" namespace Passer { namespace RoboidControl { BinaryMsg::BinaryMsg(char *buffer) { unsigned char ix = 1; this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; this->bytes = buffer + ix; // This is only valid because the code ensures the the msg // lifetime is shorter than the buffer lifetime... } BinaryMsg::BinaryMsg(unsigned char networkId, Thing *thing) { this->networkId = networkId; this->thingId = thing->id; this->thing = thing; } BinaryMsg::~BinaryMsg() {} unsigned char BinaryMsg::Serialize(char *buffer) { unsigned char ix = this->length; this->thing->GenerateBinary(buffer, &ix); if (ix <= this->length) // in this case, no data is actually sent return 0; buffer[0] = this->id; buffer[1] = this->networkId; buffer[2] = this->thingId; return ix; } BinaryMsg BinaryMsg::Receive(char *buffer, unsigned char bufferSize) { BinaryMsg msg = BinaryMsg(buffer); return msg; } } // namespace RoboidControl } // namespace Passer