Bvfprintcb — Print view to callback function
#include <ubf.h>
int Bvprint (char * cstruct, char * view);
int Bvfprint (char * cstruct, char * view, FILE * outf);
int Bvfprintcb (char * cstruct, char * view, ndrx_plugin_tplogprintubf_hook_t p_writef, void * dataptr1);
Link with -lubf -lnstd -lm -lpthread
Group of functions used for printing the VIEW type structure. Bvprint() prints the view to stdout. Bvfprint() prints the view to specified output file stream. Bvfprintcb() prints the buffer to callback function.
The callback function shall be created according to ndrx_plugin_tplogprintubf_hook_t signature which is:
typedef int (*ndrx_plugin_tplogprintubf_hook_t)(char **buffer, long datalen, void *dataptr1, int *do_write, FILE * outf, int fid);
The callback receives buffer parameter with ASCII chars to print. The datalen indicates the data length in the buffer, this includes a newline and EOS byte. dataptr1 is forwarded from the Bvfprintcb() call to callback. Parameters: do_write, outf are not used. fid is set field number starting from 0 which is being printed. On return callback function shall return 0 in case of success. In case of failure, non 0 value shall be returned.
Data format for printing to stdout or FILE stream is following: "<FIELD><TAB><VALUE><NEW_LINE>". When printing to callback, additionally EOS (0x00) byte is added for each of the lines printed in *buffer.
When printing char, strings or carray data output is escaped with following rules, if given ASCII chars is not isprint() or is iscntrl(), then data is escaped as "\xx", where xx is hex number of byte, in lower case.
View structure:
VIEW UBTESTVIEW1 #type cname fbname count flag size null int tint2 T_LONG_2_FLD 2 FS - 0 int tint3 - 1 - - -1 int tint4 - 2 - - -1 char tchar1 T_CHAR_FLD 1 F - '\n' char tchar2 T_CHAR_2_FLD 5 SC - 'A' carray tcarray2 T_CARRAY_2_FLD 1 LFSP 25 '\0\n\t\f\\\'\"\vHELLOWORL\n' END
Would be printed as:
tint2 54545 tint2 23232 tint3 -100 tint4 1010101 tint4 989898 tchar1 A tchar2 A tchar2 B tchar2 C tchar2 \0a tchar2 \09 tcarray2 \01\02\03\04\05
When array fields are printed, if they have "C" count indicator, then this number of fields are printed (i.e. may be printed less fields than actually defined in array). If "L" length indicator is present for field definition for carray type, then only number of bytes set in length indicator is printed.
On success, Bvprint(), Bvfprint() and Bvfprintcb() return zero; on error, -1 is returned, with Berror set to indicate the error.
Note that Bstrerror() returns generic error message plus custom message with debug info from last function call.
Following additional errors may be returned by this function:
BEINVAL cstruct, view or p_writef is NULL. p_writef callback failed (returned non 0).
BBADVIEW View name specified in view is not found in VIEWFILES env config.
BNOCNAME Invalid counter "C" indicator specified in view structure (i.e. count set is higher than dimensions for array).
BMALLOC Failed to malloc temporary buffers.