WYRDTEK Home Features Reference Downloads About



int es_mb_save( struct es_mb *db, 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 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_mb_save() repeatedly invokes writefn to save the serialized database in chunks. 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.

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

Node reference fields (i.e. fields of type ES_FLDTYPE_MBN - see es_mbc_addfld()) and duplicate child nodes (i.e. a particular child node instance assigned to two or more parent node instances) are preserved in the save process.

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

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