45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
namespace Passer.Control.Core {
|
|
|
|
public class ThingMsg : IMessage {
|
|
public const byte length = 5;
|
|
public const byte id = 0x80;
|
|
public byte networkId;
|
|
public byte thingId;
|
|
public byte thingType;
|
|
public byte parentId;
|
|
|
|
public ThingMsg(byte networkId, Thing thing) {
|
|
this.networkId = networkId;
|
|
this.thingId = thing.id;
|
|
this.thingType = thing.type;
|
|
if (thing.parent != null)
|
|
this.parentId = thing.parent.id;
|
|
else
|
|
this.parentId = 0;
|
|
}
|
|
public ThingMsg(byte networkId, byte thingId, byte thingType, byte parentId) {
|
|
this.networkId = networkId;
|
|
this.thingId = thingId;
|
|
this.thingType = thingType;
|
|
this.parentId = parentId;
|
|
}
|
|
public ThingMsg(byte[] buffer) {
|
|
uint ix = 1;
|
|
this.networkId = buffer[ix++];
|
|
this.thingId = buffer[ix++];
|
|
this.thingType = buffer[ix++];
|
|
this.parentId = buffer[ix];
|
|
}
|
|
|
|
public override byte Serialize(ref byte[] buffer) {
|
|
byte ix = 0;
|
|
buffer[ix++] = ThingMsg.id;
|
|
buffer[ix++] = this.networkId;
|
|
buffer[ix++] = this.thingId;
|
|
buffer[ix++] = this.thingType;
|
|
buffer[ix++] = this.parentId;
|
|
return ThingMsg.length;
|
|
}
|
|
}
|
|
|
|
} |