initial commit
This commit is contained in:
84
common/xbuf/xbuf.h
Executable file
84
common/xbuf/xbuf.h
Executable file
@@ -0,0 +1,84 @@
|
||||
/*************************************************
|
||||
File name : xbuf.h
|
||||
Module :
|
||||
Author : amir
|
||||
Version : 0.1
|
||||
Created on : 2024-04-27
|
||||
Description : buf for protocol transmission
|
||||
协议间传输
|
||||
Modify History:
|
||||
1. Date: Author: Modification:
|
||||
*************************************************/
|
||||
|
||||
#ifndef __XBUF__
|
||||
#define __XBUF__
|
||||
#include <stdint.h>
|
||||
#include "kpacket.h"
|
||||
#include "iobuffer.h"
|
||||
|
||||
typedef struct{
|
||||
uint16_t event;
|
||||
uint32_t (*on_event)(const kpacket *packet);
|
||||
}packet_event;
|
||||
|
||||
|
||||
typedef struct{
|
||||
|
||||
/**
|
||||
* @brief 当接收完整一包kpacket, 触发回调
|
||||
*
|
||||
* @param [in] box, box的地址.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void (*on_packet)(const kpacket *packet);
|
||||
|
||||
packet_event *ev_list;
|
||||
uint16_t ev_list_sz;
|
||||
|
||||
|
||||
/* private data*/
|
||||
iobuffer read_io;
|
||||
/* 高阶应用
|
||||
* 1. iobuffer_iobuffer_reserve(&read_io, 4096); // 设置iobuffer的缓冲大小
|
||||
* 2. recv(read_io.iodata, read_io.capacity - read_io.size); xbuf_flush(); // 直接将数据读到iobuffer里,并尝试触发回调
|
||||
**/
|
||||
|
||||
|
||||
}xbuf_handler;
|
||||
|
||||
|
||||
uint32_t xbuf_init(xbuf_handler *hdlr);
|
||||
|
||||
|
||||
uint32_t xbuf_deinit(xbuf_handler *hdlr);
|
||||
|
||||
/**
|
||||
* @brief 入数据处理, 满足包条件时触发on_packet回调
|
||||
*
|
||||
* @param [in] hdlr, 外部保存的xbuf_handler.
|
||||
* @param [in] data, 入数.
|
||||
* @param [in] sz, 入数长度.
|
||||
* @note 成长返回OK, 返回NG内存不足--查一下read_io的capacity和size.
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t xbuf_put(xbuf_handler *hdlr, const char *data, const uint32_t sz);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 尝试主动触发回调
|
||||
*
|
||||
* @param [in] hdlr, 外部保存的xbuf_handler.
|
||||
* @note 成长返回OK, 返回NG内存不足--查一下read_io的capacity和size.
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t xbuf_flush(xbuf_handler *hdlr);
|
||||
|
||||
|
||||
void xbuf_test();
|
||||
|
||||
|
||||
#endif /* __XBUF__ */
|
||||
|
||||
Reference in New Issue
Block a user