namespace Passer.Control.Core {

    public class CustomMsg : IMessage {
        public const byte Id = 0xB1;
        public byte networkId;
        public byte thingId;
        public byte[] bytes;

        public CustomMsg(byte[] buffer) {
            byte ix = 1;
            this.networkId = buffer[ix++];
            this.thingId = buffer[ix++];
            byte length = (byte)(buffer.Length - ix);
            this.bytes = new byte[length];
            for (uint bytesIx = 0; bytesIx < length; bytesIx++)
                this.bytes[bytesIx] = buffer[ix++];
        }
        public CustomMsg(byte networkId, byte thingId, byte[] bytes) : base() {
            this.networkId = networkId;
            this.thingId = thingId;
            this.bytes = bytes;
        }

        public override byte Serialize(ref byte[] buffer) {
            byte ix = 0;
            buffer[ix++] = CustomMsg.Id;
            buffer[ix++] = this.networkId;
            buffer[ix++] = this.thingId;
            //buffer[ix++] = (byte)bytes.Length;
            foreach (byte b in bytes)
                buffer[ix++] = b;

            return ix;
        }

        //public static async Task<bool> Receive(Stream dataStream, Participant client, byte packetSize) {
        //    byte[] buffer = await Receive(dataStream, packetSize);

        //    CustomMsg msg = new(buffer);
        //    client.messageQueue.Enqueue(msg);
        //    return true;
        //}
    }

}