33 lines
No EOL
743 B
C#
33 lines
No EOL
743 B
C#
namespace lib;
|
|
|
|
public enum RequestType {
|
|
Register = 1,
|
|
ConfirmRegister = 2,
|
|
Login = 3,
|
|
GetMessages = 4,
|
|
GetUserKey = 5,
|
|
SendMessage = 6,
|
|
}
|
|
|
|
public static class Request {
|
|
public static byte[] CreateRequest(RequestType Type, ref byte counter, byte[] data) {
|
|
if(data.Length > 13) {
|
|
throw new Exception("extra data is too long");
|
|
}
|
|
|
|
byte[] msg = new byte[128];
|
|
msg[0] = 0; // version
|
|
msg[1] = (byte)Type;
|
|
msg[2] = counter;
|
|
if(counter == byte.MaxValue) {
|
|
counter = 0;
|
|
}
|
|
else {
|
|
counter += 1;
|
|
}
|
|
|
|
// insert data 3..16
|
|
Array.Copy(data, 0, msg, 3, data.Length);
|
|
return msg;
|
|
}
|
|
} |