User Tools

Site Tools


Sidebar

Table Of Contents

endurox:v7.0.x:api:xatmi:tpjsontoview.3

TPJSONTOVIEW

TPJSONTOVIEW

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
ERRORS
EXAMPLE
BUGS
SEE ALSO
COPYING

NAME

tpjsontoview − Convert JSON object to VIEW buffer

SYNOPSIS

#include <atmi.h>

char * tpjsontoview(char *view, char *buffer)

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

DESCRIPTION

Function converts JSON formatted text in buffer to VIEW buffer. JSON should be formatted in two levels. In first level there is single field named as VIEW name, and in second level JSON field names matches VIEW field name. If multiple occurrences/array of values is present in JSON, then it is converted in VIEW field array elements. The function in case of success returns XATMI (tpcalloc’ed) VIEW buffer, which is initialised to NULL values and then recovered from JSON.

For example following JSON:

{
"MYVIEW2":
{

"tshort1":100,
"tlong1":5,
"tchar1":"",
"tfloat1":1.10000,
"tdouble1":0.000000,
"tstring1":["HELLO WORLD", "Enduro/X", "HELLO WORLD],
"tcarray1":"SGVsbG8gd29ybGQ="
}
}

Can be loaded into following VIEW:

VIEW MYVIEW2
#type cname fbname count flag size null
short tshort1 − 1 − − −
long tlong1 − 1 − − −
char tchar1 − 1 − − −
float tfloat1 − 1 − − −
double tdouble1 − 1 − − −
string tstring1 − 3 − 15 −
carray tcarray1 − 1 − 10 −
END

Note that carray (binary data) fields should be present in base64 encoding in JSON buffer.

RETURN VALUE

On success, tpcall() return pointer to XATMI allocated VIEW buffer; on error, NULL is returned, with tperrno set to indicate the error.

ERRORS

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

TPEINVAL Invalid JSON or invalid base64 encoding, view is NULL or buffer is NULL.

TPEOTYPE Invalid type specified to function − view name specified in JSON message is not found in view files.

TPESYSTEM VIEW sub−system error, JSON sub−system error or Enduro/X environment not configured.

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.

EXAMPLE

See atmitest/test040_typedview/atmiclt40.c for sample code.

BUGS

Report bugs to support@mavimax.com

SEE ALSO

tpviewtojson(3) viewfile(5) viewc(8) ex_env(5)

COPYING

© Mavimax, Ltd