From 355dd5c1c519cf07cfb6b9f9200f7f7311e68f20 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Fri, 6 Dec 2024 17:48:55 +0100 Subject: [PATCH] Fixed ThingMsg format --- Messages.cs | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/Messages.cs b/Messages.cs index f23e497..56518cd 100644 --- a/Messages.cs +++ b/Messages.cs @@ -237,26 +237,39 @@ namespace Passer.Control { public class ThingMsg : IMessage { public const byte length = 5; public const byte Id = 0x80; - public byte objectId; - public byte objectType; + public byte networkId; + public byte thingId; + public byte thingType; public byte parentId; + 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[] data) : base(data) { } - public override void Deserialize(byte[] data) { + + public override byte[] Serialize() { + byte[] data = new byte[ThingMsg.length]; + data[0] = ThingMsg.Id; + data[1] = this.networkId; + data[2] = this.thingId; + data[3] = this.thingType; + data[4] = this.parentId; + return data; + } + public override void Deserialize(byte[] data) { uint ix = 0; - objectId = data[ix++]; - objectType = data[ix++]; - parentId = data[ix]; + this.networkId = data[ix++]; + this.thingId = data[ix++]; + this.thingType = data[ix++]; + this.parentId = data[ix]; } public static bool Send(Client client, byte thingId, byte thingType, byte parentId) { - byte[] data = new byte[ThingMsg.length]; - data[0] = ThingMsg.Id; - data[1] = client.networkId; - data[2] = thingId; - data[3] = thingType; - data[4] = parentId; - return SendMsg(client, data); + ThingMsg msg = new(client.networkId, thingId, thingType, parentId); + return SendMsg(client, msg); } public static async Task Receive(Stream dataStream, Client client, byte packetSize) { if (packetSize != length)