compact-encoding 2.17.0 → 2.18.0
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/.gitattributes +1 -0
- package/.github/workflows/test-node.yml +7 -7
- package/.prettierrc +1 -0
- package/README.md +92 -93
- package/endian.js +2 -1
- package/index.js +306 -217
- package/lexint.js +19 -16
- package/package.json +5 -3
- package/raw.js +34 -34
- package/test.js +234 -60
package/test.js
CHANGED
|
@@ -14,11 +14,24 @@ test('uint', function (t) {
|
|
|
14
14
|
|
|
15
15
|
state.buffer = b4a.alloc(state.end)
|
|
16
16
|
enc.uint.encode(state, 42)
|
|
17
|
-
t.alike(
|
|
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
|
+
)
|
|
18
21
|
enc.uint.encode(state, 4200)
|
|
19
|
-
t.alike(
|
|
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
|
+
)
|
|
20
26
|
enc.uint.encode(state, Number.MAX_SAFE_INTEGER)
|
|
21
|
-
t.alike(
|
|
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
|
+
)
|
|
22
35
|
|
|
23
36
|
state.start = 0
|
|
24
37
|
t.is(enc.uint.decode(state), 42)
|
|
@@ -60,7 +73,10 @@ test('float64', function (t) {
|
|
|
60
73
|
state.buffer = b4a.alloc(state.end)
|
|
61
74
|
t.alike(state, enc.state(0, 8, b4a.from([0, 0, 0, 0, 0, 0, 0, 0])))
|
|
62
75
|
enc.float64.encode(state, 162.2377294)
|
|
63
|
-
t.alike(
|
|
76
|
+
t.alike(
|
|
77
|
+
state,
|
|
78
|
+
enc.state(8, 8, b4a.from([0x87, 0xc9, 0xaf, 0x7a, 0x9b, 0x47, 0x64, 0x40]))
|
|
79
|
+
)
|
|
64
80
|
|
|
65
81
|
state.start = 0
|
|
66
82
|
t.is(enc.float64.decode(state), 162.2377294)
|
|
@@ -81,7 +97,14 @@ test('float64', function (t) {
|
|
|
81
97
|
t.alike(state, enc.state(0, 9, b4a.from([0, 0, 0, 0, 0, 0, 0, 0, 0])))
|
|
82
98
|
enc.int.encode(state, 0)
|
|
83
99
|
enc.float64.encode(state, 162.2377294)
|
|
84
|
-
t.alike(
|
|
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
|
+
)
|
|
85
108
|
|
|
86
109
|
state.start = 0
|
|
87
110
|
t.is(enc.int.decode(state), 0)
|
|
@@ -95,7 +118,14 @@ test('float64', function (t) {
|
|
|
95
118
|
t.alike(state, enc.state(0, 9, b4a.from([0, 0, 0, 0, 0, 0, 0, 0, 0])))
|
|
96
119
|
enc.int.encode(state, 0)
|
|
97
120
|
enc.float64.encode(state, 162.2377294)
|
|
98
|
-
t.alike(
|
|
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
|
+
)
|
|
99
129
|
t.alike(buf, b4a.from([0, 0, 0x87, 0xc9, 0xaf, 0x7a, 0x9b, 0x47, 0x64, 0x40]))
|
|
100
130
|
|
|
101
131
|
state.start = 0
|
|
@@ -139,7 +169,10 @@ test('float64', function (t) {
|
|
|
139
169
|
enc.float64.preencode(state, 0.1 + 0.2)
|
|
140
170
|
state.buffer = b4a.alloc(state.end)
|
|
141
171
|
enc.float64.encode(state, 0.1 + 0.2)
|
|
142
|
-
t.alike(
|
|
172
|
+
t.alike(
|
|
173
|
+
state,
|
|
174
|
+
enc.state(8, 8, b4a.from([0x34, 0x33, 0x33, 0x33, 0x33, 0x33, 0xd3, 0x3f]))
|
|
175
|
+
)
|
|
143
176
|
|
|
144
177
|
state.start = 0
|
|
145
178
|
t.is(enc.float64.decode(state), 0.1 + 0.2)
|
|
@@ -156,7 +189,10 @@ test('biguint64', function (t) {
|
|
|
156
189
|
|
|
157
190
|
state.buffer = b4a.alloc(state.end)
|
|
158
191
|
enc.biguint64.encode(state, n)
|
|
159
|
-
t.alike(
|
|
192
|
+
t.alike(
|
|
193
|
+
state,
|
|
194
|
+
enc.state(8, 8, b4a.from([0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1]))
|
|
195
|
+
)
|
|
160
196
|
|
|
161
197
|
state.start = 0
|
|
162
198
|
t.is(enc.biguint64.decode(state), n)
|
|
@@ -175,7 +211,10 @@ test('bigint64', function (t) {
|
|
|
175
211
|
|
|
176
212
|
state.buffer = b4a.alloc(state.end)
|
|
177
213
|
enc.bigint64.encode(state, n)
|
|
178
|
-
t.alike(
|
|
214
|
+
t.alike(
|
|
215
|
+
state,
|
|
216
|
+
enc.state(8, 8, b4a.from([0xf, 0xe, 0xc, 0xa, 0x8, 0x6, 0x4, 0x2]))
|
|
217
|
+
)
|
|
179
218
|
|
|
180
219
|
state.start = 0
|
|
181
220
|
t.is(enc.bigint64.decode(state), n)
|
|
@@ -194,7 +233,17 @@ test('biguint', function (t) {
|
|
|
194
233
|
|
|
195
234
|
state.buffer = b4a.alloc(state.end)
|
|
196
235
|
enc.biguint.encode(state, n)
|
|
197
|
-
t.alike(
|
|
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
|
+
)
|
|
198
247
|
|
|
199
248
|
state.start = 0
|
|
200
249
|
t.is(enc.biguint.decode(state), n)
|
|
@@ -213,7 +262,17 @@ test('bigint', function (t) {
|
|
|
213
262
|
|
|
214
263
|
state.buffer = b4a.alloc(state.end)
|
|
215
264
|
enc.bigint.encode(state, n)
|
|
216
|
-
t.alike(
|
|
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
|
+
)
|
|
217
276
|
|
|
218
277
|
state.start = 0
|
|
219
278
|
t.is(enc.bigint.decode(state), n)
|
|
@@ -234,7 +293,10 @@ test('buffer', function (t) {
|
|
|
234
293
|
|
|
235
294
|
state.buffer = b4a.alloc(state.end)
|
|
236
295
|
enc.buffer.encode(state, b4a.from('hi'))
|
|
237
|
-
t.alike(
|
|
296
|
+
t.alike(
|
|
297
|
+
state,
|
|
298
|
+
enc.state(3, 10, b4a.from('\x02hi\x00\x00\x00\x00\x00\x00\x00'))
|
|
299
|
+
)
|
|
238
300
|
enc.buffer.encode(state, b4a.from('hello'))
|
|
239
301
|
t.alike(state, enc.state(9, 10, b4a.from('\x02hi\x05hello\x00')))
|
|
240
302
|
enc.buffer.encode(state, null)
|
|
@@ -265,7 +327,10 @@ test('arraybuffer', function (t) {
|
|
|
265
327
|
|
|
266
328
|
state.buffer = b4a.alloc(state.end)
|
|
267
329
|
enc.arraybuffer.encode(state, b1)
|
|
268
|
-
t.alike(
|
|
330
|
+
t.alike(
|
|
331
|
+
state,
|
|
332
|
+
enc.state(5, 14, b4a.from('\x04aaaa\x00\x00\x00\x00\x00\x00\x00\x00\x00'))
|
|
333
|
+
)
|
|
269
334
|
enc.arraybuffer.encode(state, b2)
|
|
270
335
|
t.alike(state, enc.state(14, 14, b4a.from('\x04aaaa\x08bbbbbbbb')))
|
|
271
336
|
|
|
@@ -338,9 +403,15 @@ test('uint32array', function (t) {
|
|
|
338
403
|
|
|
339
404
|
state.buffer = b4a.alloc(state.end)
|
|
340
405
|
enc.uint32array.encode(state, new Uint32Array([1]))
|
|
341
|
-
t.alike(
|
|
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
|
+
)
|
|
342
410
|
enc.uint32array.encode(state, new Uint32Array([42, 43]))
|
|
343
|
-
t.alike(
|
|
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
|
+
)
|
|
344
415
|
|
|
345
416
|
state.start = 0
|
|
346
417
|
t.alike(enc.uint32array.decode(state), new Uint32Array([1]))
|
|
@@ -375,7 +446,14 @@ test('int32array', function (t) {
|
|
|
375
446
|
|
|
376
447
|
state.buffer = b4a.alloc(state.end)
|
|
377
448
|
enc.int32array.encode(state, new Int32Array([1, -2, 3]))
|
|
378
|
-
t.alike(
|
|
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
|
+
)
|
|
379
457
|
|
|
380
458
|
state.start = 0
|
|
381
459
|
t.alike(enc.int32array.decode(state), new Int32Array([1, -2, 3]))
|
|
@@ -394,7 +472,17 @@ test('biguint64array', function (t) {
|
|
|
394
472
|
|
|
395
473
|
state.buffer = b4a.alloc(state.end)
|
|
396
474
|
enc.biguint64array.encode(state, arr)
|
|
397
|
-
t.alike(
|
|
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
|
+
)
|
|
398
486
|
|
|
399
487
|
state.start = 0
|
|
400
488
|
t.alike(enc.biguint64array.decode(state), arr)
|
|
@@ -413,7 +501,17 @@ test('bigint64array', function (t) {
|
|
|
413
501
|
|
|
414
502
|
state.buffer = b4a.alloc(state.end)
|
|
415
503
|
enc.bigint64array.encode(state, arr)
|
|
416
|
-
t.alike(
|
|
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
|
+
)
|
|
417
515
|
|
|
418
516
|
state.start = 0
|
|
419
517
|
t.alike(enc.bigint64array.decode(state), arr)
|
|
@@ -430,7 +528,17 @@ test('float32array', function (t) {
|
|
|
430
528
|
|
|
431
529
|
state.buffer = b4a.alloc(state.end)
|
|
432
530
|
enc.float32array.encode(state, new Float32Array([1.1, -2.2, 3.3]))
|
|
433
|
-
t.alike(
|
|
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
|
+
)
|
|
434
542
|
|
|
435
543
|
state.start = 0
|
|
436
544
|
t.alike(enc.float32array.decode(state), new Float32Array([1.1, -2.2, 3.3]))
|
|
@@ -447,7 +555,18 @@ test('float64array', function (t) {
|
|
|
447
555
|
|
|
448
556
|
state.buffer = b4a.alloc(state.end)
|
|
449
557
|
enc.float64array.encode(state, new Float64Array([1.1, -2.2, 3.3]))
|
|
450
|
-
t.alike(
|
|
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
|
+
)
|
|
451
570
|
|
|
452
571
|
state.start = 0
|
|
453
572
|
t.alike(enc.float64array.decode(state), new Float64Array([1.1, -2.2, 3.3]))
|
|
@@ -466,7 +585,16 @@ test('string', function (t) {
|
|
|
466
585
|
|
|
467
586
|
state.buffer = b4a.alloc(state.end)
|
|
468
587
|
enc.string.encode(state, '🌾')
|
|
469
|
-
t.alike(
|
|
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
|
+
)
|
|
470
598
|
enc.string.encode(state, 'høsten er fin')
|
|
471
599
|
t.alike(state, enc.state(20, 20, b4a.from('\x04🌾\x0ehøsten er fin')))
|
|
472
600
|
|
|
@@ -508,7 +636,10 @@ test('fixed32', function (t) {
|
|
|
508
636
|
enc.fixed32.encode(state, b4a.alloc(32).fill('a'))
|
|
509
637
|
t.alike(state, enc.state(32, 64, b4a.alloc(64).fill('a', 0, 32)))
|
|
510
638
|
enc.fixed32.encode(state, b4a.alloc(32).fill('b'))
|
|
511
|
-
t.alike(
|
|
639
|
+
t.alike(
|
|
640
|
+
state,
|
|
641
|
+
enc.state(64, 64, b4a.alloc(64).fill('a', 0, 32).fill('b', 32, 64))
|
|
642
|
+
)
|
|
512
643
|
|
|
513
644
|
state.start = 0
|
|
514
645
|
t.alike(enc.fixed32.decode(state), b4a.alloc(32).fill('a'))
|
|
@@ -530,7 +661,10 @@ test('fixed64', function (t) {
|
|
|
530
661
|
enc.fixed64.encode(state, b4a.alloc(64).fill('a'))
|
|
531
662
|
t.alike(state, enc.state(64, 128, b4a.alloc(128).fill('a', 0, 64)))
|
|
532
663
|
enc.fixed64.encode(state, b4a.alloc(64).fill('b'))
|
|
533
|
-
t.alike(
|
|
664
|
+
t.alike(
|
|
665
|
+
state,
|
|
666
|
+
enc.state(128, 128, b4a.alloc(128).fill('a', 0, 64).fill('b', 64, 128))
|
|
667
|
+
)
|
|
534
668
|
|
|
535
669
|
state.start = 0
|
|
536
670
|
t.alike(enc.fixed64.decode(state), b4a.alloc(64).fill('a'))
|
|
@@ -571,7 +705,10 @@ test('error for incorrect buffer sizes when encoding fixed-length buffers', func
|
|
|
571
705
|
|
|
572
706
|
t.exception(() => enc.encode(enc.fixed32, smallbuf), /Incorrect buffer size/)
|
|
573
707
|
t.exception(() => enc.encode(enc.fixed64, smallbuf), /Incorrect buffer size/)
|
|
574
|
-
t.exception(
|
|
708
|
+
t.exception(
|
|
709
|
+
() => enc.encode(enc.fixed(100), smallbuf),
|
|
710
|
+
/Incorrect buffer size/
|
|
711
|
+
)
|
|
575
712
|
|
|
576
713
|
t.exception(() => enc.encode(enc.fixed32, bigBuf), /Incorrect buffer size/)
|
|
577
714
|
t.exception(() => enc.encode(enc.fixed64, bigBuf), /Incorrect buffer size/)
|
|
@@ -629,10 +766,10 @@ test('json', function (t) {
|
|
|
629
766
|
|
|
630
767
|
state.buffer = b4a.alloc(state.end)
|
|
631
768
|
enc.json.encode(state, { a: 1, b: 2 })
|
|
632
|
-
t.alike(
|
|
633
|
-
|
|
634
|
-
b4a.from('{"a":1,"b":2}')
|
|
635
|
-
|
|
769
|
+
t.alike(
|
|
770
|
+
state,
|
|
771
|
+
enc.state(14, 14, b4a.concat([b4a.from([13]), b4a.from('{"a":1,"b":2}')]))
|
|
772
|
+
)
|
|
636
773
|
|
|
637
774
|
state.start = 0
|
|
638
775
|
t.alike(enc.json.decode(state), { a: 1, b: 2 })
|
|
@@ -720,7 +857,10 @@ test('lexint: throws', function (t) {
|
|
|
720
857
|
enc.lexint.encode(state, num)
|
|
721
858
|
|
|
722
859
|
t.exception(() => {
|
|
723
|
-
enc.decode(
|
|
860
|
+
enc.decode(
|
|
861
|
+
enc.lexint,
|
|
862
|
+
state.buffer.subarray(0, state.buffer.byteLength - 2)
|
|
863
|
+
)
|
|
724
864
|
})
|
|
725
865
|
|
|
726
866
|
num <<= 8
|
|
@@ -734,7 +874,10 @@ test('lexint: throws', function (t) {
|
|
|
734
874
|
enc.lexint.encode(state, num)
|
|
735
875
|
|
|
736
876
|
t.exception(() => {
|
|
737
|
-
enc.decode(
|
|
877
|
+
enc.decode(
|
|
878
|
+
enc.lexint,
|
|
879
|
+
state.buffer.subarray(0, state.buffer.byteLength - 2)
|
|
880
|
+
)
|
|
738
881
|
})
|
|
739
882
|
|
|
740
883
|
num <<= 8
|
|
@@ -748,7 +891,10 @@ test('lexint: throws', function (t) {
|
|
|
748
891
|
enc.lexint.encode(state, num)
|
|
749
892
|
|
|
750
893
|
t.exception(() => {
|
|
751
|
-
enc.decode(
|
|
894
|
+
enc.decode(
|
|
895
|
+
enc.lexint,
|
|
896
|
+
state.buffer.subarray(0, state.buffer.byteLength - 2)
|
|
897
|
+
)
|
|
752
898
|
})
|
|
753
899
|
|
|
754
900
|
num *= 256
|
|
@@ -762,7 +908,10 @@ test('lexint: throws', function (t) {
|
|
|
762
908
|
enc.lexint.encode(state, num)
|
|
763
909
|
|
|
764
910
|
t.exception(() => {
|
|
765
|
-
enc.decode(
|
|
911
|
+
enc.decode(
|
|
912
|
+
enc.lexint,
|
|
913
|
+
state.buffer.subarray(0, state.buffer.byteLength - 2)
|
|
914
|
+
)
|
|
766
915
|
})
|
|
767
916
|
|
|
768
917
|
num *= 256 * 256
|
|
@@ -776,7 +925,10 @@ test('lexint: throws', function (t) {
|
|
|
776
925
|
enc.lexint.encode(state, num)
|
|
777
926
|
|
|
778
927
|
t.exception(() => {
|
|
779
|
-
enc.decode(
|
|
928
|
+
enc.decode(
|
|
929
|
+
enc.lexint,
|
|
930
|
+
state.buffer.subarray(0, state.buffer.byteLength - 2)
|
|
931
|
+
)
|
|
780
932
|
})
|
|
781
933
|
|
|
782
934
|
t.end()
|
|
@@ -794,16 +946,20 @@ test('lexint: unpack', function (t) {
|
|
|
794
946
|
t.is(n, Infinity)
|
|
795
947
|
t.end()
|
|
796
948
|
|
|
797
|
-
function compare
|
|
949
|
+
function compare(a, b) {
|
|
798
950
|
const desc = a + ' !=~ ' + b
|
|
799
951
|
if (/e\+\d+$/.test(a) || /e\+\d+$/.test(b)) {
|
|
800
|
-
if (
|
|
801
|
-
|
|
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
|
+
) {
|
|
802
956
|
t.fail(desc)
|
|
803
957
|
}
|
|
804
958
|
} else {
|
|
805
|
-
if (
|
|
806
|
-
|
|
959
|
+
if (
|
|
960
|
+
String(a).slice(0, 8) !== String(b).slice(0, 8) ||
|
|
961
|
+
String(a).length !== String(b).length
|
|
962
|
+
) {
|
|
807
963
|
t.fail(desc)
|
|
808
964
|
}
|
|
809
965
|
}
|
|
@@ -862,11 +1018,14 @@ test('ipv4 + port', function (t) {
|
|
|
862
1018
|
const host = '1.2.3.4'
|
|
863
1019
|
const port = 1234
|
|
864
1020
|
|
|
865
|
-
t.alike(
|
|
866
|
-
host,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
1021
|
+
t.alike(
|
|
1022
|
+
enc.decode(enc.ipv4Address, enc.encode(enc.ipv4Address, { host, port })),
|
|
1023
|
+
{
|
|
1024
|
+
host,
|
|
1025
|
+
family: 4,
|
|
1026
|
+
port
|
|
1027
|
+
}
|
|
1028
|
+
)
|
|
870
1029
|
})
|
|
871
1030
|
|
|
872
1031
|
test('ipv6', function (t) {
|
|
@@ -905,14 +1064,18 @@ test('ipv6', function (t) {
|
|
|
905
1064
|
})
|
|
906
1065
|
|
|
907
1066
|
t.test('lowercase hex', function (t) {
|
|
908
|
-
const buf = Buffer.from([
|
|
1067
|
+
const buf = Buffer.from([
|
|
1068
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd
|
|
1069
|
+
])
|
|
909
1070
|
|
|
910
1071
|
t.alike(enc.encode(enc.ipv6, '::abcd'), buf)
|
|
911
1072
|
t.alike(enc.decode(enc.ipv6, buf), '0:0:0:0:0:0:0:abcd')
|
|
912
1073
|
})
|
|
913
1074
|
|
|
914
1075
|
t.test('uppercase hex', function (t) {
|
|
915
|
-
const buf = Buffer.from([
|
|
1076
|
+
const buf = Buffer.from([
|
|
1077
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd
|
|
1078
|
+
])
|
|
916
1079
|
|
|
917
1080
|
t.alike(enc.encode(enc.ipv6, '::ABCD'), buf)
|
|
918
1081
|
t.alike(enc.decode(enc.ipv6, buf), '0:0:0:0:0:0:0:abcd')
|
|
@@ -923,11 +1086,14 @@ test('ipv6 + port', function (t) {
|
|
|
923
1086
|
const host = '1:2:3:4:5:6:7:8'
|
|
924
1087
|
const port = 1234
|
|
925
1088
|
|
|
926
|
-
t.alike(
|
|
927
|
-
host,
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1089
|
+
t.alike(
|
|
1090
|
+
enc.decode(enc.ipv6Address, enc.encode(enc.ipv6Address, { host, port })),
|
|
1091
|
+
{
|
|
1092
|
+
host,
|
|
1093
|
+
family: 6,
|
|
1094
|
+
port
|
|
1095
|
+
}
|
|
1096
|
+
)
|
|
931
1097
|
})
|
|
932
1098
|
|
|
933
1099
|
test('dual ip', function (t) {
|
|
@@ -949,19 +1115,27 @@ test('dual ip + port', function (t) {
|
|
|
949
1115
|
{
|
|
950
1116
|
const host = '1.2.3.4'
|
|
951
1117
|
|
|
952
|
-
t.alike(
|
|
953
|
-
host,
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
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
|
+
)
|
|
957
1127
|
}
|
|
958
1128
|
{
|
|
959
1129
|
const host = '1:2:3:4:5:6:7:8'
|
|
960
1130
|
|
|
961
|
-
t.alike(
|
|
962
|
-
host,
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
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
|
+
)
|
|
966
1140
|
}
|
|
967
1141
|
})
|