tpexport — export UBF|VIEW|STRING|CARRAY|JSON type buffer into the JSON formatted text buffer
#include <atmi.h>
int tpexport(char *ibuf, long ilen, char *ostr, long *olen, long flags);
For XATMI client link with -latmiclt -latmi -lview -lnstd -lpthread -lrt -lm
For XATMI server link with -latmisrv|-latmisrvnomain|-latmisrvinteg -latmi -lview -lnstd -lpthread -lrt -lm
Function converts typed buffer to JSON formatted text buffer.
ibuf is XATMI buffer which will be exported to JSON formatted text buffer. ilen is used for buffer types such CARRAY, where buffer length is not described by type. ostr exported output JSON formatted text buffer. If TPEX_STRING flag is set, then JSON buffer will be converted to base64. olen define maximum size for ostr
JSON tags in the exported file:
For example following UBF buffer
T_SHORT_FLD 1765 T_LONG_FLD 3333111 T_LONG_FLD 2 T_CHAR_FLD A T_FLOAT_FLD 1.00000 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 exported to following JSON
{ "buftype":"UBF", "version":1, "data": { "T_SHORT_FLD:1765, "T_LONG_FLD":[3333111,2], "T_CHAR_FLD":"A", "T_FLOAT_FLD":1, "T_DOUBLE_FLD":[1111.220000,333,444], "T_STRING_FLD":"HELLO WORLD", "T_CARRAY_FLD":"AAECA0hFTExPIEJJTkFSWQQFAA==" } }
For example following VIEW
VIEW MYVIEW56 #type cname fbname count flag size null short tshort1 - 1 - - - long tlong1 - 1 - - - char tchar1 - 1 - - - float tfloat1 - 1 - - - double tdouble1 - 1 - - - string tstring1 - 1 - 15 - carray tcarray1 - 1 - 10 - END
Will be exported into following JSON
{ "buftype":"VIEW", "version":1, "subtype":"MYVIEW56", "data": { "MYVIEW56\": { "tshort1":1, "tlong1":2, "tchar1":"A", "tfloat1":1, "tdouble1":21, "tstring1":"ABC", "tcarray1":"SEVMTE8AAAAAAA==" } } }
For example following text buffer
HELLO WORLD
Will be imported into following JSON
{ "buftype":"STRING", "version":1, "data":"HELLO WORLD" }
For example following CARRAY buffer
0000 48 45 4c 4c 4f 20 57 4f 52 4c 44 20 43 41 52 52 HELLO WORLD CARR 0010 41 59 AY
Will be imported into following JSON
{ "buftype":"CARRAY", "version":1, "data":"SEVMTE8gV09STEQgQ0FSUkFZ" }
For example following JSON buffer
{ "T_SHORT_FLD":1765, "T_LONG_FLD":[3333111,2], "T_CHAR_FLD":"A", "T_FLOAT_FLD":1, "T_DOUBLE_FLD":[1111.220000,333,444], "T_STRING_FLD":"HELLO WORLD", "T_CARRAY_FLD":"AAECA0hFTExPIEJJTkFSWQQFAA==" }
Will be imported into following JSON
{ "buftype":"JSON", "version":1, "data": {"T_SHORT_FLD":1765, "T_LONG_FLD":[3333111,2], "T_CHAR_FLD":"A", "T_FLOAT_FLD":1, "T_DOUBLE_FLD":[1111.220000,333,444], "T_STRING_FLD":"HELLO WORLD", "T_CARRAY_FLD":"AAECA0hFTExPIEJJTkFSWQQFAA=="} }
String type data such as string VIEW fields, UBF BFLD_STRING fields or STRING buffers must correspond to UTF-8 encoding.
On success, tpexport() return 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.
TPEINVAL Invalid JSON or invalid base64 encoding, ibuf is NULL or ostr is NULL.
TPEOTYPE Invalid type specified to function. VIEW sub-type not found or environment is not configured.
TPESYSTEM System failure occurred during serving. See logs i.e. user log, or debugs for more info. Strings does not correspond to UTF-8 format.
TPEOS System failure occurred during serving. See logs i.e. user log, or debugs for more info. In case of insufficient memory this error will be generated too.
Sample code see under: