compact-encoding 2.19.2 → 3.0.1

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/index.js CHANGED
@@ -301,6 +301,20 @@ exports.float64 = {
301
301
  }
302
302
 
303
303
  const buffer = (exports.buffer = {
304
+ preencode(state, b) {
305
+ uint8array.preencode(state, b)
306
+ },
307
+ encode(state, b) {
308
+ uint8array.encode(state, b)
309
+ },
310
+ decode(state) {
311
+ const len = uint.decode(state)
312
+ if (state.end - state.start < len) throw new Error('Out of bounds')
313
+ return state.buffer.subarray(state.start, (state.start += len))
314
+ }
315
+ })
316
+
317
+ exports.optionalBuffer = {
304
318
  preencode(state, b) {
305
319
  if (b) uint8array.preencode(state, b)
306
320
  else state.end++
@@ -315,7 +329,7 @@ const buffer = (exports.buffer = {
315
329
  if (state.end - state.start < len) throw new Error('Out of bounds')
316
330
  return state.buffer.subarray(state.start, (state.start += len))
317
331
  }
318
- })
332
+ }
319
333
 
320
334
  exports.binary = {
321
335
  ...buffer,
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "compact-encoding",
3
- "version": "2.19.2",
3
+ "version": "3.0.1",
4
4
  "description": "A series of compact encoding schemes for building small and fast parsers and serializers",
5
5
  "main": "index.js",
6
+ "files": [
7
+ "endian.js",
8
+ "index.js",
9
+ "lexint.js",
10
+ "raw.js"
11
+ ],
6
12
  "dependencies": {
7
13
  "b4a": "^1.3.0"
8
14
  },
package/raw.js CHANGED
@@ -19,16 +19,13 @@ exports = module.exports = {
19
19
 
20
20
  const buffer = (exports.buffer = {
21
21
  preencode(state, b) {
22
- if (b) uint8array.preencode(state, b)
23
- else state.end++
22
+ uint8array.preencode(state, b)
24
23
  },
25
24
  encode(state, b) {
26
- if (b) uint8array.encode(state, b)
27
- else state.buffer[state.start++] = 0
25
+ uint8array.encode(state, b)
28
26
  },
29
27
  decode(state) {
30
28
  const b = state.buffer.subarray(state.start)
31
- if (b.byteLength === 0) return null
32
29
  state.start = state.end
33
30
  return b
34
31
  }
package/.gitattributes DELETED
@@ -1 +0,0 @@
1
- * text=auto eol=lf
@@ -1,23 +0,0 @@
1
- name: Build Status
2
- on:
3
- push:
4
- branches:
5
- - main
6
- pull_request:
7
- branches:
8
- - main
9
- jobs:
10
- build:
11
- strategy:
12
- matrix:
13
- node-version: [lts/*]
14
- os: [ubuntu-latest, macos-latest, windows-latest]
15
- runs-on: ${{ matrix.os }}
16
- steps:
17
- - uses: actions/checkout@v2
18
- - name: Use Node.js ${{ matrix.node-version }}
19
- uses: actions/setup-node@v2
20
- with:
21
- node-version: ${{ matrix.node-version }}
22
- - run: npm install
23
- - run: npm test
package/.prettierrc DELETED
@@ -1 +0,0 @@
1
- prettier-config-holepunch
package/NOTICE DELETED
@@ -1,13 +0,0 @@
1
- Copyright 2023 Holepunch Inc
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
package/test.js DELETED
@@ -1,1184 +0,0 @@
1
- const enc = require('./')
2
- const test = require('brittle')
3
- const b4a = require('b4a')
4
-
5
- test('uint', function (t) {
6
- const state = enc.state()
7
-
8
- enc.uint.preencode(state, 42)
9
- t.alike(state, enc.state(0, 1))
10
- enc.uint.preencode(state, 4200)
11
- t.alike(state, enc.state(0, 4))
12
- enc.uint.preencode(state, Number.MAX_SAFE_INTEGER)
13
- t.alike(state, enc.state(0, 13))
14
-
15
- state.buffer = b4a.alloc(state.end)
16
- enc.uint.encode(state, 42)
17
- t.alike(
18
- state,
19
- enc.state(1, 13, b4a.from([42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
20
- )
21
- enc.uint.encode(state, 4200)
22
- t.alike(
23
- state,
24
- enc.state(4, 13, b4a.from([42, 0xfd, 104, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
25
- )
26
- enc.uint.encode(state, Number.MAX_SAFE_INTEGER)
27
- t.alike(
28
- state,
29
- enc.state(
30
- 13,
31
- 13,
32
- b4a.from([42, 0xfd, 104, 16, 0xff, 255, 255, 255, 255, 255, 255, 31, 0])
33
- )
34
- )
35
-
36
- state.start = 0
37
- t.is(enc.uint.decode(state), 42)
38
- t.is(enc.uint.decode(state), 4200)
39
- t.is(enc.uint.decode(state), Number.MAX_SAFE_INTEGER)
40
- t.is(state.start, state.end)
41
-
42
- t.exception(() => enc.uint.decode(state))
43
- })
44
-
45
- test('int', function (t) {
46
- const state = enc.state()
47
-
48
- enc.int.preencode(state, 42)
49
- t.alike(state, enc.state(0, 1))
50
- enc.int.preencode(state, -4200)
51
- t.alike(state, enc.state(0, 4))
52
-
53
- state.buffer = b4a.alloc(state.end)
54
- enc.int.encode(state, 42)
55
- t.alike(state, enc.state(1, 4, b4a.from([84, 0, 0, 0])))
56
- enc.int.encode(state, -4200)
57
- t.alike(state, enc.state(4, 4, b4a.from([84, 0xfd, 207, 32])))
58
-
59
- state.start = 0
60
- t.is(enc.int.decode(state), 42)
61
- t.is(enc.int.decode(state), -4200)
62
- t.is(state.start, state.end)
63
-
64
- t.exception(() => enc.int.decode(state))
65
- })
66
-
67
- test('float64', function (t) {
68
- const state = enc.state()
69
-
70
- enc.float64.preencode(state, 162.2377294)
71
- t.alike(state, enc.state(0, 8))
72
-
73
- state.buffer = b4a.alloc(state.end)
74
- t.alike(state, enc.state(0, 8, b4a.from([0, 0, 0, 0, 0, 0, 0, 0])))
75
- enc.float64.encode(state, 162.2377294)
76
- t.alike(
77
- state,
78
- enc.state(8, 8, b4a.from([0x87, 0xc9, 0xaf, 0x7a, 0x9b, 0x47, 0x64, 0x40]))
79
- )
80
-
81
- state.start = 0
82
- t.is(enc.float64.decode(state), 162.2377294)
83
- t.is(state.start, state.end)
84
-
85
- t.exception(() => enc.float64.decode(state))
86
-
87
- // alignement
88
- state.start = 0
89
- state.end = 0
90
- state.buffer = null
91
-
92
- enc.int.preencode(state, 0)
93
- enc.float64.preencode(state, 162.2377294)
94
- t.alike(state, enc.state(0, 9))
95
-
96
- state.buffer = b4a.alloc(state.end)
97
- t.alike(state, enc.state(0, 9, b4a.from([0, 0, 0, 0, 0, 0, 0, 0, 0])))
98
- enc.int.encode(state, 0)
99
- enc.float64.encode(state, 162.2377294)
100
- t.alike(
101
- state,
102
- enc.state(
103
- 9,
104
- 9,
105
- b4a.from([0, 0x87, 0xc9, 0xaf, 0x7a, 0x9b, 0x47, 0x64, 0x40])
106
- )
107
- )
108
-
109
- state.start = 0
110
- t.is(enc.int.decode(state), 0)
111
- t.is(enc.float64.decode(state), 162.2377294)
112
- t.is(state.start, state.end)
113
-
114
- // subarray
115
- const buf = b4a.alloc(10)
116
- state.start = 0
117
- state.buffer = buf.subarray(1)
118
- t.alike(state, enc.state(0, 9, b4a.from([0, 0, 0, 0, 0, 0, 0, 0, 0])))
119
- enc.int.encode(state, 0)
120
- enc.float64.encode(state, 162.2377294)
121
- t.alike(
122
- state,
123
- enc.state(
124
- 9,
125
- 9,
126
- b4a.from([0, 0x87, 0xc9, 0xaf, 0x7a, 0x9b, 0x47, 0x64, 0x40])
127
- )
128
- )
129
- t.alike(buf, b4a.from([0, 0, 0x87, 0xc9, 0xaf, 0x7a, 0x9b, 0x47, 0x64, 0x40]))
130
-
131
- state.start = 0
132
- t.is(enc.int.decode(state), 0)
133
- t.is(enc.float64.decode(state), 162.2377294)
134
- t.is(state.start, state.end)
135
-
136
- // 0
137
- state.start = 0
138
- state.end = 0
139
- state.buffer = null
140
-
141
- enc.float64.preencode(state, 162.2377294)
142
- state.buffer = b4a.alloc(state.end)
143
- enc.float64.encode(state, 0)
144
- t.alike(state, enc.state(8, 8, b4a.from([0, 0, 0, 0, 0, 0, 0, 0])))
145
-
146
- state.start = 0
147
- t.is(enc.float64.decode(state), 0)
148
- t.is(state.start, state.end)
149
-
150
- // Infinity
151
- state.start = 0
152
- state.end = 0
153
- state.buffer = null
154
-
155
- enc.float64.preencode(state, Infinity)
156
- state.buffer = b4a.alloc(state.end)
157
- enc.float64.encode(state, Infinity)
158
- t.alike(state, enc.state(8, 8, b4a.from([0, 0, 0, 0, 0, 0, 0xf0, 0x7f])))
159
-
160
- state.start = 0
161
- t.is(enc.float64.decode(state), Infinity)
162
- t.is(state.start, state.end)
163
-
164
- // Edge cases
165
- state.start = 0
166
- state.end = 0
167
- state.buffer = null
168
-
169
- enc.float64.preencode(state, 0.1 + 0.2)
170
- state.buffer = b4a.alloc(state.end)
171
- enc.float64.encode(state, 0.1 + 0.2)
172
- t.alike(
173
- state,
174
- enc.state(8, 8, b4a.from([0x34, 0x33, 0x33, 0x33, 0x33, 0x33, 0xd3, 0x3f]))
175
- )
176
-
177
- state.start = 0
178
- t.is(enc.float64.decode(state), 0.1 + 0.2)
179
- t.is(state.start, state.end)
180
- })
181
-
182
- test('biguint64', function (t) {
183
- const state = enc.state()
184
-
185
- const n = 0x0102030405060708n
186
-
187
- enc.biguint64.preencode(state, n)
188
- t.alike(state, enc.state(0, 8))
189
-
190
- state.buffer = b4a.alloc(state.end)
191
- enc.biguint64.encode(state, n)
192
- t.alike(
193
- state,
194
- enc.state(8, 8, b4a.from([0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1]))
195
- )
196
-
197
- state.start = 0
198
- t.is(enc.biguint64.decode(state), n)
199
- t.is(state.start, state.end)
200
-
201
- t.exception(() => enc.biguint64.decode(state))
202
- })
203
-
204
- test('bigint64', function (t) {
205
- const state = enc.state()
206
-
207
- const n = -0x0102030405060708n
208
-
209
- enc.bigint64.preencode(state, n)
210
- t.alike(state, enc.state(0, 8))
211
-
212
- state.buffer = b4a.alloc(state.end)
213
- enc.bigint64.encode(state, n)
214
- t.alike(
215
- state,
216
- enc.state(8, 8, b4a.from([0xf, 0xe, 0xc, 0xa, 0x8, 0x6, 0x4, 0x2]))
217
- )
218
-
219
- state.start = 0
220
- t.is(enc.bigint64.decode(state), n)
221
- t.is(state.start, state.end)
222
-
223
- t.exception(() => enc.bigint64.decode(state))
224
- })
225
-
226
- test('biguint', function (t) {
227
- const state = enc.state()
228
-
229
- const n = 0x0102030405060708090a0b0cn
230
-
231
- enc.biguint.preencode(state, n)
232
- t.alike(state, enc.state(0, 17))
233
-
234
- state.buffer = b4a.alloc(state.end)
235
- enc.biguint.encode(state, n)
236
- t.alike(
237
- state,
238
- enc.state(
239
- 17,
240
- 17,
241
- b4a.from([
242
- 2, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0, 0x0,
243
- 0x0, 0x0
244
- ])
245
- )
246
- )
247
-
248
- state.start = 0
249
- t.is(enc.biguint.decode(state), n)
250
- t.is(state.start, state.end)
251
-
252
- t.exception(() => enc.biguint.decode(state))
253
- })
254
-
255
- test('bigint', function (t) {
256
- const state = enc.state()
257
-
258
- const n = -0x0102030405060708090a0b0cn
259
-
260
- enc.bigint.preencode(state, n)
261
- t.alike(state, enc.state(0, 17))
262
-
263
- state.buffer = b4a.alloc(state.end)
264
- enc.bigint.encode(state, n)
265
- t.alike(
266
- state,
267
- enc.state(
268
- 17,
269
- 17,
270
- b4a.from([
271
- 2, 0x17, 0x16, 0x14, 0x12, 0x10, 0xe, 0xc, 0xa, 0x8, 0x6, 0x4, 0x2, 0x0,
272
- 0x0, 0x0, 0x0
273
- ])
274
- )
275
- )
276
-
277
- state.start = 0
278
- t.is(enc.bigint.decode(state), n)
279
- t.is(state.start, state.end)
280
-
281
- t.exception(() => enc.bigint.decode(state))
282
- })
283
-
284
- test('buffer', function (t) {
285
- const state = enc.state()
286
-
287
- enc.buffer.preencode(state, b4a.from('hi'))
288
- t.alike(state, enc.state(0, 3))
289
- enc.buffer.preencode(state, b4a.from('hello'))
290
- t.alike(state, enc.state(0, 9))
291
- enc.buffer.preencode(state, null)
292
- t.alike(state, enc.state(0, 10))
293
-
294
- state.buffer = b4a.alloc(state.end)
295
- enc.buffer.encode(state, b4a.from('hi'))
296
- t.alike(
297
- state,
298
- enc.state(3, 10, b4a.from('\x02hi\x00\x00\x00\x00\x00\x00\x00'))
299
- )
300
- enc.buffer.encode(state, b4a.from('hello'))
301
- t.alike(state, enc.state(9, 10, b4a.from('\x02hi\x05hello\x00')))
302
- enc.buffer.encode(state, null)
303
- t.alike(state, enc.state(10, 10, b4a.from('\x02hi\x05hello\x00')))
304
-
305
- state.start = 0
306
- t.alike(enc.buffer.decode(state), b4a.from('hi'))
307
- t.alike(enc.buffer.decode(state), b4a.from('hello'))
308
- t.is(enc.buffer.decode(state), null)
309
- t.is(state.start, state.end)
310
-
311
- t.exception(() => enc.buffer.decode(state))
312
- })
313
-
314
- test('arraybuffer', function (t) {
315
- const state = enc.state()
316
-
317
- const b1 = new ArrayBuffer(4)
318
- b4a.from(b1).fill('a')
319
-
320
- const b2 = new ArrayBuffer(8)
321
- b4a.from(b2).fill('b')
322
-
323
- enc.arraybuffer.preencode(state, b1)
324
- t.alike(state, enc.state(0, 5))
325
- enc.arraybuffer.preencode(state, b2)
326
- t.alike(state, enc.state(0, 14))
327
-
328
- state.buffer = b4a.alloc(state.end)
329
- enc.arraybuffer.encode(state, b1)
330
- t.alike(
331
- state,
332
- enc.state(5, 14, b4a.from('\x04aaaa\x00\x00\x00\x00\x00\x00\x00\x00\x00'))
333
- )
334
- enc.arraybuffer.encode(state, b2)
335
- t.alike(state, enc.state(14, 14, b4a.from('\x04aaaa\x08bbbbbbbb')))
336
-
337
- state.start = 0
338
- t.alike(enc.arraybuffer.decode(state), b1)
339
- t.alike(enc.arraybuffer.decode(state), b2)
340
- t.is(state.start, state.end)
341
-
342
- t.exception(() => enc.arraybuffer.decode(state))
343
- })
344
-
345
- test('raw', function (t) {
346
- const state = enc.state()
347
-
348
- enc.raw.preencode(state, b4a.from('hi'))
349
- t.alike(state, enc.state(0, 2))
350
-
351
- state.buffer = b4a.alloc(state.end)
352
- enc.raw.encode(state, b4a.from('hi'))
353
- t.alike(state, enc.state(2, 2, b4a.from('hi')))
354
-
355
- state.start = 0
356
- t.alike(enc.raw.decode(state), b4a.from('hi'))
357
- t.is(state.start, state.end)
358
- })
359
-
360
- test('raw uint8array', function (t) {
361
- const state = enc.state()
362
-
363
- enc.raw.uint8array.preencode(state, Uint8Array.of(1, 2))
364
- t.alike(state, enc.state(0, 2))
365
- enc.raw.uint8array.preencode(state, Uint8Array.of(3, 4))
366
- t.alike(state, enc.state(0, 4))
367
-
368
- state.buffer = b4a.alloc(state.end)
369
- enc.raw.uint8array.encode(state, Uint8Array.of(1, 2))
370
- t.alike(state, enc.state(2, 4, b4a.from([1, 2, 0, 0])))
371
- enc.raw.uint8array.encode(state, Uint8Array.of(3, 4))
372
- t.alike(state, enc.state(4, 4, b4a.from([1, 2, 3, 4])))
373
-
374
- state.start = 0
375
- t.alike(enc.raw.uint8array.decode(state), Uint8Array.of(1, 2, 3, 4))
376
- t.alike(enc.raw.uint8array.decode(state), Uint8Array.of())
377
- })
378
-
379
- test('uint16array', function (t) {
380
- const state = enc.state()
381
-
382
- enc.uint16array.preencode(state, new Uint16Array([1, 2, 3]))
383
- t.alike(state, enc.state(0, 7))
384
-
385
- state.buffer = b4a.alloc(state.end)
386
- enc.uint16array.encode(state, new Uint16Array([1, 2, 3]))
387
- t.alike(state, enc.state(7, 7, b4a.from([3, 1, 0, 2, 0, 3, 0])))
388
-
389
- state.start = 0
390
- t.alike(enc.uint16array.decode(state), new Uint16Array([1, 2, 3]))
391
- t.is(state.start, state.end)
392
-
393
- t.exception(() => enc.uint16array.decode(state))
394
- })
395
-
396
- test('uint32array', function (t) {
397
- const state = enc.state()
398
-
399
- enc.uint32array.preencode(state, new Uint32Array([1]))
400
- t.alike(state, enc.state(0, 5))
401
- enc.uint32array.preencode(state, new Uint32Array([42, 43]))
402
- t.alike(state, enc.state(0, 14))
403
-
404
- state.buffer = b4a.alloc(state.end)
405
- enc.uint32array.encode(state, new Uint32Array([1]))
406
- t.alike(
407
- state,
408
- enc.state(5, 14, b4a.from([1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
409
- )
410
- enc.uint32array.encode(state, new Uint32Array([42, 43]))
411
- t.alike(
412
- state,
413
- enc.state(14, 14, b4a.from([1, 1, 0, 0, 0, 2, 42, 0, 0, 0, 43, 0, 0, 0]))
414
- )
415
-
416
- state.start = 0
417
- t.alike(enc.uint32array.decode(state), new Uint32Array([1]))
418
- t.alike(enc.uint32array.decode(state), new Uint32Array([42, 43]))
419
- t.is(state.start, state.end)
420
-
421
- t.exception(() => enc.uint32array.decode(state))
422
- })
423
-
424
- test('int16array', function (t) {
425
- const state = enc.state()
426
-
427
- enc.int16array.preencode(state, new Int16Array([1, -2, 3]))
428
- t.alike(state, enc.state(0, 7))
429
-
430
- state.buffer = b4a.alloc(state.end)
431
- enc.int16array.encode(state, new Int16Array([1, -2, 3]))
432
- t.alike(state, enc.state(7, 7, b4a.from([3, 1, 0, 0xfe, 0xff, 3, 0])))
433
-
434
- state.start = 0
435
- t.alike(enc.int16array.decode(state), new Int16Array([1, -2, 3]))
436
- t.is(state.start, state.end)
437
-
438
- t.exception(() => enc.int16array.decode(state))
439
- })
440
-
441
- test('int32array', function (t) {
442
- const state = enc.state()
443
-
444
- enc.int32array.preencode(state, new Int32Array([1, -2, 3]))
445
- t.alike(state, enc.state(0, 13))
446
-
447
- state.buffer = b4a.alloc(state.end)
448
- enc.int32array.encode(state, new Int32Array([1, -2, 3]))
449
- t.alike(
450
- state,
451
- enc.state(
452
- 13,
453
- 13,
454
- b4a.from([3, 1, 0, 0, 0, 0xfe, 0xff, 0xff, 0xff, 3, 0, 0, 0])
455
- )
456
- )
457
-
458
- state.start = 0
459
- t.alike(enc.int32array.decode(state), new Int32Array([1, -2, 3]))
460
- t.is(state.start, state.end)
461
-
462
- t.exception(() => enc.int32array.decode(state))
463
- })
464
-
465
- test('biguint64array', function (t) {
466
- const state = enc.state()
467
-
468
- const arr = new BigUint64Array([0x01020304n, 0x05060708n, 0x090a0b0cn])
469
-
470
- enc.biguint64array.preencode(state, arr)
471
- t.alike(state, enc.state(0, 25))
472
-
473
- state.buffer = b4a.alloc(state.end)
474
- enc.biguint64array.encode(state, arr)
475
- t.alike(
476
- state,
477
- enc.state(
478
- 25,
479
- 25,
480
- b4a.from([
481
- 3, 0x4, 0x3, 0x2, 0x1, 0x0, 0x0, 0x0, 0x0, 0x8, 0x7, 0x6, 0x5, 0x0, 0x0,
482
- 0x0, 0x0, 0xc, 0xb, 0xa, 0x9, 0x0, 0x0, 0x0, 0x0
483
- ])
484
- )
485
- )
486
-
487
- state.start = 0
488
- t.alike(enc.biguint64array.decode(state), arr)
489
- t.is(state.start, state.end)
490
-
491
- t.exception(() => enc.biguint64array.decode(state))
492
- })
493
-
494
- test('bigint64array', function (t) {
495
- const state = enc.state()
496
-
497
- const arr = new BigInt64Array([-0x01020304n, 0x05060708n, -0x090a0b0cn])
498
-
499
- enc.bigint64array.preencode(state, arr)
500
- t.alike(state, enc.state(0, 25))
501
-
502
- state.buffer = b4a.alloc(state.end)
503
- enc.bigint64array.encode(state, arr)
504
- t.alike(
505
- state,
506
- enc.state(
507
- 25,
508
- 25,
509
- b4a.from([
510
- 3, 0xfc, 0xfc, 0xfd, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x8, 0x7, 0x6, 0x5,
511
- 0x0, 0x0, 0x0, 0x0, 0xf4, 0xf4, 0xf5, 0xf6, 0xff, 0xff, 0xff, 0xff
512
- ])
513
- )
514
- )
515
-
516
- state.start = 0
517
- t.alike(enc.bigint64array.decode(state), arr)
518
- t.is(state.start, state.end)
519
-
520
- t.exception(() => enc.bigint64array.decode(state))
521
- })
522
-
523
- test('float32array', function (t) {
524
- const state = enc.state()
525
-
526
- enc.float32array.preencode(state, new Float32Array([1.1, -2.2, 3.3]))
527
- t.alike(state, enc.state(0, 13))
528
-
529
- state.buffer = b4a.alloc(state.end)
530
- enc.float32array.encode(state, new Float32Array([1.1, -2.2, 3.3]))
531
- t.alike(
532
- state,
533
- enc.state(
534
- 13,
535
- 13,
536
- b4a.from([
537
- 3, 0xcd, 0xcc, 0x8c, 0x3f, 0xcd, 0xcc, 0x0c, 0xc0, 0x33, 0x33, 0x53,
538
- 0x40
539
- ])
540
- )
541
- )
542
-
543
- state.start = 0
544
- t.alike(enc.float32array.decode(state), new Float32Array([1.1, -2.2, 3.3]))
545
- t.is(state.start, state.end)
546
-
547
- t.exception(() => enc.float32array.decode(state))
548
- })
549
-
550
- test('float64array', function (t) {
551
- const state = enc.state()
552
-
553
- enc.float64array.preencode(state, new Float64Array([1.1, -2.2, 3.3]))
554
- t.alike(state, enc.state(0, 25))
555
-
556
- state.buffer = b4a.alloc(state.end)
557
- enc.float64array.encode(state, new Float64Array([1.1, -2.2, 3.3]))
558
- t.alike(
559
- state,
560
- enc.state(
561
- 25,
562
- 25,
563
- b4a.from([
564
- 3, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f, 0x9a, 0x99, 0x99,
565
- 0x99, 0x99, 0x99, 0x01, 0xc0, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x0a,
566
- 0x40
567
- ])
568
- )
569
- )
570
-
571
- state.start = 0
572
- t.alike(enc.float64array.decode(state), new Float64Array([1.1, -2.2, 3.3]))
573
- t.is(state.start, state.end)
574
-
575
- t.exception(() => enc.float64array.decode(state))
576
- })
577
-
578
- test('string', function (t) {
579
- const state = enc.state()
580
-
581
- enc.string.preencode(state, '🌾')
582
- t.alike(state, enc.state(0, 5))
583
- enc.string.preencode(state, 'høsten er fin')
584
- t.alike(state, enc.state(0, 20))
585
-
586
- state.buffer = b4a.alloc(state.end)
587
- enc.string.encode(state, '🌾')
588
- t.alike(
589
- state,
590
- enc.state(
591
- 5,
592
- 20,
593
- b4a.from(
594
- '\x04🌾\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
595
- )
596
- )
597
- )
598
- enc.string.encode(state, 'høsten er fin')
599
- t.alike(state, enc.state(20, 20, b4a.from('\x04🌾\x0ehøsten er fin')))
600
-
601
- state.start = 0
602
- t.is(enc.string.decode(state), '🌾')
603
- t.is(enc.string.decode(state), 'høsten er fin')
604
- t.is(state.start, state.end)
605
-
606
- t.exception(() => enc.string.decode(state))
607
- })
608
-
609
- test('raw string', function (t) {
610
- const state = enc.state()
611
-
612
- enc.raw.string.preencode(state, 'hello')
613
- t.alike(state, enc.state(0, 5))
614
- enc.raw.string.preencode(state, ' world')
615
- t.alike(state, enc.state(0, 11))
616
-
617
- state.buffer = b4a.alloc(state.end)
618
- enc.raw.string.encode(state, 'hello')
619
- enc.raw.string.encode(state, ' world')
620
- t.alike(state, enc.state(11, 11, b4a.from('hello world')))
621
-
622
- state.start = 0
623
- t.is(enc.raw.string.decode(state), 'hello world')
624
- t.is(enc.raw.string.decode(state), '')
625
- })
626
-
627
- test('fixed32', function (t) {
628
- const state = enc.state()
629
-
630
- enc.fixed32.preencode(state, b4a.alloc(32).fill('a'))
631
- t.alike(state, enc.state(0, 32))
632
- enc.fixed32.preencode(state, b4a.alloc(32).fill('b'))
633
- t.alike(state, enc.state(0, 64))
634
-
635
- state.buffer = b4a.alloc(state.end)
636
- enc.fixed32.encode(state, b4a.alloc(32).fill('a'))
637
- t.alike(state, enc.state(32, 64, b4a.alloc(64).fill('a', 0, 32)))
638
- enc.fixed32.encode(state, b4a.alloc(32).fill('b'))
639
- t.alike(
640
- state,
641
- enc.state(64, 64, b4a.alloc(64).fill('a', 0, 32).fill('b', 32, 64))
642
- )
643
-
644
- state.start = 0
645
- t.alike(enc.fixed32.decode(state), b4a.alloc(32).fill('a'))
646
- t.alike(enc.fixed32.decode(state), b4a.alloc(32).fill('b'))
647
- t.is(state.start, state.end)
648
-
649
- t.exception(() => enc.fixed32.decode(state))
650
- })
651
-
652
- test('fixed64', function (t) {
653
- const state = enc.state()
654
-
655
- enc.fixed64.preencode(state, b4a.alloc(64).fill('a'))
656
- t.alike(state, enc.state(0, 64))
657
- enc.fixed64.preencode(state, b4a.alloc(64).fill('b'))
658
- t.alike(state, enc.state(0, 128))
659
-
660
- state.buffer = b4a.alloc(state.end)
661
- enc.fixed64.encode(state, b4a.alloc(64).fill('a'))
662
- t.alike(state, enc.state(64, 128, b4a.alloc(128).fill('a', 0, 64)))
663
- enc.fixed64.encode(state, b4a.alloc(64).fill('b'))
664
- t.alike(
665
- state,
666
- enc.state(128, 128, b4a.alloc(128).fill('a', 0, 64).fill('b', 64, 128))
667
- )
668
-
669
- state.start = 0
670
- t.alike(enc.fixed64.decode(state), b4a.alloc(64).fill('a'))
671
- t.alike(enc.fixed64.decode(state), b4a.alloc(64).fill('b'))
672
- t.is(state.start, state.end)
673
-
674
- t.exception(() => enc.fixed64.decode(state))
675
- })
676
-
677
- test('fixed n', function (t) {
678
- const state = enc.state()
679
- const fixed = enc.fixed(3)
680
-
681
- fixed.preencode(state, b4a.alloc(3).fill('a'))
682
- t.alike(state, enc.state(0, 3))
683
- fixed.preencode(state, b4a.alloc(3).fill('b'))
684
- t.alike(state, enc.state(0, 6))
685
-
686
- state.buffer = b4a.alloc(state.end)
687
- fixed.encode(state, b4a.alloc(3).fill('a'))
688
- t.alike(state, enc.state(3, 6, b4a.alloc(6).fill('a', 0, 3)))
689
- fixed.encode(state, b4a.alloc(3).fill('b'))
690
- t.alike(state, enc.state(6, 6, b4a.alloc(6).fill('a', 0, 3).fill('b', 3, 6)))
691
-
692
- state.start = 0
693
- t.alike(fixed.decode(state), b4a.alloc(3).fill('a'))
694
- t.alike(fixed.decode(state), b4a.alloc(3).fill('b'))
695
- t.is(state.start, state.end)
696
-
697
- t.exception(() => fixed.decode(state))
698
- state.start = 4
699
- t.exception(() => fixed.decode(state))
700
- })
701
-
702
- test('error for incorrect buffer sizes when encoding fixed-length buffers', function (t) {
703
- const smallbuf = b4a.from('aa', 'hex')
704
- const bigBuf = b4a.from('aa'.repeat(500), 'hex')
705
-
706
- t.exception(() => enc.encode(enc.fixed32, smallbuf), /Incorrect buffer size/)
707
- t.exception(() => enc.encode(enc.fixed64, smallbuf), /Incorrect buffer size/)
708
- t.exception(
709
- () => enc.encode(enc.fixed(100), smallbuf),
710
- /Incorrect buffer size/
711
- )
712
-
713
- t.exception(() => enc.encode(enc.fixed32, bigBuf), /Incorrect buffer size/)
714
- t.exception(() => enc.encode(enc.fixed64, bigBuf), /Incorrect buffer size/)
715
- t.exception(() => enc.encode(enc.fixed(100), bigBuf), /Incorrect buffer size/)
716
- })
717
-
718
- test('array', function (t) {
719
- const state = enc.state()
720
- const arr = enc.array(enc.bool)
721
-
722
- arr.preencode(state, [true, false, true])
723
- t.alike(state, enc.state(0, 4))
724
- arr.preencode(state, [false, false, true, true])
725
- t.alike(state, enc.state(0, 9))
726
-
727
- state.buffer = b4a.alloc(state.end)
728
- arr.encode(state, [true, false, true])
729
- t.alike(state, enc.state(4, 9, b4a.from([3, 1, 0, 1, 0, 0, 0, 0, 0])))
730
- arr.encode(state, [false, false, true, true])
731
- t.alike(state, enc.state(9, 9, b4a.from([3, 1, 0, 1, 4, 0, 0, 1, 1])))
732
-
733
- state.start = 0
734
- t.alike(arr.decode(state), [true, false, true])
735
- t.alike(arr.decode(state), [false, false, true, true])
736
- t.is(state.start, state.end)
737
-
738
- t.exception(() => arr.decode(state))
739
- })
740
-
741
- test('raw array', function (t) {
742
- const state = enc.state()
743
- const arr = enc.raw.array(enc.bool)
744
-
745
- arr.preencode(state, [true])
746
- t.alike(state, enc.state(0, 1))
747
- arr.preencode(state, [true])
748
- t.alike(state, enc.state(0, 2))
749
-
750
- state.buffer = b4a.alloc(state.end)
751
- arr.encode(state, [true])
752
- t.alike(state, enc.state(1, 2, b4a.from([1, 0])))
753
- arr.encode(state, [true])
754
- t.alike(state, enc.state(2, 2, b4a.from([1, 1])))
755
-
756
- state.start = 0
757
- t.alike(arr.decode(state), [true, true])
758
- t.alike(arr.decode(state), [])
759
- })
760
-
761
- test('json', function (t) {
762
- const state = enc.state()
763
-
764
- enc.json.preencode(state, { a: 1, b: 2 })
765
- t.alike(state, enc.state(0, 14))
766
-
767
- state.buffer = b4a.alloc(state.end)
768
- enc.json.encode(state, { a: 1, b: 2 })
769
- t.alike(
770
- state,
771
- enc.state(14, 14, b4a.concat([b4a.from([13]), b4a.from('{"a":1,"b":2}')]))
772
- )
773
-
774
- state.start = 0
775
- t.alike(enc.json.decode(state), { a: 1, b: 2 })
776
-
777
- t.exception(() => enc.json.decode(state))
778
- })
779
-
780
- test('raw json', function (t) {
781
- const state = enc.state()
782
-
783
- enc.raw.json.preencode(state, { a: 1, b: 2 })
784
- t.alike(state, enc.state(0, 13))
785
-
786
- state.buffer = b4a.alloc(state.end)
787
- enc.raw.json.encode(state, { a: 1, b: 2 })
788
- t.alike(state, enc.state(13, 13, b4a.from('{"a":1,"b":2}')))
789
-
790
- state.start = 0
791
- t.alike(enc.raw.json.decode(state), { a: 1, b: 2 })
792
-
793
- t.exception(() => enc.json.decode(state))
794
- })
795
-
796
- test('lexint: big numbers', function (t) {
797
- t.plan(1)
798
-
799
- let prev = enc.encode(enc.lexint, 0)
800
-
801
- let n
802
- let skip = 1
803
-
804
- for (n = 1; n < Number.MAX_VALUE; n += skip) {
805
- const cur = enc.encode(enc.lexint, n)
806
- if (b4a.compare(cur, prev) < 1) break
807
- prev = cur
808
- skip = 1 + Math.pow(245, Math.ceil(Math.log(n) / Math.log(256)))
809
- }
810
- t.is(n, Infinity)
811
- })
812
-
813
- test('lexint: range precision', function (t) {
814
- t.plan(2)
815
- const a = 1e55
816
- const b = 1.0000000000001e55
817
- const ha = enc.encode(enc.lexint, a).toString('hex')
818
- const hb = enc.encode(enc.lexint, b).toString('hex')
819
- t.not(a, b)
820
- t.not(ha, hb)
821
- })
822
-
823
- test('lexint: range precision', function (t) {
824
- let prev = enc.encode(enc.lexint, 0)
825
- const skip = 0.000000001e55
826
- for (let i = 0, n = 1e55; i < 1000; n = 1e55 + skip * ++i) {
827
- const cur = enc.encode(enc.lexint, n)
828
- if (b4a.compare(cur, prev) < 1) t.fail('cur <= prev')
829
- prev = cur
830
- }
831
- t.ok(true)
832
- t.end()
833
- })
834
-
835
- test('lexint: small numbers', function (t) {
836
- let prev = enc.encode(enc.lexint, 0)
837
- for (let n = 1; n < 256 * 256 * 16; n++) {
838
- const cur = enc.encode(enc.lexint, n)
839
- if (b4a.compare(cur, prev) < 1) t.fail('cur <= prev')
840
- prev = cur
841
- }
842
- t.ok(true)
843
- t.end()
844
- })
845
-
846
- test('lexint: throws', function (t) {
847
- t.exception(() => {
848
- enc.decode(enc.lexint, b4a.alloc(1, 251))
849
- })
850
-
851
- let num = 252
852
-
853
- const state = enc.state()
854
-
855
- enc.lexint.preencode(state, num)
856
- state.buffer = b4a.alloc(state.end - state.start)
857
- enc.lexint.encode(state, num)
858
-
859
- t.exception(() => {
860
- enc.decode(
861
- enc.lexint,
862
- state.buffer.subarray(0, state.buffer.byteLength - 2)
863
- )
864
- })
865
-
866
- num <<= 8
867
-
868
- state.start = 0
869
- state.end = 0
870
- state.buffer = null
871
-
872
- enc.lexint.preencode(state, num)
873
- state.buffer = b4a.alloc(state.end - state.start)
874
- enc.lexint.encode(state, num)
875
-
876
- t.exception(() => {
877
- enc.decode(
878
- enc.lexint,
879
- state.buffer.subarray(0, state.buffer.byteLength - 2)
880
- )
881
- })
882
-
883
- num <<= 8
884
-
885
- state.start = 0
886
- state.end = 0
887
- state.buffer = null
888
-
889
- enc.lexint.preencode(state, num)
890
- state.buffer = b4a.alloc(state.end - state.start)
891
- enc.lexint.encode(state, num)
892
-
893
- t.exception(() => {
894
- enc.decode(
895
- enc.lexint,
896
- state.buffer.subarray(0, state.buffer.byteLength - 2)
897
- )
898
- })
899
-
900
- num *= 256
901
-
902
- state.start = 0
903
- state.end = 0
904
- state.buffer = null
905
-
906
- enc.lexint.preencode(state, num)
907
- state.buffer = b4a.alloc(state.end - state.start)
908
- enc.lexint.encode(state, num)
909
-
910
- t.exception(() => {
911
- enc.decode(
912
- enc.lexint,
913
- state.buffer.subarray(0, state.buffer.byteLength - 2)
914
- )
915
- })
916
-
917
- num *= 256 * 256
918
-
919
- state.start = 0
920
- state.end = 0
921
- state.buffer = null
922
-
923
- enc.lexint.preencode(state, num)
924
- state.buffer = b4a.alloc(state.end - state.start)
925
- enc.lexint.encode(state, num)
926
-
927
- t.exception(() => {
928
- enc.decode(
929
- enc.lexint,
930
- state.buffer.subarray(0, state.buffer.byteLength - 2)
931
- )
932
- })
933
-
934
- t.end()
935
- })
936
-
937
- test('lexint: unpack', function (t) {
938
- let n
939
- let skip = 1
940
-
941
- for (n = 1; n < Number.MAX_VALUE; n += skip) {
942
- const cur = enc.encode(enc.lexint, n)
943
- compare(n, enc.decode(enc.lexint, cur))
944
- skip = 1 + Math.pow(245, Math.ceil(Math.log(n) / Math.log(256)))
945
- }
946
- t.is(n, Infinity)
947
- t.end()
948
-
949
- function compare(a, b) {
950
- const desc = a + ' !=~ ' + b
951
- if (/e\+\d+$/.test(a) || /e\+\d+$/.test(b)) {
952
- if (
953
- String(a).slice(0, 8) !== String(b).slice(0, 8) ||
954
- /e\+(\d+)$/.exec(a)[1] !== /e\+(\d+)$/.exec(b)[1]
955
- ) {
956
- t.fail(desc)
957
- }
958
- } else {
959
- if (
960
- String(a).slice(0, 8) !== String(b).slice(0, 8) ||
961
- String(a).length !== String(b).length
962
- ) {
963
- t.fail(desc)
964
- }
965
- }
966
- }
967
- })
968
-
969
- test('date', function (t) {
970
- const d = new Date()
971
-
972
- t.alike(enc.decode(enc.date, enc.encode(enc.date, d)), d)
973
- })
974
-
975
- test('any', function (t) {
976
- const o = {
977
- hello: 'world',
978
- num: 42,
979
- neg: -42,
980
- arr: [{ yes: 1 }, { no: false }],
981
- nest: {},
982
- today: new Date(),
983
- float: 0.54
984
- }
985
-
986
- t.alike(enc.decode(enc.any, enc.encode(enc.any, o)), o)
987
-
988
- const arr = new Array(3)
989
-
990
- t.alike(enc.decode(enc.any, enc.encode(enc.any, arr)), [null, null, null])
991
- })
992
-
993
- test('framed', function (t) {
994
- const e = enc.frame(enc.uint)
995
- t.alike(enc.encode(e, 42), b4a.from([0x01, 0x2a]))
996
- t.alike(enc.decode(e, b4a.from([0x01, 0x2a])), 42)
997
- t.alike(enc.encode(e, 4200), b4a.from([0x03, 0xfd, 0x68, 0x10]))
998
- t.alike(enc.decode(e, b4a.from([0x03, 0xfd, 0x68, 0x10])), 4200)
999
- })
1000
-
1001
- test('port', function (t) {
1002
- const p = 0x1234
1003
- const buf = Buffer.from([0x34, 0x12])
1004
-
1005
- t.alike(enc.encode(enc.port, p), buf)
1006
- t.alike(enc.decode(enc.port, buf), p)
1007
- })
1008
-
1009
- test('ipv4', function (t) {
1010
- const ip = '1.2.3.4'
1011
- const buf = Buffer.from([1, 2, 3, 4])
1012
-
1013
- t.alike(enc.encode(enc.ipv4, ip), buf)
1014
- t.alike(enc.decode(enc.ipv4, buf), ip)
1015
- })
1016
-
1017
- test('ipv4 + port', function (t) {
1018
- const host = '1.2.3.4'
1019
- const port = 1234
1020
-
1021
- t.alike(
1022
- enc.decode(enc.ipv4Address, enc.encode(enc.ipv4Address, { host, port })),
1023
- {
1024
- host,
1025
- family: 4,
1026
- port
1027
- }
1028
- )
1029
- })
1030
-
1031
- test('ipv6', function (t) {
1032
- const ip = '1:2:3:4:5:6:7:8'
1033
- const buf = Buffer.from([0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8])
1034
-
1035
- t.alike(enc.encode(enc.ipv6, ip), buf)
1036
- t.alike(enc.decode(enc.ipv6, buf), ip)
1037
-
1038
- t.test('abbreviated', function (t) {
1039
- const buf = Buffer.from([0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 8])
1040
-
1041
- t.alike(enc.encode(enc.ipv6, '1:2::7:8'), buf)
1042
- t.alike(enc.decode(enc.ipv6, buf), '1:2:0:0:0:0:7:8')
1043
- })
1044
-
1045
- t.test('prefix abbreviated', function (t) {
1046
- const buf = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 7, 0, 8])
1047
-
1048
- t.alike(enc.encode(enc.ipv6, '::5:6:7:8'), buf)
1049
- t.alike(enc.decode(enc.ipv6, buf), '0:0:0:0:5:6:7:8')
1050
- })
1051
-
1052
- t.test('suffix abbreviated', function (t) {
1053
- const buf = Buffer.from([0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0])
1054
-
1055
- t.alike(enc.encode(enc.ipv6, '1:2:3:4::'), buf)
1056
- t.alike(enc.decode(enc.ipv6, buf), '1:2:3:4:0:0:0:0')
1057
- })
1058
-
1059
- t.test('any', function (t) {
1060
- const buf = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
1061
-
1062
- t.alike(enc.encode(enc.ipv6, '::'), buf)
1063
- t.alike(enc.decode(enc.ipv6, buf), '0:0:0:0:0:0:0:0')
1064
- })
1065
-
1066
- t.test('lowercase hex', function (t) {
1067
- const buf = Buffer.from([
1068
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd
1069
- ])
1070
-
1071
- t.alike(enc.encode(enc.ipv6, '::abcd'), buf)
1072
- t.alike(enc.decode(enc.ipv6, buf), '0:0:0:0:0:0:0:abcd')
1073
- })
1074
-
1075
- t.test('uppercase hex', function (t) {
1076
- const buf = Buffer.from([
1077
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd
1078
- ])
1079
-
1080
- t.alike(enc.encode(enc.ipv6, '::ABCD'), buf)
1081
- t.alike(enc.decode(enc.ipv6, buf), '0:0:0:0:0:0:0:abcd')
1082
- })
1083
- })
1084
-
1085
- test('ipv6 + port', function (t) {
1086
- const host = '1:2:3:4:5:6:7:8'
1087
- const port = 1234
1088
-
1089
- t.alike(
1090
- enc.decode(enc.ipv6Address, enc.encode(enc.ipv6Address, { host, port })),
1091
- {
1092
- host,
1093
- family: 6,
1094
- port
1095
- }
1096
- )
1097
- })
1098
-
1099
- test('dual ip', function (t) {
1100
- {
1101
- const host = '1.2.3.4'
1102
-
1103
- t.alike(enc.decode(enc.ip, enc.encode(enc.ip, host)), host, 'ipv4')
1104
- }
1105
- {
1106
- const host = '1:2:3:4:5:6:7:8'
1107
-
1108
- t.alike(enc.decode(enc.ip, enc.encode(enc.ip, host)), host, 'ipv6')
1109
- }
1110
- })
1111
-
1112
- test('dual ip + port', function (t) {
1113
- const port = 1234
1114
-
1115
- {
1116
- const host = '1.2.3.4'
1117
-
1118
- t.alike(
1119
- enc.decode(enc.ipAddress, enc.encode(enc.ipAddress, { host, port })),
1120
- {
1121
- host,
1122
- family: 4,
1123
- port
1124
- },
1125
- 'ipv4'
1126
- )
1127
- }
1128
- {
1129
- const host = '1:2:3:4:5:6:7:8'
1130
-
1131
- t.alike(
1132
- enc.decode(enc.ipAddress, enc.encode(enc.ipAddress, { host, port })),
1133
- {
1134
- host,
1135
- family: 6,
1136
- port
1137
- },
1138
- 'ipv6'
1139
- )
1140
- }
1141
- })
1142
-
1143
- test('record', function (t) {
1144
- const encoding = enc.record(enc.string, enc.string)
1145
-
1146
- t.alike(
1147
- enc.decode(encoding, enc.encode(encoding, { a: 'hello', b: 'world' })),
1148
- Object.assign(Object.create(null), {
1149
- a: 'hello',
1150
- b: 'world'
1151
- })
1152
- )
1153
- })
1154
-
1155
- test('record - nested', function (t) {
1156
- const encoding = enc.record(enc.string, enc.record(enc.string, enc.string))
1157
-
1158
- t.alike(
1159
- enc.decode(
1160
- encoding,
1161
- enc.encode(encoding, {
1162
- a: { b: 'record' },
1163
- c: { d: 'nested', e: 'test' }
1164
- })
1165
- ),
1166
- Object.assign(Object.create(null), {
1167
- a: Object.assign(Object.create(null), { b: 'record' }),
1168
- c: Object.assign(Object.create(null), { d: 'nested', e: 'test' })
1169
- })
1170
- )
1171
- })
1172
-
1173
- test('stringRecord', function (t) {
1174
- t.alike(
1175
- enc.decode(
1176
- enc.stringRecord,
1177
- enc.encode(enc.stringRecord, { a: 'hello', b: 'world' })
1178
- ),
1179
- Object.assign(Object.create(null), {
1180
- a: 'hello',
1181
- b: 'world'
1182
- })
1183
- )
1184
- })