-
Notifications
You must be signed in to change notification settings - Fork 0
/
input-packet.h
67 lines (56 loc) · 1.46 KB
/
input-packet.h
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
#ifndef INPUT_PACKET_H
#define INPUT_PACKET_H 1
#if defined(_WIN32) || defined(_WIN64)
#include <WinSock2.h>
#else
#include <sys/socket.h>
#endif
#include <google/protobuf/message.h>
#include "output-message.h"
struct PacketHeader
{
char name;
};
/**
* @brief nanomsg packet
*/
class InputPacket
{
private:
struct sockaddr socket_address_src;
struct sockaddr socket_address_dst;
void *buffer;
bool allocated; ///< true- buffer is malloc'ed, false- external buffer
bool parse();
public:
struct OutputMessageKey key;
google::protobuf::Message *message;
InputPacket(char typ, size_t data_size);
InputPacket(void *data, size_t data_size);
InputPacket(const std::string &data);
virtual ~InputPacket();
/// buffer
void *get();
/// buffer size including address and header
size_t size;
struct PacketHeader* header();
struct sockaddr_storage *get_socket_addr_src();
struct sockaddr_storage *get_socket_addr_dst();
struct sockaddr_in *get_sockaddr_src();
struct sockaddr_in *get_sockaddr_dst();
bool set_socket_addr_src(struct addrinfo *value);
bool set_socket_addr_dst(struct addrinfo *value);
void *data();
/// max data buffer size
int max_data_size;
/// actual data length
int length;
void setLength(int length);
int error();
/**
* @brief return payload size
* @return payload size
*/
static int getPayloadSize(int full_packet_size);
};
#endif