#include "PixelMessage.h" #include "PixelBot.h" #include PixelMessage::PixelMessage() { ProtocolVersion = PixelBot::PROTOCOL_VERSION; } PixelMessage::PixelMessage(byte* rawMessage) : PixelMessage() { // Casting solution from http://stackoverflow.com/a/300837/1460422 // Basically, it casts a byte* pointer reference to the start of the bit we want to extract // into a void* (which is just a point that points to a specific point in memory without a // specific type associated with it), which we then cast into a pointer of the type we // actually want. This extra step is needed to get it to cast multiple consecutive bytes // in the raw message into the type we want. // With the casts done, we simply dereference the pointer to shove the value into the // instance of this class that we're building. ProtocolVersion = *(static_cast(static_cast(rawMessage))); MessageType = *(static_cast(static_cast(rawMessage + 2))); MessageId = *(static_cast(static_cast(rawMessage + 4))); MessageLength = *(static_cast(static_cast(rawMessage + 8))); // TODO: Sort out the payload here. } PixelMessage::~PixelMessage() { }