Generating a data file
To generate a data file, a bindrv writer context has to be allocated with a call to bindrv_newwriter. This initialisation routine requires a callback function that is used for outputing data to some stream (e.g. use the C function fwrite to write to a file opened with the function fopen). Then, each data value to be saved to the stream is passed to the function corresponding to its type: this routine builds a token equivalent to the provided object and sends it to the stream. For instance, function bindrv_putint will be used to output an integer etc.. In order to structure the data flow, special markers may be inserted: the function bindrv_putctrl allows to add these control tokens. A control token is characterised by its code (an integer between 0 and 31) such that different types of markers can be used. For instance, control code 1 could indicate the beginning of a list of integers, code 4 the beginning of a list of text strings, code 2 for the end of a list and code 3 could be used to mark the end of the data flow. Using this convention, a file containing a list of integers (e.g. 5,6,7) and a list of strings (e.g. "a","b") could be produced with the following code:
bindrv_putctrl(bctx,1); bindrv_putint(bctx,5); bindrv_putint(bctx,6); bindrv_putint(bctx,7); bindrv_putctrl(bctx,2); bindrv_putctrl(bctx,4); bindrv_putstring(bctx,"a"); bindrv_putstring(bctx,"b"); bindrv_putctrl(bctx,2); bindrv_putctrl(bctx,3);