#ifndef UCX_BUFFER_H
#define UCX_BUFFER_H
#include "common.h"
#include "allocator.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CX_BUFFER_DEFAULT 0x00
#define CX_BUFFER_FREE_CONTENTS 0x01
#define CX_BUFFER_AUTO_EXTEND 0x02
typedef struct {
union {
char *space;
unsigned char *bytes;
};
const CxAllocator *allocator;
size_t pos;
size_t capacity;
size_t size;
size_t flush_threshold;
size_t flush_blksize;
size_t flush_blkmax;
cx_write_func flush_func;
void *flush_target;
int flags;
} cx_buffer_s;
typedef cx_buffer_s CxBuffer;
__attribute__((__nonnull__(
1)))
int cxBufferInit(
CxBuffer *buffer,
void *space,
size_t capacity,
const CxAllocator *allocator,
int flags
);
CxBuffer *cxBufferCreate(
void *space,
size_t capacity,
const CxAllocator *allocator,
int flags
);
__attribute__((__nonnull__))
void cxBufferDestroy(CxBuffer *buffer);
__attribute__((__nonnull__))
void cxBufferFree(CxBuffer *buffer);
__attribute__((__nonnull__))
int cxBufferShift(
CxBuffer *buffer,
off_t shift
);
__attribute__((__nonnull__))
int cxBufferShiftRight(
CxBuffer *buffer,
size_t shift
);
__attribute__((__nonnull__))
int cxBufferShiftLeft(
CxBuffer *buffer,
size_t shift
);
__attribute__((__nonnull__))
int cxBufferSeek(
CxBuffer *buffer,
off_t offset,
int whence
);
__attribute__((__nonnull__))
void cxBufferClear(CxBuffer *buffer);
__attribute__((__nonnull__))
void cxBufferReset(CxBuffer *buffer);
__attribute__((__nonnull__))
int cxBufferEof(
const CxBuffer *buffer);
__attribute__((__nonnull__))
int cxBufferMinimumCapacity(
CxBuffer *buffer,
size_t capacity
);
__attribute__((__nonnull__))
size_t cxBufferWrite(
const void *ptr,
size_t size,
size_t nitems,
CxBuffer *buffer
);
__attribute__((__nonnull__))
size_t cxBufferRead(
void *ptr,
size_t size,
size_t nitems,
CxBuffer *buffer
);
__attribute__((__nonnull__))
int cxBufferPut(
CxBuffer *buffer,
int c
);
__attribute__((__nonnull__))
size_t cxBufferPutString(
CxBuffer *buffer,
const char *str
);
__attribute__((__nonnull__))
int cxBufferGet(CxBuffer *buffer);
#ifdef __cplusplus
}
#endif
#endif