Simple tools for networking / objects in plain C Snapshot
Classes | Defines | Typedefs | Functions
bf.h File Reference
#include <nutils/endutil.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  tagBF

Defines

#define BF_DECLARE_PUT_MACRO(type)
#define BF_DECLARE_GET_MACRO(type)
#define BF_DECLARE_PUT_UNSAFE_MACRO(type)
#define BF_DECLARE_GET_UNSAFE_MACRO(type)

Typedefs

typedef struct tagBF BF

Functions

M_INLINE void BF_init (BF *bf, void *buffer, size_t buffer_size)
 initialise an empty protocol buffer object. start and end cover the whole memory range. nitiay get and put pointer are set to start of range.
int BF_check (BF *bf)
 validates a buffer - checks all invariants.
M_INLINE void BF_get_mode (BF *bf)
 set pointers so that we can 'get' the whole range from start to end.
M_INLINE void BF_put_mode (BF *bf)
 set pointers so that we can 'put' the whole range from start to end.
M_INLINE size_t BF_get_size (BF *bf)
 returns number of bytes that can be returned by _get_
M_INLINE size_t BF_put_size (BF *bf)
 returns number of bytes that can be written by _put_
int BF_set_start (BF *bf, size_t pos)
 set start position, position is relative to start of memory range.
int BF_set_end (BF *bf, size_t pos)
 set end position, position is relative to start of memory range.
int BF_set_get (BF *bf, size_t pos)
 set get position, position is relative to 'start' pointer.
int BF_set_put (BF *bf, size_t pos)
 set put position, position is relative to 'start' pointer.
M_INLINE size_t BF_can_get (BF *bf)
 returns number of bytes that cam be read from this buffer (i.e. that BF_get_(type) return )
M_INLINE size_t BF_can_put (BF *bf)
 returns number of bytes that cam be placed into this buffer (i.e. that BF_put_(type) places into this buffer )
M_INLINE int BF_is_full (BF *bf)
 return 1 if the whole buffer is fulled with data (get_pos == start && put_pos == end)
int BF_compact (BF *bf)
 moves get_pos to start position; moves content between get_pos and put_pos if not empty.a Always succeeds returns 0 if bytes were moved, 1 if buffer was empty to begin with.
char * BF_get_line (BF *bf, int eof_line)
char * BF_get_line_ext (BF *bf, const char *eof_line, size_t eof_line_size)
M_INLINE int BF_putn (BF *bf, void *data, size_t data_size)
 add memory block to buffer