WYRDTEK Home Features Reference Downloads About



int es_mb_load( struct es_mb *db, struct es_mbio *iofn );


struct es_mb *db Database 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.


Read and deserialize database with using user-supplied "read" function. The db database parameter is assumed to be empty and must have previously been constructed with es_mb_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_mb_load() repeatedly invokes readfn to load the serialized database in chunks. 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.

User-defined fields (see es_mbc_addfldmbu()) must have an associated "load" function defined in order to be de-serialized as part of es_mb_load.

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

[Back To Reference] [Back To Reference/es_mb]