-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
72 lines (55 loc) · 1.37 KB
/
utils.h
File metadata and controls
72 lines (55 loc) · 1.37 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
#ifndef UTILS_H
#define UTILS_H
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <math.h>
#include <unistd.h>
#include <netinet/tcp.h>
#include <vector>
#include <poll.h>
#include <unordered_map>
#include <string>
#include <unordered_set>
#include <arpa/inet.h>
#include <regex>
#define short_real_tcp_t uint16_t
#define MAXBUF 1552
#define DIE(assertion, reason) \
if (assertion) { \
fprintf(stderr, "ERROR: " reason); \
exit(EXIT_FAILURE); \
}
struct udp_message_t {
char topic[50];
uint8_t data_type;
char content[1501];
} __attribute__((packed));
struct tcp_message_t {
char type[11];
uint8_t data_type;
uint16_t port;
char ip_addr[16];
char payload[1501];
char topic[51];
} __attribute__((packed));
struct tcp_client_request {
bool subscribe;
char topic[51];
} __attribute__((packed));
struct int_tcp_t {
int8_t sign_byte;
uint32_t integer;
} __attribute__((packed));
struct float_tcp_t {
int8_t sign_byte;
uint32_t value;
uint8_t negative_exp;
} __attribute__((packed));
int decode_for_tcp_clients(udp_message_t *udp_msg, tcp_message_t *tcp_msg);
void create_buffer_confirmation(char *buffer, bool connected);
bool is_wildcard(std::string topic);
std::string build_regex(std::string& wildcard);
#endif // UTILS_H