Electroneum
sbuffer.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  sldns_buffer
 

Macros

#define INLINE   static inline
 

Typedefs

typedef struct sldns_buffer sldns_buffer
 

Functions

INLINE uint16_t sldns_read_uint16 (const void *src)
 
INLINE uint32_t sldns_read_uint32 (const void *src)
 
INLINE void sldns_write_uint16 (void *dst, uint16_t data)
 
INLINE void sldns_write_uint32 (void *dst, uint32_t data)
 
INLINE void sldns_write_uint48 (void *dst, uint64_t data)
 
INLINE void sldns_buffer_invariant (sldns_buffer *buffer)
 
sldns_buffersldns_buffer_new (size_t capacity)
 
void sldns_buffer_new_frm_data (sldns_buffer *buffer, void *data, size_t size)
 
void sldns_buffer_init_frm_data (sldns_buffer *buffer, void *data, size_t size)
 
void sldns_buffer_init_vfixed_frm_data (sldns_buffer *buffer, void *data, size_t size)
 
INLINE void sldns_buffer_clear (sldns_buffer *buffer)
 
INLINE void sldns_buffer_flip (sldns_buffer *buffer)
 
INLINE void sldns_buffer_rewind (sldns_buffer *buffer)
 
INLINE size_t sldns_buffer_position (sldns_buffer *buffer)
 
INLINE void sldns_buffer_set_position (sldns_buffer *buffer, size_t mark)
 
INLINE void sldns_buffer_skip (sldns_buffer *buffer, ssize_t count)
 
INLINE size_t sldns_buffer_limit (sldns_buffer *buffer)
 
INLINE void sldns_buffer_set_limit (sldns_buffer *buffer, size_t limit)
 
INLINE size_t sldns_buffer_capacity (sldns_buffer *buffer)
 
int sldns_buffer_set_capacity (sldns_buffer *buffer, size_t capacity)
 
int sldns_buffer_reserve (sldns_buffer *buffer, size_t amount)
 
INLINE uint8_tsldns_buffer_at (const sldns_buffer *buffer, size_t at)
 
INLINE uint8_tsldns_buffer_begin (const sldns_buffer *buffer)
 
INLINE uint8_tsldns_buffer_end (sldns_buffer *buffer)
 
INLINE uint8_tsldns_buffer_current (sldns_buffer *buffer)
 
INLINE size_t sldns_buffer_remaining_at (sldns_buffer *buffer, size_t at)
 
INLINE size_t sldns_buffer_remaining (sldns_buffer *buffer)
 
INLINE int sldns_buffer_available_at (sldns_buffer *buffer, size_t at, size_t count)
 
INLINE int sldns_buffer_available (sldns_buffer *buffer, size_t count)
 
INLINE void sldns_buffer_write_at (sldns_buffer *buffer, size_t at, const void *data, size_t count)
 
INLINE void sldns_buffer_set_at (sldns_buffer *buffer, size_t at, int c, size_t count)
 
INLINE void sldns_buffer_write (sldns_buffer *buffer, const void *data, size_t count)
 
INLINE void sldns_buffer_write_string_at (sldns_buffer *buffer, size_t at, const char *str)
 
INLINE void sldns_buffer_write_string (sldns_buffer *buffer, const char *str)
 
INLINE void sldns_buffer_write_u8_at (sldns_buffer *buffer, size_t at, uint8_t data)
 
INLINE void sldns_buffer_write_u8 (sldns_buffer *buffer, uint8_t data)
 
INLINE void sldns_buffer_write_u16_at (sldns_buffer *buffer, size_t at, uint16_t data)
 
INLINE void sldns_buffer_write_u16 (sldns_buffer *buffer, uint16_t data)
 
INLINE void sldns_buffer_write_u32_at (sldns_buffer *buffer, size_t at, uint32_t data)
 
INLINE void sldns_buffer_write_u48_at (sldns_buffer *buffer, size_t at, uint64_t data)
 
INLINE void sldns_buffer_write_u32 (sldns_buffer *buffer, uint32_t data)
 
INLINE void sldns_buffer_write_u48 (sldns_buffer *buffer, uint64_t data)
 
INLINE void sldns_buffer_read_at (sldns_buffer *buffer, size_t at, void *data, size_t count)
 
INLINE void sldns_buffer_read (sldns_buffer *buffer, void *data, size_t count)
 
INLINE uint8_t sldns_buffer_read_u8_at (sldns_buffer *buffer, size_t at)
 
INLINE uint8_t sldns_buffer_read_u8 (sldns_buffer *buffer)
 
INLINE uint16_t sldns_buffer_read_u16_at (sldns_buffer *buffer, size_t at)
 
INLINE uint16_t sldns_buffer_read_u16 (sldns_buffer *buffer)
 
INLINE uint32_t sldns_buffer_read_u32_at (sldns_buffer *buffer, size_t at)
 
INLINE uint32_t sldns_buffer_read_u32 (sldns_buffer *buffer)
 
INLINE int sldns_buffer_status (sldns_buffer *buffer)
 
INLINE int sldns_buffer_status_ok (sldns_buffer *buffer)
 
int sldns_buffer_printf (sldns_buffer *buffer, const char *format,...) ATTR_FORMAT(printf
 
int void sldns_buffer_free (sldns_buffer *buffer)
 
void * sldns_buffer_export (sldns_buffer *buffer)
 
void sldns_buffer_copy (sldns_buffer *result, sldns_buffer *from)
 

Detailed Description

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

Definition in file sbuffer.h.

Macro Definition Documentation

◆ INLINE

#define INLINE   static inline

Definition at line 26 of file sbuffer.h.

Typedef Documentation

◆ sldns_buffer

typedef struct sldns_buffer sldns_buffer

Definition at line 149 of file sbuffer.h.

Function Documentation

◆ sldns_buffer_at()

INLINE uint8_t* sldns_buffer_at ( const sldns_buffer buffer,
size_t  at 
)

returns a pointer to the data at the indicated position.

Parameters
[in]bufferthe buffer
[in]atposition
Returns
the pointer to the data

Definition at line 355 of file sbuffer.h.

356 {
357  assert(at <= buffer->_limit || buffer->_vfixed);
358  return buffer->_data + at;
359 }
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
Here is the caller graph for this function:

◆ sldns_buffer_available()

INLINE int sldns_buffer_available ( sldns_buffer buffer,
size_t  count 
)

checks if the buffer has count bytes available at the current position

Parameters
[in]bufferthe buffer
[in]counthow much is available
Returns
true or false (as int?)

Definition at line 445 of file sbuffer.h.

446 {
447  return sldns_buffer_available_at(buffer, buffer->_position, count);
448 }
size_t _position
Definition: sbuffer.h:119
mdb_size_t count(MDB_cursor *cur)
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:

◆ sldns_buffer_available_at()

INLINE int sldns_buffer_available_at ( sldns_buffer buffer,
size_t  at,
size_t  count 
)

checks if the buffer has at least COUNT more bytes available. Before reading or writing the caller needs to ensure enough space is available!

Parameters
[in]bufferthe buffer
[in]atindicated position
[in]counthow much is available
Returns
true or false (as int?)

Definition at line 433 of file sbuffer.h.

434 {
435  return count <= sldns_buffer_remaining_at(buffer, at);
436 }
INLINE size_t sldns_buffer_remaining_at(sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:404
mdb_size_t count(MDB_cursor *cur)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_begin()

INLINE uint8_t* sldns_buffer_begin ( const sldns_buffer buffer)

returns a pointer to the beginning of the buffer (the data at position 0).

Parameters
[in]bufferthe buffer
Returns
the pointer

Definition at line 368 of file sbuffer.h.

369 {
370  return sldns_buffer_at(buffer, 0);
371 }
INLINE uint8_t * sldns_buffer_at(const sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:355
Here is the call graph for this function:

◆ sldns_buffer_capacity()

INLINE size_t sldns_buffer_capacity ( sldns_buffer buffer)

returns the number of bytes the buffer can hold.

Parameters
[in]bufferthe buffer
Returns
the number of bytes

Definition at line 321 of file sbuffer.h.

322 {
323  return buffer->_capacity;
324 }
size_t _capacity
Definition: sbuffer.h:125

◆ sldns_buffer_clear()

INLINE void sldns_buffer_clear ( sldns_buffer buffer)

clears the buffer and make it ready for writing. The buffer's limit is set to the capacity and the position is set to 0.

Parameters
[in]bufferthe buffer to clear

Definition at line 213 of file sbuffer.h.

214 {
215  sldns_buffer_invariant(buffer);
216 
217  /* reset status here? */
218 
219  buffer->_position = 0;
220  buffer->_limit = buffer->_capacity;
221 }
size_t _position
Definition: sbuffer.h:119
size_t _limit
Definition: sbuffer.h:122
INLINE void sldns_buffer_invariant(sldns_buffer *buffer)
Definition: sbuffer.h:158
size_t _capacity
Definition: sbuffer.h:125
Here is the call graph for this function:

◆ 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.

◆ sldns_buffer_current()

INLINE uint8_t* sldns_buffer_current ( sldns_buffer buffer)

returns a pointer to the data at the buffer's current position.

Parameters
[in]bufferthe buffer
Returns
the pointer

Definition at line 391 of file sbuffer.h.

392 {
393  return sldns_buffer_at(buffer, buffer->_position);
394 }
size_t _position
Definition: sbuffer.h:119
INLINE uint8_t * sldns_buffer_at(const sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:355
Here is the call graph for this function:

◆ sldns_buffer_end()

INLINE uint8_t* sldns_buffer_end ( sldns_buffer buffer)

returns a pointer to the end of the buffer (the data at the buffer's limit).

Parameters
[in]bufferthe buffer
Returns
the pointer

Definition at line 380 of file sbuffer.h.

381 {
382  return sldns_buffer_at(buffer, buffer->_limit);
383 }
size_t _limit
Definition: sbuffer.h:122
INLINE uint8_t * sldns_buffer_at(const sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:355
Here is the call graph for this function:

◆ sldns_buffer_export()

void* sldns_buffer_export ( sldns_buffer buffer)

Makes the buffer fixed and returns a pointer to the data. The caller is responsible for free'ing the result.

Parameters
[in]*bufferthe buffer to be exported
Returns
void

◆ sldns_buffer_flip()

INLINE void sldns_buffer_flip ( sldns_buffer buffer)

makes the buffer ready for reading the data that has been written to the buffer. The buffer's limit is set to the current position and the position is set to 0.

Parameters
[in]bufferthe buffer to flip
Returns
void

Definition at line 231 of file sbuffer.h.

232 {
233  sldns_buffer_invariant(buffer);
234 
235  buffer->_limit = buffer->_position;
236  buffer->_position = 0;
237 }
size_t _position
Definition: sbuffer.h:119
size_t _limit
Definition: sbuffer.h:122
INLINE void sldns_buffer_invariant(sldns_buffer *buffer)
Definition: sbuffer.h:158
Here is the call graph for this function:

◆ sldns_buffer_free()

int void sldns_buffer_free ( sldns_buffer buffer)

frees the buffer.

Parameters
[in]*bufferthe buffer to be freed
Returns
void

◆ 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

◆ sldns_buffer_init_vfixed_frm_data()

void sldns_buffer_init_vfixed_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 "virtually" fixed. Writes beyond size (the capacity) will only update position, but no data will be written beyond capacity. This allows to determine how big the buffer should have been to contain all the written data, by looking at the position with sldns_buffer_position(), similarly to the return value of POSIX's snprintf.

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

◆ sldns_buffer_invariant()

INLINE void sldns_buffer_invariant ( sldns_buffer buffer)

Definition at line 158 of file sbuffer.h.

159 {
160  assert(buffer != NULL);
161  assert(buffer->_position <= buffer->_limit || buffer->_vfixed);
162  assert(buffer->_limit <= buffer->_capacity);
163  assert(buffer->_data != NULL || (buffer->_vfixed && buffer->_capacity == 0));
164 }
size_t _position
Definition: sbuffer.h:119
size_t _limit
Definition: sbuffer.h:122
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
size_t _capacity
Definition: sbuffer.h:125
Here is the caller graph for this function:

◆ sldns_buffer_limit()

INLINE size_t sldns_buffer_limit ( sldns_buffer buffer)

returns the maximum size of the buffer

Parameters
[in]buffer
Returns
the size

Definition at line 295 of file sbuffer.h.

296 {
297  return buffer->_limit;
298 }
size_t _limit
Definition: sbuffer.h:122

◆ sldns_buffer_new()

sldns_buffer* sldns_buffer_new ( size_t  capacity)

creates a new buffer with the specified capacity.

Parameters
[in]capacitythe size (in bytes) to allocate for the buffer
Returns
the created buffer

◆ 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

◆ sldns_buffer_position()

INLINE size_t sldns_buffer_position ( sldns_buffer buffer)

returns the current position in the buffer (as a number of bytes)

Parameters
[in]bufferthe buffer
Returns
the current position

Definition at line 257 of file sbuffer.h.

258 {
259  return buffer->_position;
260 }
size_t _position
Definition: sbuffer.h:119

◆ sldns_buffer_printf()

int sldns_buffer_printf ( sldns_buffer buffer,
const char *  format,
  ... 
)

prints to the buffer, increasing the capacity if required using buffer_reserve(). The buffer's position is set to the terminating '\0' Returns the number of characters written (not including the terminating '\0') or -1 on failure.

◆ sldns_buffer_read()

INLINE void sldns_buffer_read ( sldns_buffer buffer,
void *  data,
size_t  count 
)

copies count bytes of data at the current position to the given data-array

Parameters
[in]bufferthe buffer
[out]databuffer to copy to
[in]countthe length of the data to copy

Definition at line 657 of file sbuffer.h.

658 {
659  sldns_buffer_read_at(buffer, buffer->_position, data, count);
660  buffer->_position += count;
661 }
size_t _position
Definition: sbuffer.h:119
INLINE void sldns_buffer_read_at(sldns_buffer *buffer, size_t at, void *data, size_t count)
Definition: sbuffer.h:644
mdb_size_t count(MDB_cursor *cur)
Here is the call graph for this function:

◆ sldns_buffer_read_at()

INLINE void sldns_buffer_read_at ( sldns_buffer buffer,
size_t  at,
void *  data,
size_t  count 
)

copies count bytes of data at the given position to the given data-array

Parameters
[in]bufferthe buffer
[in]atthe position in the buffer to start
[out]databuffer to copy to
[in]countthe length of the data to copy

Definition at line 644 of file sbuffer.h.

645 {
646  assert(sldns_buffer_available_at(buffer, at, count));
647  memcpy(data, buffer->_data + at, count);
648 }
mdb_size_t count(MDB_cursor *cur)
uint8_t * _data
Definition: sbuffer.h:128
void * memcpy(void *a, const void *b, size_t c)
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_read_u16()

INLINE uint16_t sldns_buffer_read_u16 ( sldns_buffer buffer)

returns the 2-byte integer value at the current position in the buffer

Parameters
[in]bufferthe buffer
Returns
2 byte integer

Definition at line 708 of file sbuffer.h.

709 {
710  uint16_t result = sldns_buffer_read_u16_at(buffer, buffer->_position);
711  buffer->_position += sizeof(uint16_t);
712  return result;
713 }
size_t _position
Definition: sbuffer.h:119
unsigned short uint16_t
Definition: stdint.h:125
INLINE uint16_t sldns_buffer_read_u16_at(sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:696
Here is the call graph for this function:

◆ sldns_buffer_read_u16_at()

INLINE uint16_t sldns_buffer_read_u16_at ( sldns_buffer buffer,
size_t  at 
)

returns the 2-byte integer value at the given position in the buffer

Parameters
[in]bufferthe buffer
[in]atposition in the buffer
Returns
2 byte integer

Definition at line 696 of file sbuffer.h.

697 {
698  assert(sldns_buffer_available_at(buffer, at, sizeof(uint16_t)));
699  return sldns_read_uint16(buffer->_data + at);
700 }
unsigned short uint16_t
Definition: stdint.h:125
INLINE uint16_t sldns_read_uint16(const void *src)
Definition: sbuffer.h:35
uint8_t * _data
Definition: sbuffer.h:128
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_read_u32()

INLINE uint32_t sldns_buffer_read_u32 ( sldns_buffer buffer)

returns the 4-byte integer value at the current position in the buffer

Parameters
[in]bufferthe buffer
Returns
4 byte integer

Definition at line 734 of file sbuffer.h.

735 {
736  uint32_t result = sldns_buffer_read_u32_at(buffer, buffer->_position);
737  buffer->_position += sizeof(uint32_t);
738  return result;
739 }
INLINE uint32_t sldns_buffer_read_u32_at(sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:722
size_t _position
Definition: sbuffer.h:119
unsigned int uint32_t
Definition: stdint.h:126
Here is the call graph for this function:

◆ sldns_buffer_read_u32_at()

INLINE uint32_t sldns_buffer_read_u32_at ( sldns_buffer buffer,
size_t  at 
)

returns the 4-byte integer value at the given position in the buffer

Parameters
[in]bufferthe buffer
[in]atposition in the buffer
Returns
4 byte integer

Definition at line 722 of file sbuffer.h.

723 {
724  assert(sldns_buffer_available_at(buffer, at, sizeof(uint32_t)));
725  return sldns_read_uint32(buffer->_data + at);
726 }
INLINE uint32_t sldns_read_uint32(const void *src)
Definition: sbuffer.h:46
unsigned int uint32_t
Definition: stdint.h:126
uint8_t * _data
Definition: sbuffer.h:128
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_read_u8()

INLINE uint8_t sldns_buffer_read_u8 ( sldns_buffer buffer)

returns the byte value at the current position in the buffer

Parameters
[in]bufferthe buffer
Returns
1 byte integer

Definition at line 682 of file sbuffer.h.

683 {
684  uint8_t result = sldns_buffer_read_u8_at(buffer, buffer->_position);
685  buffer->_position += sizeof(uint8_t);
686  return result;
687 }
size_t _position
Definition: sbuffer.h:119
INLINE uint8_t sldns_buffer_read_u8_at(sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:670
unsigned char uint8_t
Definition: stdint.h:124
Here is the call graph for this function:

◆ sldns_buffer_read_u8_at()

INLINE uint8_t sldns_buffer_read_u8_at ( sldns_buffer buffer,
size_t  at 
)

returns the byte value at the given position in the buffer

Parameters
[in]bufferthe buffer
[in]atthe position in the buffer
Returns
1 byte integer

Definition at line 670 of file sbuffer.h.

671 {
672  assert(sldns_buffer_available_at(buffer, at, sizeof(uint8_t)));
673  return buffer->_data[at];
674 }
unsigned char uint8_t
Definition: stdint.h:124
uint8_t * _data
Definition: sbuffer.h:128
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_remaining()

INLINE size_t sldns_buffer_remaining ( sldns_buffer buffer)

returns the number of bytes remaining between the buffer's position and limit.

Parameters
[in]bufferthe buffer
Returns
the number of bytes

Definition at line 418 of file sbuffer.h.

419 {
420  return sldns_buffer_remaining_at(buffer, buffer->_position);
421 }
size_t _position
Definition: sbuffer.h:119
INLINE size_t sldns_buffer_remaining_at(sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:404
Here is the call graph for this function:

◆ sldns_buffer_remaining_at()

INLINE size_t sldns_buffer_remaining_at ( sldns_buffer buffer,
size_t  at 
)

returns the number of bytes remaining between the indicated position and the limit.

Parameters
[in]bufferthe buffer
[in]atindicated position
Returns
number of bytes

Definition at line 404 of file sbuffer.h.

405 {
406  sldns_buffer_invariant(buffer);
407  assert(at <= buffer->_limit || buffer->_vfixed);
408  return at < buffer->_limit ? buffer->_limit - at : 0;
409 }
size_t _limit
Definition: sbuffer.h:122
INLINE void sldns_buffer_invariant(sldns_buffer *buffer)
Definition: sbuffer.h:158
unsigned _vfixed
Definition: sbuffer.h:142
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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_rewind()

INLINE void sldns_buffer_rewind ( sldns_buffer buffer)

make the buffer ready for re-reading the data. The buffer's position is reset to 0.

Parameters
[in]bufferthe buffer to rewind

Definition at line 244 of file sbuffer.h.

245 {
246  sldns_buffer_invariant(buffer);
247 
248  buffer->_position = 0;
249 }
size_t _position
Definition: sbuffer.h:119
INLINE void sldns_buffer_invariant(sldns_buffer *buffer)
Definition: sbuffer.h:158
Here is the call graph for this function:

◆ sldns_buffer_set_at()

INLINE void sldns_buffer_set_at ( sldns_buffer buffer,
size_t  at,
int  c,
size_t  count 
)

set the given byte to the buffer at the specified position

Parameters
[in]bufferthe buffer
[in]atthe position (in number of bytes) to write the data at
[in]cthe byte to set to the buffer
[in]countthe number of bytes of bytes to write

Definition at line 481 of file sbuffer.h.

482 {
483  if (!buffer->_vfixed)
484  assert(sldns_buffer_available_at(buffer, at, count));
485  else if (sldns_buffer_remaining_at(buffer, at) == 0)
486  return;
487  else if (count > sldns_buffer_remaining_at(buffer, at)) {
488  memset(buffer->_data + at, c,
489  sldns_buffer_remaining_at(buffer, at));
490  return;
491  }
492  memset(buffer->_data + at, c, count);
493 }
INLINE size_t sldns_buffer_remaining_at(sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:404
mdb_size_t count(MDB_cursor *cur)
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:

◆ 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_set_limit()

INLINE void sldns_buffer_set_limit ( sldns_buffer buffer,
size_t  limit 
)

changes the buffer's limit. If the buffer's position is greater than the new limit the position is set to the limit.

Parameters
[in]bufferthe buffer
[in]limitthe new limit

Definition at line 307 of file sbuffer.h.

308 {
309  assert(limit <= buffer->_capacity);
310  buffer->_limit = limit;
311  if (buffer->_position > buffer->_limit)
312  buffer->_position = buffer->_limit;
313 }
size_t _position
Definition: sbuffer.h:119
size_t _limit
Definition: sbuffer.h:122

◆ sldns_buffer_set_position()

INLINE void sldns_buffer_set_position ( sldns_buffer buffer,
size_t  mark 
)

sets the buffer's position to MARK. The position must be less than or equal to the buffer's limit.

Parameters
[in]bufferthe buffer
[in]markthe mark to use

Definition at line 269 of file sbuffer.h.

270 {
271  assert(mark <= buffer->_limit || buffer->_vfixed);
272  buffer->_position = mark;
273 }
size_t _position
Definition: sbuffer.h:119
unsigned _vfixed
Definition: sbuffer.h:142

◆ sldns_buffer_skip()

INLINE void sldns_buffer_skip ( sldns_buffer buffer,
ssize_t  count 
)

changes the buffer's position by COUNT bytes. The position must not be moved behind the buffer's limit or before the beginning of the buffer.

Parameters
[in]bufferthe buffer
[in]countthe count to use

Definition at line 283 of file sbuffer.h.

284 {
285  assert(buffer->_position + count <= buffer->_limit || buffer->_vfixed);
286  buffer->_position += count;
287 }
size_t _position
Definition: sbuffer.h:119
mdb_size_t count(MDB_cursor *cur)
unsigned _vfixed
Definition: sbuffer.h:142
Here is the call graph for this function:

◆ sldns_buffer_status()

INLINE int sldns_buffer_status ( sldns_buffer buffer)

returns the status of the buffer

Parameters
[in]buffer
Returns
the status

Definition at line 747 of file sbuffer.h.

748 {
749  return (int)buffer->_status_err;
750 }
unsigned _status_err
Definition: sbuffer.h:147
Here is the caller graph for this function:

◆ sldns_buffer_status_ok()

INLINE int sldns_buffer_status_ok ( sldns_buffer buffer)

returns true if the status of the buffer is LDNS_STATUS_OK, false otherwise

Parameters
[in]bufferthe buffer
Returns
true or false

Definition at line 758 of file sbuffer.h.

759 {
760  if (buffer) {
761  return sldns_buffer_status(buffer) == 0;
762  } else {
763  return 0;
764  }
765 }
INLINE int sldns_buffer_status(sldns_buffer *buffer)
Definition: sbuffer.h:747
Here is the call graph for this function:

◆ sldns_buffer_write()

INLINE void sldns_buffer_write ( sldns_buffer buffer,
const void *  data,
size_t  count 
)

writes count bytes of data to the current position of the buffer

Parameters
[in]bufferthe buffer
[in]datathe data to write
[in]countthe length of the data to write

Definition at line 503 of file sbuffer.h.

504 {
505  sldns_buffer_write_at(buffer, buffer->_position, data, count);
506  buffer->_position += count;
507 }
size_t _position
Definition: sbuffer.h:119
mdb_size_t count(MDB_cursor *cur)
INLINE void sldns_buffer_write_at(sldns_buffer *buffer, size_t at, const void *data, size_t count)
Definition: sbuffer.h:458
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_write_at()

INLINE void sldns_buffer_write_at ( sldns_buffer buffer,
size_t  at,
const void *  data,
size_t  count 
)

writes the given data to the buffer at the specified position

Parameters
[in]bufferthe buffer
[in]atthe position (in number of bytes) to write the data at
[in]datapointer to the data to write to the buffer
[in]countthe number of bytes of data to write

Definition at line 458 of file sbuffer.h.

459 {
460  if (!buffer->_vfixed)
461  assert(sldns_buffer_available_at(buffer, at, count));
462  else if (sldns_buffer_remaining_at(buffer, at) == 0)
463  return;
464  else if (count > sldns_buffer_remaining_at(buffer, at)) {
465  memcpy(buffer->_data + at, data,
466  sldns_buffer_remaining_at(buffer, at));
467  return;
468  }
469  memcpy(buffer->_data + at, data, count);
470 }
INLINE size_t sldns_buffer_remaining_at(sldns_buffer *buffer, size_t at)
Definition: sbuffer.h:404
mdb_size_t count(MDB_cursor *cur)
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
void * memcpy(void *a, const void *b, size_t c)
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_write_string()

INLINE void sldns_buffer_write_string ( sldns_buffer buffer,
const char *  str 
)

copies the given (null-delimited) string to the current position at the buffer

Parameters
[in]bufferthe buffer
[in]strthe string to write

Definition at line 527 of file sbuffer.h.

528 {
529  sldns_buffer_write(buffer, str, strlen(str));
530 }
INLINE void sldns_buffer_write(sldns_buffer *buffer, const void *data, size_t count)
Definition: sbuffer.h:503
Here is the call graph for this function:

◆ sldns_buffer_write_string_at()

INLINE void sldns_buffer_write_string_at ( sldns_buffer buffer,
size_t  at,
const char *  str 
)

copies the given (null-delimited) string to the specified position at the buffer

Parameters
[in]bufferthe buffer
[in]atthe position in the buffer
[in]strthe string to write

Definition at line 516 of file sbuffer.h.

517 {
518  sldns_buffer_write_at(buffer, at, str, strlen(str));
519 }
INLINE void sldns_buffer_write_at(sldns_buffer *buffer, size_t at, const void *data, size_t count)
Definition: sbuffer.h:458
Here is the call graph for this function:

◆ sldns_buffer_write_u16()

INLINE void sldns_buffer_write_u16 ( sldns_buffer buffer,
uint16_t  data 
)

writes the given 2 byte integer at the current position in the buffer

Parameters
[in]bufferthe buffer
[in]datathe 16 bits to write

Definition at line 578 of file sbuffer.h.

579 {
580  sldns_buffer_write_u16_at(buffer, buffer->_position, data);
581  buffer->_position += sizeof(data);
582 }
size_t _position
Definition: sbuffer.h:119
INLINE void sldns_buffer_write_u16_at(sldns_buffer *buffer, size_t at, uint16_t data)
Definition: sbuffer.h:565
Here is the call graph for this function:

◆ sldns_buffer_write_u16_at()

INLINE void sldns_buffer_write_u16_at ( sldns_buffer buffer,
size_t  at,
uint16_t  data 
)

writes the given 2 byte integer at the given position in the buffer

Parameters
[in]bufferthe buffer
[in]atthe position in the buffer
[in]datathe 16 bits to write

Definition at line 565 of file sbuffer.h.

566 {
567  if (buffer->_vfixed && at + sizeof(data) > buffer->_limit) return;
568  assert(sldns_buffer_available_at(buffer, at, sizeof(data)));
569  sldns_write_uint16(buffer->_data + at, data);
570 }
size_t _limit
Definition: sbuffer.h:122
INLINE void sldns_write_uint16(void *dst, uint16_t data)
Definition: sbuffer.h:64
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_write_u32()

INLINE void sldns_buffer_write_u32 ( sldns_buffer buffer,
uint32_t  data 
)

writes the given 4 byte integer at the current position in the buffer

Parameters
[in]bufferthe buffer
[in]datathe 32 bits to write

Definition at line 618 of file sbuffer.h.

619 {
620  sldns_buffer_write_u32_at(buffer, buffer->_position, data);
621  buffer->_position += sizeof(data);
622 }
size_t _position
Definition: sbuffer.h:119
INLINE void sldns_buffer_write_u32_at(sldns_buffer *buffer, size_t at, uint32_t data)
Definition: sbuffer.h:591
Here is the call graph for this function:

◆ sldns_buffer_write_u32_at()

INLINE void sldns_buffer_write_u32_at ( sldns_buffer buffer,
size_t  at,
uint32_t  data 
)

writes the given 4 byte integer at the given position in the buffer

Parameters
[in]bufferthe buffer
[in]atthe position in the buffer
[in]datathe 32 bits to write

Definition at line 591 of file sbuffer.h.

592 {
593  if (buffer->_vfixed && at + sizeof(data) > buffer->_limit) return;
594  assert(sldns_buffer_available_at(buffer, at, sizeof(data)));
595  sldns_write_uint32(buffer->_data + at, data);
596 }
size_t _limit
Definition: sbuffer.h:122
INLINE void sldns_write_uint32(void *dst, uint32_t data)
Definition: sbuffer.h:76
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_write_u48()

INLINE void sldns_buffer_write_u48 ( sldns_buffer buffer,
uint64_t  data 
)

writes the given 6 byte integer at the current position in the buffer

Parameters
[in]bufferthe buffer
[in]datathe 48 bits to write

Definition at line 630 of file sbuffer.h.

631 {
632  sldns_buffer_write_u48_at(buffer, buffer->_position, data);
633  buffer->_position += 6;
634 }
size_t _position
Definition: sbuffer.h:119
INLINE void sldns_buffer_write_u48_at(sldns_buffer *buffer, size_t at, uint64_t data)
Definition: sbuffer.h:605
Here is the call graph for this function:

◆ sldns_buffer_write_u48_at()

INLINE void sldns_buffer_write_u48_at ( sldns_buffer buffer,
size_t  at,
uint64_t  data 
)

writes the given 6 byte integer at the given position in the buffer

Parameters
[in]bufferthe buffer
[in]atthe position in the buffer
[in]datathe (lower) 48 bits to write

Definition at line 605 of file sbuffer.h.

606 {
607  if (buffer->_vfixed && at + 6 > buffer->_limit) return;
608  assert(sldns_buffer_available_at(buffer, at, 6));
609  sldns_write_uint48(buffer->_data + at, data);
610 }
size_t _limit
Definition: sbuffer.h:122
INLINE void sldns_write_uint48(void *dst, uint64_t data)
Definition: sbuffer.h:91
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_buffer_write_u8()

INLINE void sldns_buffer_write_u8 ( sldns_buffer buffer,
uint8_t  data 
)

writes the given byte of data at the current position in the buffer

Parameters
[in]bufferthe buffer
[in]datathe 8 bits to write

Definition at line 552 of file sbuffer.h.

553 {
554  sldns_buffer_write_u8_at(buffer, buffer->_position, data);
555  buffer->_position += sizeof(data);
556 }
size_t _position
Definition: sbuffer.h:119
INLINE void sldns_buffer_write_u8_at(sldns_buffer *buffer, size_t at, uint8_t data)
Definition: sbuffer.h:539
Here is the call graph for this function:

◆ sldns_buffer_write_u8_at()

INLINE void sldns_buffer_write_u8_at ( sldns_buffer buffer,
size_t  at,
uint8_t  data 
)

writes the given byte of data at the given position in the buffer

Parameters
[in]bufferthe buffer
[in]atthe position in the buffer
[in]datathe 8 bits to write

Definition at line 539 of file sbuffer.h.

540 {
541  if (buffer->_vfixed && at + sizeof(data) > buffer->_limit) return;
542  assert(sldns_buffer_available_at(buffer, at, sizeof(data)));
543  buffer->_data[at] = data;
544 }
size_t _limit
Definition: sbuffer.h:122
uint8_t * _data
Definition: sbuffer.h:128
unsigned _vfixed
Definition: sbuffer.h:142
INLINE int sldns_buffer_available_at(sldns_buffer *buffer, size_t at, size_t count)
Definition: sbuffer.h:433
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sldns_read_uint16()

INLINE uint16_t sldns_read_uint16 ( const void *  src)

Definition at line 35 of file sbuffer.h.

36 {
37 #ifdef ALLOW_UNALIGNED_ACCESSES
38  return ntohs(*(const uint16_t *) src);
39 #else
40  const uint8_t *p = (const uint8_t *) src;
41  return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
42 #endif
43 }
unsigned short uint16_t
Definition: stdint.h:125
unsigned char uint8_t
Definition: stdint.h:124
Here is the caller graph for this function:

◆ sldns_read_uint32()

INLINE uint32_t sldns_read_uint32 ( const void *  src)

Definition at line 46 of file sbuffer.h.

47 {
48 #ifdef ALLOW_UNALIGNED_ACCESSES
49  return ntohl(*(const uint32_t *) src);
50 #else
51  const uint8_t *p = (const uint8_t *) src;
52  return ( ((uint32_t) p[0] << 24)
53  | ((uint32_t) p[1] << 16)
54  | ((uint32_t) p[2] << 8)
55  | (uint32_t) p[3]);
56 #endif
57 }
unsigned char uint8_t
Definition: stdint.h:124
unsigned int uint32_t
Definition: stdint.h:126
Here is the caller graph for this function:

◆ sldns_write_uint16()

INLINE void sldns_write_uint16 ( void *  dst,
uint16_t  data 
)

Definition at line 64 of file sbuffer.h.

65 {
66 #ifdef ALLOW_UNALIGNED_ACCESSES
67  * (uint16_t *) dst = htons(data);
68 #else
69  uint8_t *p = (uint8_t *) dst;
70  p[0] = (uint8_t) ((data >> 8) & 0xff);
71  p[1] = (uint8_t) (data & 0xff);
72 #endif
73 }
unsigned short uint16_t
Definition: stdint.h:125
unsigned char uint8_t
Definition: stdint.h:124
Here is the caller graph for this function:

◆ sldns_write_uint32()

INLINE void sldns_write_uint32 ( void *  dst,
uint32_t  data 
)

Definition at line 76 of file sbuffer.h.

77 {
78 #ifdef ALLOW_UNALIGNED_ACCESSES
79  * (uint32_t *) dst = htonl(data);
80 #else
81  uint8_t *p = (uint8_t *) dst;
82  p[0] = (uint8_t) ((data >> 24) & 0xff);
83  p[1] = (uint8_t) ((data >> 16) & 0xff);
84  p[2] = (uint8_t) ((data >> 8) & 0xff);
85  p[3] = (uint8_t) (data & 0xff);
86 #endif
87 }
unsigned char uint8_t
Definition: stdint.h:124
unsigned int uint32_t
Definition: stdint.h:126
Here is the caller graph for this function:

◆ sldns_write_uint48()

INLINE void sldns_write_uint48 ( void *  dst,
uint64_t  data 
)

Definition at line 91 of file sbuffer.h.

92 {
93  uint8_t *p = (uint8_t *) dst;
94  p[0] = (uint8_t) ((data >> 40) & 0xff);
95  p[1] = (uint8_t) ((data >> 32) & 0xff);
96  p[2] = (uint8_t) ((data >> 24) & 0xff);
97  p[3] = (uint8_t) ((data >> 16) & 0xff);
98  p[4] = (uint8_t) ((data >> 8) & 0xff);
99  p[5] = (uint8_t) (data & 0xff);
100 }
unsigned char uint8_t
Definition: stdint.h:124
Here is the caller graph for this function: