43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include "NameMsg.h"
|
|
|
|
namespace Passer {
|
|
namespace Control {
|
|
|
|
NameMsg::NameMsg(const char *buffer) {
|
|
unsigned char ix = 1; // first byte is msg id
|
|
this->networkId = buffer[ix++];
|
|
this->thingId = buffer[ix++];
|
|
this->nameLength = buffer[ix++];
|
|
this->name = &buffer[ix]; // dangerous! name should not be used anymore after
|
|
// buffer has been re-used...
|
|
}
|
|
|
|
NameMsg::NameMsg(unsigned char networkId, Thing *thing) {
|
|
this->networkId = networkId;
|
|
this->thingId = thing->id;
|
|
this->nameLength = strlen(thing->name);
|
|
this->name = thing->name; // dangerous!
|
|
}
|
|
|
|
// NameMsg::NameMsg(unsigned char networkId, unsigned char thingId,
|
|
// const char *name, unsigned char nameLength) {
|
|
// this->networkId = networkId;
|
|
// this->thingId = thingId;
|
|
// this->name = name;
|
|
// this->nameLength = nameLength;
|
|
// }
|
|
|
|
unsigned char NameMsg::Serialize(char *buffer) {
|
|
unsigned char ix = 0;
|
|
buffer[ix++] = this->id;
|
|
buffer[ix++] = this->networkId;
|
|
buffer[ix++] = this->thingId;
|
|
buffer[ix++] = this->nameLength;
|
|
for (int nameIx = 0; nameIx < this->nameLength; nameIx++)
|
|
buffer[ix++] = this->name[nameIx];
|
|
|
|
return ix;
|
|
}
|
|
|
|
} // namespace Control
|
|
} // namespace Passer
|