WYRDTEK Home Features Reference Downloads About


Reference/es_mb_load

Syntax

int es_mbd_load( struct es_mbd *db, struct es_mbio *iofn );

Arguments

struct es_mbd *def Database definition to be loaded.
struct es_mbio *iofn Handle to user-supplied read function.

Return Codes

ES_ERROR_NONE Success. No errors.
ES_ERROR_FAILTOLOAD Failed to load. Check errno for any system errors.

Description

Read and deserialize database definition using user-supplied "read" function. The def definition parameter is assumed to be empty and must have previously been constructed with es_mbd_new().

The iofn parameter is a reference to a struct es_mbio. It contains hooks to user-supplied "read" function (readfn) plus any static data the user function may require:

/* read/write function prototype */
typedef int (*es_mb_io_t)( void *fndata, void *buf, unsigned numbytes );

/* handle for read/write functions and static-data */
struct es_mbio
{
  void      *fndata;  /* user-specific data */
  es_mb_io_t writefn; /* write function */
  es_mb_io_t readfn;  /* read function */
};

es_mbd_load() repeatedly invokes readfn to de-serialize the definition. readfn must load numbytes bytes into buffer buf. The fndata parameter to readfn is provided by the fndata member of struct es_mbio.

readfn must return 0 on success and non-zero on error.

There are two wrapper functions over es_mbd_load, provided for convenience. These include es_mbd_loadfile() for loading from a file and es_mbd_loadbuffer() for loading from an arbitrary file-descriptor - most notably a socket.

[Back To Reference] [Back To Reference/es_mbd]