Function rcutils_encode_base64

Function Documentation

rcutils_ret_t rcutils_encode_base64(const rcutils_uint8_array_t *byte_array, char **base64_str, const rcutils_allocator_t *allocator)

Encode a byte array into a base64-encoded string.

This function converts a binary byte array into its base64-encoded representation. Base64 encoding uses 4 ASCII characters to represent 3 bytes of data.

The output string should be freed by the caller using the provided allocator.

Parameters:
  • byte_array – The rcutils_uint8_array_t structure containing the byte array to encode.

  • base64_str – Pointer to store the allocated base64 string (output).

  • allocator – The allocator to use for memory allocation.

Returns:

RCUTILS_RET_OK on success.

Returns:

RCUTILS_RET_INVALID_ARGUMENT if byte_array is NULL, or if byte_array->buffer is NULL, or if byte_array->buffer_length is zero, or if base64_str is NULL, or if allocator is NULL or invalid.

Returns:

RCUTILS_RET_ERROR if byte_array length exceeds limit for base64 encoding.

Returns:

RCUTILS_RET_BAD_ALLOC if memory allocation fails.