forked from netmail-open/wjelement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwjwriter.html
196 lines (187 loc) · 4.96 KB
/
wjwriter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<html>
<head>
<title>WJElement Documentation: wjwriter</title>
</head>
<body>
<a href="index.html">Index</a>
<h1>WJWriter Synopsis</h1>
<p>
The WARP JSON Writer provides the ability to easily write a JSON document to
a stream. All data formatting is done automatically.
</p>
<h1>WJWriter Data Types</h1>
<p>
<strong>WJWriter</strong>
is The WJWriter document, the library's primary structure
</p>
<p>
From wjwriter.h:
<blockquote><pre>
typedef struct {
XplBool pretty;
/*
Base may be set to 8, 10 (default), or 16. Using a base other than 10
will result in a non standard JSON document which may not be read
properly by all parsers.
*/
int base;
struct {
void *data;
WJWriteCallback cb;
} write;
struct {
void *data;
void (* freecb)(void *data);
} user;
} WJWriterPublic;
typedef WJWriterPublic* WJWriter;
</pre></blockquote>
</p>
<p>
<strong>WJWriteCallback</strong>
- Generic data writer (to file, socket, encoder, etc.)
</p>
<p>
<blockquote><pre>
typedef size_t (* WJWriteCallback)(char *data, size_t size, void *writedata);
</pre></blockquote>
</p>
<h1>WJWriter Interfaces</h1>
<h2>Document/Writer Management</h2>
<p>
<strong>WJWOpenDocument</strong>
- Open a stream that is ready to accept a JSON document.
</p>
<p>
<blockquote><pre>
WJWriter WJWOpenDocument(XplBool pretty, WJWriteCallback callback,
void *writeData);
WJWriter _WJWOpenDocument(XplBool pretty, WJWriteCallback callback,
void *writedata, size_t buffersize);
</pre></blockquote>
</p>
<p>
A callback function
must be provided which will be used to write data as it is ready.
</p>
<p>
A buffersize of 0 will disable write buffering entirely. The write buffer
used will be at least the size requested, but may be larger.
</p>
<p>
<strong>WJWOpenFILEDocument</strong>
- helper to write to an open FILE *.
</p>
<p>
<blockquote><pre>
WJWriter WJWOpenFILEDocument(XplBool pretty, FILE *file);
</pre></blockquote>
</p>
<p>
An alternative method of opening a JSON document for writing, which will
provide a proper callback for writing the data to an open FILE *.
</p>
<p>
<strong>WJWCloseDocument</strong>
- Close a WJWriter document
</p>
<p>
<blockquote><pre>
XplBool WJWCloseDocument(WJWriter doc);
</pre></blockquote>
</p>
<h2>JSON Structures</h2>
<p>
<strong>WJWOpenArray</strong>
- Open an array.
</p>
<p>
<blockquote><pre>
XplBool WJWOpenArray(char *name, WJWriter doc);
</pre></blockquote>
</p>
<p>
All objects that are direct children of the array MUST NOT
be named. A value of NULL should be passed as name for any such values.
</p>
<p>
When all values of the array have been written it can be closed with
WJWCloseArray().
</p>
<p>
<strong>WJWCloseArray</strong>
- Close an array.
</p>
<p>
<blockquote><pre>
XplBool WJWCloseArray(WJWriter doc);
</pre></blockquote>
</p>
<p>
<strong>WJWOpenObject</strong>
- Open an object.
</p>
<p>
<blockquote><pre>
XplBool WJWOpenObject(char *name, WJWriter doc);
</pre></blockquote>
</p>
<p>
Open an object. All objects that are direct children of the object MUST be
named. A value of NULL should NOT be passed as name for any such values.
</p>
<p>
When all values of the object have been written it can be closed with
WJWCloseObject().
</p>
<p>
<strong>WJWCloseObject</strong>
- Close an object.
</p>
<p>
<blockquote><pre>
XplBool WJWCloseObject(WJWriter doc);
</pre></blockquote>
</p>
<h2>JSON Values</h2>
<p>
These WJWriter functions
write a value to the document. If any values are written that are a direct
child of an object then a non-NULL name MUST be provided. If any values are
written that are a direct child of an array then a non-NULL name MUST NOT be
provided.
</p>
<p>
A string value may be written in multiple pieces. A JSON string will be
started with the first call to WJWString, or WJWStringN and the string will
not be completed until the "done" argument is set to TRUE or there is a call
to write a non-string type value.
</p>
<p>
<blockquote><pre>
XplBool WJWStringN(char *name, char *value, size_t length, XplBool done, WJWriter doc);
XplBool WJWString(char *name, char *value, XplBool done, WJWriter doc);
XplBool WJWBoolean(char *name, XplBool value, WJWriter doc);
XplBool WJWNull(char *name, WJWriter doc);
XplBool WJWInt32(char *name, int32 value, WJWriter doc);
XplBool WJWUInt32(char *name, uint32 value, WJWriter doc);
XplBool WJWInt64(char *name, int64 value, WJWriter doc);
XplBool WJWUInt64(char *name, uint64 value, WJWriter doc);
XplBool WJWDouble(char *name, double value, WJWriter doc);
</pre></blockquote>
</p>
<p>
<strong>WJWRawValue</strong>
- Write a raw, pre-formatted value to the document.
</p>
<p>
<blockquote><pre>
XplBool WJWRawValue(char *name, char *value, XplBool done, WJWriter doc);
</pre></blockquote>
</p>
<p>
It is up to the caller to
ensure that the data is properly formatted and complete.
</p>
</body>
</html>