finished the protocol

This commit is contained in:
Rusty Striker 2025-01-07 18:40:03 +02:00
parent 84d9bd0ef0
commit 661c217a73
Signed by: RustyStriker
GPG key ID: 87E4D691632DFF15
4 changed files with 121 additions and 20 deletions

View file

@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
@ -54,16 +52,17 @@ public class Message
public byte[] Bytes()
{
// initialize a list
List<byte> msg = [];
// 0..4
// 0..4 - message id
msg.AddRange(BitConverter.GetBytes(Id));
// 4..12
// 4..12 - sender's phone number
msg.AddRange(Utils.NumberToBytes(Sender));
// 12
// 12 - is this message an acknowledgement or a normal message
msg.Add((byte)(IsAck ? 1 : 0));
// 13..(len - 32)
// 13.. the message itself (should be empty for an acknowledgement)
msg.AddRange(Encoding.UTF8.GetBytes(Content));
// Turn into array, prepending the version byte
return [0, .. msg];
}
}