mirror of https://github.com/deavminet/libdnet.git
Added more message types, added unittest for testing creation, encoding and decoding of the Header message type
This commit is contained in:
parent
1cf64931ff
commit
eba9608f89
|
@ -70,8 +70,83 @@ struct ClientMessage
|
|||
ubyte[] payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* AuthenticateMessage
|
||||
*
|
||||
* This message is used to authenticate
|
||||
* the user with the server
|
||||
*/
|
||||
struct AuthenticateMessage
|
||||
{
|
||||
string username;
|
||||
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]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue