Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
sol-buffer.h File Reference

These are routines that Soletta provides for its buffer implementation. More...

#include <assert.h>
#include <errno.h>
#include <sol-str-slice.h>
#include <sol-types.h>
#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct  sol_buffer
 A sol_buffer is a dynamic array, that can be resized if needed. More...
 

Macros

#define SOL_BUFFER_C_CAST   (struct sol_buffer)
 
#define SOL_BUFFER_CAN_RESIZE(buf)   (!(buf->flags & (SOL_BUFFER_FLAGS_FIXED_CAPACITY | SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED)))
 Convenience flag to check if the buffer is resizable. More...
 
#define SOL_BUFFER_DECLARE_STATIC(name_, size_)
 A helper macro to create a static allocated buffer with a fixed capacity. More...
 
#define SOL_BUFFER_INIT_CONST(data_, size_)   SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = size_, .flags = SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED }
 Helper macro to initialize an buffer with const data. More...
 
#define SOL_BUFFER_INIT_DATA(data_, size_)   SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = size_, .flags = SOL_BUFFER_FLAGS_DEFAULT }
 Helper macro to initialize an buffer with the given data. More...
 
#define SOL_BUFFER_INIT_EMPTY   SOL_BUFFER_C_CAST { .data = NULL, .capacity = 0, .used = 0, .flags = SOL_BUFFER_FLAGS_DEFAULT }
 Helper macro to initialize an empty buffer. More...
 
#define SOL_BUFFER_INIT_FLAGS(data_, size_, flags_)   SOL_BUFFER_C_CAST { .data = data_, .capacity = size_, .used = 0, .flags = (enum sol_buffer_flags)(flags_) }
 Helper macro to initialize an buffer with the given data and flags. More...
 
#define SOL_BUFFER_NEEDS_NUL_BYTE(buf)   (!((buf)->flags & SOL_BUFFER_FLAGS_NO_NUL_BYTE))
 Convenience flag to check for flags not containing SOL_BUFFER_FLAGS_NO_NUL_BYTE, that is, buffers that needs the trailing nul byte terminator. More...
 

Typedefs

typedef struct sol_buffer sol_buffer
 A sol_buffer is a dynamic array, that can be resized if needed. More...
 

Enumerations

enum  sol_buffer_flags {
  SOL_BUFFER_FLAGS_DEFAULT = 0, SOL_BUFFER_FLAGS_FIXED_CAPACITY = (1 << 0), SOL_BUFFER_FLAGS_NO_FREE = (1 << 1), SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED = (SOL_BUFFER_FLAGS_FIXED_CAPACITY | SOL_BUFFER_FLAGS_NO_FREE),
  SOL_BUFFER_FLAGS_NO_NUL_BYTE = (1 << 2), SOL_BUFFER_FLAGS_CLEAR_MEMORY = (1 << 3)
}
 Flags used to set sol_buffer capabilities. More...
 
enum  sol_decode_case { SOL_DECODE_UPPERCASE, SOL_DECODE_LOWERCASE, SOL_DECODE_BOTH }
 Case of a string to be decoded. More...
 

Functions

int sol_buffer_append_as_base16 (struct sol_buffer *buf, const struct sol_str_slice slice, bool uppercase)
 Append the 'slice' at the end of 'buf' encoded as base16 (hexadecimal). More...
 
int sol_buffer_append_as_base64 (struct sol_buffer *buf, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)])
 Append the 'slice' at the end of 'buf' encoded as base64 using the given map. More...
 
int sol_buffer_append_buffer (struct sol_buffer *dst, const struct sol_buffer *src)
 Appends the contents of the buffer from in the end of buf, reallocating if necessary. More...
 
int sol_buffer_append_bytes (struct sol_buffer *buf, const uint8_t *bytes, size_t size)
 Appends the bytes array to the end of buf, reallocating if necessary. More...
 
int sol_buffer_append_char (struct sol_buffer *buf, const char c)
 Appends character c into the end of buf, reallocating if necessary. More...
 
int sol_buffer_append_from_base16 (struct sol_buffer *buf, const struct sol_str_slice slice, enum sol_decode_case decode_case)
 Append the 'slice' at the end of 'buf' decoded from base16 (hexadecimal). More...
 
int sol_buffer_append_from_base64 (struct sol_buffer *buf, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)])
 Append the 'slice' at the end of 'buf' decoded from base64 using the given map. More...
 
int static int sol_buffer_append_printf (struct sol_buffer *buf, const char *fmt,...) SOL_ATTR_PRINTF(2
 Append the formatted string in the end of the buffer (including trailing '\0'). More...
 
int sol_buffer_append_slice (struct sol_buffer *buf, const struct sol_str_slice slice)
 Appends slice into the end of buf, reallocating if necessary. More...
 
int sol_buffer_append_vprintf (struct sol_buffer *buf, const char *fmt, va_list args) SOL_ATTR_PRINTF(2
 Append the formatted string in the end of the buffer (including trailing '\0'). More...
 
static void * sol_buffer_at (const struct sol_buffer *buf, size_t pos)
 Returns a pointer to the data at position pos in the buffer buf. More...
 
static void * sol_buffer_at_end (const struct sol_buffer *buf)
 Returns a pointer to the end of the used portion of the buffer. More...
 
struct sol_buffersol_buffer_copy (const struct sol_buffer *buf)
 Allocate a new sol_buffer and a new data block and copy the contents of the provided sol_buffer. More...
 
int sol_buffer_ensure (struct sol_buffer *buf, size_t min_size)
 Ensures that buf has at least min_size. More...
 
int sol_buffer_ensure_nul_byte (struct sol_buffer *buf)
 Ensures that buffer has a terminating NULL byte. More...
 
int sol_buffer_expand (struct sol_buffer *buf, size_t bytes)
 Increment the buffer capacity to fit the bytes. More...
 
void sol_buffer_fini (struct sol_buffer *buf)
 Finalizes the buffer. More...
 
static void sol_buffer_free (struct sol_buffer *buf)
 Delete the buffer. More...
 
static struct sol_str_slice sol_buffer_get_slice (const struct sol_buffer *buf)
 Creates a string slice from the buffer's valid data. More...
 
static struct sol_str_slice sol_buffer_get_slice_at (const struct sol_buffer *buf, size_t pos)
 Creates a string slice from the buffer's data starting at position pos. More...
 
static void sol_buffer_init (struct sol_buffer *buf)
 Initializes a sol_buffer structure. More...
 
static void sol_buffer_init_flags (struct sol_buffer *buf, void *data, size_t data_size, enum sol_buffer_flags flags)
 Initializes a sol_buffer structure with the given data and flags. More...
 
int sol_buffer_insert_as_base16 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, bool uppercase)
 Insert the 'slice' into 'buf' at position 'pos' encoded as base16 (hexadecimal). More...
 
int sol_buffer_insert_as_base64 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)])
 Insert the 'slice' into 'buf' at position 'pos' encoded as base64 using the given map. More...
 
static int sol_buffer_insert_buffer (struct sol_buffer *dst, size_t pos, const struct sol_buffer *src)
 Insert the dst into src at position pos, reallocating if necessary. More...
 
int sol_buffer_insert_bytes (struct sol_buffer *buf, size_t pos, const uint8_t *bytes, size_t size)
 Insert the bytes array into buf at position pos, reallocating if necessary. More...
 
int sol_buffer_insert_char (struct sol_buffer *buf, size_t pos, const char c)
 Insert character c into buf at position pos, reallocating if necessary. More...
 
int sol_buffer_insert_from_base16 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, enum sol_decode_case decode_case)
 Insert the 'slice' into 'buf' at position 'pos' decoded from base16 (hexadecimal). More...
 
int sol_buffer_insert_from_base64 (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)])
 Insert the 'slice' into 'buf' at position 'pos' decoded from base64 using the given map. More...
 
int static int sol_buffer_insert_printf (struct sol_buffer *buf, size_t pos, const char *fmt,...) SOL_ATTR_PRINTF(3
 Insert the formatted string in the given position in the buffer. More...
 
int sol_buffer_insert_slice (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice)
 Insert the slice into buf at position pos, reallocating if necessary. More...
 
int sol_buffer_insert_vprintf (struct sol_buffer *buf, size_t pos, const char *fmt, va_list args) SOL_ATTR_PRINTF(3
 Insert the formatted string in the given position in the buffer. More...
 
static struct sol_buffersol_buffer_new (void)
 Creates a new buffer. More...
 
int sol_buffer_remove_data (struct sol_buffer *buf, size_t offset, size_t size)
 Removes part of data inside the buffer rearranging the memory properly. More...
 
static void sol_buffer_reset (struct sol_buffer *buf)
 Reset the buffer content. More...
 
int sol_buffer_resize (struct sol_buffer *buf, size_t new_size)
 Resize the buffer to the given size. More...
 
static int sol_buffer_set_buffer (struct sol_buffer *dst, const struct sol_buffer *src)
 Copy src into dst, ensuring that will fit. More...
 
static int sol_buffer_set_buffer_at (struct sol_buffer *dst, size_t pos, const struct sol_buffer *src)
 Copy src into dst at position pos, ensuring that will fit. More...
 
int sol_buffer_set_char_at (struct sol_buffer *buf, size_t pos, char c)
 Set character c into buf at position pos, reallocating if necessary. More...
 
int sol_buffer_set_slice (struct sol_buffer *buf, const struct sol_str_slice slice)
 Copy slice into buf, ensuring that will fit. More...
 
int sol_buffer_set_slice_at (struct sol_buffer *buf, size_t pos, const struct sol_str_slice slice)
 Set the string slice slice into buf at position pos, reallocating if necessary. More...
 
void * sol_buffer_steal (struct sol_buffer *buf, size_t *size)
 'Steals' sol_buffer internal buffer and resets sol_buffer. More...
 
void * sol_buffer_steal_or_copy (struct sol_buffer *buf, size_t *size)
 'Steals' buf internal buffer and resets it. More...
 
struct sol_blobsol_buffer_to_blob (struct sol_buffer *buf)
 Convert a buffer to a struct sol_blob. More...
 
static int sol_buffer_trim (struct sol_buffer *buf)
 Frees memory that is not in being used by the buffer. More...
 

Variables

const char SOL_BASE64_MAP [66]
 The default base 64 map to use. More...
 

Detailed Description

These are routines that Soletta provides for its buffer implementation.

Macro Definition Documentation

#define SOL_BUFFER_C_CAST   (struct sol_buffer)