more code
This commit is contained in:
parent
a8e9407375
commit
75f1d15be1
|
@ -30,7 +30,9 @@ typedef struct SBufferReader SBufferReader;
|
|||
#define BUFFER_INITILIZER ((SBuffer){0, 0, NULL})
|
||||
static int32_t tBufferInit(SBuffer *buffer);
|
||||
static int32_t tBufferDestroy(SBuffer *buffer);
|
||||
static int32_t tBufferClear(SBuffer *buffer);
|
||||
static int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capacity);
|
||||
static int32_t tBufferAppend(SBuffer *buffer, const void *data, uint32_t size);
|
||||
#define tBufferGetSize(buffer) ((buffer)->size)
|
||||
#define tBufferGetCapacity(buffer) ((buffer)->capacity)
|
||||
#define tBufferGetData(buffer) ((const void *)(buffer)->data)
|
||||
|
|
|
@ -52,6 +52,11 @@ static FORCE_INLINE int32_t tBufferDestroy(SBuffer *buffer) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferClear(SBuffer *buffer) {
|
||||
buffer->size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capacity) {
|
||||
if (buffer->capacity < capacity) {
|
||||
uint32_t newCapacity = (buffer->capacity > 0) ? (buffer->capacity << 1) : 1024;
|
||||
|
@ -68,6 +73,14 @@ static FORCE_INLINE int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capa
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tBufferAppend(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||
if (code) return code;
|
||||
memcpy((char *)buffer->data + buffer->size, data, size);
|
||||
buffer->size += size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// SBufferWriter
|
||||
static FORCE_INLINE int32_t tBufferPutFixed(SBufferWriter *writer, const void *data, uint32_t size) {
|
||||
if (!writer->forward && writer->offset < size) {
|
||||
|
|
Loading…
Reference in New Issue