@cloudpss/ubjson 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stream/encoder.js +4 -8
- package/dist/stream/encoder.js.map +1 -1
- package/index.d.ts +7 -0
- package/jest.config.js +3 -0
- package/package.json +4 -8
- package/src/stream/encoder.ts +4 -8
- package/tests/decode.js +433 -0
- package/{test → tests}/e2e.js +19 -27
- package/tests/encode.js +354 -0
- package/tests/stream/encode.js +380 -0
- package/tests/string-encoding.js +71 -0
- package/tests/tsconfig.json +7 -0
- package/tsconfig.json +1 -2
- package/test/decode.js +0 -491
- package/test/encode-stream.js +0 -450
- package/test/encode.js +0 -432
- package/test/string-encoding.js +0 -72
- package/test.js +0 -8
package/test/decode.js
DELETED
|
@@ -1,491 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests from https://bitbucket.org/shelacek/ubjson
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import test from 'tape';
|
|
6
|
-
import * as ubjson from '../dist/index.js';
|
|
7
|
-
|
|
8
|
-
function toBuffer(...args) {
|
|
9
|
-
return Uint8Array.from(args, (x) => (x === +x ? x : x.charCodeAt()));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
test('decode unsupported type', (t) => {
|
|
13
|
-
t.throws(() => ubjson.decode(toBuffer('!')));
|
|
14
|
-
t.end();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('decode undefined data', (t) => {
|
|
18
|
-
t.throws(() => ubjson.decode(undefined));
|
|
19
|
-
t.end();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('decode undefined', (t) => {
|
|
23
|
-
t.equal(ubjson.decode(toBuffer('N')), undefined);
|
|
24
|
-
t.end();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('decode undefined (multiple noop)', (t) => {
|
|
28
|
-
t.equal(ubjson.decode(toBuffer('N', 'N', 'N')), undefined);
|
|
29
|
-
t.end();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('decode undefined (empty buffer)', (t) => {
|
|
33
|
-
t.equal(ubjson.decode(toBuffer()), undefined);
|
|
34
|
-
t.end();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('decode null', (t) => {
|
|
38
|
-
t.equal(ubjson.decode(toBuffer('Z')), null);
|
|
39
|
-
t.end();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('decode true', (t) => {
|
|
43
|
-
t.equal(ubjson.decode(toBuffer('T')), true);
|
|
44
|
-
t.end();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('decode false', (t) => {
|
|
48
|
-
t.equal(ubjson.decode(toBuffer('F')), false);
|
|
49
|
-
t.end();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('decode int8', (t) => {
|
|
53
|
-
t.equal(ubjson.decode(toBuffer('i', 100)), 100);
|
|
54
|
-
t.end();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('decode uint8', (t) => {
|
|
58
|
-
t.equal(ubjson.decode(toBuffer('U', 200)), 200);
|
|
59
|
-
t.end();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('decode int16', (t) => {
|
|
63
|
-
t.equal(ubjson.decode(toBuffer('I', 0x12, 0x34)), 0x1234);
|
|
64
|
-
t.end();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('decode int32', (t) => {
|
|
68
|
-
t.equal(ubjson.decode(toBuffer('l', 0x12, 0x34, 0x56, 0x78)), 0x12345678);
|
|
69
|
-
t.end();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('decode int64 [error]', (t) => {
|
|
73
|
-
t.throws(() => ubjson.decode(toBuffer('L', 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0)));
|
|
74
|
-
t.end();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('decode float32', (t) => {
|
|
78
|
-
t.equal(ubjson.decode(toBuffer('d', 0x3f, 0x80, 0x80, 0x00)), 1.00390625);
|
|
79
|
-
t.end();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('decode float64', (t) => {
|
|
83
|
-
t.equal(ubjson.decode(toBuffer('D', 0x40, 0xf8, 0x6a, 0x00, 0x10, 0x00, 0x00, 0x00)), 100000.00390625);
|
|
84
|
-
t.end();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('decode high-precision number [error]', (t) => {
|
|
88
|
-
t.throws(() => ubjson.decode(toBuffer('H', 'i', 3, '1', '.', '1')));
|
|
89
|
-
t.end();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('decode char', (t) => {
|
|
93
|
-
t.equal(ubjson.decode(toBuffer('C', 'a')), 'a');
|
|
94
|
-
t.end();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('decode string', (t) => {
|
|
98
|
-
t.equal(ubjson.decode(toBuffer('S', 'i', 6, 'u', 'b', 'j', 's', 'o', 'n')), 'ubjson');
|
|
99
|
-
t.end();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test('decode empty string', (t) => {
|
|
103
|
-
t.equal(ubjson.decode(toBuffer('S', 'i', 0)), '');
|
|
104
|
-
t.end();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('decode string (bad size) [error]', (t) => {
|
|
108
|
-
t.throws(() => ubjson.decode(toBuffer('S', 'i', 0xff, 'x')), /Invalid length/);
|
|
109
|
-
t.end();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('decode string (unexpected eof) [error]', (t) => {
|
|
113
|
-
t.throws(() => ubjson.decode(toBuffer('S', 'i', 2, 'x')), /Unexpected EOF/);
|
|
114
|
-
t.end();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('decode ascii string', (t) => {
|
|
118
|
-
const header = toBuffer('S', 'I', 0x3f, 0xff);
|
|
119
|
-
const payload = new Uint8Array(0x3fff + header.byteLength).fill('a'.charCodeAt(0));
|
|
120
|
-
payload.set(header);
|
|
121
|
-
t.equal(ubjson.decode(payload), 'a'.repeat(0x3fff));
|
|
122
|
-
t.end();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('decode ascii string [huge]', (t) => {
|
|
126
|
-
const header = toBuffer('S', 'I', 0x7f, 0xff);
|
|
127
|
-
const payload = new Uint8Array(0x7fff + header.byteLength).fill('a'.charCodeAt(0));
|
|
128
|
-
payload.set(header);
|
|
129
|
-
t.equal(ubjson.decode(payload), 'a'.repeat(0x7fff));
|
|
130
|
-
t.end();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('decode huge string', (t) => {
|
|
134
|
-
t.equal(ubjson.decode(toBuffer('S', 'l', 0x00, 0x00, 0x00, 6, 'u', 'b', 'j', 's', 'o', 'n')), 'ubjson');
|
|
135
|
-
t.end();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test('decode huge string [error]', (t) => {
|
|
139
|
-
t.throws(
|
|
140
|
-
() => ubjson.decode(toBuffer('S', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 'x')),
|
|
141
|
-
/Unsupported type int64/,
|
|
142
|
-
);
|
|
143
|
-
t.end();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('decode array', (t) => {
|
|
147
|
-
t.deepEqual(ubjson.decode(toBuffer('[', 'i', 1, 'i', 2, 'i', 3, ']')), [1, 2, 3]);
|
|
148
|
-
t.end();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test('decode array (with no-op)', (t) => {
|
|
152
|
-
t.deepEqual(ubjson.decode(toBuffer('[', 'i', 1, 'N', 'i', 2, 'i', 3, 'N', ']')), [1, 2, 3]);
|
|
153
|
-
t.end();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('decode array (empty)', (t) => {
|
|
157
|
-
t.deepEqual(ubjson.decode(toBuffer('[', ']')), []);
|
|
158
|
-
t.end();
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('decode array (empty, optimized)', (t) => {
|
|
162
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '#', 'i', 0)), []);
|
|
163
|
-
t.end();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test('decode array (empty, strongly typed, optimized)', (t) => {
|
|
167
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '$', 'i', '#', 'i', 0)), new Int8Array(0));
|
|
168
|
-
t.end();
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test('decode array (mixed, optimized)', (t) => {
|
|
172
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '#', 'i', 3, 'i', 1, 'C', 'a', 'T')), [1, 'a', true]);
|
|
173
|
-
t.end();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test('decode array (strongly typed, optimized)', (t) => {
|
|
177
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '$', 'i', '#', 'i', 3, 1, 2, 3)), new Int8Array([1, 2, 3]));
|
|
178
|
-
t.end();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test('decode array (strongly typed, empty, optimized)', (t) => {
|
|
182
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '$', 'i', '#', 'i', 0)), new Int8Array([]));
|
|
183
|
-
t.end();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test('decode N-D array (strongly typed, optimized)', (t) => {
|
|
187
|
-
t.deepEqual(
|
|
188
|
-
ubjson.decode(
|
|
189
|
-
toBuffer('[', '$', '[', '#', 'i', 2, '$', 'i', '#', 'i', 3, 1, 2, 3, '$', 'i', '#', 'i', 3, 4, 5, 6),
|
|
190
|
-
),
|
|
191
|
-
[new Int8Array([1, 2, 3]), new Int8Array([4, 5, 6])],
|
|
192
|
-
);
|
|
193
|
-
t.end();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test('decode array of objects (optimized)', (t) => {
|
|
197
|
-
t.deepEqual(
|
|
198
|
-
ubjson.decode(
|
|
199
|
-
toBuffer(
|
|
200
|
-
'[',
|
|
201
|
-
'$',
|
|
202
|
-
'{',
|
|
203
|
-
'#',
|
|
204
|
-
'i',
|
|
205
|
-
2,
|
|
206
|
-
'$',
|
|
207
|
-
'i',
|
|
208
|
-
'#',
|
|
209
|
-
'i',
|
|
210
|
-
3,
|
|
211
|
-
'i',
|
|
212
|
-
1,
|
|
213
|
-
'a',
|
|
214
|
-
1,
|
|
215
|
-
'i',
|
|
216
|
-
1,
|
|
217
|
-
'b',
|
|
218
|
-
2,
|
|
219
|
-
'i',
|
|
220
|
-
1,
|
|
221
|
-
'c',
|
|
222
|
-
3,
|
|
223
|
-
'$',
|
|
224
|
-
'i',
|
|
225
|
-
'#',
|
|
226
|
-
'i',
|
|
227
|
-
3,
|
|
228
|
-
'i',
|
|
229
|
-
1,
|
|
230
|
-
'd',
|
|
231
|
-
4,
|
|
232
|
-
'i',
|
|
233
|
-
1,
|
|
234
|
-
'e',
|
|
235
|
-
5,
|
|
236
|
-
'i',
|
|
237
|
-
1,
|
|
238
|
-
'f',
|
|
239
|
-
6,
|
|
240
|
-
),
|
|
241
|
-
),
|
|
242
|
-
[
|
|
243
|
-
{ a: 1, b: 2, c: 3 },
|
|
244
|
-
{ d: 4, e: 5, f: 6 },
|
|
245
|
-
],
|
|
246
|
-
);
|
|
247
|
-
t.end();
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
test('decode array of objects of arrays (optimized)', (t) => {
|
|
251
|
-
t.deepEqual(
|
|
252
|
-
ubjson.decode(
|
|
253
|
-
toBuffer(
|
|
254
|
-
'[',
|
|
255
|
-
'$',
|
|
256
|
-
'{',
|
|
257
|
-
'#',
|
|
258
|
-
'i',
|
|
259
|
-
2,
|
|
260
|
-
'$',
|
|
261
|
-
'[',
|
|
262
|
-
'#',
|
|
263
|
-
'i',
|
|
264
|
-
2,
|
|
265
|
-
'i',
|
|
266
|
-
1,
|
|
267
|
-
'a',
|
|
268
|
-
'$',
|
|
269
|
-
'i',
|
|
270
|
-
'#',
|
|
271
|
-
'i',
|
|
272
|
-
2,
|
|
273
|
-
1,
|
|
274
|
-
2,
|
|
275
|
-
'i',
|
|
276
|
-
1,
|
|
277
|
-
'b',
|
|
278
|
-
'$',
|
|
279
|
-
'i',
|
|
280
|
-
'#',
|
|
281
|
-
'i',
|
|
282
|
-
2,
|
|
283
|
-
3,
|
|
284
|
-
4,
|
|
285
|
-
'$',
|
|
286
|
-
'[',
|
|
287
|
-
'#',
|
|
288
|
-
'i',
|
|
289
|
-
2,
|
|
290
|
-
'i',
|
|
291
|
-
1,
|
|
292
|
-
'c',
|
|
293
|
-
'$',
|
|
294
|
-
'i',
|
|
295
|
-
'#',
|
|
296
|
-
'i',
|
|
297
|
-
2,
|
|
298
|
-
5,
|
|
299
|
-
6,
|
|
300
|
-
'i',
|
|
301
|
-
1,
|
|
302
|
-
'd',
|
|
303
|
-
'$',
|
|
304
|
-
'i',
|
|
305
|
-
'#',
|
|
306
|
-
'i',
|
|
307
|
-
2,
|
|
308
|
-
7,
|
|
309
|
-
8,
|
|
310
|
-
),
|
|
311
|
-
),
|
|
312
|
-
[
|
|
313
|
-
{ a: new Int8Array([1, 2]), b: new Int8Array([3, 4]) },
|
|
314
|
-
{ c: new Int8Array([5, 6]), d: new Int8Array([7, 8]) },
|
|
315
|
-
],
|
|
316
|
-
);
|
|
317
|
-
t.end();
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
test('decode array (strongly typed, unexpected eof, optimized)', (t) => {
|
|
321
|
-
t.throws(() => ubjson.decode(toBuffer('[', '$', 'i', '#', 'i', 3, 1, 2)));
|
|
322
|
-
t.end();
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
test('decode array (strongly typed, invalid length value, optimized)', (t) => {
|
|
326
|
-
t.throws(() => ubjson.decode(toBuffer('[', '$', 'i', '#', 'i', -1)));
|
|
327
|
-
t.end();
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
test('decode array (strongly typed, invalid length type, optimized)', (t) => {
|
|
331
|
-
t.throws(() => ubjson.decode(toBuffer('[', '$', 'i', '#', 'C', '0')));
|
|
332
|
-
t.end();
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test('decode array (strongly typed, malformed, optimized)', (t) => {
|
|
336
|
-
t.throws(() => ubjson.decode(toBuffer('[', '$', 'i', 1, 2, 3, ']')));
|
|
337
|
-
t.end();
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
test('decode array (only null values, optimized)', (t) => {
|
|
341
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '$', 'Z', '#', 'i', 3)), [null, null, null]);
|
|
342
|
-
t.end();
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
test('decode array (only true values, optimized)', (t) => {
|
|
346
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '$', 'T', '#', 'i', 3)), [true, true, true]);
|
|
347
|
-
t.end();
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
test('decode array (only false values, optimized)', (t) => {
|
|
351
|
-
t.deepEqual(ubjson.decode(toBuffer('[', '$', 'F', '#', 'i', 3)), [false, false, false]);
|
|
352
|
-
t.end();
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
test('decode array (int8, strongly typed, optimized) [use typed array]', (t) => {
|
|
356
|
-
const actual = ubjson.decode(toBuffer('[', '$', 'i', '#', 'i', 2, 0x12, 0xfe));
|
|
357
|
-
t.assert(actual instanceof Int8Array);
|
|
358
|
-
t.deepEqual(actual, Int8Array.from([18, -2]));
|
|
359
|
-
t.end();
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
test('decode array (uint8, strongly typed, optimized) [use typed array]', (t) => {
|
|
363
|
-
const actual = ubjson.decode(toBuffer('[', '$', 'U', '#', 'i', 2, 0x12, 0xfe));
|
|
364
|
-
t.assert(actual instanceof Uint8Array);
|
|
365
|
-
t.deepEqual(actual, Uint8Array.from([18, 254]));
|
|
366
|
-
t.end();
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
test('decode array (int16, strongly typed, optimized) [use typed array]', (t) => {
|
|
370
|
-
const actual = ubjson.decode(toBuffer('[', '$', 'I', '#', 'i', 2, 0x12, 0x34, 0xfe, 0xdc));
|
|
371
|
-
t.assert(actual instanceof Int16Array);
|
|
372
|
-
t.deepEqual(actual, Int16Array.from([4660, -292]));
|
|
373
|
-
t.end();
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
test('decode array (int32, strongly typed, optimized) [use typed array]', (t) => {
|
|
377
|
-
const actual = ubjson.decode(toBuffer('[', '$', 'l', '#', 'i', 2, 0x12, 0x34, 0x56, 0x78, 0xfe, 0xdc, 0xba, 0x98));
|
|
378
|
-
t.assert(actual instanceof Int32Array);
|
|
379
|
-
t.deepEqual(actual, Int32Array.from([305419896, -19088744]));
|
|
380
|
-
t.end();
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
test('decode array (int64, strongly typed, optimized) [use typed array]', (t) => {
|
|
384
|
-
t.throws(() => ubjson.decode(toBuffer('[', '$', 'L', '#', 'i', 1, 0x12, 0x34, 0x56, 0x78, 0xfe, 0xdc, 0xba, 0x98)));
|
|
385
|
-
t.end();
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
test('decode array (float32, strongly typed, optimized) [use typed array]', (t) => {
|
|
389
|
-
const actual = ubjson.decode(toBuffer('[', '$', 'd', '#', 'i', 2, 0x3e, 0x80, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00));
|
|
390
|
-
t.assert(actual instanceof Float32Array);
|
|
391
|
-
t.deepEqual(actual, Float32Array.from([0.25, 0.125]));
|
|
392
|
-
t.end();
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
test('decode array (float64, strongly typed, optimized) [use typed array]', (t) => {
|
|
396
|
-
const actual = ubjson.decode(
|
|
397
|
-
toBuffer(
|
|
398
|
-
'[',
|
|
399
|
-
'$',
|
|
400
|
-
'D',
|
|
401
|
-
'#',
|
|
402
|
-
'i',
|
|
403
|
-
2,
|
|
404
|
-
0x3f,
|
|
405
|
-
0xd0,
|
|
406
|
-
0x00,
|
|
407
|
-
0x00,
|
|
408
|
-
0x00,
|
|
409
|
-
0x00,
|
|
410
|
-
0x00,
|
|
411
|
-
0x00,
|
|
412
|
-
0x3f,
|
|
413
|
-
0xc0,
|
|
414
|
-
0x00,
|
|
415
|
-
0x00,
|
|
416
|
-
0x00,
|
|
417
|
-
0x00,
|
|
418
|
-
0x00,
|
|
419
|
-
0x00,
|
|
420
|
-
),
|
|
421
|
-
);
|
|
422
|
-
t.assert(actual instanceof Float64Array);
|
|
423
|
-
t.deepEqual(actual, Float64Array.from([0.25, 0.125]));
|
|
424
|
-
t.end();
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
test('decode object', (t) => {
|
|
428
|
-
t.deepEqual(ubjson.decode(toBuffer('{', 'i', 1, 'a', 'i', 1, 'i', 1, 'b', 'i', 2, 'i', 1, 'c', 'i', 3, '}')), {
|
|
429
|
-
a: 1,
|
|
430
|
-
b: 2,
|
|
431
|
-
c: 3,
|
|
432
|
-
});
|
|
433
|
-
t.end();
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
test('decode object (with no-op)', (t) => {
|
|
437
|
-
t.deepEqual(
|
|
438
|
-
ubjson.decode(
|
|
439
|
-
toBuffer('N', '{', 'N', 'i', 1, 'a', 'i', 1, 'i', 1, 'b', 'N', 'i', 2, 'i', 1, 'c', 'i', 3, 'N', '}', 'N'),
|
|
440
|
-
),
|
|
441
|
-
{ a: 1, b: 2, c: 3 },
|
|
442
|
-
);
|
|
443
|
-
t.end();
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
test('decode array (empty, optimized)', (t) => {
|
|
447
|
-
t.deepEqual(ubjson.decode(toBuffer('{', '#', 'i', 0)), {});
|
|
448
|
-
t.end();
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
test('decode object (mixed, optimized)', (t) => {
|
|
452
|
-
t.deepEqual(
|
|
453
|
-
ubjson.decode(toBuffer('{', '#', 'i', 3, 'i', 1, 'a', 'i', 1, 'i', 1, 'b', 'C', 'a', 'i', 1, 'c', 'T')),
|
|
454
|
-
{ a: 1, b: 'a', c: true },
|
|
455
|
-
);
|
|
456
|
-
t.end();
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
test('decode object (strongly typed, optimized)', (t) => {
|
|
460
|
-
t.deepEqual(ubjson.decode(toBuffer('{', '$', 'i', '#', 'i', 3, 'i', 1, 'a', 1, 'i', 1, 'b', 2, 'i', 1, 'c', 3)), {
|
|
461
|
-
a: 1,
|
|
462
|
-
b: 2,
|
|
463
|
-
c: 3,
|
|
464
|
-
});
|
|
465
|
-
t.end();
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
test('decode object (only null values, optimized)', (t) => {
|
|
469
|
-
t.deepEqual(ubjson.decode(toBuffer('{', '$', 'Z', '#', 'i', 3, 'i', 1, 'a', 'i', 1, 'b', 'i', 1, 'c')), {
|
|
470
|
-
a: null,
|
|
471
|
-
b: null,
|
|
472
|
-
c: null,
|
|
473
|
-
});
|
|
474
|
-
t.end();
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
test('decode object (empty key)', (t) => {
|
|
478
|
-
t.deepEqual(ubjson.decode(toBuffer('{', 'i', 0, 'T', '}')), {
|
|
479
|
-
'': true,
|
|
480
|
-
});
|
|
481
|
-
t.end();
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
test('decode object (empty key, optimized)', (t) => {
|
|
485
|
-
t.deepEqual(ubjson.decode(toBuffer('{', '$', 'Z', '#', 'i', 3, 'i', 0, 'i', 1, 'a', 'i', 1, 'b')), {
|
|
486
|
-
'': null,
|
|
487
|
-
a: null,
|
|
488
|
-
b: null,
|
|
489
|
-
});
|
|
490
|
-
t.end();
|
|
491
|
-
});
|