#include "ThingMsg.h" namespace Passer { namespace Control { ThingMsg::ThingMsg(const char *buffer) { unsigned char ix = 1; // first byte is msg id this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; this->thingType = buffer[ix++]; this->parentId = buffer[ix++]; } ThingMsg::ThingMsg(unsigned char networkId, Thing *thing) { this->networkId = networkId; this->thingId = thing->id; this->thingType = thing->type; Thing *parent = thing->GetParent(); if (parent != nullptr) this->parentId = parent->id; else this->parentId = 0; } // ThingMsg::ThingMsg(unsigned char networkId, unsigned char thingId, // unsigned char thingType, unsigned char parentId) { // this->networkId = networkId; // this->thingId = thingId; // this->thingType = thingType; // this->parentId = parentId; // } unsigned char ThingMsg::Serialize(char *buffer) { unsigned char ix = 0; buffer[ix++] = this->id; buffer[ix++] = this->networkId; buffer[ix++] = this->thingId; buffer[ix++] = this->thingType; buffer[ix++] = this->parentId; return ix; } } // namespace Control } // namespace Passer