PebbleOS
Loading...
Searching...
No Matches
Data Structures | Functions
circular_buffer.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Data Structures

struct  CircularBuffer
 Circular buffer state. More...
 

Functions

void circular_buffer_init (CircularBuffer *buffer, uint8_t *storage, uint16_t storage_size)
 Initialize a circular buffer, with auto reset enabled.
 
void circular_buffer_init_ex (CircularBuffer *buffer, uint8_t *storage, uint16_t storage_size, bool auto_reset)
 Initialize a circular buffer, choosing whether it auto resets.
 
bool circular_buffer_write (CircularBuffer *buffer, const void *data, uint16_t length)
 Copy data into the circular buffer.
 
uint16_t circular_buffer_write_prepare (CircularBuffer *buffer, uint8_t **data_out)
 Get a contiguous area of the circular buffer to write to directly.
 
void circular_buffer_write_finish (CircularBuffer *buffer, uint16_t written_length)
 Commit data written after circular_buffer_write_prepare().
 
bool circular_buffer_read (const CircularBuffer *buffer, uint16_t length, const uint8_t **data_out, uint16_t *length_out)
 Get a pointer to the oldest data, without consuming it.
 
uint16_t circular_buffer_copy (const CircularBuffer *buffer, void *data_out, uint16_t length)
 Copy the oldest data out of the circular buffer, without consuming it.
 
uint16_t circular_buffer_copy_offset (const CircularBuffer *buffer, uint16_t start_offset, uint8_t *data_out, uint16_t length)
 Copy data out of the circular buffer, handling the wrap, without consuming it.
 
bool circular_buffer_read_or_copy (const CircularBuffer *buffer, uint8_t **data_out, size_t length, void *(*malloc_imp)(size_t), bool *caller_should_free)
 Get the oldest data as one contiguous array, copying it only when it wraps.
 
bool circular_buffer_consume (CircularBuffer *buffer, uint16_t length)
 Remove the oldest data from the circular buffer.
 
uint16_t circular_buffer_get_write_space_remaining (const CircularBuffer *buffer)
 Get the free space.
 
uint16_t circular_buffer_get_read_space_remaining (const CircularBuffer *buffer)
 Get the amount of data.