User Tools

Site Tools


Sidebar

Table Of Contents

endurox:v7.5.x:api:ubf:bextread.3

bextread

Name

Bextread — Restore the buffer from printed text stream

Synopsis

#include <ubf.h>

int Bextread (UBFH *p_ub, FILE *inf);

Link with -lubf -lnstd -lm -lpthread

DESCRIPTION

Restore the buffer from text populated by Bprint(3) or Bprintf(3).

The read format is "[COMMAND]<FIELD><TAB><VALUE><NEW_LINE>". Input also support fields by id, then format for <FIELD> is "((BFLDID32)<FIELD_ID>)"

Sample buffer:

T_SHORT_FLD     1765
T_LONG_FLD      3333111
T_LONG_FLD      2
T_CHAR_FLD      A
T_FLOAT_FLD     1.33000
T_DOUBLE_FLD    1111.220000
T_DOUBLE_FLD    333.000000
T_DOUBLE_FLD    444.000000
T_STRING_FLD    HELLO WORLD
T_CARRAY_FLD    \00\01\02\03HELLO BINARY\04\05\00\\
((BFLDID32)167772261)   HELLOSVC

p_ub is buffer to write the data to, inf is input stream.

Input format supports also macro commands. This is optional COMMAND block, that can have following values:

+ set the field value at occurrence 0.

- delete field from buffer.

= copy the field value from field name which is stored at <VALUE>.

# comment, line ignored

For example:

# Set the field value
T_SHORT_FLD     123
# Copy the value from T_SHORT_FLD to T_LONG_FLD
=T_LONG_FLD     T_SHORT_FLD
# Change the occurrence 0 to 444
+T_SHORT_FLD    444

The final buffer will be:

T_SHORT_FLD     444
T_LONG_FLD      123

This format is used by ud(8) command line utility which allows to send arbitrary buffer to specified service.

RETURN VALUE

On success, Bextread() return zero; on error, -1 is returned, with Berror set to indicate the error.

ERRORS

Note that Bstrerror() returns generic error message plus custom message with debug info from last function call.

BALIGNERR Corrupted buffer or pointing to not aligned memory area.

BNOTFLD Buffer not fielded, not correctly allocated or corrupted.

BEINVAL inf is NULL.

BSYNTAX Missing tab between field id or missing newline.

BBADNAME Field not found in field table.

EXAMPLE

See ubftest/test_print.c for sample code.

BUGS

Report bugs to support@mavimax.com

COPYING

© Mavimax, Ltd