tpubftojson − Convert UBF buffer to JSON object
#include <atmi.h>
int tpubftojson(UBFH *p_ub, char *buffer, int bufsize);
For XATMI client link with −latmiclt −latmi −lubf −lnstd −lpthread −lrt −lm
For XATMI server link with −latmisrv|−latmisrvnomain|−latmisrvinteg −latmi −lubf −lnstd −lpthread −lrt −lm
Function converts UBF buffer in p_ub to JSON object string to buffer string. The field bufsize must indicate the space in buffer. If the size is not enough, function will fail.
For example, following buffer in p_ub:
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
will be converted in following JSON buffer:
{
"T_SHORT_FLD":1765,
"T_LONG_FLD":[
3333111,
2
],
"T_CHAR_FLD":"A",
"T_FLOAT_FLD":1.330000,
"T_DOUBLE_FLD":[
1111.220000,
333,
444
],
"T_STRING_FLD":"HELLO WORLD",
"T_CARRAY_FLD":"AAECA0hFTExPIEJJTkFSWQQFAA=="
}
CARRAY (byte array) data will be converted as base64 string in JSON. In output JSON output formatting newlines might not be present.
Any BFLD_STRING fields converted must be valid UTF−8 encoded strings.
On success, tpacall() return call descriptor (>0); on error, −1 is returned, with tperrno set to indicate the error.
Note that tpstrerror() returns generic error message plus custom message with debug info from last function call.
TPESYSTEM System failure occurred during serving. See logs i.e. user log, or debugs for more info. Might be insufficient memory, JSON or UBF library failure. String does not correspond to UTF−8 format.
TPEOS Not enough space in output buffer.
See atmitest/test024_json/atmiclt24.c for sample code.
Report bugs to support@mavimax.com
ndrxdebug.conf(5), tpjsontoubf(3)
© Mavimax, Ltd