longlink_packer.h 2.3 KB
//
//  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_