This repository was archived by the owner on Aug 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessages.h
More file actions
73 lines (60 loc) · 1.92 KB
/
Copy pathmessages.h
File metadata and controls
73 lines (60 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef COMUNICARPCS_MESSAGES_H
#define COMUNICARPCS_MESSAGES_H
#include <stdbool.h>
/*
* this must be pragma packed so that all compilations maintain
* consistent structures for receiving and reading the values to
* the correct positions, with bit precision.
*/
#pragma pack(push, 8)
//TODO the pragma packed, it can be very inefficient
#define MAX_SIZE_USERNAME 35
#define MAX_SIZE_CHANNEL (MAX_SIZE_USERNAME)
struct username_message {
char username[MAX_SIZE_USERNAME];
};
#define MAX_SIZE_MESSAGE 1024
struct named_text_message {
char username[MAX_SIZE_USERNAME];
char channel[MAX_SIZE_CHANNEL];
char data[MAX_SIZE_MESSAGE];
};
struct private_message {
char sender[MAX_SIZE_USERNAME];
char receiver[MAX_SIZE_USERNAME];
char data[MAX_SIZE_MESSAGE];
};
struct response_username_message {
bool isFailure;
};
struct user_joins_message {
char username[MAX_SIZE_USERNAME];
char channel[MAX_SIZE_CHANNEL];
};
struct user_exits_message {
char username[MAX_SIZE_USERNAME];
char channel[MAX_SIZE_CHANNEL];
};
struct server_termination_message {};
/*
* Invariantes:
* - Toda campo de tipo enum message_type se chequea con un switch o con un if
* - Siempre que se switch o if sobre un campo de este tipo, se debe incluir el caso UNSET (o default), que tira un error
*/
enum message_type { UNSET = 0, USERNAME_MESSAGE = 1, NAMED_TEXT_MESSAGE = 3,
RESPONSE_USERNAME_MESSAGE = 4, PRIVATE_MESSAGE = 5, USER_EXITS_MESSAGE = 6, SERVER_TERMINATION_MESSAGE = 7,
USER_JOINS_MESSAGE = 8 };
struct message {
union {
struct username_message usernameMessage;
struct named_text_message namedTextMessage;
struct response_username_message responseUsernameMessage;
struct private_message privateMessage;
struct user_joins_message userJoinsMessage;
struct user_exits_message userExitsMessage;
struct server_termination_message serverTerminationMessage;
};
enum message_type messageType;
};
#pragma pack(pop)
#endif //COMUNICARPCS_MESSAGES_H