forked from ithewei/libhv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotorpc.h
35 lines (27 loc) · 794 Bytes
/
protorpc.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
#ifndef HV_PROTO_RPC_H_
#define HV_PROTO_RPC_H_
#ifdef __cplusplus
extern "C" {
#endif
// flags:1byte + length:4bytes = 5bytes
#define PROTORPC_HEAD_LENGTH 5
typedef struct {
unsigned char flags;
unsigned int length;
} protorpc_head;
typedef const char* protorpc_body;
typedef struct {
protorpc_head head;
protorpc_body body;
} protorpc_message;
static inline unsigned int protorpc_package_length(const protorpc_head* head) {
return PROTORPC_HEAD_LENGTH + head->length;
}
// @retval >0 package_length, <0 error
int protorpc_pack(const protorpc_message* msg, void* buf, int len);
// @retval >0 package_length, <0 error
int protorpc_unpack(protorpc_message* msg, const void* buf, int len);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // HV_PROTO_RPC_H_