Buffer manipulation functions.
More...
|
typedef struct _nugu_buffer | NuguBuffer |
| Buffer object.
|
|
|
NUGU_API size_t | nugu_buffer_add (NuguBuffer *buf, const void *data, size_t data_len) |
| Append the data to buffer object. More...
|
|
NUGU_API size_t | nugu_buffer_add_byte (NuguBuffer *buf, unsigned char byte) |
| Append the data to buffer object. More...
|
|
NUGU_API int | nugu_buffer_clear (NuguBuffer *buf) |
| Clear the buffer. More...
|
|
NUGU_API int | nugu_buffer_clear_from (NuguBuffer *buf, size_t pos) |
| Clear data from a specific position to the end. More...
|
|
NUGU_API size_t | nugu_buffer_find_byte (NuguBuffer *buf, unsigned char want) |
| Get the position of the data you want to find. More...
|
|
NUGU_API void * | nugu_buffer_free (NuguBuffer *buf, int is_data_free) |
| Destroy the buffer object. More...
|
|
NUGU_API size_t | nugu_buffer_get_alloc_size (NuguBuffer *buf) |
| Gets the size of the entire data allocated for the buffer. More...
|
|
NUGU_API size_t | nugu_buffer_get_size (NuguBuffer *buf) |
| Gets the size of the entire data added to the buffer. More...
|
|
NUGU_API NuguBuffer * | nugu_buffer_new (size_t default_size) |
| Create new buffer object. More...
|
|
NUGU_API const void * | nugu_buffer_peek (NuguBuffer *buf) |
| Get the internal buffer. More...
|
|
NUGU_API unsigned char | nugu_buffer_peek_byte (NuguBuffer *buf, size_t pos) |
| Get data at a specific position. More...
|
|
NUGU_API void * | nugu_buffer_pop (NuguBuffer *buf, size_t size) |
| Extract data by a certain size. More...
|
|
NUGU_API int | nugu_buffer_set_byte (NuguBuffer *buf, size_t pos, unsigned char byte) |
| Append the data to buffer object. More...
|
|
NUGU_API int | nugu_buffer_shift_left (NuguBuffer *buf, size_t size) |
| Delete a certain amount of data and move the remaining data forward. More...
|
|
Buffer manipulation functions.
The Buffer module makes it easy to add, delete, and move data in byte units.
The Buffer object allocates and uses a single flat buffer inside, and adjusts its size flexibly as needed.
The Buffer object is not thread safe.
◆ NUGU_BUFFER_NOT_FOUND
#define NUGU_BUFFER_NOT_FOUND ((size_t) - 1) |
◆ nugu_buffer_new()
NUGU_API NuguBuffer* nugu_buffer_new |
( |
size_t |
default_size | ) |
|
Create new buffer object.
- Parameters
-
[in] | default_size | default allocation size of buffer (0 is default size) |
- Returns
- Buffer object
- See also
- nugu_buffer_free()
◆ nugu_buffer_free()
NUGU_API void* nugu_buffer_free |
( |
NuguBuffer * |
buf, |
|
|
int |
is_data_free |
|
) |
| |
Destroy the buffer object.
- Parameters
-
[in] | buf | buffer object |
[in] | data_free | If 1, the internal buffer is also freed. If 0, only the buffer object is freed, not the internal buffer. |
- Returns
- If data_free is false, developer must free the internal buffer manually. If false, always return NULL.
- See also
- nugu_buffer_new()
◆ nugu_buffer_add()
NUGU_API size_t nugu_buffer_add |
( |
NuguBuffer * |
buf, |
|
|
const void * |
data, |
|
|
size_t |
data_len |
|
) |
| |
Append the data to buffer object.
- Parameters
-
[in] | buf | buffer object |
[in] | data | The data to add to the buffer. |
[in] | data_len | Length of the data |
- Returns
- added length (0 = failure)
◆ nugu_buffer_add_byte()
NUGU_API size_t nugu_buffer_add_byte |
( |
NuguBuffer * |
buf, |
|
|
unsigned char |
byte |
|
) |
| |
Append the data to buffer object.
- Parameters
-
[in] | buf | buffer object |
[in] | byte | The data to add to the buffer. |
- Returns
- added length (0 = failure)
◆ nugu_buffer_set_byte()
NUGU_API int nugu_buffer_set_byte |
( |
NuguBuffer * |
buf, |
|
|
size_t |
pos, |
|
|
unsigned char |
byte |
|
) |
| |
Append the data to buffer object.
- Parameters
-
[in] | buf | buffer object |
[in] | pos | position |
[in] | byte | The data to add to the buffer. |
- Returns
- Result
- Return values
-
◆ nugu_buffer_peek()
NUGU_API const void* nugu_buffer_peek |
( |
NuguBuffer * |
buf | ) |
|
Get the internal buffer.
- Parameters
-
- Returns
- Internal buffer address. Please do not modify the data manually.
- See also
- nugu_buffer_peek_byte()
◆ nugu_buffer_get_size()
NUGU_API size_t nugu_buffer_get_size |
( |
NuguBuffer * |
buf | ) |
|
◆ nugu_buffer_get_alloc_size()
NUGU_API size_t nugu_buffer_get_alloc_size |
( |
NuguBuffer * |
buf | ) |
|
Gets the size of the entire data allocated for the buffer.
- Parameters
-
- Returns
- size of allocated internal buffer.
- See also
- nugu_buffer_get_size()
◆ nugu_buffer_find_byte()
NUGU_API size_t nugu_buffer_find_byte |
( |
NuguBuffer * |
buf, |
|
|
unsigned char |
want |
|
) |
| |
Get the position of the data you want to find.
- Parameters
-
[in] | buf | buffer object |
[in] | want | byte data you want to find |
- Returns
- position. if fail, return NUGU_BUFFER_NOT_FOUND
- See also
- NUGU_BUFFER_NOT_FOUND
◆ nugu_buffer_peek_byte()
NUGU_API unsigned char nugu_buffer_peek_byte |
( |
NuguBuffer * |
buf, |
|
|
size_t |
pos |
|
) |
| |
Get data at a specific position.
- Parameters
-
[in] | buf | buffer object |
[in] | pos | position |
- Returns
- byte data
◆ nugu_buffer_clear()
NUGU_API int nugu_buffer_clear |
( |
NuguBuffer * |
buf | ) |
|
◆ nugu_buffer_clear_from()
NUGU_API int nugu_buffer_clear_from |
( |
NuguBuffer * |
buf, |
|
|
size_t |
pos |
|
) |
| |
Clear data from a specific position to the end.
- Parameters
-
[in] | buf | buffer object |
[in] | pos | position |
- Returns
- Result
- Return values
-
- See also
- nugu_buffer_clear()
◆ nugu_buffer_shift_left()
NUGU_API int nugu_buffer_shift_left |
( |
NuguBuffer * |
buf, |
|
|
size_t |
size |
|
) |
| |
Delete a certain amount of data and move the remaining data forward.
- Parameters
-
[in] | buf | buffer object |
[in] | size | size to delete. |
- Returns
- Result
- Return values
-
◆ nugu_buffer_pop()
NUGU_API void* nugu_buffer_pop |
( |
NuguBuffer * |
buf, |
|
|
size_t |
size |
|
) |
| |
Extract data by a certain size.
- Parameters
-
[in] | buf | buffer object |
[in] | size | size to extract |
- Returns
- Extracted data. Developer must free the data manually.