-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbehav.html
510 lines (505 loc) · 11 KB
/
behav.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
<!DOCTYPE html>
<html lang="en">
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
<title>
JsonWax for Qt
</title>
<link href='css/style.css' rel='stylesheet'>
</head>
<body>
<h1>
JsonWax for Qt
</h1>
<h2>
NOW WITH SERIALIZATION
</h2>
<div id='blackspace'></div>
<svg height='7.5em' id='SVG' viewBox='20 20 50 50' width='100%'>
<text fill='red' id='jsonwaxtext' transform='translate(420, -57) rotate(45) scale(1.2)'>
<tspan dy='1em' x='-1.1em'>
------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-2.1em'>
---
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-3.1em'>
------------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-4.1em'>
----
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-5.1em'>
-------------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-6.1em'>
----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-7.1em'>
-----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-8.1em'>
--------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-9.1em'>
------------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-10.1em'>
-------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-11.1em'>
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-12.1em'>
---------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-13.1em'>
-----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-14.1em'>
--
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-15.1em'>
--------------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-16.1em'>
----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-17.1em'>
--------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-18.1em'>
----
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-19.1em'>
---------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-20.1em'>
----
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-21.1em'>
--
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-22.1em'>
----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-23.1em'>
---------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-24.1em'>
-------------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-25.1em'>
-
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-26.1em'>
----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-27.1em'>
-----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-28.1em'>
------------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-29.1em'>
----------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-30.1em'>
--------------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-31.1em'>
-------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-32.1em'>
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-33.1em'>
--------
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-34.1em'>
-----
JsonWax JsonWax JsonWax
</tspan>
<tspan dy='1em' x='-35.1em'>
JsonWax JsonWax JsonWax
</tspan>
</text>
</svg>
<div id='menucontainer'>
<div id='menu'>
<div class='MENU_ELEMENT' id='menu_element0'>
<a href='index.html'>
WHAT IS IT?
</a>
</div>
<div class='MENU_ELEMENT' id='menu_element1'>
<a href='start.html'>
GETTING STARTED
</a>
</div>
<div class='MENU_ELEMENT' id='menu_element2'>
<a href='examples.html'>
EXAMPLES
</a>
</div>
<div class='MENU_ELEMENT' id='menu_element3'>
<a href='func.html'>
FUNCTIONALITY
</a>
</div>
<div class='MENU_ELEMENT' id='menu_element4'>
<a href='behav.html'>
BEHAVIOR
</a>
</div>
</div>
</div>
<div id='content'>
<nav>
<i>
functions:<br>
</i>
<a href='func.html#append'>
append
</a>
<a href='func.html#copy'>
copy
</a>
<a href='func.html#deserializeBytes'>
deserializeBytes
</a>
<a href='func.html#deserializeJson'>
deserializeJson
</a>
<a href='func.html#errorCode'>
errorCode
</a>
<a href='func.html#errorMsg'>
errorMsg
</a>
<a href='func.html#errorPos'>
errorPos
</a>
<a href='func.html#exists'>
exists
</a>
<a href='func.html#fromByteArray'>
fromByteArray
</a>
<a href='func.html#isArray'>
isArray
</a>
<a href='func.html#isNullValue'>
isNullValue
</a>
<a href='func.html#isObject'>
isObject
</a>
<a href='func.html#isValue'>
isValue
</a>
<a href='func.html#keys'>
keys
</a>
<a href='func.html#loadFile'>
loadFile
</a>
<a href='func.html#move'>
move
</a>
<a href='func.html#popFirst'>
popFirst
</a>
<a href='func.html#popLast'>
popLast
</a>
<a href='func.html#prepend'>
prepend
</a>
<a href='func.html#remove'>
remove
</a>
<a href='func.html#save'>
save
</a>
<a href='func.html#saveAs'>
saveAs
</a>
<a href='func.html#serializeToBytes'>
serializeToBytes
</a>
<a href='func.html#serializeToJson'>
serializeToJson
</a>
<a href='func.html#setEmptyArray'>
setEmptyArray
</a>
<a href='func.html#setEmptyObject'>
setEmptyObject
</a>
<a href='func.html#setNull'>
setNull
</a>
<a href='func.html#setValue'>
setValue
</a>
<a href='func.html#size'>
size
</a>
<a href='func.html#toString'>
toString
</a>
<a href='func.html#type'>
type
</a>
<a href='func.html#value'>
value
</a>
</nav>
<div id='articles'>
<article class='wide'>
<h3>
JSON COMPLIANCE
</h3>
<p>
JsonWax can handle any JSON-document adhering to the JSON standard. This includes
handling numbers and escaped characters.
</p>
</article>
<article class='wide'>
<h3>
PERFORMANCE
</h3>
<p>
Unfortunately, JsonWax isn't as fast at internalizing a document as QJsonDocument is.
To test the speed, create a folder named "speedtest" in your working-directory,
and fill it up with .json documents.
Include JsonWaxTests.h, then run the line:
</p>
<div class='code'>
<div class='source'>
JsonWaxInternals::Tests::speedTest();
</div>
</div>
<p>
This will load all the files, and compare the time it takes to parse the files
(comparing only the differences between parsing from memory).
I ran this test with about 40 MB worth of JSON-documents, and JsonWax internalizes documents with time spent being
about 4 times of Qt's class.
Below you can see a comparison of the relative speeds under specific circumstances. These values vary depending on the compiler and the system. Lowest value means fastest.<br><br>
</p>
<table>
<tr>
<th>
QJsonDocument
</th>
<th>
Task
</th>
<th>
JsonWax
</th>
</tr>
<tr>
<td>
1
</td>
<td>
Parse and internalize a document.
</td>
<td>
3.3 to 4.7
</td>
</tr>
<tr>
<td>
1
</td>
<td>
Read 20,000 values from array, depth 0
</td>
<td>
16 to 24
</td>
</tr>
<tr>
<td>
1
</td>
<td>
Read 20,000 values from array, depth 5
</td>
<td>
21 to 22
</td>
</tr>
<tr>
<td>
1 to 18
</td>
<td>
Change 20,000 values in array, depth 0
</td>
<td>
1 to 7.5
</td>
</tr>
<tr>
<td>
1 to 1.2
</td>
<td>
Change 20,000 values in array, depth 5
</td>
<td>
1 to 7.7
</td>
</tr>
</table>
</article>
<article class='wide'>
<h3>
WILL IT WORK ON A QT VERSION EARLIER THAN 5.7?
</h3>
<p>
Probably not. 5.6 might work.
In Qt 5.5, certain classes don't like being static, which means: crash when destructing.
I really would like to fix this problem, since it means JsonWax won't work
on Windows XP. Other than that, there are problems when converting number values to string.
The Qt 5.5 version of <em>QVariant</em> preferred a different conversion style, i.e. writing all possible digits of
a Double value, instead of only the relevant ones (so, a lot more 0's than expected).
</p>
</article>
<article class='wide'>
<h3>
THREAD-SAFETY
</h3>
<p>
JsonWax is NOT thread-safe. You can interact with multiple JsonWax objects simultaneously, in separate threads, but you should only interact
with the object from that same thread (or it'll crash).
</p>
</article>
<article class='wide'>
<h3>
ESCAPED CHARACTERS
</h3>
<p>
JsonWax reads UTF-8 text files and converts any unicode code points and escaped characters to
their respective characters. This means that <em>value(keys).toString()</em> always returns de-escaped
characters. When writing special characters (\,",\b,\f,\n,\r,\t) to a file, the characters are converted
to escaped form. UTF-8 characters aren't converted to escaped form, unless you choose so,
by using the <em>convertToCodePoints</em>-argument in the <em>save()</em>-functions.
</p>
</article>
<article class='wide'>
<h3>
SERIALIZING OBJECTS
</h3>
<p>
<u>The <em>serializeToBytes()</em> function uses QDataStream, and its serialization depends on your version of Qt. So, if you want the serialized data to always be readable, independent of what version of Qt you are currently running, you should set the versions on the QDataStreams. In order to do so, you must uncomment the three
<em>stream.setVersion(...);</em> lines in JsonWaxSerializer.h, and choose a version number (I'll make it simpler in the future).</u><br><br>
In Qt there are at least 2 ways of serializing objects: Via <em>QTextStream</em>, which serializes
the object to a string, and via <em>QDataStream</em>, which serializes to a byte array.
In <em>QObject</em>, per default, there is support for serializing its member variables to <em>QVariants</em>.
Look in the Qt docs for: "Serializing Qt Data Types" to see how many types <em>QDataStream</em> can (de)serialize.<br><br>
In JsonWax you can use any of the three methods of (de)serializing:<br>
• <em>serializeToJson()</em>, which uses <em>QTextStream</em>.<br>
• <em>serializeToBytes()</em>, which uses <em>QDataStream</em>.<br>
• Having it as a member variable of a <em>QObject</em>, then serializeToJson() or serializeToBytes().<br><br>
I've overloaded the operators for the Q..Streams, so anything that can be serialized in a normal Qt
can be serialized by JsonWax.<br>
If you use <em>serializeToBytes()</em>, the object is converted to a Base64 byteArray, which is then stored as
a string in the JSON-document.
This string is unreadable, and you'd get better performance and use less space if you serialized objects to regular byte arrays, and then stored them in a binary file, instead of a JSON-document. However, it's many times faster at serializing and deserializing than <em>serializeToJson()</em>.<br><br>
If you use <em>serializeToJson()</em>, the defining member values of the object are stored as readable strings in the JSON-document.
See under "serializeToJson", which Qt data types are supported.
</p>
</article>
<article class='wide'>
<h3>
IN CASE OF PARSING ERRORS
</h3>
<p>
If the JSON-document is invalid, JsonWax will store all values until
the point where the document became invalid. You can edit that document
as normal.
</p>
<div class='code'>
<div class='source'>
JsonWax json;<br>
json.fromByteArray("[{\"A\":\"zebra\"},{\"B\":f\"koala\"},{\"C\":\"wolf\"}]");<br>
json.saveAs( "out.json");<br>
</div>
</div>
<p>
There is an 'f' between "B:" and "koala", which is invalid JSON. "out.json" contains only:
</p>
<div class='code'>
<div class='json'>
[<br>
{<br>
"A": "zebra"<br>
}<br>
]<br>
</div>
</div>
<p>
Let's try a different scenario.
</p>
<div class='code'>
<div class='source'>
JsonWax json;<br>
json.fromByteArray("[{\"A\":\"cow\"},{\"B\":1565f},{\"C\":\"lion\"}]");<br>
json.saveAs( "out.json");<br>
</div>
</div>
<p>
The number ends with an invalid character 'f'. JsonWax will stop parsing, so "out.json" contains:
</p>
<div class='code'>
<div class='json'>
[<br>
{<br>
"A": "cow"<br>
},<br>
{<br>
"B": 1565<br>
}<br>
]
</div>
</div>
</article>
</div></div>
<footer></footer>
</body></html>