zkjson 0.5.0 → 0.5.2
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/decoder-v2.js +16 -4
- package/encoder-v2.js +11 -9
- package/package.json +1 -1
package/decoder-v2.js
CHANGED
@@ -7,7 +7,7 @@ const {
|
|
7
7
|
base64,
|
8
8
|
} = require("./utils.js")
|
9
9
|
|
10
|
-
|
10
|
+
class decoder {
|
11
11
|
constructor() {
|
12
12
|
this.c = 0
|
13
13
|
this.json = null
|
@@ -65,10 +65,10 @@ module.exports = class decoder {
|
|
65
65
|
this.getKflags()
|
66
66
|
this.getKlinks()
|
67
67
|
this.getKeyLens()
|
68
|
+
this.getKeys()
|
68
69
|
this.getTypes()
|
69
70
|
this.getBools()
|
70
71
|
this.getNums()
|
71
|
-
this.getKeys()
|
72
72
|
this.build()
|
73
73
|
}
|
74
74
|
}
|
@@ -115,9 +115,11 @@ module.exports = class decoder {
|
|
115
115
|
}
|
116
116
|
}
|
117
117
|
}
|
118
|
+
|
118
119
|
getLen() {
|
119
120
|
this.len = this.short()
|
120
121
|
}
|
122
|
+
|
121
123
|
show() {
|
122
124
|
console.log()
|
123
125
|
console.log("len", this.len)
|
@@ -129,6 +131,7 @@ module.exports = class decoder {
|
|
129
131
|
console.log("keys", this.keys)
|
130
132
|
console.log()
|
131
133
|
}
|
134
|
+
|
132
135
|
getVflags() {
|
133
136
|
let i = 0
|
134
137
|
while (i < this.len) {
|
@@ -137,6 +140,7 @@ module.exports = class decoder {
|
|
137
140
|
i++
|
138
141
|
}
|
139
142
|
}
|
143
|
+
|
140
144
|
getKflags() {
|
141
145
|
let i = 0
|
142
146
|
while (i < this.key_length - 1) {
|
@@ -201,6 +205,7 @@ module.exports = class decoder {
|
|
201
205
|
prev = val
|
202
206
|
return prev
|
203
207
|
}
|
208
|
+
|
204
209
|
addKlink(diff, val, prev) {
|
205
210
|
val -= 1
|
206
211
|
if (diff) {
|
@@ -371,7 +376,7 @@ module.exports = class decoder {
|
|
371
376
|
this.keys.push([code])
|
372
377
|
} else {
|
373
378
|
let key = ""
|
374
|
-
for (let i2 = 0; i2 < len -
|
379
|
+
for (let i2 = 0; i2 < len - 1; i2++) key += base64_rev[this.n(6)]
|
375
380
|
this.keys.push(key)
|
376
381
|
}
|
377
382
|
} else {
|
@@ -379,7 +384,7 @@ module.exports = class decoder {
|
|
379
384
|
this.keys.push("")
|
380
385
|
} else {
|
381
386
|
let key = ""
|
382
|
-
for (let i2 = 0; i2 < len -
|
387
|
+
for (let i2 = 0; i2 < len - 1; i2++) {
|
383
388
|
key += String.fromCharCode(Number(this.leb128()))
|
384
389
|
}
|
385
390
|
this.keys.push(key)
|
@@ -590,3 +595,10 @@ module.exports = class decoder {
|
|
590
595
|
}
|
591
596
|
}
|
592
597
|
}
|
598
|
+
|
599
|
+
function decode_x(v, d) {
|
600
|
+
d.decode(v)
|
601
|
+
return d.json
|
602
|
+
}
|
603
|
+
|
604
|
+
module.exports = { decoder, decode_x }
|
package/encoder-v2.js
CHANGED
@@ -492,6 +492,14 @@ class u8 {
|
|
492
492
|
} else this.leb128_vals(v)
|
493
493
|
}
|
494
494
|
|
495
|
+
short_nums(v) {
|
496
|
+
if (v < 16) {
|
497
|
+
const d = v < 4 ? 2 : this.fastBits(v)
|
498
|
+
this.add_nums(d - 2, 2)
|
499
|
+
this.add_nums(v, d)
|
500
|
+
} else this.leb128_nums(v)
|
501
|
+
}
|
502
|
+
|
495
503
|
short_kvals(v) {
|
496
504
|
if (v < 16) {
|
497
505
|
const d = v < 4 ? 2 : this.fastBits(v)
|
@@ -641,10 +649,10 @@ class u8 {
|
|
641
649
|
writeBuffer(this.kflags, this.kflags_len)
|
642
650
|
writeBuffer(this.klinks, this.klinks_len)
|
643
651
|
writeBuffer(this.keys, this.keys_len)
|
652
|
+
writeBuffer(this.kvals, this.kvals_len)
|
644
653
|
writeBuffer(this.types, this.types_len)
|
645
654
|
writeBuffer(this.bools, this.bools_len)
|
646
655
|
writeBuffer(this.nums, this.nums_len)
|
647
|
-
writeBuffer(this.kvals, this.kvals_len)
|
648
656
|
writeBuffer(this.vals, this.vals_len)
|
649
657
|
|
650
658
|
if (padBits > 0) writeBits(0, padBits)
|
@@ -676,7 +684,7 @@ function pushPathStr(u, v2, prev = null) {
|
|
676
684
|
if (is64) ktype = 2
|
677
685
|
}
|
678
686
|
u.add_keys(ktype, 2)
|
679
|
-
u.push_keylen(len +
|
687
|
+
u.push_keylen(len + 1)
|
680
688
|
if (ktype === 3) for (let v of codes2) u.leb128_2_kvals(v)
|
681
689
|
else for (let v of codes) u.add_kvals(v, 6)
|
682
690
|
}
|
@@ -686,7 +694,6 @@ function pushPathStr(u, v2, prev = null) {
|
|
686
694
|
function pushPathNum(u, prev = null, keylen) {
|
687
695
|
if (u.dcount > 0) u.push_klink(prev === null ? 0 : prev + 1)
|
688
696
|
u.add_keys(keylen, 2)
|
689
|
-
const id = keylen === 0 ? u.iid++ : u.oid++
|
690
697
|
u.dcount++
|
691
698
|
}
|
692
699
|
|
@@ -876,9 +883,4 @@ function _encode_x(
|
|
876
883
|
}
|
877
884
|
}
|
878
885
|
|
879
|
-
|
880
|
-
d.decode(v)
|
881
|
-
return d.json
|
882
|
-
}
|
883
|
-
|
884
|
-
module.exports = { encode_x, decode_x, u8 }
|
886
|
+
module.exports = { encode_x, u8 }
|