WYRDTEK Home Features Reference Downloads About



int es_mbd_save( struct es_mbd *def, struct es_mbio *iofn );


struct es_mb *db Database to be saved.
struct es_mbio *iofn Handle to user-supplied write function.

Return Codes

ES_ERROR_NONE Success. No errors.
ES_ERROR_FAILTOSAVE Failed to save. Check errno for any system errors.


Serialize database definition into binary stream and pass to user-provided "write" function.

The iofn parameter is a reference to a struct es_mbio. This contains hooks to user-supplied "write" function (writefn) 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_save() repeatedly invokes writefn to serialize the database definition. writefn must save numbytes bytes of the buffer buf. The fndata parameter to writefn is provided by the fndata member of struct es_mbio.

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

The callback function interface for user-defined fields (provided via es_mbc_addfldmbu() ) are not saved and must be re-applied explicitly to any schema de-serialized via es_mbd_load().

There are two wrapper functions over es_mbd_save, provided for convenience. These include es_mbd_savefile() for saving to files and es_mbd_savebuffer() for saving to arbitrary file-descriptors - most notably sockets.

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