hat-util  0.6.14
Utility library
buff.h File Reference

Data buffer. More...

#include <stdint.h>
#include <string.h>
Include dependency graph for buff.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  hat_buff_t
 Data buffer. More...
 

Macros

#define HAT_BUFF_SUCCESS   0
 
#define HAT_BUFF_ERROR   1
 

Functions

static size_t hat_buff_available (hat_buff_t *buff)
 Available capacity. More...
 
static int hat_buff_write (hat_buff_t *buff, uint8_t *data, size_t data_len)
 Write data to buffer. More...
 
static uint8_t * hat_buff_read (hat_buff_t *buff, size_t size)
 Read data from buffer. More...
 

Detailed Description

Data buffer.

Data buffer is simple byte storage with associated size (capacity) and position pointer.

If used as data source, position points to location which is not yet consumed.

If used as data storage, position points to location where next byte should be stored.

Macro Definition Documentation

◆ HAT_BUFF_ERROR

#define HAT_BUFF_ERROR   1

◆ HAT_BUFF_SUCCESS

#define HAT_BUFF_SUCCESS   0

Function Documentation

◆ hat_buff_available()

static size_t hat_buff_available ( hat_buff_t buff)
inlinestatic

Available capacity.

Parameters
[in]buffbuffer instance
Returns
size

Returns difference between size and current position or 0 if current position is greater or equal to size.

◆ hat_buff_read()

static uint8_t* hat_buff_read ( hat_buff_t buff,
size_t  size 
)
inlinestatic

Read data from buffer.

Parameters
[in]buffbuffer instance
[in]sizedata size
Returns
data

Returned data pointer points to buffered data starting from current position. If buffer available capacity is smaller than requested size, NULL is returned. Position is incremented if data is successfully read.

◆ hat_buff_write()

static int hat_buff_write ( hat_buff_t buff,
uint8_t *  data,
size_t  data_len 
)
inlinestatic

Write data to buffer.

Parameters
[in]buffbuffer instance
[in]datadata
[in]data_lendata length
Returns
HAT_BUFF_SUCCESS or HAT_BUFF_ERROR

Data is written to buffer starting from current position. Position is incremented if data is successfully written.