fusion/common/iobuffer/iobuffer.h

43 lines
1.3 KiB
C
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IOBUFFER_H_INCLUDED
#define IOBUFFER_H_INCLUDED
typedef struct {
char* iodata; //if not null, always 16 byte alignment for better AES encrypt
int size;
int capacity; //capacity, always >= size
} iobuffer;
void iobuffer_init(iobuffer* p);
void iobuffer_deinit(iobuffer* p);
/* 申请cap大小的缓冲 */
int iobuffer_reserve(iobuffer* p, int cap);
/* 获取剩余缓冲的大小 */
int iobuffer_freesize(iobuffer* p);
/* to后的data移到from位置 */
void iobuffer_erase(iobuffer* p, int from, int to);
/* 设置size=0 清除所有data */
void iobuffer_eraseall(iobuffer* p);
/* 读size大小的数据到to的内存 */
void iobuffer_read(iobuffer* p, void* to, int size);
/* 插入字符串 */
int iobuffer_append_string(iobuffer* p, const void* str);
/* 插入数据 */
int iobuffer_appendData(iobuffer* p, const void* iodata, int count);
/* 插入格式打印iobuffer_printf(p, "i m %s, years old", "liming", 5)*/
int iobuffer_printf(iobuffer* p, const char *format, ...) __attribute__((__format__ (printf, 2, 3)));/* first arg is this pointer */
// Don't call it but change your code logic
// int iobuffer_prependData(iobuffer* p, const void* iodata, int count);
#endif /* IOBUFFER_H_INCLUDED */