sbuffer.c File Reference
#include "config.h"
#include "sldns/sbuffer.h"
#include <stdarg.h>

Functions

sldns_buffersldns_buffer_new (size_t capacity)
 creates a new buffer with the specified capacity. More...
 
void sldns_buffer_new_frm_data (sldns_buffer *buffer, void *data, size_t size)
 creates a buffer with the specified data. More...
 
void sldns_buffer_init_frm_data (sldns_buffer *buffer, void *data, size_t size)
 Setup a buffer with the data pointed to. More...
 
int sldns_buffer_set_capacity (sldns_buffer *buffer, size_t capacity)
 changes the buffer's capacity. More...
 
int sldns_buffer_reserve (sldns_buffer *buffer, size_t amount)
 ensures BUFFER can contain at least AMOUNT more bytes. More...
 
int sldns_buffer_printf (sldns_buffer *buffer, const char *format,...)
 
void sldns_buffer_free (sldns_buffer *buffer)
 frees the buffer. More...
 
void sldns_buffer_copy (sldns_buffer *result, sldns_buffer *from)
 Copy contents of the from buffer to the result buffer and then flips the result buffer. More...
 

Detailed Description

This file contains the definition of sldns_buffer, and functions to manipulate those.

Function Documentation

◆ sldns_buffer_new()

◆ sldns_buffer_new_frm_data()

void sldns_buffer_new_frm_data ( sldns_buffer buffer,
void *  data,
size_t  size 
)

creates a buffer with the specified data.

The data IS copied and MEMORY allocations are done. The buffer is not fixed and can be resized using buffer_reserve().

Parameters
[in]bufferpointer to the buffer to put the data in
[in]datathe data to encapsulate in the buffer
[in]sizethe size of the data

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, sldns_buffer::_limit, sldns_buffer::_position, and sldns_buffer::_status_err.

Referenced by hex_buffer2wire().

◆ sldns_buffer_init_frm_data()

void sldns_buffer_init_frm_data ( sldns_buffer buffer,
void *  data,
size_t  size 
)

Setup a buffer with the data pointed to.

No data copied, no memory allocs. The buffer is fixed.

Parameters
[in]bufferpointer to the buffer to put the data in
[in]datathe data to encapsulate in the buffer
[in]sizethe size of the data

References sldns_buffer::_capacity, sldns_buffer::_data, sldns_buffer::_fixed, and sldns_buffer::_limit.

Referenced by decompress_rr_into_buffer().

◆ sldns_buffer_set_capacity()

int sldns_buffer_set_capacity ( sldns_buffer buffer,
size_t  capacity 
)

changes the buffer's capacity.

The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity.

Parameters
[in]bufferthe buffer
[in]capacitythe capacity to use
Returns
whether this failed or succeeded

◆ sldns_buffer_reserve()

int sldns_buffer_reserve ( sldns_buffer buffer,
size_t  amount 
)

ensures BUFFER can contain at least AMOUNT more bytes.

The buffer's capacity is increased if necessary using buffer_set_capacity().

The buffer's limit is always set to the (possibly increased) capacity.

Parameters
[in]bufferthe buffer
[in]amountamount to use
Returns
whether this failed or succeeded

◆ sldns_buffer_free()

◆ sldns_buffer_copy()

void sldns_buffer_copy ( sldns_buffer result,
sldns_buffer from 
)

Copy contents of the from buffer to the result buffer and then flips the result buffer.

Data will be silently truncated if the result buffer is too small.

Parameters
[out]*resultresulting buffer which is copied to.
[in]*fromwhat to copy to result.

References sldns_buffer_begin(), sldns_buffer_capacity(), sldns_buffer_clear(), sldns_buffer_flip(), sldns_buffer_limit(), and sldns_buffer_write().

Referenced by entry_to_buf(), mesh_make_new_space(), and reply_and_prefetch().