msgpackr 1.11.11 → 2.0.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/README.md +16 -0
- package/dist/index-no-eval.cjs +209 -245
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +209 -245
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +245 -1072
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +246 -1137
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +167 -186
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.js +5 -5
- package/iterators.js +28 -28
- package/node-index.js +12 -13
- package/pack.js +580 -611
- package/package.json +1 -1
- package/stream.js +37 -32
- package/unpack.js +612 -630
- package/struct.js +0 -815
package/unpack.js
CHANGED
|
@@ -1,678 +1,667 @@
|
|
|
1
|
-
var decoder
|
|
1
|
+
var decoder;
|
|
2
2
|
try {
|
|
3
|
-
decoder = new TextDecoder()
|
|
3
|
+
decoder = new TextDecoder();
|
|
4
4
|
} catch(error) {}
|
|
5
|
-
var src
|
|
6
|
-
var srcEnd
|
|
7
|
-
var position = 0
|
|
8
|
-
var alreadySet
|
|
9
|
-
const EMPTY_ARRAY = []
|
|
10
|
-
var strings = EMPTY_ARRAY
|
|
11
|
-
var stringPosition = 0
|
|
12
|
-
var currentUnpackr = {}
|
|
13
|
-
var currentStructures
|
|
14
|
-
var srcString
|
|
15
|
-
var srcStringStart = 0
|
|
16
|
-
var srcStringEnd = 0
|
|
17
|
-
var bundledStrings
|
|
18
|
-
var referenceMap
|
|
19
|
-
var currentExtensions = []
|
|
20
|
-
var dataView
|
|
5
|
+
var src;
|
|
6
|
+
var srcEnd;
|
|
7
|
+
var position = 0;
|
|
8
|
+
var alreadySet;
|
|
9
|
+
const EMPTY_ARRAY = [];
|
|
10
|
+
var strings = EMPTY_ARRAY;
|
|
11
|
+
var stringPosition = 0;
|
|
12
|
+
var currentUnpackr = {};
|
|
13
|
+
var currentStructures;
|
|
14
|
+
var srcString;
|
|
15
|
+
var srcStringStart = 0;
|
|
16
|
+
var srcStringEnd = 0;
|
|
17
|
+
var bundledStrings;
|
|
18
|
+
var referenceMap;
|
|
19
|
+
var currentExtensions = [];
|
|
20
|
+
var dataView;
|
|
21
21
|
var defaultOptions = {
|
|
22
22
|
useRecords: false,
|
|
23
23
|
mapsAsObjects: true
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
25
|
export class C1Type {}
|
|
26
|
-
export const C1 = new C1Type()
|
|
27
|
-
C1.name = 'MessagePack 0xC1'
|
|
28
|
-
var sequentialMode = false
|
|
29
|
-
var inlineObjectReadThreshold = 2
|
|
30
|
-
var
|
|
31
|
-
var BlockedFunction // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
|
|
26
|
+
export const C1 = new C1Type();
|
|
27
|
+
C1.name = 'MessagePack 0xC1';
|
|
28
|
+
var sequentialMode = false;
|
|
29
|
+
var inlineObjectReadThreshold = 2;
|
|
30
|
+
var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
|
|
32
31
|
|
|
33
32
|
export class Unpackr {
|
|
34
33
|
constructor(options) {
|
|
35
34
|
if (options) {
|
|
36
35
|
if (options.useRecords === false && options.mapsAsObjects === undefined)
|
|
37
|
-
options.mapsAsObjects = true
|
|
36
|
+
options.mapsAsObjects = true;
|
|
38
37
|
if (options.sequential && options.trusted !== false) {
|
|
39
38
|
options.trusted = true;
|
|
40
39
|
if (!options.structures && options.useRecords != false) {
|
|
41
|
-
options.structures = []
|
|
40
|
+
options.structures = [];
|
|
42
41
|
if (!options.maxSharedStructures)
|
|
43
|
-
options.maxSharedStructures = 0
|
|
42
|
+
options.maxSharedStructures = 0;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
if (options.structures)
|
|
47
|
-
options.structures.sharedLength = options.structures.length
|
|
46
|
+
options.structures.sharedLength = options.structures.length;
|
|
48
47
|
else if (options.getStructures) {
|
|
49
|
-
(options.structures = []).uninitialized = true // this is what we use to denote an uninitialized structures
|
|
50
|
-
options.structures.sharedLength = 0
|
|
48
|
+
(options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
|
|
49
|
+
options.structures.sharedLength = 0;
|
|
51
50
|
}
|
|
52
51
|
if (options.int64AsNumber) {
|
|
53
|
-
options.int64AsType = 'number'
|
|
52
|
+
options.int64AsType = 'number';
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
|
-
Object.assign(this, options)
|
|
55
|
+
Object.assign(this, options);
|
|
57
56
|
}
|
|
58
57
|
unpack(source, options) {
|
|
59
58
|
if (src) {
|
|
60
59
|
// re-entrant execution, save the state and restore it after we do this unpack
|
|
61
60
|
return saveState(() => {
|
|
62
|
-
clearSource()
|
|
63
|
-
return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
|
|
64
|
-
})
|
|
61
|
+
clearSource();
|
|
62
|
+
return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
|
|
63
|
+
});
|
|
65
64
|
}
|
|
66
65
|
if (!source.buffer && source.constructor === ArrayBuffer)
|
|
67
66
|
source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
|
|
68
67
|
if (typeof options === 'object') {
|
|
69
|
-
srcEnd = options.end || source.length
|
|
70
|
-
position = options.start || 0
|
|
68
|
+
srcEnd = options.end || source.length;
|
|
69
|
+
position = options.start || 0;
|
|
71
70
|
} else {
|
|
72
|
-
position = 0
|
|
73
|
-
srcEnd = options > -1 ? options : source.length
|
|
71
|
+
position = 0;
|
|
72
|
+
srcEnd = options > -1 ? options : source.length;
|
|
74
73
|
}
|
|
75
|
-
stringPosition = 0
|
|
76
|
-
srcStringEnd = 0
|
|
77
|
-
srcString = null
|
|
78
|
-
strings = EMPTY_ARRAY
|
|
79
|
-
bundledStrings = null
|
|
80
|
-
src = source
|
|
74
|
+
stringPosition = 0;
|
|
75
|
+
srcStringEnd = 0;
|
|
76
|
+
srcString = null;
|
|
77
|
+
strings = EMPTY_ARRAY;
|
|
78
|
+
bundledStrings = null;
|
|
79
|
+
src = source;
|
|
81
80
|
// this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
|
|
82
81
|
// technique for getting data from a database where it can be copied into an existing buffer instead of creating
|
|
83
82
|
// new ones
|
|
84
83
|
try {
|
|
85
|
-
dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength))
|
|
84
|
+
dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength));
|
|
86
85
|
} catch(error) {
|
|
87
86
|
// if it doesn't have a buffer, maybe it is the wrong type of object
|
|
88
|
-
src = null
|
|
87
|
+
src = null;
|
|
89
88
|
if (source instanceof Uint8Array)
|
|
90
|
-
throw error
|
|
91
|
-
throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
|
|
89
|
+
throw error;
|
|
90
|
+
throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
|
|
92
91
|
}
|
|
93
92
|
if (this instanceof Unpackr) {
|
|
94
|
-
currentUnpackr = this
|
|
93
|
+
currentUnpackr = this;
|
|
95
94
|
if (this.structures) {
|
|
96
|
-
currentStructures = this.structures
|
|
97
|
-
return checkedRead(options)
|
|
95
|
+
currentStructures = this.structures;
|
|
96
|
+
return checkedRead(options);
|
|
98
97
|
} else if (!currentStructures || currentStructures.length > 0) {
|
|
99
|
-
currentStructures = []
|
|
98
|
+
currentStructures = [];
|
|
100
99
|
}
|
|
101
100
|
} else {
|
|
102
|
-
currentUnpackr = defaultOptions
|
|
101
|
+
currentUnpackr = defaultOptions;
|
|
103
102
|
if (!currentStructures || currentStructures.length > 0)
|
|
104
|
-
currentStructures = []
|
|
103
|
+
currentStructures = [];
|
|
105
104
|
}
|
|
106
|
-
return checkedRead(options)
|
|
105
|
+
return checkedRead(options);
|
|
107
106
|
}
|
|
108
107
|
unpackMultiple(source, forEach) {
|
|
109
|
-
let values, lastPosition = 0
|
|
108
|
+
let values, lastPosition = 0;
|
|
110
109
|
try {
|
|
111
|
-
sequentialMode = true
|
|
112
|
-
let size = source.length
|
|
113
|
-
let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size)
|
|
110
|
+
sequentialMode = true;
|
|
111
|
+
let size = source.length;
|
|
112
|
+
let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
|
|
114
113
|
if (forEach) {
|
|
115
114
|
if (forEach(value, lastPosition, position) === false) return;
|
|
116
115
|
while(position < size) {
|
|
117
|
-
lastPosition = position
|
|
116
|
+
lastPosition = position;
|
|
118
117
|
if (forEach(checkedRead(), lastPosition, position) === false) {
|
|
119
|
-
return
|
|
118
|
+
return;
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
else {
|
|
124
|
-
values = [ value ]
|
|
123
|
+
values = [ value ];
|
|
125
124
|
while(position < size) {
|
|
126
|
-
lastPosition = position
|
|
127
|
-
values.push(checkedRead())
|
|
125
|
+
lastPosition = position;
|
|
126
|
+
values.push(checkedRead());
|
|
128
127
|
}
|
|
129
|
-
return values
|
|
128
|
+
return values;
|
|
130
129
|
}
|
|
131
130
|
} catch(error) {
|
|
132
|
-
error.lastPosition = lastPosition
|
|
133
|
-
error.values = values
|
|
134
|
-
throw error
|
|
131
|
+
error.lastPosition = lastPosition;
|
|
132
|
+
error.values = values;
|
|
133
|
+
throw error;
|
|
135
134
|
} finally {
|
|
136
|
-
sequentialMode = false
|
|
137
|
-
clearSource()
|
|
135
|
+
sequentialMode = false;
|
|
136
|
+
clearSource();
|
|
138
137
|
}
|
|
139
138
|
}
|
|
140
139
|
_mergeStructures(loadedStructures, existingStructures) {
|
|
141
|
-
|
|
142
|
-
loadedStructures = onLoadedStructures.call(this, loadedStructures);
|
|
143
|
-
loadedStructures = loadedStructures || []
|
|
140
|
+
loadedStructures = loadedStructures || [];
|
|
144
141
|
if (Object.isFrozen(loadedStructures))
|
|
145
|
-
loadedStructures = loadedStructures.map(structure => structure.slice(0))
|
|
142
|
+
loadedStructures = loadedStructures.map(structure => structure.slice(0));
|
|
146
143
|
for (let i = 0, l = loadedStructures.length; i < l; i++) {
|
|
147
|
-
let structure = loadedStructures[i]
|
|
144
|
+
let structure = loadedStructures[i];
|
|
148
145
|
if (structure) {
|
|
149
|
-
structure.isShared = true
|
|
146
|
+
structure.isShared = true;
|
|
150
147
|
if (i >= 32)
|
|
151
|
-
structure.highByte = (i - 32) >> 5
|
|
148
|
+
structure.highByte = (i - 32) >> 5;
|
|
152
149
|
}
|
|
153
150
|
}
|
|
154
|
-
loadedStructures.sharedLength = loadedStructures.length
|
|
151
|
+
loadedStructures.sharedLength = loadedStructures.length;
|
|
155
152
|
for (let id in existingStructures || []) {
|
|
156
153
|
if (id >= 0) {
|
|
157
|
-
let structure = loadedStructures[id]
|
|
158
|
-
let existing = existingStructures[id]
|
|
154
|
+
let structure = loadedStructures[id];
|
|
155
|
+
let existing = existingStructures[id];
|
|
159
156
|
if (existing) {
|
|
160
157
|
if (structure)
|
|
161
|
-
(loadedStructures.restoreStructures || (loadedStructures.restoreStructures = []))[id] = structure
|
|
162
|
-
loadedStructures[id] = existing
|
|
158
|
+
(loadedStructures.restoreStructures || (loadedStructures.restoreStructures = []))[id] = structure;
|
|
159
|
+
loadedStructures[id] = existing;
|
|
163
160
|
}
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
|
-
return this.structures = loadedStructures
|
|
163
|
+
return this.structures = loadedStructures;
|
|
167
164
|
}
|
|
168
165
|
decode(source, options) {
|
|
169
|
-
return this.unpack(source, options)
|
|
166
|
+
return this.unpack(source, options);
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
export function getPosition() {
|
|
173
|
-
return position
|
|
170
|
+
return position;
|
|
174
171
|
}
|
|
175
172
|
export function checkedRead(options) {
|
|
176
173
|
try {
|
|
177
174
|
if (!currentUnpackr.trusted && !sequentialMode) {
|
|
178
|
-
let sharedLength = currentStructures.sharedLength || 0
|
|
175
|
+
let sharedLength = currentStructures.sharedLength || 0;
|
|
179
176
|
if (sharedLength < currentStructures.length)
|
|
180
|
-
currentStructures.length = sharedLength
|
|
177
|
+
currentStructures.length = sharedLength;
|
|
181
178
|
}
|
|
182
|
-
let result
|
|
183
|
-
if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
|
|
184
|
-
result = readStruct(src, position, srcEnd, currentUnpackr)
|
|
185
|
-
src = null // dispose of this so that recursive unpack calls don't save state
|
|
186
|
-
if (!(options && options.lazy) && result)
|
|
187
|
-
result = result.toJSON()
|
|
188
|
-
position = srcEnd
|
|
189
|
-
} else
|
|
190
|
-
result = read()
|
|
179
|
+
let result = read();
|
|
191
180
|
if (bundledStrings) { // bundled strings to skip past
|
|
192
|
-
position = bundledStrings.postBundlePosition
|
|
193
|
-
bundledStrings = null
|
|
181
|
+
position = bundledStrings.postBundlePosition;
|
|
182
|
+
bundledStrings = null;
|
|
194
183
|
}
|
|
195
184
|
if (sequentialMode)
|
|
196
185
|
// we only need to restore the structures if there was an error, but if we completed a read,
|
|
197
186
|
// we can clear this out and keep the structures we read
|
|
198
|
-
currentStructures.restoreStructures = null
|
|
187
|
+
currentStructures.restoreStructures = null;
|
|
199
188
|
|
|
200
189
|
if (position == srcEnd) {
|
|
201
190
|
// finished reading this source, cleanup references
|
|
202
191
|
if (currentStructures && currentStructures.restoreStructures)
|
|
203
|
-
restoreStructures()
|
|
204
|
-
currentStructures = null
|
|
205
|
-
src = null
|
|
192
|
+
restoreStructures();
|
|
193
|
+
currentStructures = null;
|
|
194
|
+
src = null;
|
|
206
195
|
if (referenceMap)
|
|
207
|
-
referenceMap = null
|
|
196
|
+
referenceMap = null;
|
|
208
197
|
} else if (position > srcEnd) {
|
|
209
198
|
// over read
|
|
210
|
-
throw new Error('Unexpected end of MessagePack data')
|
|
199
|
+
throw new Error('Unexpected end of MessagePack data');
|
|
211
200
|
} else if (!sequentialMode) {
|
|
212
201
|
let jsonView;
|
|
213
202
|
try {
|
|
214
|
-
jsonView = JSON.stringify(result, (_, value) => typeof value === "bigint" ? `${value}n` : value).slice(0, 100)
|
|
203
|
+
jsonView = JSON.stringify(result, (_, value) => typeof value === "bigint" ? `${value}n` : value).slice(0, 100);
|
|
215
204
|
} catch(error) {
|
|
216
|
-
jsonView = '(JSON view not available ' + error + ')'
|
|
205
|
+
jsonView = '(JSON view not available ' + error + ')';
|
|
217
206
|
}
|
|
218
|
-
throw new Error('Data read, but end of buffer not reached ' + jsonView)
|
|
207
|
+
throw new Error('Data read, but end of buffer not reached ' + jsonView);
|
|
219
208
|
}
|
|
220
209
|
// else more to read, but we are reading sequentially, so don't clear source yet
|
|
221
|
-
return result
|
|
210
|
+
return result;
|
|
222
211
|
} catch(error) {
|
|
223
212
|
if (currentStructures && currentStructures.restoreStructures)
|
|
224
|
-
restoreStructures()
|
|
225
|
-
clearSource()
|
|
213
|
+
restoreStructures();
|
|
214
|
+
clearSource();
|
|
226
215
|
if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
|
|
227
|
-
error.incomplete = true
|
|
216
|
+
error.incomplete = true;
|
|
228
217
|
}
|
|
229
|
-
throw error
|
|
218
|
+
throw error;
|
|
230
219
|
}
|
|
231
220
|
}
|
|
232
221
|
|
|
233
222
|
function restoreStructures() {
|
|
234
223
|
for (let id in currentStructures.restoreStructures) {
|
|
235
|
-
currentStructures[id] = currentStructures.restoreStructures[id]
|
|
224
|
+
currentStructures[id] = currentStructures.restoreStructures[id];
|
|
236
225
|
}
|
|
237
|
-
currentStructures.restoreStructures = null
|
|
226
|
+
currentStructures.restoreStructures = null;
|
|
238
227
|
}
|
|
239
228
|
|
|
240
229
|
export function read() {
|
|
241
|
-
let token = src[position++]
|
|
230
|
+
let token = src[position++];
|
|
242
231
|
if (token < 0xa0) {
|
|
243
232
|
if (token < 0x80) {
|
|
244
233
|
if (token < 0x40)
|
|
245
|
-
return token
|
|
234
|
+
return token;
|
|
246
235
|
else {
|
|
247
236
|
let structure = currentStructures[token & 0x3f] ||
|
|
248
|
-
currentUnpackr.getStructures && loadStructures()[token & 0x3f]
|
|
237
|
+
currentUnpackr.getStructures && loadStructures()[token & 0x3f];
|
|
249
238
|
if (structure) {
|
|
250
239
|
if (!structure.read) {
|
|
251
|
-
structure.read = createStructureReader(structure, token & 0x3f)
|
|
240
|
+
structure.read = createStructureReader(structure, token & 0x3f);
|
|
252
241
|
}
|
|
253
|
-
return structure.read()
|
|
242
|
+
return structure.read();
|
|
254
243
|
} else
|
|
255
|
-
return token
|
|
244
|
+
return token;
|
|
256
245
|
}
|
|
257
246
|
} else if (token < 0x90) {
|
|
258
247
|
// map
|
|
259
|
-
token -= 0x80
|
|
248
|
+
token -= 0x80;
|
|
260
249
|
if (currentUnpackr.mapsAsObjects) {
|
|
261
|
-
let object = {}
|
|
250
|
+
let object = {};
|
|
262
251
|
for (let i = 0; i < token; i++) {
|
|
263
|
-
let key = readKey()
|
|
252
|
+
let key = readKey();
|
|
264
253
|
if (key === '__proto__')
|
|
265
|
-
key = '__proto_'
|
|
266
|
-
object[key] = read()
|
|
254
|
+
key = '__proto_';
|
|
255
|
+
object[key] = read();
|
|
267
256
|
}
|
|
268
|
-
return object
|
|
257
|
+
return object;
|
|
269
258
|
} else {
|
|
270
|
-
let map = new Map()
|
|
259
|
+
let map = new Map();
|
|
271
260
|
for (let i = 0; i < token; i++) {
|
|
272
|
-
map.set(read(), read())
|
|
261
|
+
map.set(read(), read());
|
|
273
262
|
}
|
|
274
|
-
return map
|
|
263
|
+
return map;
|
|
275
264
|
}
|
|
276
265
|
} else {
|
|
277
|
-
token -= 0x90
|
|
278
|
-
let array = new Array(token)
|
|
266
|
+
token -= 0x90;
|
|
267
|
+
let array = new Array(token);
|
|
279
268
|
for (let i = 0; i < token; i++) {
|
|
280
|
-
array[i] = read()
|
|
269
|
+
array[i] = read();
|
|
281
270
|
}
|
|
282
271
|
if (currentUnpackr.freezeData)
|
|
283
|
-
return Object.freeze(array)
|
|
284
|
-
return array
|
|
272
|
+
return Object.freeze(array);
|
|
273
|
+
return array;
|
|
285
274
|
}
|
|
286
275
|
} else if (token < 0xc0) {
|
|
287
276
|
// fixstr
|
|
288
|
-
let length = token - 0xa0
|
|
277
|
+
let length = token - 0xa0;
|
|
289
278
|
if (srcStringEnd >= position) {
|
|
290
|
-
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
|
|
279
|
+
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
|
|
291
280
|
}
|
|
292
281
|
if (srcStringEnd == 0 && srcEnd < 140) {
|
|
293
282
|
// for small blocks, avoiding the overhead of the extract call is helpful
|
|
294
|
-
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length)
|
|
283
|
+
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
|
|
295
284
|
if (string != null)
|
|
296
|
-
return string
|
|
285
|
+
return string;
|
|
297
286
|
}
|
|
298
|
-
return readFixedString(length)
|
|
287
|
+
return readFixedString(length);
|
|
299
288
|
} else {
|
|
300
|
-
let value
|
|
289
|
+
let value;
|
|
301
290
|
switch (token) {
|
|
302
|
-
case 0xc0: return null
|
|
291
|
+
case 0xc0: return null;
|
|
303
292
|
case 0xc1:
|
|
304
293
|
if (bundledStrings) {
|
|
305
|
-
value = read() // followed by the length of the string in characters (not bytes!)
|
|
294
|
+
value = read(); // followed by the length of the string in characters (not bytes!)
|
|
306
295
|
if (value > 0)
|
|
307
|
-
return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
|
|
296
|
+
return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value);
|
|
308
297
|
else
|
|
309
|
-
return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
|
|
298
|
+
return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value);
|
|
310
299
|
}
|
|
311
300
|
return C1; // "never-used", return special object to denote that
|
|
312
|
-
case 0xc2: return false
|
|
313
|
-
case 0xc3: return true
|
|
301
|
+
case 0xc2: return false;
|
|
302
|
+
case 0xc3: return true;
|
|
314
303
|
case 0xc4:
|
|
315
304
|
// bin 8
|
|
316
|
-
value = src[position++]
|
|
305
|
+
value = src[position++];
|
|
317
306
|
if (value === undefined)
|
|
318
|
-
throw new Error('Unexpected end of buffer')
|
|
319
|
-
return readBin(value)
|
|
307
|
+
throw new Error('Unexpected end of buffer');
|
|
308
|
+
return readBin(value);
|
|
320
309
|
case 0xc5:
|
|
321
310
|
// bin 16
|
|
322
|
-
value = dataView.getUint16(position)
|
|
323
|
-
position += 2
|
|
324
|
-
return readBin(value)
|
|
311
|
+
value = dataView.getUint16(position);
|
|
312
|
+
position += 2;
|
|
313
|
+
return readBin(value);
|
|
325
314
|
case 0xc6:
|
|
326
315
|
// bin 32
|
|
327
|
-
value = dataView.getUint32(position)
|
|
328
|
-
position += 4
|
|
329
|
-
return readBin(value)
|
|
316
|
+
value = dataView.getUint32(position);
|
|
317
|
+
position += 4;
|
|
318
|
+
return readBin(value);
|
|
330
319
|
case 0xc7:
|
|
331
320
|
// ext 8
|
|
332
|
-
return readExt(src[position++])
|
|
321
|
+
return readExt(src[position++]);
|
|
333
322
|
case 0xc8:
|
|
334
323
|
// ext 16
|
|
335
|
-
value = dataView.getUint16(position)
|
|
336
|
-
position += 2
|
|
337
|
-
return readExt(value)
|
|
324
|
+
value = dataView.getUint16(position);
|
|
325
|
+
position += 2;
|
|
326
|
+
return readExt(value);
|
|
338
327
|
case 0xc9:
|
|
339
328
|
// ext 32
|
|
340
|
-
value = dataView.getUint32(position)
|
|
341
|
-
position += 4
|
|
342
|
-
return readExt(value)
|
|
329
|
+
value = dataView.getUint32(position);
|
|
330
|
+
position += 4;
|
|
331
|
+
return readExt(value);
|
|
343
332
|
case 0xca:
|
|
344
|
-
value = dataView.getFloat32(position)
|
|
333
|
+
value = dataView.getFloat32(position);
|
|
345
334
|
if (currentUnpackr.useFloat32 > 2) {
|
|
346
335
|
// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
347
|
-
let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)]
|
|
348
|
-
position += 4
|
|
349
|
-
return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
336
|
+
let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
|
|
337
|
+
position += 4;
|
|
338
|
+
return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
|
|
350
339
|
}
|
|
351
|
-
position += 4
|
|
352
|
-
return value
|
|
340
|
+
position += 4;
|
|
341
|
+
return value;
|
|
353
342
|
case 0xcb:
|
|
354
|
-
value = dataView.getFloat64(position)
|
|
355
|
-
position += 8
|
|
356
|
-
return value
|
|
343
|
+
value = dataView.getFloat64(position);
|
|
344
|
+
position += 8;
|
|
345
|
+
return value;
|
|
357
346
|
// uint handlers
|
|
358
347
|
case 0xcc:
|
|
359
|
-
return src[position++]
|
|
348
|
+
return src[position++];
|
|
360
349
|
case 0xcd:
|
|
361
|
-
value = dataView.getUint16(position)
|
|
362
|
-
position += 2
|
|
363
|
-
return value
|
|
350
|
+
value = dataView.getUint16(position);
|
|
351
|
+
position += 2;
|
|
352
|
+
return value;
|
|
364
353
|
case 0xce:
|
|
365
|
-
value = dataView.getUint32(position)
|
|
366
|
-
position += 4
|
|
367
|
-
return value
|
|
354
|
+
value = dataView.getUint32(position);
|
|
355
|
+
position += 4;
|
|
356
|
+
return value;
|
|
368
357
|
case 0xcf:
|
|
369
358
|
if (currentUnpackr.int64AsType === 'number') {
|
|
370
|
-
value = dataView.getUint32(position) * 0x100000000
|
|
371
|
-
value += dataView.getUint32(position + 4)
|
|
359
|
+
value = dataView.getUint32(position) * 0x100000000;
|
|
360
|
+
value += dataView.getUint32(position + 4);
|
|
372
361
|
} else if (currentUnpackr.int64AsType === 'string') {
|
|
373
|
-
value = dataView.getBigUint64(position).toString()
|
|
362
|
+
value = dataView.getBigUint64(position).toString();
|
|
374
363
|
} else if (currentUnpackr.int64AsType === 'auto') {
|
|
375
|
-
value = dataView.getBigUint64(position)
|
|
376
|
-
if (value<=BigInt(2)<<BigInt(52)) value=Number(value)
|
|
364
|
+
value = dataView.getBigUint64(position);
|
|
365
|
+
if (value<=BigInt(2)<<BigInt(52)) value=Number(value);
|
|
377
366
|
} else
|
|
378
|
-
value = dataView.getBigUint64(position)
|
|
379
|
-
position += 8
|
|
380
|
-
return value
|
|
367
|
+
value = dataView.getBigUint64(position);
|
|
368
|
+
position += 8;
|
|
369
|
+
return value;
|
|
381
370
|
|
|
382
371
|
// int handlers
|
|
383
372
|
case 0xd0:
|
|
384
|
-
return dataView.getInt8(position++)
|
|
373
|
+
return dataView.getInt8(position++);
|
|
385
374
|
case 0xd1:
|
|
386
|
-
value = dataView.getInt16(position)
|
|
387
|
-
position += 2
|
|
388
|
-
return value
|
|
375
|
+
value = dataView.getInt16(position);
|
|
376
|
+
position += 2;
|
|
377
|
+
return value;
|
|
389
378
|
case 0xd2:
|
|
390
|
-
value = dataView.getInt32(position)
|
|
391
|
-
position += 4
|
|
392
|
-
return value
|
|
379
|
+
value = dataView.getInt32(position);
|
|
380
|
+
position += 4;
|
|
381
|
+
return value;
|
|
393
382
|
case 0xd3:
|
|
394
383
|
if (currentUnpackr.int64AsType === 'number') {
|
|
395
|
-
value = dataView.getInt32(position) * 0x100000000
|
|
396
|
-
value += dataView.getUint32(position + 4)
|
|
384
|
+
value = dataView.getInt32(position) * 0x100000000;
|
|
385
|
+
value += dataView.getUint32(position + 4);
|
|
397
386
|
} else if (currentUnpackr.int64AsType === 'string') {
|
|
398
|
-
value = dataView.getBigInt64(position).toString()
|
|
387
|
+
value = dataView.getBigInt64(position).toString();
|
|
399
388
|
} else if (currentUnpackr.int64AsType === 'auto') {
|
|
400
|
-
value = dataView.getBigInt64(position)
|
|
401
|
-
if (value>=BigInt(-2)<<BigInt(52)&&value<=BigInt(2)<<BigInt(52)) value=Number(value)
|
|
389
|
+
value = dataView.getBigInt64(position);
|
|
390
|
+
if (value>=BigInt(-2)<<BigInt(52)&&value<=BigInt(2)<<BigInt(52)) value=Number(value);
|
|
402
391
|
} else
|
|
403
|
-
value = dataView.getBigInt64(position)
|
|
404
|
-
position += 8
|
|
405
|
-
return value
|
|
392
|
+
value = dataView.getBigInt64(position);
|
|
393
|
+
position += 8;
|
|
394
|
+
return value;
|
|
406
395
|
|
|
407
396
|
case 0xd4:
|
|
408
397
|
// fixext 1
|
|
409
|
-
value = src[position++]
|
|
398
|
+
value = src[position++];
|
|
410
399
|
if (value == 0x72) {
|
|
411
|
-
return recordDefinition(src[position++] & 0x3f)
|
|
400
|
+
return recordDefinition(src[position++] & 0x3f);
|
|
412
401
|
} else {
|
|
413
|
-
let extension = currentExtensions[value]
|
|
402
|
+
let extension = currentExtensions[value];
|
|
414
403
|
if (extension) {
|
|
415
404
|
if (extension.read) {
|
|
416
|
-
position
|
|
417
|
-
return extension.read(read())
|
|
405
|
+
position++; // skip filler byte
|
|
406
|
+
return extension.read(read());
|
|
418
407
|
} else if (extension.noBuffer) {
|
|
419
|
-
position
|
|
420
|
-
return extension()
|
|
408
|
+
position++; // skip filler byte
|
|
409
|
+
return extension();
|
|
421
410
|
} else
|
|
422
|
-
return extension(src.subarray(position, ++position))
|
|
411
|
+
return extension(src.subarray(position, ++position));
|
|
423
412
|
} else
|
|
424
|
-
throw new Error('Unknown extension ' + value)
|
|
413
|
+
throw new Error('Unknown extension ' + value);
|
|
425
414
|
}
|
|
426
415
|
case 0xd5:
|
|
427
416
|
// fixext 2
|
|
428
|
-
value = src[position]
|
|
417
|
+
value = src[position];
|
|
429
418
|
if (value == 0x72) {
|
|
430
|
-
position
|
|
431
|
-
return recordDefinition(src[position++] & 0x3f, src[position++])
|
|
419
|
+
position++;
|
|
420
|
+
return recordDefinition(src[position++] & 0x3f, src[position++]);
|
|
432
421
|
} else
|
|
433
|
-
return readExt(2)
|
|
422
|
+
return readExt(2);
|
|
434
423
|
case 0xd6:
|
|
435
424
|
// fixext 4
|
|
436
|
-
return readExt(4)
|
|
425
|
+
return readExt(4);
|
|
437
426
|
case 0xd7:
|
|
438
427
|
// fixext 8
|
|
439
|
-
return readExt(8)
|
|
428
|
+
return readExt(8);
|
|
440
429
|
case 0xd8:
|
|
441
430
|
// fixext 16
|
|
442
|
-
return readExt(16)
|
|
431
|
+
return readExt(16);
|
|
443
432
|
case 0xd9:
|
|
444
433
|
// str 8
|
|
445
|
-
value = src[position++]
|
|
434
|
+
value = src[position++];
|
|
446
435
|
if (srcStringEnd >= position) {
|
|
447
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
436
|
+
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
|
|
448
437
|
}
|
|
449
|
-
return readString8(value)
|
|
438
|
+
return readString8(value);
|
|
450
439
|
case 0xda:
|
|
451
440
|
// str 16
|
|
452
|
-
value = dataView.getUint16(position)
|
|
453
|
-
position += 2
|
|
441
|
+
value = dataView.getUint16(position);
|
|
442
|
+
position += 2;
|
|
454
443
|
if (srcStringEnd >= position) {
|
|
455
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
444
|
+
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
|
|
456
445
|
}
|
|
457
|
-
return readString16(value)
|
|
446
|
+
return readString16(value);
|
|
458
447
|
case 0xdb:
|
|
459
448
|
// str 32
|
|
460
|
-
value = dataView.getUint32(position)
|
|
461
|
-
position += 4
|
|
449
|
+
value = dataView.getUint32(position);
|
|
450
|
+
position += 4;
|
|
462
451
|
if (srcStringEnd >= position) {
|
|
463
|
-
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
|
|
452
|
+
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
|
|
464
453
|
}
|
|
465
|
-
return readString32(value)
|
|
454
|
+
return readString32(value);
|
|
466
455
|
case 0xdc:
|
|
467
456
|
// array 16
|
|
468
|
-
value = dataView.getUint16(position)
|
|
469
|
-
position += 2
|
|
470
|
-
return readArray(value)
|
|
457
|
+
value = dataView.getUint16(position);
|
|
458
|
+
position += 2;
|
|
459
|
+
return readArray(value);
|
|
471
460
|
case 0xdd:
|
|
472
461
|
// array 32
|
|
473
|
-
value = dataView.getUint32(position)
|
|
474
|
-
position += 4
|
|
475
|
-
return readArray(value)
|
|
462
|
+
value = dataView.getUint32(position);
|
|
463
|
+
position += 4;
|
|
464
|
+
return readArray(value);
|
|
476
465
|
case 0xde:
|
|
477
466
|
// map 16
|
|
478
|
-
value = dataView.getUint16(position)
|
|
479
|
-
position += 2
|
|
480
|
-
return readMap(value)
|
|
467
|
+
value = dataView.getUint16(position);
|
|
468
|
+
position += 2;
|
|
469
|
+
return readMap(value);
|
|
481
470
|
case 0xdf:
|
|
482
471
|
// map 32
|
|
483
|
-
value = dataView.getUint32(position)
|
|
484
|
-
position += 4
|
|
485
|
-
return readMap(value)
|
|
472
|
+
value = dataView.getUint32(position);
|
|
473
|
+
position += 4;
|
|
474
|
+
return readMap(value);
|
|
486
475
|
default: // negative int
|
|
487
476
|
if (token >= 0xe0)
|
|
488
|
-
return token - 0x100
|
|
477
|
+
return token - 0x100;
|
|
489
478
|
if (token === undefined) {
|
|
490
|
-
let error = new Error('Unexpected end of MessagePack data')
|
|
491
|
-
error.incomplete = true
|
|
492
|
-
throw error
|
|
479
|
+
let error = new Error('Unexpected end of MessagePack data');
|
|
480
|
+
error.incomplete = true;
|
|
481
|
+
throw error;
|
|
493
482
|
}
|
|
494
|
-
throw new Error('Unknown MessagePack token ' + token)
|
|
483
|
+
throw new Error('Unknown MessagePack token ' + token);
|
|
495
484
|
|
|
496
485
|
}
|
|
497
486
|
}
|
|
498
487
|
}
|
|
499
|
-
const validName = /^[a-zA-Z_$][a-zA-Z\d_$]
|
|
488
|
+
const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
|
|
500
489
|
function createStructureReader(structure, firstId) {
|
|
501
490
|
function readObject() {
|
|
502
491
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
503
492
|
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
504
|
-
let optimizedReadObject
|
|
493
|
+
let optimizedReadObject;
|
|
505
494
|
try {
|
|
506
495
|
optimizedReadObject = structure.read = (new Function('r', 'return function(){return ' + (currentUnpackr.freezeData ? 'Object.freeze' : '') +
|
|
507
|
-
'({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read)
|
|
496
|
+
'({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
|
|
508
497
|
} catch(error) {
|
|
509
498
|
// in CF workers, the new Function call could begin to fail at any point in time
|
|
510
|
-
inlineObjectReadThreshold = Infinity // disable going forward
|
|
499
|
+
inlineObjectReadThreshold = Infinity; // disable going forward
|
|
511
500
|
return readObject(); // recursively try again
|
|
512
501
|
}
|
|
513
502
|
if (structure.highByte === 0)
|
|
514
|
-
structure.read = createSecondByteReader(firstId, structure.read)
|
|
515
|
-
return optimizedReadObject() // second byte is already read, if there is one so immediately read object
|
|
503
|
+
structure.read = createSecondByteReader(firstId, structure.read);
|
|
504
|
+
return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
|
|
516
505
|
}
|
|
517
|
-
let object = {}
|
|
506
|
+
let object = {};
|
|
518
507
|
for (let i = 0, l = structure.length; i < l; i++) {
|
|
519
|
-
let key = structure[i]
|
|
508
|
+
let key = structure[i];
|
|
520
509
|
if (key === '__proto__')
|
|
521
|
-
key = '__proto_'
|
|
522
|
-
object[key] = read()
|
|
510
|
+
key = '__proto_';
|
|
511
|
+
object[key] = read();
|
|
523
512
|
}
|
|
524
513
|
if (currentUnpackr.freezeData)
|
|
525
514
|
return Object.freeze(object);
|
|
526
|
-
return object
|
|
515
|
+
return object;
|
|
527
516
|
}
|
|
528
|
-
readObject.count = 0
|
|
517
|
+
readObject.count = 0;
|
|
529
518
|
if (structure.highByte === 0) {
|
|
530
|
-
return createSecondByteReader(firstId, readObject)
|
|
519
|
+
return createSecondByteReader(firstId, readObject);
|
|
531
520
|
}
|
|
532
|
-
return readObject
|
|
521
|
+
return readObject;
|
|
533
522
|
}
|
|
534
523
|
|
|
535
524
|
const createSecondByteReader = (firstId, read0) => {
|
|
536
525
|
return function() {
|
|
537
|
-
let highByte = src[position++]
|
|
526
|
+
let highByte = src[position++];
|
|
538
527
|
if (highByte === 0)
|
|
539
|
-
return read0()
|
|
540
|
-
let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5)
|
|
541
|
-
let structure = currentStructures[id] || loadStructures()[id]
|
|
528
|
+
return read0();
|
|
529
|
+
let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
|
|
530
|
+
let structure = currentStructures[id] || loadStructures()[id];
|
|
542
531
|
if (!structure) {
|
|
543
|
-
throw new Error('Record id is not defined for ' + id)
|
|
532
|
+
throw new Error('Record id is not defined for ' + id);
|
|
544
533
|
}
|
|
545
534
|
if (!structure.read)
|
|
546
|
-
structure.read = createStructureReader(structure, firstId)
|
|
547
|
-
return structure.read()
|
|
548
|
-
}
|
|
549
|
-
}
|
|
535
|
+
structure.read = createStructureReader(structure, firstId);
|
|
536
|
+
return structure.read();
|
|
537
|
+
};
|
|
538
|
+
};
|
|
550
539
|
|
|
551
540
|
export function loadStructures() {
|
|
552
541
|
let loadedStructures = saveState(() => {
|
|
553
542
|
// save the state in case getStructures modifies our buffer
|
|
554
|
-
src = null
|
|
555
|
-
return currentUnpackr.getStructures()
|
|
556
|
-
})
|
|
557
|
-
return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
|
|
543
|
+
src = null;
|
|
544
|
+
return currentUnpackr.getStructures();
|
|
545
|
+
});
|
|
546
|
+
return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
|
|
558
547
|
}
|
|
559
548
|
|
|
560
|
-
var readFixedString = readStringJS
|
|
561
|
-
var readString8 = readStringJS
|
|
562
|
-
var readString16 = readStringJS
|
|
563
|
-
var readString32 = readStringJS
|
|
564
|
-
export let isNativeAccelerationEnabled = false
|
|
549
|
+
var readFixedString = readStringJS;
|
|
550
|
+
var readString8 = readStringJS;
|
|
551
|
+
var readString16 = readStringJS;
|
|
552
|
+
var readString32 = readStringJS;
|
|
553
|
+
export let isNativeAccelerationEnabled = false;
|
|
565
554
|
|
|
566
555
|
export function setExtractor(extractStrings) {
|
|
567
|
-
isNativeAccelerationEnabled = true
|
|
568
|
-
readFixedString = readString(1)
|
|
569
|
-
readString8 = readString(2)
|
|
570
|
-
readString16 = readString(3)
|
|
571
|
-
readString32 = readString(5)
|
|
556
|
+
isNativeAccelerationEnabled = true;
|
|
557
|
+
readFixedString = readString(1);
|
|
558
|
+
readString8 = readString(2);
|
|
559
|
+
readString16 = readString(3);
|
|
560
|
+
readString32 = readString(5);
|
|
572
561
|
function readString(headerLength) {
|
|
573
562
|
return function readString(length) {
|
|
574
|
-
let string = strings[stringPosition++]
|
|
563
|
+
let string = strings[stringPosition++];
|
|
575
564
|
if (string == null) {
|
|
576
565
|
if (bundledStrings)
|
|
577
|
-
return readStringJS(length)
|
|
578
|
-
let byteOffset = src.byteOffset
|
|
579
|
-
let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer)
|
|
566
|
+
return readStringJS(length);
|
|
567
|
+
let byteOffset = src.byteOffset;
|
|
568
|
+
let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
|
|
580
569
|
if (typeof extraction == 'string') {
|
|
581
|
-
string = extraction
|
|
582
|
-
strings = EMPTY_ARRAY
|
|
570
|
+
string = extraction;
|
|
571
|
+
strings = EMPTY_ARRAY;
|
|
583
572
|
} else {
|
|
584
|
-
strings = extraction
|
|
585
|
-
stringPosition = 1
|
|
586
|
-
srcStringEnd = 1 // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
|
|
587
|
-
string = strings[0]
|
|
573
|
+
strings = extraction;
|
|
574
|
+
stringPosition = 1;
|
|
575
|
+
srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
|
|
576
|
+
string = strings[0];
|
|
588
577
|
if (string === undefined)
|
|
589
|
-
throw new Error('Unexpected end of buffer')
|
|
578
|
+
throw new Error('Unexpected end of buffer');
|
|
590
579
|
}
|
|
591
580
|
}
|
|
592
|
-
let srcStringLength = string.length
|
|
581
|
+
let srcStringLength = string.length;
|
|
593
582
|
if (srcStringLength <= length) {
|
|
594
|
-
position += length
|
|
595
|
-
return string
|
|
583
|
+
position += length;
|
|
584
|
+
return string;
|
|
596
585
|
}
|
|
597
|
-
srcString = string
|
|
598
|
-
srcStringStart = position
|
|
599
|
-
srcStringEnd = position + srcStringLength
|
|
600
|
-
position += length
|
|
601
|
-
return string.slice(0, length) // we know we just want the beginning
|
|
602
|
-
}
|
|
586
|
+
srcString = string;
|
|
587
|
+
srcStringStart = position;
|
|
588
|
+
srcStringEnd = position + srcStringLength;
|
|
589
|
+
position += length;
|
|
590
|
+
return string.slice(0, length); // we know we just want the beginning
|
|
591
|
+
};
|
|
603
592
|
}
|
|
604
593
|
}
|
|
605
594
|
function readStringJS(length) {
|
|
606
|
-
let result
|
|
595
|
+
let result;
|
|
607
596
|
if (length < 16) {
|
|
608
597
|
if (result = shortStringInJS(length))
|
|
609
|
-
return result
|
|
598
|
+
return result;
|
|
610
599
|
}
|
|
611
600
|
if (length > 64 && decoder)
|
|
612
|
-
return decoder.decode(src.subarray(position, position += length))
|
|
613
|
-
const end = position + length
|
|
614
|
-
const units = []
|
|
615
|
-
result = ''
|
|
601
|
+
return decoder.decode(src.subarray(position, position += length));
|
|
602
|
+
const end = position + length;
|
|
603
|
+
const units = [];
|
|
604
|
+
result = '';
|
|
616
605
|
while (position < end) {
|
|
617
|
-
const byte1 = src[position++]
|
|
606
|
+
const byte1 = src[position++];
|
|
618
607
|
if ((byte1 & 0x80) === 0) {
|
|
619
608
|
// 1 byte
|
|
620
|
-
units.push(byte1)
|
|
609
|
+
units.push(byte1);
|
|
621
610
|
} else if ((byte1 & 0xe0) === 0xc0) {
|
|
622
611
|
// 2 bytes
|
|
623
|
-
const byte2 = src[position++] & 0x3f
|
|
624
|
-
const codePoint = ((byte1 & 0x1f) << 6) | byte2
|
|
612
|
+
const byte2 = src[position++] & 0x3f;
|
|
613
|
+
const codePoint = ((byte1 & 0x1f) << 6) | byte2;
|
|
625
614
|
// Reject overlong encoding: 2-byte sequences must encode values >= 0x80
|
|
626
615
|
if (codePoint < 0x80) {
|
|
627
|
-
units.push(0xFFFD) // replacement character
|
|
616
|
+
units.push(0xFFFD); // replacement character
|
|
628
617
|
} else {
|
|
629
|
-
units.push(codePoint)
|
|
618
|
+
units.push(codePoint);
|
|
630
619
|
}
|
|
631
620
|
} else if ((byte1 & 0xf0) === 0xe0) {
|
|
632
621
|
// 3 bytes
|
|
633
|
-
const byte2 = src[position++] & 0x3f
|
|
634
|
-
const byte3 = src[position++] & 0x3f
|
|
635
|
-
const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3
|
|
622
|
+
const byte2 = src[position++] & 0x3f;
|
|
623
|
+
const byte3 = src[position++] & 0x3f;
|
|
624
|
+
const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3;
|
|
636
625
|
// Reject overlong encoding: 3-byte sequences must encode values >= 0x800
|
|
637
626
|
// Also reject surrogates (0xD800-0xDFFF)
|
|
638
627
|
if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
|
|
639
|
-
units.push(0xFFFD) // replacement character
|
|
628
|
+
units.push(0xFFFD); // replacement character
|
|
640
629
|
} else {
|
|
641
|
-
units.push(codePoint)
|
|
630
|
+
units.push(codePoint);
|
|
642
631
|
}
|
|
643
632
|
} else if ((byte1 & 0xf8) === 0xf0) {
|
|
644
633
|
// 4 bytes
|
|
645
|
-
const byte2 = src[position++] & 0x3f
|
|
646
|
-
const byte3 = src[position++] & 0x3f
|
|
647
|
-
const byte4 = src[position++] & 0x3f
|
|
648
|
-
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4
|
|
634
|
+
const byte2 = src[position++] & 0x3f;
|
|
635
|
+
const byte3 = src[position++] & 0x3f;
|
|
636
|
+
const byte4 = src[position++] & 0x3f;
|
|
637
|
+
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
|
|
649
638
|
// Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
|
|
650
639
|
// Also reject values > 0x10FFFF (maximum valid Unicode)
|
|
651
640
|
if (unit < 0x10000 || unit > 0x10FFFF) {
|
|
652
|
-
units.push(0xFFFD) // replacement character
|
|
641
|
+
units.push(0xFFFD); // replacement character
|
|
653
642
|
} else if (unit > 0xffff) {
|
|
654
|
-
unit -= 0x10000
|
|
655
|
-
units.push(((unit >>> 10) & 0x3ff) | 0xd800)
|
|
656
|
-
unit = 0xdc00 | (unit & 0x3ff)
|
|
657
|
-
units.push(unit)
|
|
643
|
+
unit -= 0x10000;
|
|
644
|
+
units.push(((unit >>> 10) & 0x3ff) | 0xd800);
|
|
645
|
+
unit = 0xdc00 | (unit & 0x3ff);
|
|
646
|
+
units.push(unit);
|
|
658
647
|
} else {
|
|
659
|
-
units.push(unit)
|
|
648
|
+
units.push(unit);
|
|
660
649
|
}
|
|
661
650
|
} else {
|
|
662
|
-
units.push(0xFFFD) // replacement character for invalid lead byte
|
|
651
|
+
units.push(0xFFFD); // replacement character for invalid lead byte
|
|
663
652
|
}
|
|
664
653
|
|
|
665
654
|
if (units.length >= 0x1000) {
|
|
666
|
-
result += fromCharCode.apply(String, units)
|
|
667
|
-
units.length = 0
|
|
655
|
+
result += fromCharCode.apply(String, units);
|
|
656
|
+
units.length = 0;
|
|
668
657
|
}
|
|
669
658
|
}
|
|
670
659
|
|
|
671
660
|
if (units.length > 0) {
|
|
672
|
-
result += fromCharCode.apply(String, units)
|
|
661
|
+
result += fromCharCode.apply(String, units);
|
|
673
662
|
}
|
|
674
663
|
|
|
675
|
-
return result
|
|
664
|
+
return result;
|
|
676
665
|
}
|
|
677
666
|
export function readString(source, start, length) {
|
|
678
667
|
let existingSrc = src;
|
|
@@ -686,182 +675,182 @@ export function readString(source, start, length) {
|
|
|
686
675
|
}
|
|
687
676
|
|
|
688
677
|
function readArray(length) {
|
|
689
|
-
let array = new Array(length)
|
|
678
|
+
let array = new Array(length);
|
|
690
679
|
for (let i = 0; i < length; i++) {
|
|
691
|
-
array[i] = read()
|
|
680
|
+
array[i] = read();
|
|
692
681
|
}
|
|
693
682
|
if (currentUnpackr.freezeData)
|
|
694
|
-
return Object.freeze(array)
|
|
695
|
-
return array
|
|
683
|
+
return Object.freeze(array);
|
|
684
|
+
return array;
|
|
696
685
|
}
|
|
697
686
|
|
|
698
687
|
function readMap(length) {
|
|
699
688
|
if (currentUnpackr.mapsAsObjects) {
|
|
700
|
-
let object = {}
|
|
689
|
+
let object = {};
|
|
701
690
|
for (let i = 0; i < length; i++) {
|
|
702
|
-
let key = readKey()
|
|
691
|
+
let key = readKey();
|
|
703
692
|
if (key === '__proto__')
|
|
704
693
|
key = '__proto_';
|
|
705
|
-
object[key] = read()
|
|
694
|
+
object[key] = read();
|
|
706
695
|
}
|
|
707
|
-
return object
|
|
696
|
+
return object;
|
|
708
697
|
} else {
|
|
709
|
-
let map = new Map()
|
|
698
|
+
let map = new Map();
|
|
710
699
|
for (let i = 0; i < length; i++) {
|
|
711
|
-
map.set(read(), read())
|
|
700
|
+
map.set(read(), read());
|
|
712
701
|
}
|
|
713
|
-
return map
|
|
702
|
+
return map;
|
|
714
703
|
}
|
|
715
704
|
}
|
|
716
705
|
|
|
717
|
-
var fromCharCode = String.fromCharCode
|
|
706
|
+
var fromCharCode = String.fromCharCode;
|
|
718
707
|
function longStringInJS(length) {
|
|
719
|
-
let start = position
|
|
720
|
-
let bytes = new Array(length)
|
|
708
|
+
let start = position;
|
|
709
|
+
let bytes = new Array(length);
|
|
721
710
|
for (let i = 0; i < length; i++) {
|
|
722
711
|
const byte = src[position++];
|
|
723
712
|
if ((byte & 0x80) > 0) {
|
|
724
|
-
position = start
|
|
725
|
-
return
|
|
713
|
+
position = start;
|
|
714
|
+
return;
|
|
726
715
|
}
|
|
727
|
-
bytes[i] = byte
|
|
716
|
+
bytes[i] = byte;
|
|
728
717
|
}
|
|
729
|
-
return fromCharCode.apply(String, bytes)
|
|
718
|
+
return fromCharCode.apply(String, bytes);
|
|
730
719
|
}
|
|
731
720
|
function shortStringInJS(length) {
|
|
732
721
|
if (length < 4) {
|
|
733
722
|
if (length < 2) {
|
|
734
723
|
if (length === 0)
|
|
735
|
-
return ''
|
|
724
|
+
return '';
|
|
736
725
|
else {
|
|
737
|
-
let a = src[position++]
|
|
726
|
+
let a = src[position++];
|
|
738
727
|
if ((a & 0x80) > 1) {
|
|
739
|
-
position -= 1
|
|
740
|
-
return
|
|
728
|
+
position -= 1;
|
|
729
|
+
return;
|
|
741
730
|
}
|
|
742
|
-
return fromCharCode(a)
|
|
731
|
+
return fromCharCode(a);
|
|
743
732
|
}
|
|
744
733
|
} else {
|
|
745
|
-
let a = src[position++]
|
|
746
|
-
let b = src[position++]
|
|
734
|
+
let a = src[position++];
|
|
735
|
+
let b = src[position++];
|
|
747
736
|
if ((a & 0x80) > 0 || (b & 0x80) > 0) {
|
|
748
|
-
position -= 2
|
|
749
|
-
return
|
|
737
|
+
position -= 2;
|
|
738
|
+
return;
|
|
750
739
|
}
|
|
751
740
|
if (length < 3)
|
|
752
|
-
return fromCharCode(a, b)
|
|
753
|
-
let c = src[position++]
|
|
741
|
+
return fromCharCode(a, b);
|
|
742
|
+
let c = src[position++];
|
|
754
743
|
if ((c & 0x80) > 0) {
|
|
755
|
-
position -= 3
|
|
756
|
-
return
|
|
744
|
+
position -= 3;
|
|
745
|
+
return;
|
|
757
746
|
}
|
|
758
|
-
return fromCharCode(a, b, c)
|
|
747
|
+
return fromCharCode(a, b, c);
|
|
759
748
|
}
|
|
760
749
|
} else {
|
|
761
|
-
let a = src[position++]
|
|
762
|
-
let b = src[position++]
|
|
763
|
-
let c = src[position++]
|
|
764
|
-
let d = src[position++]
|
|
750
|
+
let a = src[position++];
|
|
751
|
+
let b = src[position++];
|
|
752
|
+
let c = src[position++];
|
|
753
|
+
let d = src[position++];
|
|
765
754
|
if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
|
|
766
|
-
position -= 4
|
|
767
|
-
return
|
|
755
|
+
position -= 4;
|
|
756
|
+
return;
|
|
768
757
|
}
|
|
769
758
|
if (length < 6) {
|
|
770
759
|
if (length === 4)
|
|
771
|
-
return fromCharCode(a, b, c, d)
|
|
760
|
+
return fromCharCode(a, b, c, d);
|
|
772
761
|
else {
|
|
773
|
-
let e = src[position++]
|
|
762
|
+
let e = src[position++];
|
|
774
763
|
if ((e & 0x80) > 0) {
|
|
775
|
-
position -= 5
|
|
776
|
-
return
|
|
764
|
+
position -= 5;
|
|
765
|
+
return;
|
|
777
766
|
}
|
|
778
|
-
return fromCharCode(a, b, c, d, e)
|
|
767
|
+
return fromCharCode(a, b, c, d, e);
|
|
779
768
|
}
|
|
780
769
|
} else if (length < 8) {
|
|
781
|
-
let e = src[position++]
|
|
782
|
-
let f = src[position++]
|
|
770
|
+
let e = src[position++];
|
|
771
|
+
let f = src[position++];
|
|
783
772
|
if ((e & 0x80) > 0 || (f & 0x80) > 0) {
|
|
784
|
-
position -= 6
|
|
785
|
-
return
|
|
773
|
+
position -= 6;
|
|
774
|
+
return;
|
|
786
775
|
}
|
|
787
776
|
if (length < 7)
|
|
788
|
-
return fromCharCode(a, b, c, d, e, f)
|
|
789
|
-
let g = src[position++]
|
|
777
|
+
return fromCharCode(a, b, c, d, e, f);
|
|
778
|
+
let g = src[position++];
|
|
790
779
|
if ((g & 0x80) > 0) {
|
|
791
|
-
position -= 7
|
|
792
|
-
return
|
|
780
|
+
position -= 7;
|
|
781
|
+
return;
|
|
793
782
|
}
|
|
794
|
-
return fromCharCode(a, b, c, d, e, f, g)
|
|
783
|
+
return fromCharCode(a, b, c, d, e, f, g);
|
|
795
784
|
} else {
|
|
796
|
-
let e = src[position++]
|
|
797
|
-
let f = src[position++]
|
|
798
|
-
let g = src[position++]
|
|
799
|
-
let h = src[position++]
|
|
785
|
+
let e = src[position++];
|
|
786
|
+
let f = src[position++];
|
|
787
|
+
let g = src[position++];
|
|
788
|
+
let h = src[position++];
|
|
800
789
|
if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
|
|
801
|
-
position -= 8
|
|
802
|
-
return
|
|
790
|
+
position -= 8;
|
|
791
|
+
return;
|
|
803
792
|
}
|
|
804
793
|
if (length < 10) {
|
|
805
794
|
if (length === 8)
|
|
806
|
-
return fromCharCode(a, b, c, d, e, f, g, h)
|
|
795
|
+
return fromCharCode(a, b, c, d, e, f, g, h);
|
|
807
796
|
else {
|
|
808
|
-
let i = src[position++]
|
|
797
|
+
let i = src[position++];
|
|
809
798
|
if ((i & 0x80) > 0) {
|
|
810
|
-
position -= 9
|
|
811
|
-
return
|
|
799
|
+
position -= 9;
|
|
800
|
+
return;
|
|
812
801
|
}
|
|
813
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i)
|
|
802
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i);
|
|
814
803
|
}
|
|
815
804
|
} else if (length < 12) {
|
|
816
|
-
let i = src[position++]
|
|
817
|
-
let j = src[position++]
|
|
805
|
+
let i = src[position++];
|
|
806
|
+
let j = src[position++];
|
|
818
807
|
if ((i & 0x80) > 0 || (j & 0x80) > 0) {
|
|
819
|
-
position -= 10
|
|
820
|
-
return
|
|
808
|
+
position -= 10;
|
|
809
|
+
return;
|
|
821
810
|
}
|
|
822
811
|
if (length < 11)
|
|
823
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j)
|
|
824
|
-
let k = src[position++]
|
|
812
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j);
|
|
813
|
+
let k = src[position++];
|
|
825
814
|
if ((k & 0x80) > 0) {
|
|
826
|
-
position -= 11
|
|
827
|
-
return
|
|
815
|
+
position -= 11;
|
|
816
|
+
return;
|
|
828
817
|
}
|
|
829
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
|
|
818
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
|
|
830
819
|
} else {
|
|
831
|
-
let i = src[position++]
|
|
832
|
-
let j = src[position++]
|
|
833
|
-
let k = src[position++]
|
|
834
|
-
let l = src[position++]
|
|
820
|
+
let i = src[position++];
|
|
821
|
+
let j = src[position++];
|
|
822
|
+
let k = src[position++];
|
|
823
|
+
let l = src[position++];
|
|
835
824
|
if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
|
|
836
|
-
position -= 12
|
|
837
|
-
return
|
|
825
|
+
position -= 12;
|
|
826
|
+
return;
|
|
838
827
|
}
|
|
839
828
|
if (length < 14) {
|
|
840
829
|
if (length === 12)
|
|
841
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
|
|
830
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
|
|
842
831
|
else {
|
|
843
|
-
let m = src[position++]
|
|
832
|
+
let m = src[position++];
|
|
844
833
|
if ((m & 0x80) > 0) {
|
|
845
|
-
position -= 13
|
|
846
|
-
return
|
|
834
|
+
position -= 13;
|
|
835
|
+
return;
|
|
847
836
|
}
|
|
848
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
|
|
837
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
|
|
849
838
|
}
|
|
850
839
|
} else {
|
|
851
|
-
let m = src[position++]
|
|
852
|
-
let n = src[position++]
|
|
840
|
+
let m = src[position++];
|
|
841
|
+
let n = src[position++];
|
|
853
842
|
if ((m & 0x80) > 0 || (n & 0x80) > 0) {
|
|
854
|
-
position -= 14
|
|
855
|
-
return
|
|
843
|
+
position -= 14;
|
|
844
|
+
return;
|
|
856
845
|
}
|
|
857
846
|
if (length < 15)
|
|
858
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
|
|
859
|
-
let o = src[position++]
|
|
847
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
|
|
848
|
+
let o = src[position++];
|
|
860
849
|
if ((o & 0x80) > 0) {
|
|
861
|
-
position -= 15
|
|
862
|
-
return
|
|
850
|
+
position -= 15;
|
|
851
|
+
return;
|
|
863
852
|
}
|
|
864
|
-
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
|
|
853
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
|
|
865
854
|
}
|
|
866
855
|
}
|
|
867
856
|
}
|
|
@@ -869,32 +858,32 @@ function shortStringInJS(length) {
|
|
|
869
858
|
}
|
|
870
859
|
|
|
871
860
|
function readOnlyJSString() {
|
|
872
|
-
let token = src[position++]
|
|
873
|
-
let length
|
|
861
|
+
let token = src[position++];
|
|
862
|
+
let length;
|
|
874
863
|
if (token < 0xc0) {
|
|
875
864
|
// fixstr
|
|
876
|
-
length = token - 0xa0
|
|
865
|
+
length = token - 0xa0;
|
|
877
866
|
} else {
|
|
878
867
|
switch(token) {
|
|
879
868
|
case 0xd9:
|
|
880
869
|
// str 8
|
|
881
|
-
length = src[position++]
|
|
882
|
-
break
|
|
870
|
+
length = src[position++];
|
|
871
|
+
break;
|
|
883
872
|
case 0xda:
|
|
884
873
|
// str 16
|
|
885
|
-
length = dataView.getUint16(position)
|
|
886
|
-
position += 2
|
|
887
|
-
break
|
|
874
|
+
length = dataView.getUint16(position);
|
|
875
|
+
position += 2;
|
|
876
|
+
break;
|
|
888
877
|
case 0xdb:
|
|
889
878
|
// str 32
|
|
890
|
-
length = dataView.getUint32(position)
|
|
891
|
-
position += 4
|
|
892
|
-
break
|
|
879
|
+
length = dataView.getUint32(position);
|
|
880
|
+
position += 4;
|
|
881
|
+
break;
|
|
893
882
|
default:
|
|
894
|
-
throw new Error('Expected string')
|
|
883
|
+
throw new Error('Expected string');
|
|
895
884
|
}
|
|
896
885
|
}
|
|
897
|
-
return readStringJS(length)
|
|
886
|
+
return readStringJS(length);
|
|
898
887
|
}
|
|
899
888
|
|
|
900
889
|
|
|
@@ -902,12 +891,12 @@ function readBin(length) {
|
|
|
902
891
|
return currentUnpackr.copyBuffers ?
|
|
903
892
|
// specifically use the copying slice (not the node one)
|
|
904
893
|
Uint8Array.prototype.slice.call(src, position, position += length) :
|
|
905
|
-
src.subarray(position, position += length)
|
|
894
|
+
src.subarray(position, position += length);
|
|
906
895
|
}
|
|
907
896
|
function readExt(length) {
|
|
908
|
-
let type = src[position++]
|
|
897
|
+
let type = src[position++];
|
|
909
898
|
if (currentExtensions[type]) {
|
|
910
|
-
let end
|
|
899
|
+
let end;
|
|
911
900
|
return currentExtensions[type](src.subarray(position, end = (position += length)), (readPosition) => {
|
|
912
901
|
position = readPosition;
|
|
913
902
|
try {
|
|
@@ -915,74 +904,74 @@ function readExt(length) {
|
|
|
915
904
|
} finally {
|
|
916
905
|
position = end;
|
|
917
906
|
}
|
|
918
|
-
})
|
|
907
|
+
});
|
|
919
908
|
}
|
|
920
909
|
else
|
|
921
|
-
throw new Error('Unknown extension type ' + type)
|
|
910
|
+
throw new Error('Unknown extension type ' + type);
|
|
922
911
|
}
|
|
923
912
|
|
|
924
|
-
var keyCache = new Array(4096)
|
|
913
|
+
var keyCache = new Array(4096);
|
|
925
914
|
function readKey() {
|
|
926
|
-
let length = src[position++]
|
|
915
|
+
let length = src[position++];
|
|
927
916
|
if (length >= 0xa0 && length < 0xc0) {
|
|
928
917
|
// fixstr, potentially use key cache
|
|
929
|
-
length = length - 0xa0
|
|
918
|
+
length = length - 0xa0;
|
|
930
919
|
if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
|
|
931
|
-
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
|
|
920
|
+
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
|
|
932
921
|
else if (!(srcStringEnd == 0 && srcEnd < 180))
|
|
933
|
-
return readFixedString(length)
|
|
922
|
+
return readFixedString(length);
|
|
934
923
|
} else { // not cacheable, go back and do a standard read
|
|
935
|
-
position
|
|
936
|
-
return asSafeString(read())
|
|
924
|
+
position--;
|
|
925
|
+
return asSafeString(read());
|
|
937
926
|
}
|
|
938
|
-
let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff
|
|
939
|
-
let entry = keyCache[key]
|
|
940
|
-
let checkPosition = position
|
|
941
|
-
let end = position + length - 3
|
|
942
|
-
let chunk
|
|
943
|
-
let i = 0
|
|
927
|
+
let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
|
|
928
|
+
let entry = keyCache[key];
|
|
929
|
+
let checkPosition = position;
|
|
930
|
+
let end = position + length - 3;
|
|
931
|
+
let chunk;
|
|
932
|
+
let i = 0;
|
|
944
933
|
if (entry && entry.bytes == length) {
|
|
945
934
|
while (checkPosition < end) {
|
|
946
|
-
chunk = dataView.getUint32(checkPosition)
|
|
935
|
+
chunk = dataView.getUint32(checkPosition);
|
|
947
936
|
if (chunk != entry[i++]) {
|
|
948
|
-
checkPosition = 0x70000000
|
|
949
|
-
break
|
|
937
|
+
checkPosition = 0x70000000;
|
|
938
|
+
break;
|
|
950
939
|
}
|
|
951
|
-
checkPosition += 4
|
|
940
|
+
checkPosition += 4;
|
|
952
941
|
}
|
|
953
|
-
end += 3
|
|
942
|
+
end += 3;
|
|
954
943
|
while (checkPosition < end) {
|
|
955
|
-
chunk = src[checkPosition++]
|
|
944
|
+
chunk = src[checkPosition++];
|
|
956
945
|
if (chunk != entry[i++]) {
|
|
957
|
-
checkPosition = 0x70000000
|
|
958
|
-
break
|
|
946
|
+
checkPosition = 0x70000000;
|
|
947
|
+
break;
|
|
959
948
|
}
|
|
960
949
|
}
|
|
961
950
|
if (checkPosition === end) {
|
|
962
|
-
position = checkPosition
|
|
963
|
-
return entry.string
|
|
951
|
+
position = checkPosition;
|
|
952
|
+
return entry.string;
|
|
964
953
|
}
|
|
965
|
-
end -= 3
|
|
966
|
-
checkPosition = position
|
|
954
|
+
end -= 3;
|
|
955
|
+
checkPosition = position;
|
|
967
956
|
}
|
|
968
|
-
entry = []
|
|
969
|
-
keyCache[key] = entry
|
|
970
|
-
entry.bytes = length
|
|
957
|
+
entry = [];
|
|
958
|
+
keyCache[key] = entry;
|
|
959
|
+
entry.bytes = length;
|
|
971
960
|
while (checkPosition < end) {
|
|
972
|
-
chunk = dataView.getUint32(checkPosition)
|
|
973
|
-
entry.push(chunk)
|
|
974
|
-
checkPosition += 4
|
|
961
|
+
chunk = dataView.getUint32(checkPosition);
|
|
962
|
+
entry.push(chunk);
|
|
963
|
+
checkPosition += 4;
|
|
975
964
|
}
|
|
976
|
-
end += 3
|
|
965
|
+
end += 3;
|
|
977
966
|
while (checkPosition < end) {
|
|
978
|
-
chunk = src[checkPosition++]
|
|
979
|
-
entry.push(chunk)
|
|
967
|
+
chunk = src[checkPosition++];
|
|
968
|
+
entry.push(chunk);
|
|
980
969
|
}
|
|
981
970
|
// for small blocks, avoiding the overhead of the extract call is helpful
|
|
982
|
-
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length)
|
|
971
|
+
let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
|
|
983
972
|
if (string != null)
|
|
984
|
-
return entry.string = string
|
|
985
|
-
return entry.string = readFixedString(length)
|
|
973
|
+
return entry.string = string;
|
|
974
|
+
return entry.string = readFixedString(length);
|
|
986
975
|
}
|
|
987
976
|
|
|
988
977
|
function asSafeString(property) {
|
|
@@ -997,244 +986,237 @@ function asSafeString(property) {
|
|
|
997
986
|
}
|
|
998
987
|
// the registration of the record definition extension (as "r")
|
|
999
988
|
const recordDefinition = (id, highByte) => {
|
|
1000
|
-
let structure = read().map(asSafeString) // ensure that all keys are strings and
|
|
989
|
+
let structure = read().map(asSafeString); // ensure that all keys are strings and
|
|
1001
990
|
// that the array is mutable
|
|
1002
|
-
let firstByte = id
|
|
991
|
+
let firstByte = id;
|
|
1003
992
|
if (highByte !== undefined) {
|
|
1004
|
-
id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id)
|
|
1005
|
-
structure.highByte = highByte
|
|
993
|
+
id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
|
|
994
|
+
structure.highByte = highByte;
|
|
1006
995
|
}
|
|
1007
|
-
let existingStructure = currentStructures[id]
|
|
996
|
+
let existingStructure = currentStructures[id];
|
|
1008
997
|
// If it is a shared structure, we need to restore any changes after reading.
|
|
1009
998
|
// Also in sequential mode, we may get incomplete reads and thus errors, and we need to restore
|
|
1010
999
|
// to the state prior to an incomplete read in order to properly resume.
|
|
1011
1000
|
if (existingStructure && (existingStructure.isShared || sequentialMode)) {
|
|
1012
|
-
(currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure
|
|
1001
|
+
(currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
|
|
1013
1002
|
}
|
|
1014
|
-
currentStructures[id] = structure
|
|
1015
|
-
structure.read = createStructureReader(structure, firstByte)
|
|
1016
|
-
return structure.read()
|
|
1017
|
-
}
|
|
1018
|
-
currentExtensions[0] = () => {} // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
1019
|
-
currentExtensions[0].noBuffer = true
|
|
1003
|
+
currentStructures[id] = structure;
|
|
1004
|
+
structure.read = createStructureReader(structure, firstByte);
|
|
1005
|
+
return structure.read();
|
|
1006
|
+
};
|
|
1007
|
+
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
1008
|
+
currentExtensions[0].noBuffer = true;
|
|
1020
1009
|
|
|
1021
1010
|
currentExtensions[0x42] = data => {
|
|
1022
|
-
let headLength = (data.byteLength % 8) || 8
|
|
1023
|
-
let head = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0])
|
|
1011
|
+
let headLength = (data.byteLength % 8) || 8;
|
|
1012
|
+
let head = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
1024
1013
|
for (let i = 1; i < headLength; i++) {
|
|
1025
|
-
head <<= BigInt(8)
|
|
1026
|
-
head += BigInt(data[i])
|
|
1014
|
+
head <<= BigInt(8);
|
|
1015
|
+
head += BigInt(data[i]);
|
|
1027
1016
|
}
|
|
1028
1017
|
if (data.byteLength !== headLength) {
|
|
1029
|
-
let view = new DataView(data.buffer, data.byteOffset, data.byteLength)
|
|
1018
|
+
let view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1030
1019
|
let decode = (start, end) => {
|
|
1031
|
-
let length = end - start
|
|
1020
|
+
let length = end - start;
|
|
1032
1021
|
if (length <= 40) {
|
|
1033
|
-
let out = view.getBigUint64(start)
|
|
1022
|
+
let out = view.getBigUint64(start);
|
|
1034
1023
|
for (let i = start + 8; i < end; i += 8) {
|
|
1035
|
-
out <<= BigInt(64)
|
|
1036
|
-
out |= view.getBigUint64(i)
|
|
1024
|
+
out <<= BigInt(64);
|
|
1025
|
+
out |= view.getBigUint64(i);
|
|
1037
1026
|
}
|
|
1038
|
-
return out
|
|
1027
|
+
return out;
|
|
1039
1028
|
}
|
|
1040
1029
|
// if (length === 8) return view.getBigUint64(start)
|
|
1041
|
-
let middle = start + (length >> 4 << 3)
|
|
1042
|
-
let left = decode(start, middle)
|
|
1043
|
-
let right = decode(middle, end)
|
|
1044
|
-
return (left << BigInt((end - middle) * 8)) | right
|
|
1045
|
-
}
|
|
1046
|
-
head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength)
|
|
1030
|
+
let middle = start + (length >> 4 << 3);
|
|
1031
|
+
let left = decode(start, middle);
|
|
1032
|
+
let right = decode(middle, end);
|
|
1033
|
+
return (left << BigInt((end - middle) * 8)) | right;
|
|
1034
|
+
};
|
|
1035
|
+
head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
|
|
1047
1036
|
}
|
|
1048
|
-
return head
|
|
1049
|
-
}
|
|
1037
|
+
return head;
|
|
1038
|
+
};
|
|
1050
1039
|
|
|
1051
1040
|
let errors = {
|
|
1052
1041
|
Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError: typeof AggregateError === 'function' ? AggregateError : null,
|
|
1053
|
-
}
|
|
1042
|
+
};
|
|
1054
1043
|
currentExtensions[0x65] = () => {
|
|
1055
|
-
let data = read()
|
|
1044
|
+
let data = read();
|
|
1056
1045
|
if (!errors[data[0]]) {
|
|
1057
|
-
let error = Error(data[1], { cause: data[2] })
|
|
1058
|
-
error.name = data[0]
|
|
1059
|
-
return error
|
|
1046
|
+
let error = Error(data[1], { cause: data[2] });
|
|
1047
|
+
error.name = data[0];
|
|
1048
|
+
return error;
|
|
1060
1049
|
}
|
|
1061
|
-
return errors[data[0]](data[1], { cause: data[2] })
|
|
1062
|
-
}
|
|
1050
|
+
return errors[data[0]](data[1], { cause: data[2] });
|
|
1051
|
+
};
|
|
1063
1052
|
|
|
1064
1053
|
currentExtensions[0x69] = (data) => {
|
|
1065
1054
|
// id extension (for structured clones)
|
|
1066
|
-
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
|
|
1067
|
-
let id = dataView.getUint32(position - 4)
|
|
1055
|
+
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
|
|
1056
|
+
let id = dataView.getUint32(position - 4);
|
|
1068
1057
|
if (!referenceMap)
|
|
1069
|
-
referenceMap = new Map()
|
|
1070
|
-
let token = src[position]
|
|
1071
|
-
let target
|
|
1058
|
+
referenceMap = new Map();
|
|
1059
|
+
let token = src[position];
|
|
1060
|
+
let target;
|
|
1072
1061
|
// TODO: handle any other types that can cycle and make the code more robust if there are other extensions
|
|
1073
1062
|
if (token >= 0x90 && token < 0xa0 || token == 0xdc || token == 0xdd)
|
|
1074
|
-
target = []
|
|
1063
|
+
target = [];
|
|
1075
1064
|
else if (token >= 0x80 && token < 0x90 || token == 0xde || token == 0xdf)
|
|
1076
|
-
target = new Map()
|
|
1065
|
+
target = new Map();
|
|
1077
1066
|
else if ((token >= 0xc7 && token <= 0xc9 || token >= 0xd4 && token <= 0xd8) && src[position + 1] === 0x73)
|
|
1078
|
-
target = new Set()
|
|
1067
|
+
target = new Set();
|
|
1079
1068
|
else
|
|
1080
|
-
target = {}
|
|
1069
|
+
target = {};
|
|
1081
1070
|
|
|
1082
|
-
let refEntry = { target } // a placeholder object
|
|
1083
|
-
referenceMap.set(id, refEntry)
|
|
1084
|
-
let targetProperties = read() // read the next value as the target object to id
|
|
1071
|
+
let refEntry = { target }; // a placeholder object
|
|
1072
|
+
referenceMap.set(id, refEntry);
|
|
1073
|
+
let targetProperties = read(); // read the next value as the target object to id
|
|
1085
1074
|
if (!refEntry.used) {
|
|
1086
1075
|
// no cycle, can just use the returned read object
|
|
1087
|
-
return refEntry.target = targetProperties // replace the placeholder with the real one
|
|
1076
|
+
return refEntry.target = targetProperties; // replace the placeholder with the real one
|
|
1088
1077
|
} else {
|
|
1089
1078
|
// there is a cycle, so we have to assign properties to original target
|
|
1090
|
-
Object.assign(target, targetProperties)
|
|
1079
|
+
Object.assign(target, targetProperties);
|
|
1091
1080
|
}
|
|
1092
1081
|
|
|
1093
1082
|
// copy over map/set entries if we're able to
|
|
1094
1083
|
if (target instanceof Map)
|
|
1095
|
-
for (let [k, v] of targetProperties.entries()) target.set(k, v)
|
|
1084
|
+
for (let [k, v] of targetProperties.entries()) target.set(k, v);
|
|
1096
1085
|
if (target instanceof Set)
|
|
1097
|
-
for (let i of Array.from(targetProperties)) target.add(i)
|
|
1098
|
-
return target
|
|
1099
|
-
}
|
|
1086
|
+
for (let i of Array.from(targetProperties)) target.add(i);
|
|
1087
|
+
return target;
|
|
1088
|
+
};
|
|
1100
1089
|
|
|
1101
1090
|
currentExtensions[0x70] = (data) => {
|
|
1102
1091
|
// pointer extension (for structured clones)
|
|
1103
|
-
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
|
|
1104
|
-
let id = dataView.getUint32(position - 4)
|
|
1105
|
-
let refEntry = referenceMap.get(id)
|
|
1106
|
-
refEntry.used = true
|
|
1107
|
-
return refEntry.target
|
|
1108
|
-
}
|
|
1092
|
+
if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
|
|
1093
|
+
let id = dataView.getUint32(position - 4);
|
|
1094
|
+
let refEntry = referenceMap.get(id);
|
|
1095
|
+
refEntry.used = true;
|
|
1096
|
+
return refEntry.target;
|
|
1097
|
+
};
|
|
1109
1098
|
|
|
1110
|
-
currentExtensions[0x73] = () => new Set(read())
|
|
1099
|
+
currentExtensions[0x73] = () => new Set(read());
|
|
1111
1100
|
|
|
1112
|
-
export const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array')
|
|
1101
|
+
export const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array');
|
|
1113
1102
|
|
|
1114
1103
|
let glbl = typeof globalThis === 'object' ? globalThis : window;
|
|
1115
1104
|
currentExtensions[0x74] = (data) => {
|
|
1116
|
-
let typeCode = data[0]
|
|
1105
|
+
let typeCode = data[0];
|
|
1117
1106
|
// we always have to slice to get a new ArrayBuffer that is aligned
|
|
1118
|
-
let buffer = Uint8Array.prototype.slice.call(data, 1).buffer
|
|
1107
|
+
let buffer = Uint8Array.prototype.slice.call(data, 1).buffer;
|
|
1119
1108
|
|
|
1120
|
-
let typedArrayName = typedArrays[typeCode]
|
|
1109
|
+
let typedArrayName = typedArrays[typeCode];
|
|
1121
1110
|
if (!typedArrayName) {
|
|
1122
|
-
if (typeCode === 16) return buffer
|
|
1123
|
-
if (typeCode === 17) return new DataView(buffer)
|
|
1124
|
-
throw new Error('Could not find typed array for code ' + typeCode)
|
|
1111
|
+
if (typeCode === 16) return buffer;
|
|
1112
|
+
if (typeCode === 17) return new DataView(buffer);
|
|
1113
|
+
throw new Error('Could not find typed array for code ' + typeCode);
|
|
1125
1114
|
}
|
|
1126
|
-
return new glbl[typedArrayName](buffer)
|
|
1127
|
-
}
|
|
1115
|
+
return new glbl[typedArrayName](buffer);
|
|
1116
|
+
};
|
|
1128
1117
|
currentExtensions[0x78] = () => {
|
|
1129
|
-
let data = read()
|
|
1130
|
-
return new RegExp(data[0], data[1])
|
|
1131
|
-
}
|
|
1132
|
-
const TEMP_BUNDLE = []
|
|
1118
|
+
let data = read();
|
|
1119
|
+
return new RegExp(data[0], data[1]);
|
|
1120
|
+
};
|
|
1121
|
+
const TEMP_BUNDLE = [];
|
|
1133
1122
|
currentExtensions[0x62] = (data) => {
|
|
1134
|
-
let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]
|
|
1135
|
-
let dataPosition = position
|
|
1136
|
-
position += dataSize - data.length
|
|
1137
|
-
bundledStrings = TEMP_BUNDLE
|
|
1138
|
-
bundledStrings = [readOnlyJSString(), readOnlyJSString()]
|
|
1139
|
-
bundledStrings.position0 = 0
|
|
1140
|
-
bundledStrings.position1 = 0
|
|
1141
|
-
bundledStrings.postBundlePosition = position
|
|
1142
|
-
position = dataPosition
|
|
1143
|
-
return read()
|
|
1144
|
-
}
|
|
1123
|
+
let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
|
|
1124
|
+
let dataPosition = position;
|
|
1125
|
+
position += dataSize - data.length;
|
|
1126
|
+
bundledStrings = TEMP_BUNDLE;
|
|
1127
|
+
bundledStrings = [readOnlyJSString(), readOnlyJSString()];
|
|
1128
|
+
bundledStrings.position0 = 0;
|
|
1129
|
+
bundledStrings.position1 = 0;
|
|
1130
|
+
bundledStrings.postBundlePosition = position;
|
|
1131
|
+
position = dataPosition;
|
|
1132
|
+
return read();
|
|
1133
|
+
};
|
|
1145
1134
|
|
|
1146
1135
|
currentExtensions[0xff] = (data) => {
|
|
1147
1136
|
// 32-bit date extension
|
|
1148
1137
|
if (data.length == 4)
|
|
1149
|
-
return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
|
|
1138
|
+
return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
|
|
1150
1139
|
else if (data.length == 8)
|
|
1151
1140
|
return new Date(
|
|
1152
1141
|
((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
|
|
1153
|
-
((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
|
|
1142
|
+
((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
|
|
1154
1143
|
else if (data.length == 12)
|
|
1155
1144
|
return new Date(
|
|
1156
1145
|
((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
|
|
1157
|
-
(((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
|
|
1146
|
+
(((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
|
|
1158
1147
|
else
|
|
1159
|
-
return new Date('invalid')
|
|
1160
|
-
}
|
|
1148
|
+
return new Date('invalid');
|
|
1149
|
+
};
|
|
1161
1150
|
// registration of bulk record definition?
|
|
1162
1151
|
// currentExtensions[0x52] = () =>
|
|
1163
1152
|
|
|
1164
1153
|
function saveState(callback) {
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
let
|
|
1168
|
-
let
|
|
1169
|
-
let
|
|
1170
|
-
let
|
|
1171
|
-
let
|
|
1172
|
-
let
|
|
1173
|
-
let
|
|
1174
|
-
let savedReferenceMap = referenceMap
|
|
1175
|
-
let savedBundledStrings = bundledStrings
|
|
1154
|
+
let savedSrcEnd = srcEnd;
|
|
1155
|
+
let savedPosition = position;
|
|
1156
|
+
let savedStringPosition = stringPosition;
|
|
1157
|
+
let savedSrcStringStart = srcStringStart;
|
|
1158
|
+
let savedSrcStringEnd = srcStringEnd;
|
|
1159
|
+
let savedSrcString = srcString;
|
|
1160
|
+
let savedStrings = strings;
|
|
1161
|
+
let savedReferenceMap = referenceMap;
|
|
1162
|
+
let savedBundledStrings = bundledStrings;
|
|
1176
1163
|
|
|
1177
1164
|
// TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
|
|
1178
|
-
let savedSrc = new Uint8Array(src.slice(0, srcEnd)) // we copy the data in case it changes while external data is processed
|
|
1179
|
-
let savedStructures = currentStructures
|
|
1180
|
-
let savedStructuresContents = currentStructures.slice(0, currentStructures.length)
|
|
1181
|
-
let savedPackr = currentUnpackr
|
|
1182
|
-
let savedSequentialMode = sequentialMode
|
|
1183
|
-
let value = callback()
|
|
1184
|
-
srcEnd = savedSrcEnd
|
|
1185
|
-
position = savedPosition
|
|
1186
|
-
stringPosition = savedStringPosition
|
|
1187
|
-
srcStringStart = savedSrcStringStart
|
|
1188
|
-
srcStringEnd = savedSrcStringEnd
|
|
1189
|
-
srcString = savedSrcString
|
|
1190
|
-
strings = savedStrings
|
|
1191
|
-
referenceMap = savedReferenceMap
|
|
1192
|
-
bundledStrings = savedBundledStrings
|
|
1193
|
-
src = savedSrc
|
|
1194
|
-
sequentialMode = savedSequentialMode
|
|
1195
|
-
currentStructures = savedStructures
|
|
1196
|
-
currentStructures.splice(0, currentStructures.length, ...savedStructuresContents)
|
|
1197
|
-
currentUnpackr = savedPackr
|
|
1198
|
-
dataView = new DataView(src.buffer, src.byteOffset, src.byteLength)
|
|
1199
|
-
return value
|
|
1165
|
+
let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
|
|
1166
|
+
let savedStructures = currentStructures;
|
|
1167
|
+
let savedStructuresContents = currentStructures.slice(0, currentStructures.length);
|
|
1168
|
+
let savedPackr = currentUnpackr;
|
|
1169
|
+
let savedSequentialMode = sequentialMode;
|
|
1170
|
+
let value = callback();
|
|
1171
|
+
srcEnd = savedSrcEnd;
|
|
1172
|
+
position = savedPosition;
|
|
1173
|
+
stringPosition = savedStringPosition;
|
|
1174
|
+
srcStringStart = savedSrcStringStart;
|
|
1175
|
+
srcStringEnd = savedSrcStringEnd;
|
|
1176
|
+
srcString = savedSrcString;
|
|
1177
|
+
strings = savedStrings;
|
|
1178
|
+
referenceMap = savedReferenceMap;
|
|
1179
|
+
bundledStrings = savedBundledStrings;
|
|
1180
|
+
src = savedSrc;
|
|
1181
|
+
sequentialMode = savedSequentialMode;
|
|
1182
|
+
currentStructures = savedStructures;
|
|
1183
|
+
currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
|
|
1184
|
+
currentUnpackr = savedPackr;
|
|
1185
|
+
dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
|
|
1186
|
+
return value;
|
|
1200
1187
|
}
|
|
1201
1188
|
export function clearSource() {
|
|
1202
|
-
src = null
|
|
1203
|
-
referenceMap = null
|
|
1204
|
-
currentStructures = null
|
|
1189
|
+
src = null;
|
|
1190
|
+
referenceMap = null;
|
|
1191
|
+
currentStructures = null;
|
|
1205
1192
|
}
|
|
1206
1193
|
|
|
1207
1194
|
export function addExtension(extension) {
|
|
1208
1195
|
if (extension.unpack)
|
|
1209
|
-
currentExtensions[extension.type] = extension.unpack
|
|
1196
|
+
currentExtensions[extension.type] = extension.unpack;
|
|
1210
1197
|
else
|
|
1211
|
-
currentExtensions[extension.type] = extension
|
|
1198
|
+
currentExtensions[extension.type] = extension;
|
|
1212
1199
|
}
|
|
1213
1200
|
|
|
1214
|
-
export const mult10 = new Array(147) // this is a table matching binary exponents to the multiplier to determine significant digit rounding
|
|
1201
|
+
export const mult10 = new Array(147); // this is a table matching binary exponents to the multiplier to determine significant digit rounding
|
|
1215
1202
|
for (let i = 0; i < 256; i++) {
|
|
1216
|
-
mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103))
|
|
1203
|
+
mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103));
|
|
1217
1204
|
}
|
|
1218
|
-
export const Decoder = Unpackr
|
|
1219
|
-
var defaultUnpackr = new Unpackr({ useRecords: false })
|
|
1220
|
-
export const unpack = defaultUnpackr.unpack
|
|
1221
|
-
export const unpackMultiple = defaultUnpackr.unpackMultiple
|
|
1222
|
-
export const decode = defaultUnpackr.unpack
|
|
1205
|
+
export const Decoder = Unpackr;
|
|
1206
|
+
var defaultUnpackr = new Unpackr({ useRecords: false });
|
|
1207
|
+
export const unpack = defaultUnpackr.unpack;
|
|
1208
|
+
export const unpackMultiple = defaultUnpackr.unpackMultiple;
|
|
1209
|
+
export const decode = defaultUnpackr.unpack;
|
|
1223
1210
|
export const FLOAT32_OPTIONS = {
|
|
1224
1211
|
NEVER: 0,
|
|
1225
1212
|
ALWAYS: 1,
|
|
1226
1213
|
DECIMAL_ROUND: 3,
|
|
1227
1214
|
DECIMAL_FIT: 4
|
|
1228
|
-
}
|
|
1229
|
-
let f32Array = new Float32Array(1)
|
|
1230
|
-
let u8Array = new Uint8Array(f32Array.buffer, 0, 4)
|
|
1215
|
+
};
|
|
1216
|
+
let f32Array = new Float32Array(1);
|
|
1217
|
+
let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
|
|
1231
1218
|
export function roundFloat32(float32Number) {
|
|
1232
|
-
f32Array[0] = float32Number
|
|
1233
|
-
let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)]
|
|
1234
|
-
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
|
|
1235
|
-
}
|
|
1236
|
-
export function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
|
|
1237
|
-
readStruct = updatedReadStruct;
|
|
1238
|
-
onLoadedStructures = loadedStructs;
|
|
1239
|
-
onSaveState = saveState;
|
|
1219
|
+
f32Array[0] = float32Number;
|
|
1220
|
+
let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
|
|
1221
|
+
return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
|
|
1240
1222
|
}
|