Added more message types, added unittest for testing creation, encoding and decoding of the Header message type

This commit is contained in:
Tristan B. Velloza Kildaire 2022-01-11 14:42:08 +02:00
parent 1cf64931ff
commit eba9608f89
1 changed files with 75 additions and 0 deletions

View File

@ -70,8 +70,83 @@ struct ClientMessage
ubyte[] payload; ubyte[] payload;
} }
/**
* AuthenticateMessage
*
* This message is used to authenticate
* the user with the server
*/
struct AuthenticateMessage struct AuthenticateMessage
{ {
string username; string username;
string password; string password;
} }
/**
* EntityMessage
*
* A message to a user or a channel
*/
struct EntityMessage
{
/**
* Sender-receiver details
*/
string to;
string from;
/* Payload */
string message;
/* Timestamp (date and time) */
string timestamp;
}
/**
* ProfileMessage
*
* A user's profile
*/
struct ProfileMessage
{
string fullname;
string server;
string hostmask;
/*
* Keys for extra data
*/
string[] dataKeys;
}
struct KeyedData
{
string key;
ubyte[] data;
}
/**
* Testing header creation, encoding and
* decoding
*/
unittest
{
/* Create a new Header */
Header testHeader;
testHeader.type = HeaderType.CLIENT;
testHeader.payload = [1,2,3,4];
/* Encode Header */
ubyte[] encodedHeader= pack(testHeader);
/* Decode the Header */
Header headerReceived = unpack!(Header)(encodedHeader);
/* Make sure it was properly received */
assert(headerReceived.type == testHeader.type);
assert(headerReceived.payload[0] == testHeader.payload[0]);
assert(headerReceived.payload[1] == testHeader.payload[1]);
assert(headerReceived.payload[2] == testHeader.payload[2]);
assert(headerReceived.payload[3] == testHeader.payload[3]);
}