libusual  0.1
Data Structures | Defines | Functions
usual/mbuf.h File Reference

Safe and easy access to memory buffer. More...

Data Structures

struct  MBuf
 MBuf structure. More...

Defines

#define MBUF_FMT
 Format fragment for *printf()
#define MBUF_ARG(m)
 Argument layout for *printf()

Functions

static void mbuf_init_fixed_reader (struct MBuf *buf, const void *ptr, unsigned len)
 Initialize R/O buffer to fixed memory area.
static void mbuf_init_fixed_writer (struct MBuf *buf, void *ptr, unsigned len)
 Initialize R/W buffer to fixed memory area.
static void mbuf_init_dynamic (struct MBuf *buf)
 Initialize R/W buffer to dynamically allocated memory area.
static void mbuf_free (struct MBuf *buf)
 Free dynamically allocated area, if exists.
static void mbuf_rewind_reader (struct MBuf *buf)
 Move read cursor to start of buffer.
static void mbuf_rewind_writer (struct MBuf *buf)
 Move both read and write cursor to start of buffer.
static unsigned mbuf_avail_for_read (const struct MBuf *buf)
 How many bytes can be read with read cursor.
static unsigned mbuf_avail_for_write (const struct MBuf *buf)
 How many bytes can be written with write cursor, without realloc.
static unsigned mbuf_written (const struct MBuf *buf)
 How many data bytes are in buffer.
static unsigned mbuf_consumed (const struct MBuf *buf)
 How many bytes have been read from buffer.
static const void * mbuf_data (const struct MBuf *buf)
 Return pointer to data area.
static bool mbuf_eq (const struct MBuf *buf1, const struct MBuf *buf2)
 Do the mbufs contain same data.
static bool mbuf_eq_str (const struct MBuf *buf1, const char *s)
 Complare mbuf to asciiz string.
static _MUSTCHECK bool mbuf_get_byte (struct MBuf *buf, uint8_t *dst_p)
 Read a byte from read cursor.
static _MUSTCHECK bool mbuf_get_char (struct MBuf *buf, char *dst_p)
 Read big-endian uint16 from read cursor.
static _MUSTCHECK bool mbuf_get_uint32be (struct MBuf *buf, uint32_t *dst_p)
 Read big-endian uint32 from read cursor.
static _MUSTCHECK bool mbuf_get_uint64be (struct MBuf *buf, uint64_t *dst_p)
 Get reference to len bytes from read cursor.
static _MUSTCHECK bool mbuf_get_chars (struct MBuf *buf, unsigned len, const char **dst_p)
 Get reference to asciiz string from read cursor.
_MUSTCHECK bool mbuf_make_room (struct MBuf *buf, unsigned len)
 Allocate more room if needed and the mbuf allows.
static _MUSTCHECK bool mbuf_write_byte (struct MBuf *buf, uint8_t val)
 Write a byte to write cursor.
static _MUSTCHECK bool mbuf_write (struct MBuf *buf, const void *ptr, unsigned len)
 Write len bytes to write cursor.
static _MUSTCHECK bool mbuf_write_raw_mbuf (struct MBuf *dst, struct MBuf *src)
 writes full contents of another mbuf, without touching it
static _MUSTCHECK bool mbuf_write_mbuf (struct MBuf *dst, struct MBuf *src, unsigned len)
 writes partial contents of another mbuf, with touching it
static _MUSTCHECK bool mbuf_fill (struct MBuf *buf, uint8_t byte, unsigned len)
 Fiil mbuf with byte value.
static _MUSTCHECK bool mbuf_cut (struct MBuf *buf, unsigned ofs, unsigned len)
 remove some data from mbuf

Detailed Description

Safe and easy access to memory buffer.


Define Documentation

#define MBUF_FMT

Format fragment for *printf()

#define MBUF_ARG (   m)

Argument layout for *printf()


Function Documentation

static void mbuf_init_fixed_reader ( struct MBuf buf,
const void *  ptr,
unsigned  len 
) [inline, static]

Initialize R/O buffer to fixed memory area.

Referenced by mbuf_eq_str().

static void mbuf_init_fixed_writer ( struct MBuf buf,
void *  ptr,
unsigned  len 
) [inline, static]

Initialize R/W buffer to fixed memory area.

static void mbuf_init_dynamic ( struct MBuf buf) [inline, static]

Initialize R/W buffer to dynamically allocated memory area.

static void mbuf_free ( struct MBuf buf) [inline, static]

Free dynamically allocated area, if exists.

References free.

static void mbuf_rewind_reader ( struct MBuf buf) [inline, static]

Move read cursor to start of buffer.

static void mbuf_rewind_writer ( struct MBuf buf) [inline, static]

Move both read and write cursor to start of buffer.

static unsigned mbuf_avail_for_read ( const struct MBuf buf) [inline, static]

How many bytes can be read with read cursor.

static unsigned mbuf_avail_for_write ( const struct MBuf buf) [inline, static]

How many bytes can be written with write cursor, without realloc.

static unsigned mbuf_written ( const struct MBuf buf) [inline, static]

How many data bytes are in buffer.

Referenced by mbuf_eq(), and mdict_put_buf().

static unsigned mbuf_consumed ( const struct MBuf buf) [inline, static]

How many bytes have been read from buffer.

static const void* mbuf_data ( const struct MBuf buf) [inline, static]

Return pointer to data area.

Referenced by mbuf_eq(), and mdict_put_buf().

static bool mbuf_eq ( const struct MBuf buf1,
const struct MBuf buf2 
) [inline, static]

Do the mbufs contain same data.

References mbuf_data(), and mbuf_written().

Referenced by mbuf_eq_str().

static bool mbuf_eq_str ( const struct MBuf buf1,
const char *  s 
) [inline, static]

Complare mbuf to asciiz string.

References mbuf_eq(), and mbuf_init_fixed_reader().

static _MUSTCHECK bool mbuf_get_byte ( struct MBuf buf,
uint8_t *  dst_p 
) [inline, static]

Read a byte from read cursor.

static _MUSTCHECK bool mbuf_get_char ( struct MBuf buf,
char *  dst_p 
) [inline, static]

Read big-endian uint16 from read cursor.

static _MUSTCHECK bool mbuf_get_uint32be ( struct MBuf buf,
uint32_t *  dst_p 
) [inline, static]

Read big-endian uint32 from read cursor.

Referenced by mbuf_get_uint64be().

static _MUSTCHECK bool mbuf_get_uint64be ( struct MBuf buf,
uint64_t *  dst_p 
) [inline, static]

Get reference to len bytes from read cursor.

References mbuf_get_uint32be().

static _MUSTCHECK bool mbuf_get_chars ( struct MBuf buf,
unsigned  len,
const char **  dst_p 
) [inline, static]

Get reference to asciiz string from read cursor.

_MUSTCHECK bool mbuf_make_room ( struct MBuf buf,
unsigned  len 
)

Allocate more room if needed and the mbuf allows.

Referenced by mbuf_fill(), mbuf_write(), and mbuf_write_byte().

static _MUSTCHECK bool mbuf_write_byte ( struct MBuf buf,
uint8_t  val 
) [inline, static]

Write a byte to write cursor.

References mbuf_make_room().

static _MUSTCHECK bool mbuf_write ( struct MBuf buf,
const void *  ptr,
unsigned  len 
) [inline, static]

Write len bytes to write cursor.

References mbuf_make_room().

Referenced by mbuf_write_mbuf(), and mbuf_write_raw_mbuf().

static _MUSTCHECK bool mbuf_write_raw_mbuf ( struct MBuf dst,
struct MBuf src 
) [inline, static]

writes full contents of another mbuf, without touching it

References mbuf_write().

static _MUSTCHECK bool mbuf_write_mbuf ( struct MBuf dst,
struct MBuf src,
unsigned  len 
) [inline, static]

writes partial contents of another mbuf, with touching it

References mbuf_write().

static _MUSTCHECK bool mbuf_fill ( struct MBuf buf,
uint8_t  byte,
unsigned  len 
) [inline, static]

Fiil mbuf with byte value.

References mbuf_make_room().

static _MUSTCHECK bool mbuf_cut ( struct MBuf buf,
unsigned  ofs,
unsigned  len 
) [inline, static]

remove some data from mbuf