uLib
Functions
ustream.h File Reference

ustream implementation for local memory More...

#include "ustream_base.h"
#include "azure_macro_utils/macro_utils.h"
#include "umock_c/umock_c_prod.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

AZ_ULIB_RESULT az_ustream_init (AZ_USTREAM *ustream_instance, AZ_USTREAM_DATA_CB *ustream_control_block, AZ_RELEASE_CALLBACK control_block_release, const uint8_t *const data_buffer, size_t data_buffer_length, AZ_RELEASE_CALLBACK data_buffer_release)
 Factory to initialize a new ustream. More...
 
AZ_ULIB_RESULT az_ustream_concat (AZ_USTREAM *ustream_instance, AZ_USTREAM *ustream_to_concat, AZ_USTREAM_MULTI_DATA_CB *multi_data, AZ_RELEASE_CALLBACK multi_data_release)
 Concatenate a ustream to the existing ustream. More...
 
AZ_ULIB_RESULT az_ustream_split (AZ_USTREAM *ustream_instance, AZ_USTREAM *ustream_instance_split, offset_t split_pos)
 Split a ustream at a given position. More...
 

Detailed Description

ustream implementation for local memory

Definition in file ustream.h.

Function Documentation

◆ az_ustream_concat()

AZ_ULIB_RESULT az_ustream_concat ( AZ_USTREAM ustream_instance,
AZ_USTREAM ustream_to_concat,
AZ_USTREAM_MULTI_DATA_CB multi_data,
AZ_RELEASE_CALLBACK  multi_data_release 
)

Concatenate a ustream to the existing ustream.

The concat will effectively append a ustream at the end of the passed ustream_instance. To do that, the concat will copy the ustream_instance into a AZ_USTREAM_MULTI_DATA_CB and clone the ustream_to_concat inside the AZ_USTREAM_MULTI_DATA_CB. When returned, the original ustream_instance will point to the AZ_USTREAM_DATA_CB inside of the passed multi_data. The data of the passed ustream_instance will at that point be read as if the content of the orignal ustream_instance and ustream_to_concat were one ustream. This means that both ustream_instance and ustream_to_concat will have to be disposed by the calling function.

Parameters
[in,out]ustream_instanceThe AZ_USTREAM* with the interface of the ustream. It cannot be NULL, and it shall be a valid ustream.
[in]ustream_to_concatThe AZ_USTREAM* with the interface of the ustream to concat to ustream_instance. It cannot be NULL, and it shall be a valid ustream.
[in]multi_dataThe AZ_USTREAM_MULTI_DATA_CB* pointing to the allocated multi data control block. It must be allocated in a way that it remains a valid address until the passed multi_data_release is invoked some time in the future.
[in]multi_data_releaseThe AZ_RELEASE_CALLBACK callback which will be called once the number of references to the control block reaches zero. It may be NULL if no future cleanup is needed.
Returns
The AZ_ULIB_RESULT with the result of the concat operation.
Return values
AZ_ULIB_SUCCESSIf the AZ_USTREAM is concatenated with success.
AZ_ULIB_ILLEGAL_ARGUMENT_ERRORIf one of the provided parameters is invalid.

◆ az_ustream_init()

AZ_ULIB_RESULT az_ustream_init ( AZ_USTREAM ustream_instance,
AZ_USTREAM_DATA_CB ustream_control_block,
AZ_RELEASE_CALLBACK  control_block_release,
const uint8_t *const  data_buffer,
size_t  data_buffer_length,
AZ_RELEASE_CALLBACK  data_buffer_release 
)

Factory to initialize a new ustream.

This factory initializes a ustream that handles the content of the provided buffer. As a result, it will return an AZ_USTREAM* with this content. The initialized ustream takes ownership of the passed memory and will release the memory with the passed AZ_RELEASE_CALLBACK function when the ref count of the ustream_control_block goes to zero.

Parameters
[out]ustream_instanceThe pointer to the allocated AZ_USTREAM struct. This memory must be valid from the time az_ustream_init() is called through az_ustream_dispose(). The ustream will not free this struct and it is the responsibility of the developer to make sure it is valid during the time frame described above. It cannot be NULL.
[in]ustream_control_blockThe pointer to the allocated AZ_USTREAM_DATA_CB struct. This memory should be allocated in a way that it stays valid until the passed control_block_release is called at some (potentially) unknown time in the future. It cannot be NULL.
[in]control_block_releaseThe AZ_RELEASE_CALLBACK function that will be called to release the control block (the passed ustream_control_block parameter) once all the references to the ustream are diposed. If NULL is passed, the data is assumed to be constant with no need to be free'd. In other words, there is no need for notification that the memory may be released. As a default, developers may use the stdlib free to release malloc'd memory.
[in]data_bufferThe const uint8_t* const that points to a memory position where the buffer starts. It cannot be NULL.
[in]data_buffer_lengthThe size_t with the number of uint8_t in the provided buffer. It shall be larger than zero.
[in]data_buffer_releaseThe AZ_RELEASE_CALLBACK function that will be called to release the data once all the references to the ustream are disposed. If NULL is passed, the data is assumed to be constant with no need to be free'd. In other words, there is no need for notification that the memory may be released. As a default, developers may use the stdlib free to release malloc'd memory.
Returns
The AZ_ULIB_RESULT with result of the initialization.
Return values
AZ_ULIB_SUCCESSIf the AZ_USTREAM* is successfully initialized.
AZ_ULIB_ILLEGAL_ARGUMENT_EXCEPTIONIf one of the provided parameters is invalid.

◆ az_ustream_split()

AZ_ULIB_RESULT az_ustream_split ( AZ_USTREAM ustream_instance,
AZ_USTREAM ustream_instance_split,
offset_t  split_pos 
)

Split a ustream at a given position.

The split will divide a given ustream into two parts, divided at the passed split_pos. The result of this operation will be two ustream instances. The first and original ustream will contain the data from the original first valid position up to but not including the passed split_pos. Its current position will be the same as it was when passed. The second ustream will contain the data from the passed split_pos up to the end of the ustream_instance before the function was called. It's current position will be the same as split_pos. The split_pos should be relative to the position returned from az_ustream_get_position() and the remaining size of ustream_instance.

Parameters
[in,out]ustream_instanceThe AZ_USTREAM* with the interface of the ustream. It cannot be NULL, and it shall be a valid ustream.
[out]ustream_instance_splitThe AZ_USTREAM* with the interface of the ustream which will contain the controls to the data after split_pos. It cannot be NULL.
[in]split_posThe offset_t at which to split the passed ustream_instance. It cannot be equal to the current position of ustream_instance or equal to the current position + remaining size. In other words, resulting ustreams of size 0 are not allowed.
Returns
The AZ_ULIB_RESULT with the result of the concat operation.
Return values
AZ_ULIB_SUCCESSIf the AZ_USTREAM is split with success.
AZ_ULIB_ILLEGAL_ARGUMENT_ERRORIf one of the provided parameters is invalid.
AZ_ULIB_NO_SUCH_ELEMENT_ERRORIf the input split_pos is outside the allowed range.