NUGU SDK Linux  1.7.6
Buffer

Buffer manipulation functions. More...

+ Collaboration diagram for Buffer:

Macros

#define NUGU_BUFFER_NOT_FOUND   ((size_t) - 1)
 Not found return type of nugu_buffer_find_byte() More...
 

Typedefs

typedef struct _nugu_buffer NuguBuffer
 Buffer object.
 

Functions

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 NuguBuffernugu_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...
 

Detailed Description

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.

Macro Definition Documentation

◆ NUGU_BUFFER_NOT_FOUND

#define NUGU_BUFFER_NOT_FOUND   ((size_t) - 1)

Not found return type of nugu_buffer_find_byte()

See also
nugu_buffer_find_byte()

Function Documentation

◆ nugu_buffer_new()

NUGU_API NuguBuffer* nugu_buffer_new ( size_t  default_size)

Create new buffer object.

Parameters
[in]default_sizedefault 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]bufbuffer object
[in]data_freeIf 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]bufbuffer object
[in]dataThe data to add to the buffer.
[in]data_lenLength 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]bufbuffer object
[in]byteThe 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]bufbuffer object
[in]posposition
[in]byteThe data to add to the buffer.
Returns
Result
Return values
0success
-1failure

◆ nugu_buffer_peek()

NUGU_API const void* nugu_buffer_peek ( NuguBuffer buf)

Get the internal buffer.

Parameters
[in]bufbuffer object
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)

Gets the size of the entire data added to the buffer.

Parameters
[in]bufbuffer object
Returns
size of data
See also
nugu_buffer_get_alloc_size()

◆ 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
[in]bufbuffer object
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]bufbuffer object
[in]wantbyte 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]bufbuffer object
[in]posposition
Returns
byte data

◆ nugu_buffer_clear()

NUGU_API int nugu_buffer_clear ( NuguBuffer buf)

Clear the buffer.

Parameters
[in]bufbuffer object
Returns
Result
Return values
0success
-1failure
See also
nugu_buffer_clear_from()

◆ 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]bufbuffer object
[in]posposition
Returns
Result
Return values
0success
-1failure
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]bufbuffer object
[in]sizesize to delete.
Returns
Result
Return values
0success
-1failure

◆ nugu_buffer_pop()

NUGU_API void* nugu_buffer_pop ( NuguBuffer buf,
size_t  size 
)

Extract data by a certain size.

Parameters
[in]bufbuffer object
[in]sizesize to extract
Returns
Extracted data. Developer must free the data manually.