3
.\" Copyright (c) 2020 Kristaps Dzonsons <kristaps@bsd.lv>
5
.\" Permission to use, copy, modify, and distribute this software for any
6
.\" purpose with or without fee is hereby granted, provided that the above
7
.\" copyright notice and this permission notice appear in all copies.
9
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
.Nm kjson_string_putint
26
.Nd put integer content for kcgijson
37
.Fa "struct kjsonreq *req"
42
.Fa "struct kjsonreq *req"
47
.Fo kjson_string_putint
48
.Fa "struct kjsonreq *req"
53
.Fa "struct kjsonreq *r"
58
.Fa "struct kjsonreq *r"
69
This formats the value as
76
forms are for array scopes,
81
.Fn kjson_string_putint
84
Since JavaScript is limited to 53 bits, it's possible that integers may
92
emit the value within a string.
93
This allows the JavaScript to parse the integer and handle overflow and
104
is equivalent to calling
112
indicating the error state.
115
Success (not an error).
117
Internal memory allocation failure.
119
The output connection has been terminated.
120
For FastCGI connections, the current connection should be released with
122
and parse loop reentered.
124
The connection is still expecting headers with
128
did not return with success or was not invoked.
129
For FastCGI connections, the current connection should be released with
131
and parse loop reentered.
133
Internal system error writing to the output stream.
135
The incorrect form was used for the current scope, for example, an
136
array-type write within an object.
139
The following outputs a simple JSON document.
145
For brevity, it does not do any error checking.
146
.Bd -literal -offset indent
147
khttp_head(r, kresps[KRESP_STATUS],
148
"%s", khttps[KHTTP_200]);
149
khttp_head(r, kresps[KRESP_CONTENT_TYPE],
150
"%s", kmimetypes[KMIME_APP_JSON]);
154
kjson_putintp(&req, "bar", 12345);
155
kjson_arrayp_open(&req, "baz");
156
kjson_putint(&req, 1)); /* 1 */
157
kjson_putintstr(&req, 1)); /* "1" */
164
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .