0001 TPVIEWTOJSON(3)
0002 ==============
0003 :doctype: manpage
0004
0005
0006 NAME
0007 ----
0008 tpviewtojson - Convert VIEW buffer to JSON object
0009
0010
0011 SYNOPSIS
0012 --------
0013 #include <atmi.h>
0014
0015 int tpviewtojson(char *'cstruct', char *'view', char *'buffer', int 'bufsize', long 'flags');
0016
0017 For XATMI client link with '-latmiclt -latmi -lview -lnstd -lpthread -lrt -lm'
0018
0019 For XATMI server link with '-latmisrv|-latmisrvnomain|-latmisrvinteg -latmi -lview -lnstd -lpthread -lrt -lm'
0020
0021 DESCRIPTION
0022 -----------
0023 Function converts VIEW buffer in 'cstruct', described by 'view' to JSON
0024 string stored in 'buffer' string. The field 'bufsize' must indicate the space in *buffer*.
0025 If the size is not enough, function will fail. 'flags' current is used to define
0026 the function logic in case for 'NULL' fields in view file.
0027
0028 For example, following buffer in 'cstruct'/'view':
0029
0030 --------------------------------------------------------------------------------
0031 VIEW MYVIEW2
0032 #type cname fbname count flag size null
0033 short tshort1 - 1 - - 2000
0034 long tlong1 - 1 - - 5
0035 char tchar1 - 1 - - '\0'
0036 float tfloat1 - 1 - - 1.1
0037 double tdouble1 - 1 - - 0.0
0038 string tstring1 - 3 - 15 'HELLO WORLD'
0039 carray tcarray1 - 1 - 10 '-'
0040 END
0041 --------------------------------------------------------------------------------
0042
0043 and structure initialized to (in C, no error handling for simplicity):
0044
0045 --------------------------------------------------------------------------------
0046 struct MYVIEW2 v2;
0047 char buf_with_nulls[65000];
0048 char buf_no_nulls[65000];
0049
0050 Bvsinit((char *)&v2, "MYVIEW2"); /* initialize to NULL values */
0051
0052 v2.tshort1=100;
0053 strcpy(v2.tstring1[1], "Enduro/X");
0054
0055
0056 /* by default null fields are exported */
0057 tpviewtojson((char *)&v2, "MYVIEW2", buf_with_nulls, sizeof(buf_with_nulls), 0);
0058
0059 /* BVACCESS_NOTNULL makes to export only non NULL fields*/
0060 tpviewtojson((char *)&v2, "MYVIEW2", buf_no_nulls, sizeof(buf_with_nulls), BVACCESS_NOTNULL);
0061
0062 --------------------------------------------------------------------------------
0063
0064 Buffer 'buf_with_nulls' in this example will be filled with following message:
0065
0066 --------------------------------------------------------------------------------
0067
0068 {
0069 "MYVIEW2":
0070 {
0071
0072 "tshort1":100,
0073 "tlong1":5,
0074 "tchar1":"",
0075 "tfloat1":1.10000,
0076 "tdouble1":0.000000,
0077 "tstring1":["HELLO WORLD", "Enduro/X", "HELLO WORLD],
0078 "tcarray1":"LQ=="
0079 }
0080 }
0081
0082 --------------------------------------------------------------------------------
0083
0084 Buffer 'buf_no_nulls' in this example will be filled with following message:
0085
0086 --------------------------------------------------------------------------------
0087
0088 {
0089 "MYVIEW2":
0090 {
0091
0092 "tshort1":100,
0093 "tstring1":["HELLO WORLD", "Enduro/X"]
0094 }
0095 }
0096
0097 --------------------------------------------------------------------------------
0098
0099 NOTE that "carray" typed view fields are exported as base64 strings.
0100
0101 RETURN VALUE
0102 ------------
0103 On success, *tpacall()* return call descriptor (>0); on error, -1 is returned,
0104 with *tperrno* set to indicate the error.
0105
0106 ERRORS
0107 ------
0108 Note that *tpstrerror()* returns generic error message plus custom message with
0109 debug info from last function call.
0110
0111 *TPESYSTEM* System failure occurred during serving.
0112 See logs i.e. user log, or debugs for more info. Might be insufficient memory,
0113 JSON or UBF library failure. Enduro/X environment not configured.
0114
0115 *TPEOS* Not enough space in output 'buffer'.
0116
0117 *TPEINVAL* 'cstruct' is NULL, 'view' is NULL or empty string, 'buffer' is NULL.
0118
0119 EXAMPLE
0120 -------
0121 See *atmitest/test040_typedview/atmiclt40.c* for sample code.
0122
0123 BUGS
0124 ----
0125 Report bugs to support@mavimax.com
0126
0127 SEE ALSO
0128 --------
0129 *ndrxdebug.conf(5)* *tpjsontoview(3)* *viewc(8)* *ex_env(5)*
0130
0131 COPYING
0132 -------
0133 (C) Mavimax, Ltd
0134