48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
#nullable enable
|
|
|
|
namespace Passer.Control.Core {
|
|
|
|
public class ModelUrlMsg : IMessage {
|
|
public const byte Id = 0x90; // (144) Model URL
|
|
public const byte length = 4;
|
|
public byte networkId;
|
|
public byte thingId;
|
|
public string? url = null;
|
|
|
|
public ModelUrlMsg(byte networkId, Thing thing) {
|
|
this.networkId = networkId;
|
|
this.thingId = thing.id;
|
|
this.url = thing.modelUrl;
|
|
}
|
|
public ModelUrlMsg(byte networkId, byte thingId, string url, float scale = 1) {
|
|
this.networkId = networkId;
|
|
this.thingId = thingId;
|
|
this.url = url;
|
|
}
|
|
public ModelUrlMsg(byte[] buffer) {
|
|
byte ix = 1;
|
|
this.networkId = buffer[ix++];
|
|
this.thingId = buffer[ix++];
|
|
|
|
int strlen = buffer[ix++];
|
|
url = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, strlen);
|
|
}
|
|
|
|
public override byte Serialize(ref byte[] buffer) {
|
|
if (this.url == null)
|
|
return 0;
|
|
|
|
byte ix = 0;
|
|
buffer[ix++] = ModelUrlMsg.Id;
|
|
buffer[ix++] = this.networkId;
|
|
buffer[ix++] = this.thingId; // Thing Id
|
|
|
|
buffer[ix++] = (byte)this.url.Length;
|
|
for (int urlIx = 0; urlIx < this.url.Length; urlIx++)
|
|
buffer[ix++] = (byte)url[urlIx];
|
|
return ix;
|
|
}
|
|
|
|
}
|
|
|
|
} |