Dynamic Buffer

Utilities for populating a buffer of variable length. More...

Modules

Types
Dynamic Buffer data types.

Functions

gos_result_t gos_dynamic_buffer_alloc ( gos_dynamic_buffer_t *buffer, uint32_t length)
gos_result_t gos_dynamic_buffer_realloc ( gos_dynamic_buffer_t *buffer, uint32_t additional_length)
gos_result_t gos_dynamic_buffer_copy ( gos_dynamic_buffer_t *dst, const gos_dynamic_buffer_t *src)
void gos_dynamic_buffer_free ( gos_dynamic_buffer_t *buffer)
void gos_dynamic_buffer_reset ( gos_dynamic_buffer_t *buffer)
gos_result_t gos_dynamic_buffer_write ( gos_dynamic_buffer_t *buffer, const void *data, uint32_t data_length)
gos_result_t gos_dynamic_buffer_writef ( gos_dynamic_buffer_t *buffer, const char *fmt,...)
gos_result_t gos_dynamic_buffer_vwrite ( gos_dynamic_buffer_t *buffer, const char *fmt, va_list args)
uint32_t gos_dynamic_buffer_get_length (const gos_dynamic_buffer_t *buffer)
uint32_t gos_dynamic_buffer_get_total_size (const gos_dynamic_buffer_t *buffer)
uint32_t gos_dynamic_buffer_get_remaining_length (const gos_dynamic_buffer_t *buffer)
gos_result_t gos_dynamic_buffer_get_buffer (const gos_dynamic_buffer_t *dynamic_buffer, gos_buffer_t *buffer)
gos_result_t gos_dynamic_buffer_adjust_data_end ( gos_dynamic_buffer_t *buffer, int32_t adjust_amount)
gos_result_t gos_dynamic_buffer_adjust_data_start ( gos_dynamic_buffer_t *buffer, int32_t adjust_amount)

Detailed Description

Utilities for populating a buffer of variable length.

Function Documentation

gos_dynamic_buffer_adjust_data_end()

gos_result_t gos_dynamic_buffer_adjust_data_end ( gos_dynamic_buffer_t * buffer,
int32_t adjust_amount
)

Adjust append pointer of buffer

This moves the append pointer forwards or backwards by (signed)adjust_amount

Parameters
[in] buffer gos_dynamic_buffer_t
[in] adjust_amount Amount to move append pointer
Returns
gos_result_t , result of API

gos_dynamic_buffer_adjust_data_start()

gos_result_t gos_dynamic_buffer_adjust_data_start ( gos_dynamic_buffer_t * buffer,
int32_t adjust_amount
)

Adjust prepend pointer of buffer

This moves the prepend pointer forwards or backwards by (signed)adjust_amount

Parameters
[in] buffer gos_dynamic_buffer_t
[in] adjust_amount Amount to move prepend pointer
Returns
gos_result_t , result of API

gos_dynamic_buffer_alloc()

gos_result_t gos_dynamic_buffer_alloc ( gos_dynamic_buffer_t * buffer,
uint32_t length
)

Allocate dynamic buffer

This allocates a dynamic buffer of the specified length

Parameters
[in] buffer gos_dynamic_buffer_t object to allocate a buffer for
[in] length Length in bytes of allocated buffer
Returns
gos_result_t , result of API
Examples:
cloud/dps_demo/main.c .

gos_dynamic_buffer_copy()

gos_result_t gos_dynamic_buffer_copy ( gos_dynamic_buffer_t * dst,
const gos_dynamic_buffer_t * src
)

Copy dynamic buffer

This copies the contents of the src gos_dynamic_buffer_t into the dst buffer.

Parameters
[in] dst Destination buffer to receive copied data from src
[in] src Source buffer to copy to dst
Returns
gos_result_t , result of API

gos_dynamic_buffer_free()

void gos_dynamic_buffer_free ( gos_dynamic_buffer_t * buffer )

De-allocate dynamic buffer

This de-allocates the memory used by a gos_dynamic_buffer_t

Parameters
[in] buffer Buffer to de-allocate memory
Examples:
cloud/dps_demo/main.c .

gos_dynamic_buffer_get_buffer()

gos_result_t gos_dynamic_buffer_get_buffer ( const gos_dynamic_buffer_t * dynamic_buffer,
gos_buffer_t * buffer
)

Get buffer contents

This returns a pointer to the buffer and populated size. e.g.:

buffer->data = dynamic_buffer->prepend
buffer->size = buffer->append - buffer->prepend
Parameters
[in] dynamic_buffer gos_dynamic_buffer_t
[out] buffer gos_buffer_t to populated with contents
Returns
gos_result_t , result of API

gos_dynamic_buffer_get_length()

uint32_t gos_dynamic_buffer_get_length ( const gos_dynamic_buffer_t * buffer )

Get populated data length

This returns the populated data length of the buffer. e.g.:

length = buffer->append - buffer->prepend
Parameters
[in] buffer gos_dynamic_buffer_t
Returns
Length of populated data

gos_dynamic_buffer_get_remaining_length()

uint32_t gos_dynamic_buffer_get_remaining_length ( const gos_dynamic_buffer_t * buffer )

Get amount remaining in allocated buffer

This returns the number of unpopulated bytes in the allocated buffer. e.g.:

length = buffer->buffer_end - buffer->append
Parameters
[in] buffer gos_dynamic_buffer_t
Returns
Bytes remaining in allocated buffer

gos_dynamic_buffer_get_total_size()

uint32_t gos_dynamic_buffer_get_total_size ( const gos_dynamic_buffer_t * buffer )

Get allocated buffer size

This return the total size of the gos_dynamic_buffer_t allocated buffer. e.g.:

size = buffer->buffer_end - buffer->buffer
Parameters
[in] buffer gos_dynamic_buffer_t
Returns
Size of allocated buffer

gos_dynamic_buffer_realloc()

gos_result_t gos_dynamic_buffer_realloc ( gos_dynamic_buffer_t * buffer,
uint32_t additional_length
)

Re-allocate dynamic buffer

This allocates a larger buffer if necessary. After this API returns, the given buffer will have at least additional_length of additional space.

Note
The contents of the previous buffer will remain unchanged.
Parameters
[in] buffer gos_dynamic_buffer_t object to allocate a larger buffer (if necessary)
[in] additional_length Additional required size
Returns
gos_result_t , result of API

gos_dynamic_buffer_reset()

void gos_dynamic_buffer_reset ( gos_dynamic_buffer_t * buffer )

Reset buffer pointers

This resets the gos_dynamic_buffer_t append and prepend pointer to the beginning of the allocated buffer.

Parameters
[in] buffer Buffer to reset

gos_dynamic_buffer_vwrite()

gos_result_t gos_dynamic_buffer_vwrite ( gos_dynamic_buffer_t * buffer,
const char * fmt,
va_list args
)

Write formatted string to buffer

This writes a formatted string to the gos_dynamic_buffer_t . The gos_dynamic_buffer_t buffer size will increase as necessary.

Parameters
[in] buffer Buffer to write
[in] fmt Formatted string
[in] args Formatted string arguments
Returns
gos_result_t , result of API

gos_dynamic_buffer_write()

gos_result_t gos_dynamic_buffer_write ( gos_dynamic_buffer_t * buffer,
const void * data,
uint32_t data_length
)

Write data to dynamic buffer

This write data to a gos_dynamic_buffer_t . If the amount of data to write is larger than the buffer's current size then more buffer will be allocated as necessary.

Parameters
[in] buffer Buffer to write
[in] data Data to write to buffer
[in] data_length Size in bytes of `data
Returns
gos_result_t , result of API

gos_dynamic_buffer_writef()

gos_result_t gos_dynamic_buffer_writef ( gos_dynamic_buffer_t * buffer,
const char * fmt,
...
)

Write formatted string to buffer

This writes a formatted string to the gos_dynamic_buffer_t . The gos_dynamic_buffer_t buffer size will increase as necessary.

Parameters
[in] buffer Buffer to write
[in] fmt Formatted string
Returns
gos_result_t , result of API