longlink_packer.h
2.3 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
74
75
76
77
78
79
80
//
// netbuffer.h
// BBAAPIRequest
//
// Created by cairui01 on 2020/05/11.
//
#ifndef STN_SRC_LONGLINK_PACKER_H_
#define STN_SRC_LONGLINK_PACKER_H_
#include <stdlib.h>
#include <stdint.h>
#define LONGLINK_UNPACK_CONTINUE (-2)
#define LONGLINK_UNPACK_FALSE (-1)
#define LONGLINK_UNPACK_OK (0)
//for HTTP2
#define LONGLINK_UNPACK_STREAM_END LONGLINK_UNPACK_OK
#define LONGLINK_UNPACK_STREAM_PACKAGE (1)
#ifndef __cplusplus
#error "support cpp only"
#endif
static const uint32_t kNoopTaskID = 0xFFFFFFFF;
class NetBuffer;
namespace apirequest {
namespace sdt {
class longlink_tracker {
public:
static longlink_tracker* (*Create)();
public:
virtual ~longlink_tracker(){};
};
/**
* package the request data
* _cmdid: business identifier
* _seq: task id
* _raw: business send buffer
* _packed: business send buffer + request header
*/
extern void (*longlink_pack)(uint32_t _cmdid, uint32_t _seq, const NetBuffer& _body, const NetBuffer& _extension, NetBuffer& _packed, longlink_tracker* _tracker);
/**
* unpackage the response data
* _packed: data received from server
* _cmdid: business identifier
* _seq: task id
* _package_len:
* _body: business receive buffer
* return: 0 if unpackage succ
*/
extern int (*longlink_unpack)(const NetBuffer& _packed, uint32_t& _cmdid, uint32_t& _seq, size_t& _package_len, NetBuffer& _body, NetBuffer& _extension, longlink_tracker* _tracker);
//heartbeat signal to keep longlink network alive
extern uint32_t (*longlink_noop_cmdid)();
extern bool (*longlink_noop_isresp)(uint32_t _taskid, uint32_t _cmdid, uint32_t _recv_seq, const NetBuffer& _body, const NetBuffer& _extend);
extern uint32_t (*signal_keep_cmdid)();
extern void (*longlink_noop_req_body)(NetBuffer& _body, NetBuffer& _extend);
extern void (*longlink_noop_resp_body)(const NetBuffer& _body, const NetBuffer& _extend);
extern uint32_t (*longlink_noop_interval)();
extern bool (*longlink_complexconnect_need_verify)();
/**
* return: whether the received data is pushing from server or not
*/
extern bool (*longlink_ispush)(uint32_t _cmdid, uint32_t _taskid, const NetBuffer& _body, const NetBuffer& _extend);
extern bool (*longlink_identify_isresp)(uint32_t _sent_seq, uint32_t _cmdid, uint32_t _recv_seq, const NetBuffer& _body, const NetBuffer& _extend);
}
}
#endif // STN_SRC_LONGLINKPACKER_H_