rcutils  master
C API providing common utilities and data structures.
Classes | Typedefs | Functions
uint8_array.h File Reference
#include <stdint.h>
#include "rcutils/allocator.h"
#include "rcutils/types/rcutils_ret.h"
#include "rcutils/visibility_control.h"
Include dependency graph for uint8_array.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rcutils_uint8_array_t
 

Typedefs

typedef struct rcutils_uint8_array_t rcutils_uint8_array_t
 

Functions

rcutils_uint8_array_t rcutils_get_zero_initialized_uint8_array (void)
 Return a zero initialized uint8 array struct. More...
 
rcutils_ret_t rcutils_uint8_array_init (rcutils_uint8_array_t *uint8_array, size_t buffer_capacity, const rcutils_allocator_t *allocator)
 Initialize a zero initialized uint8 array struct. More...
 
rcutils_ret_t rcutils_uint8_array_fini (rcutils_uint8_array_t *uint8_array)
 Finalize a uint8 array struct. More...
 
rcutils_ret_t rcutils_uint8_array_resize (rcutils_uint8_array_t *uint8_array, size_t new_size)
 Resize the internal buffer of the uint8 array. More...
 

Typedef Documentation

◆ rcutils_uint8_array_t

Function Documentation

◆ rcutils_get_zero_initialized_uint8_array()

rcutils_uint8_array_t rcutils_get_zero_initialized_uint8_array ( void  )

Return a zero initialized uint8 array struct.

Returns
rcutils_uint8_array_t a zero initialized uint8 array struct

◆ rcutils_uint8_array_init()

rcutils_ret_t rcutils_uint8_array_init ( rcutils_uint8_array_t uint8_array,
size_t  buffer_capacity,
const rcutils_allocator_t allocator 
)

Initialize a zero initialized uint8 array struct.

This function may leak if the uint8 array struct is already initialized. If the capacity is set to 0, no memory is allocated and the internal buffer is still NULL.

Parameters
[in,out]uint8_arraya pointer to the to be initialized uint8 array struct
[in]buffer_capacitythe size of the memory to allocate for the byte stream
[in]allocatorthe allocator to use for the memory allocation
Returns
RCUTILS_RET_OK if successful, or
RCUTILS_RET_INVALID_ARGUMENTS if any arguments are invalid, or
'RCUTILS_RET_BAD_ALLOCif no memory could be allocated correctly \returnRCUTILS_RET_ERROR` if an unexpected error occurs

◆ rcutils_uint8_array_fini()

rcutils_ret_t rcutils_uint8_array_fini ( rcutils_uint8_array_t uint8_array)

Finalize a uint8 array struct.

Cleans up and deallocates any resources used in a rcutils_uint8_array_t. The array passed to this function needs to have been initialized by rcutils_uint8_array_init(). Passing an uninitialized instance to this function leads to undefined behavior.

Parameters
[in]uint8_arraypointer to the rcutils_uint8_array_t to be cleaned up
Returns
RCUTILS_RET_OK if successful, or
RCUTILS_RET_INVALID_ARGUMENTS if the uint8_array argument is invalid
RCUTILS_RET_ERROR if an unexpected error occurs

◆ rcutils_uint8_array_resize()

rcutils_ret_t rcutils_uint8_array_resize ( rcutils_uint8_array_t uint8_array,
size_t  new_size 
)

Resize the internal buffer of the uint8 array.

The internal buffer of the uint8 array can be resized dynamically if needed. If the new size is smaller than the current capacity, then the memory is truncated. Be aware, that this might deallocate the memory and therefore invalidates any pointers to this storage.

Parameters
[in,out]uint8_arraypointer to the instance of rcutils_uint8_array_t which is being resized
[in]new_sizethe new size of the internal buffer
Returns
RCUTILS_RET_OK if successful, or
RCUTILS_RET_INVALID_ARGUMENT if new_size is set to zero
RCUTILS_RET_BAD_ALLOC if memory allocation failed, or
RCUTILS_RET_ERROR if an unexpected error occurs