@itee/client 10.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/CHANGELOG.md +251 -0
- package/LICENSE.md +23 -0
- package/README.md +76 -0
- package/builds/itee-client.cjs.js +6517 -0
- package/builds/itee-client.cjs.js.map +1 -0
- package/builds/itee-client.cjs.min.js +125 -0
- package/builds/itee-client.esm.js +6468 -0
- package/builds/itee-client.esm.js.map +1 -0
- package/builds/itee-client.esm.min.js +124 -0
- package/builds/itee-client.iife.js +6524 -0
- package/builds/itee-client.iife.js.map +1 -0
- package/builds/itee-client.iife.min.js +125 -0
- package/package.json +87 -0
- package/sources/client.js +14 -0
- package/sources/cores/TAbstractFactory.js +42 -0
- package/sources/cores/TCloningFactory.js +39 -0
- package/sources/cores/TConstants.js +433 -0
- package/sources/cores/TInstancingFactory.js +41 -0
- package/sources/cores/TStore.js +303 -0
- package/sources/cores/_cores.js +13 -0
- package/sources/input_devices/TKeyboardController.js +158 -0
- package/sources/input_devices/TMouseController.js +31 -0
- package/sources/input_devices/_inputDevices.js +11 -0
- package/sources/loaders/TBinaryConverter.js +35 -0
- package/sources/loaders/TBinaryReader.js +1029 -0
- package/sources/loaders/TBinarySerializer.js +258 -0
- package/sources/loaders/TBinaryWriter.js +429 -0
- package/sources/loaders/_loaders.js +21 -0
- package/sources/loaders/converters/ArrayBinaryConverter.js +33 -0
- package/sources/loaders/converters/BooleanBinaryConverter.js +24 -0
- package/sources/loaders/converters/DateBinaryConverter.js +21 -0
- package/sources/loaders/converters/NullBinaryConverter.js +13 -0
- package/sources/loaders/converters/NumberBinaryConverter.js +15 -0
- package/sources/loaders/converters/ObjectBinaryConverter.js +101 -0
- package/sources/loaders/converters/RegExBinaryConverter.js +11 -0
- package/sources/loaders/converters/StringBinaryConverter.js +26 -0
- package/sources/loaders/converters/UndefinedBinaryConverter.js +13 -0
- package/sources/managers/TDataBaseManager.js +1649 -0
- package/sources/managers/_managers.js +10 -0
- package/sources/utils/TIdFactory.js +84 -0
- package/sources/utils/_utils.js +9 -0
- package/sources/webapis/WebAPI.js +773 -0
- package/sources/webapis/WebAPIOrigin.js +141 -0
- package/sources/webapis/_webapis.js +10 -0
- package/sources/webapis/messages/WebAPIMessage.js +75 -0
- package/sources/webapis/messages/WebAPIMessageData.js +51 -0
- package/sources/webapis/messages/WebAPIMessageError.js +79 -0
- package/sources/webapis/messages/WebAPIMessageEvent.js +58 -0
- package/sources/webapis/messages/WebAPIMessageProgress.js +91 -0
- package/sources/webapis/messages/WebAPIMessageReady.js +66 -0
- package/sources/webapis/messages/WebAPIMessageRequest.js +94 -0
- package/sources/webapis/messages/WebAPIMessageResponse.js +80 -0
- package/sources/webapis/messages/_messages.js +16 -0
- package/sources/workers/AbstractWorker.js +149 -0
- package/sources/workers/_workers.js +10 -0
- package/sources/workers/messages/WorkerMessage.js +33 -0
- package/sources/workers/messages/WorkerMessageData.js +30 -0
- package/sources/workers/messages/WorkerMessageError.js +32 -0
- package/sources/workers/messages/WorkerMessageMethodCall.js +60 -0
- package/sources/workers/messages/WorkerMessageProgress.js +67 -0
- package/sources/workers/messages/_messages.js +14 -0
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
import { toEnum } from '@itee/utils'
|
|
2
|
+
import {
|
|
3
|
+
isNotArrayBuffer,
|
|
4
|
+
isNotBoolean,
|
|
5
|
+
isNotNumber,
|
|
6
|
+
isNull,
|
|
7
|
+
isUndefined
|
|
8
|
+
} from '@itee/validators'
|
|
9
|
+
|
|
10
|
+
/* eslint-env browser */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {Enum} Endianness
|
|
14
|
+
* @property {Boolean} Little=true - The Little endianess
|
|
15
|
+
* @property {Number} Big=false - The Big endianess
|
|
16
|
+
*
|
|
17
|
+
* @constant
|
|
18
|
+
* @type {Endianness}
|
|
19
|
+
* @description Endianness enum allow semantic usage.
|
|
20
|
+
*/
|
|
21
|
+
const Endianness = /*#__PURE__*/toEnum( {
|
|
22
|
+
Little: true,
|
|
23
|
+
Big: false
|
|
24
|
+
} )
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Enum} Byte
|
|
28
|
+
* @property {Number} One=1 - Octet
|
|
29
|
+
* @property {Number} Two=2 - Doublet
|
|
30
|
+
* @property {Number} Four=4 - Quadlet
|
|
31
|
+
* @property {Number} Height=8 - Octlet
|
|
32
|
+
*
|
|
33
|
+
* @constant
|
|
34
|
+
* @type {Byte}
|
|
35
|
+
* @description Byte allow semantic meaning of quantity of bytes based on power of two.
|
|
36
|
+
*/
|
|
37
|
+
const Byte = /*#__PURE__*/toEnum( {
|
|
38
|
+
One: 1,
|
|
39
|
+
Two: 2,
|
|
40
|
+
Four: 4,
|
|
41
|
+
Eight: 8
|
|
42
|
+
} )
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @class
|
|
47
|
+
* @classdesc TBinaryReader is design to perform fast binary read/write
|
|
48
|
+
*
|
|
49
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
50
|
+
* @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
|
|
51
|
+
*/
|
|
52
|
+
class TBinaryReader {
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @constructor
|
|
56
|
+
* @param [parameters]
|
|
57
|
+
* @param parameters.buffer
|
|
58
|
+
* @param parameters.offset
|
|
59
|
+
* @param parameters.length
|
|
60
|
+
* @param parameters.endianness
|
|
61
|
+
*/
|
|
62
|
+
constructor( parameters = {} ) {
|
|
63
|
+
|
|
64
|
+
const _parameters = {
|
|
65
|
+
...{
|
|
66
|
+
buffer: new ArrayBuffer( 0 ),
|
|
67
|
+
offset: 0,
|
|
68
|
+
length: 0,
|
|
69
|
+
endianness: Endianness.Little
|
|
70
|
+
},
|
|
71
|
+
...parameters
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.buffer = _parameters.buffer
|
|
75
|
+
// this.offset = _parameters.offset
|
|
76
|
+
// this.length = _parameters.length
|
|
77
|
+
this.endianness = _parameters.endianness
|
|
78
|
+
|
|
79
|
+
// For bit reading use same approche than byte
|
|
80
|
+
this._bits = {
|
|
81
|
+
buffer: null,
|
|
82
|
+
offset: 0,
|
|
83
|
+
length: 0
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this._updateDataView()
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* @returns {*}
|
|
93
|
+
*/
|
|
94
|
+
get buffer() {
|
|
95
|
+
return this._buffer
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
set buffer( value ) {
|
|
99
|
+
|
|
100
|
+
const memberName = 'Buffer'
|
|
101
|
+
const expect = 'Expect an instance of ArrayBuffer.'
|
|
102
|
+
|
|
103
|
+
if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
|
|
104
|
+
if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
|
|
105
|
+
if ( isNotArrayBuffer( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
|
|
106
|
+
|
|
107
|
+
this._buffer = value
|
|
108
|
+
this._offset = 0
|
|
109
|
+
this._length = value.byteLength
|
|
110
|
+
|
|
111
|
+
this._updateDataView()
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
*
|
|
117
|
+
* @returns {*}
|
|
118
|
+
*/
|
|
119
|
+
get offset() {
|
|
120
|
+
return this._offset
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
set offset( value ) {
|
|
124
|
+
|
|
125
|
+
const memberName = 'Offset'
|
|
126
|
+
const expect = 'Expect a number.'
|
|
127
|
+
|
|
128
|
+
if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
|
|
129
|
+
if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
|
|
130
|
+
if ( isNotNumber( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
|
|
131
|
+
|
|
132
|
+
this._offset = value
|
|
133
|
+
|
|
134
|
+
this._updateDataView()
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get length() {
|
|
139
|
+
return this._length
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* @param value
|
|
145
|
+
*/
|
|
146
|
+
set length( value ) {
|
|
147
|
+
|
|
148
|
+
const memberName = 'Length'
|
|
149
|
+
const expect = 'Expect a number.'
|
|
150
|
+
|
|
151
|
+
if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
|
|
152
|
+
if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
|
|
153
|
+
if ( isNotNumber( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
|
|
154
|
+
|
|
155
|
+
this._length = value
|
|
156
|
+
|
|
157
|
+
this._updateDataView()
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
* @returns {*}
|
|
164
|
+
*/
|
|
165
|
+
get endianness() {
|
|
166
|
+
return this._endianness
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
set endianness( value ) {
|
|
170
|
+
|
|
171
|
+
const memberName = 'Endianness'
|
|
172
|
+
const expect = 'Expect a boolean.'
|
|
173
|
+
|
|
174
|
+
if ( isNull( value ) ) { throw new TypeError( `${ memberName } cannot be null ! ${ expect }` ) }
|
|
175
|
+
if ( isUndefined( value ) ) { throw new TypeError( `${ memberName } cannot be undefined ! ${ expect }` ) }
|
|
176
|
+
if ( isNotBoolean( value ) ) { throw new TypeError( `${ memberName } cannot be an instance of ${ value.constructor.name } ! ${ expect }` ) }
|
|
177
|
+
|
|
178
|
+
this._endianness = value
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
* @param buffer
|
|
184
|
+
* @param offset
|
|
185
|
+
* @param length
|
|
186
|
+
* @returns {TBinaryReader}
|
|
187
|
+
*/
|
|
188
|
+
setBuffer( buffer, offset, length ) {
|
|
189
|
+
|
|
190
|
+
this.buffer = buffer
|
|
191
|
+
this.offset = offset || 0
|
|
192
|
+
this.length = length || buffer.byteLength
|
|
193
|
+
|
|
194
|
+
return this
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
*
|
|
200
|
+
* @param value
|
|
201
|
+
* @returns {TBinaryReader}
|
|
202
|
+
*/
|
|
203
|
+
setOffset( value ) {
|
|
204
|
+
|
|
205
|
+
this.offset = value
|
|
206
|
+
return this
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @param value
|
|
213
|
+
* @returns {TBinaryReader}
|
|
214
|
+
*/
|
|
215
|
+
setLength( value ) {
|
|
216
|
+
|
|
217
|
+
this.length = value
|
|
218
|
+
return this
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
*
|
|
224
|
+
* @param endianness
|
|
225
|
+
* @returns {TBinaryReader}
|
|
226
|
+
*/
|
|
227
|
+
setEndianness( endianness ) {
|
|
228
|
+
|
|
229
|
+
this.endianness = endianness
|
|
230
|
+
return this
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
*
|
|
236
|
+
* @param increment
|
|
237
|
+
* @returns {*}
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
_getAndUpdateOffsetBy( increment ) {
|
|
241
|
+
|
|
242
|
+
const currentOffset = this._offset
|
|
243
|
+
this._offset += increment
|
|
244
|
+
|
|
245
|
+
return currentOffset
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
*
|
|
251
|
+
* @private
|
|
252
|
+
*/
|
|
253
|
+
_updateDataView() {
|
|
254
|
+
|
|
255
|
+
this._dataView = new DataView( this._buffer, this._offset, this._length )
|
|
256
|
+
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @returns {boolean}
|
|
262
|
+
*/
|
|
263
|
+
isEndOfFile() {
|
|
264
|
+
|
|
265
|
+
return ( this._offset === this._length )
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Bits
|
|
270
|
+
|
|
271
|
+
_isNullBitBuffer() {
|
|
272
|
+
|
|
273
|
+
return this._bits.buffer === null
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
_nextBit() {
|
|
277
|
+
this._bits.offset += 1
|
|
278
|
+
}
|
|
279
|
+
_isEndOfBitBuffer() {
|
|
280
|
+
|
|
281
|
+
return this._bits.offset === this._bits.length
|
|
282
|
+
|
|
283
|
+
}
|
|
284
|
+
_isOutOfRangeBitOffset( offset ) {
|
|
285
|
+
return offset > this._bits.length
|
|
286
|
+
}
|
|
287
|
+
_readBit8() {
|
|
288
|
+
this._bits.buffer = this.getUint8()
|
|
289
|
+
this._bits.length = 8
|
|
290
|
+
this._bits.offset = 0
|
|
291
|
+
}
|
|
292
|
+
_readBit16() {
|
|
293
|
+
this._bits.buffer = this.getUint16()
|
|
294
|
+
this._bits.length = 16
|
|
295
|
+
this._bits.offset = 0
|
|
296
|
+
}
|
|
297
|
+
_readBit32() {
|
|
298
|
+
this._bits.buffer = this.getUint32()
|
|
299
|
+
this._bits.length = 32
|
|
300
|
+
this._bits.offset = 0
|
|
301
|
+
}
|
|
302
|
+
_getBitAt( bitOffset ) {
|
|
303
|
+
|
|
304
|
+
return ( this._bits.buffer & ( 1 << bitOffset ) ) === 0 ? 0 : 1
|
|
305
|
+
|
|
306
|
+
}
|
|
307
|
+
_resetBits() {
|
|
308
|
+
this._bits.buffer = null
|
|
309
|
+
this._bits.length = 0
|
|
310
|
+
this._bits.offset = 0
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
skipBitOffsetTo( bitOffset ) {
|
|
314
|
+
//todo is positive bitoffset
|
|
315
|
+
|
|
316
|
+
// In case we start directly by a skip offset try to determine which kind of data is expected
|
|
317
|
+
if ( this._isNullBitBuffer() ) {
|
|
318
|
+
|
|
319
|
+
if ( bitOffset <= 8 ) {
|
|
320
|
+
|
|
321
|
+
this._readBit8()
|
|
322
|
+
|
|
323
|
+
} else if ( 8 < bitOffset && bitOffset <= 16 ) {
|
|
324
|
+
|
|
325
|
+
this._readBit16()
|
|
326
|
+
|
|
327
|
+
} else if ( 16 < bitOffset && bitOffset <= 32 ) {
|
|
328
|
+
|
|
329
|
+
this._readBit32()
|
|
330
|
+
|
|
331
|
+
} else {
|
|
332
|
+
|
|
333
|
+
throw new RangeError( 'You cannot skip more than 32 bits. Please use skipOffsetOf instead !' )
|
|
334
|
+
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
} else if ( this._isOutOfRangeBitOffset( bitOffset ) ) { throw new RangeError( 'Bit offset is out of range of the current bits field.' ) }
|
|
338
|
+
|
|
339
|
+
this._bits.offset = bitOffset
|
|
340
|
+
if ( this._isEndOfBitBuffer() ) {
|
|
341
|
+
this._resetBits()
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
skipBitOffsetOf( nBits ) {
|
|
347
|
+
|
|
348
|
+
this.skipBitOffsetTo( this._bits.offset + nBits )
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
getBit8( moveNext = true ) {
|
|
353
|
+
|
|
354
|
+
if ( this._isNullBitBuffer() ) {
|
|
355
|
+
this._readBit8()
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const bitValue = this._getBitAt( this._bits.offset )
|
|
359
|
+
|
|
360
|
+
if ( moveNext ) {
|
|
361
|
+
this._nextBit()
|
|
362
|
+
if ( this._isEndOfBitBuffer() ) {
|
|
363
|
+
this._resetBits()
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return bitValue
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
getBits8( numberOfBitToRead, moveNext = true ) {
|
|
372
|
+
|
|
373
|
+
const currentOffset = this._bits.offset
|
|
374
|
+
|
|
375
|
+
let bits = 0
|
|
376
|
+
|
|
377
|
+
// In last turn avoid bits reset if move next is false,
|
|
378
|
+
// else the skipBitOffset will be based on reseted/null bit buffer
|
|
379
|
+
for ( let i = 0 ; i < numberOfBitToRead ; i++ ) {
|
|
380
|
+
if ( i === numberOfBitToRead - 1 ) {
|
|
381
|
+
bits |= ( this.getBit8( moveNext ) << i )
|
|
382
|
+
} else {
|
|
383
|
+
bits |= ( this.getBit8() << i )
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if ( !moveNext ) {
|
|
388
|
+
this.skipBitOffsetTo( currentOffset )
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return bits
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
getBit16( moveNext = true ) {
|
|
396
|
+
|
|
397
|
+
if ( this._isNullBitBuffer() ) {
|
|
398
|
+
this._readBit16()
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const bitValue = this._getBitAt( this._bits.offset )
|
|
402
|
+
|
|
403
|
+
if ( moveNext ) {
|
|
404
|
+
this._nextBit()
|
|
405
|
+
if ( this._isEndOfBitBuffer() ) {
|
|
406
|
+
this._resetBits()
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return bitValue
|
|
411
|
+
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
getBits16( numberOfBitToRead, moveNext = true ) {
|
|
415
|
+
|
|
416
|
+
const currentOffset = this._bits.offset
|
|
417
|
+
|
|
418
|
+
let bits = 0
|
|
419
|
+
|
|
420
|
+
// In last turn avoid bits reset if move next is false,
|
|
421
|
+
// else the skipBitOffset will be based on reseted/null bit buffer
|
|
422
|
+
for ( let i = 0 ; i < numberOfBitToRead ; i++ ) {
|
|
423
|
+
if ( i === numberOfBitToRead - 1 ) {
|
|
424
|
+
bits |= ( this.getBit16( moveNext ) << i )
|
|
425
|
+
} else {
|
|
426
|
+
bits |= ( this.getBit16() << i )
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if ( !moveNext ) {
|
|
431
|
+
this.skipBitOffsetTo( currentOffset )
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return bits
|
|
435
|
+
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
getBit32( moveNext = true ) {
|
|
439
|
+
|
|
440
|
+
if ( this._isNullBitBuffer() ) {
|
|
441
|
+
this._readBit32()
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const bitValue = this._getBitAt( this._bits.offset )
|
|
445
|
+
|
|
446
|
+
if ( moveNext ) {
|
|
447
|
+
this._nextBit()
|
|
448
|
+
if ( this._isEndOfBitBuffer() ) {
|
|
449
|
+
this._resetBits()
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return bitValue
|
|
454
|
+
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
getBits32( numberOfBitToRead, moveNext = true ) {
|
|
458
|
+
|
|
459
|
+
const currentOffset = this._bits.offset
|
|
460
|
+
|
|
461
|
+
let bits = 0
|
|
462
|
+
|
|
463
|
+
// In last turn avoid bits reset if move next is false,
|
|
464
|
+
// else the skipBitOffset will be based on reseted/null bit buffer
|
|
465
|
+
for ( let i = 0 ; i < numberOfBitToRead ; i++ ) {
|
|
466
|
+
if ( i === numberOfBitToRead - 1 ) {
|
|
467
|
+
bits |= ( this.getBit32( moveNext ) << i )
|
|
468
|
+
} else {
|
|
469
|
+
bits |= ( this.getBit32() << i )
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if ( !moveNext ) {
|
|
474
|
+
this.skipBitOffsetTo( currentOffset )
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return bits
|
|
478
|
+
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Bytes
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
*
|
|
485
|
+
* @param offset
|
|
486
|
+
*/
|
|
487
|
+
skipOffsetTo( offset ) {
|
|
488
|
+
|
|
489
|
+
this._offset = offset
|
|
490
|
+
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
*
|
|
495
|
+
* @param nBytes
|
|
496
|
+
*/
|
|
497
|
+
skipOffsetOf( nBytes ) {
|
|
498
|
+
|
|
499
|
+
this._offset += nBytes
|
|
500
|
+
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
*
|
|
505
|
+
* @returns {boolean}
|
|
506
|
+
*/
|
|
507
|
+
getBoolean( moveNext = true ) {
|
|
508
|
+
|
|
509
|
+
return ( ( this.getUint8( moveNext ) & 1 ) === 1 )
|
|
510
|
+
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
*
|
|
515
|
+
* @param length
|
|
516
|
+
* @param moveNext
|
|
517
|
+
* @returns {Array}
|
|
518
|
+
*/
|
|
519
|
+
getBooleanArray( length, moveNext = true ) {
|
|
520
|
+
|
|
521
|
+
const currentOffset = this._offset
|
|
522
|
+
const array = []
|
|
523
|
+
|
|
524
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
525
|
+
|
|
526
|
+
array.push( this.getBoolean() )
|
|
527
|
+
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if ( !moveNext ) {
|
|
531
|
+
this._offset = currentOffset
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return array
|
|
535
|
+
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
*
|
|
540
|
+
* @returns {number}
|
|
541
|
+
*/
|
|
542
|
+
getInt8( moveNext = true ) {
|
|
543
|
+
|
|
544
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.One ) : this._offset
|
|
545
|
+
return this._dataView.getInt8( offset )
|
|
546
|
+
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
*
|
|
551
|
+
* @param length
|
|
552
|
+
* @param moveNext
|
|
553
|
+
* @returns {Array}
|
|
554
|
+
*/
|
|
555
|
+
getInt8Array( length, moveNext = true ) {
|
|
556
|
+
|
|
557
|
+
const currentOffset = this._offset
|
|
558
|
+
const array = []
|
|
559
|
+
|
|
560
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
561
|
+
|
|
562
|
+
array.push( this.getInt8() )
|
|
563
|
+
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if ( !moveNext ) {
|
|
567
|
+
this._offset = currentOffset
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return array
|
|
571
|
+
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
*
|
|
576
|
+
* @returns {number}
|
|
577
|
+
*/
|
|
578
|
+
getUint8( moveNext = true ) {
|
|
579
|
+
|
|
580
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.One ) : this._offset
|
|
581
|
+
return this._dataView.getUint8( offset )
|
|
582
|
+
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
*
|
|
587
|
+
* @param length
|
|
588
|
+
* @param moveNext
|
|
589
|
+
* @returns {Array}
|
|
590
|
+
*/
|
|
591
|
+
getUint8Array( length, moveNext = true ) {
|
|
592
|
+
|
|
593
|
+
const currentOffset = this._offset
|
|
594
|
+
const array = []
|
|
595
|
+
|
|
596
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
597
|
+
|
|
598
|
+
array.push( this.getUint8() )
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if ( !moveNext ) {
|
|
603
|
+
this._offset = currentOffset
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return array
|
|
607
|
+
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
*
|
|
612
|
+
* @returns {number}
|
|
613
|
+
*/
|
|
614
|
+
getInt16( moveNext = true ) {
|
|
615
|
+
|
|
616
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.Two ) : this._offset
|
|
617
|
+
return this._dataView.getInt16( offset, this._endianness )
|
|
618
|
+
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
*
|
|
623
|
+
* @param length
|
|
624
|
+
* @param moveNext
|
|
625
|
+
* @returns {Array}
|
|
626
|
+
*/
|
|
627
|
+
getInt16Array( length, moveNext = true ) {
|
|
628
|
+
|
|
629
|
+
const currentOffset = this._offset
|
|
630
|
+
const array = []
|
|
631
|
+
|
|
632
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
633
|
+
|
|
634
|
+
array.push( this.getInt16() )
|
|
635
|
+
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
if ( !moveNext ) {
|
|
639
|
+
this._offset = currentOffset
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return array
|
|
643
|
+
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
*
|
|
648
|
+
* @returns {number}
|
|
649
|
+
*/
|
|
650
|
+
getUint16( moveNext = true ) {
|
|
651
|
+
|
|
652
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.Two ) : this._offset
|
|
653
|
+
return this._dataView.getUint16( offset, this._endianness )
|
|
654
|
+
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
*
|
|
659
|
+
* @param length
|
|
660
|
+
* @param moveNext
|
|
661
|
+
* @returns {Array}
|
|
662
|
+
*/
|
|
663
|
+
getUint16Array( length, moveNext = true ) {
|
|
664
|
+
|
|
665
|
+
const currentOffset = this._offset
|
|
666
|
+
const array = []
|
|
667
|
+
|
|
668
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
669
|
+
|
|
670
|
+
array.push( this.getUint16() )
|
|
671
|
+
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if ( !moveNext ) {
|
|
675
|
+
this._offset = currentOffset
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
return array
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
*
|
|
684
|
+
* @returns {number}
|
|
685
|
+
*/
|
|
686
|
+
getInt32( moveNext = true ) {
|
|
687
|
+
|
|
688
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.Four ) : this._offset
|
|
689
|
+
return this._dataView.getInt32( offset, this._endianness )
|
|
690
|
+
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
*
|
|
695
|
+
* @param length
|
|
696
|
+
* @param moveNext
|
|
697
|
+
* @returns {Array}
|
|
698
|
+
*/
|
|
699
|
+
getInt32Array( length, moveNext = true ) {
|
|
700
|
+
|
|
701
|
+
const currentOffset = this._offset
|
|
702
|
+
const array = []
|
|
703
|
+
|
|
704
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
705
|
+
|
|
706
|
+
array.push( this.getInt32() )
|
|
707
|
+
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if ( !moveNext ) {
|
|
711
|
+
this._offset = currentOffset
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
return array
|
|
715
|
+
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
*
|
|
720
|
+
* @returns {number}
|
|
721
|
+
*/
|
|
722
|
+
getUint32( moveNext = true ) {
|
|
723
|
+
|
|
724
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.Four ) : this._offset
|
|
725
|
+
return this._dataView.getUint32( offset, this._endianness )
|
|
726
|
+
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
*
|
|
731
|
+
* @param length
|
|
732
|
+
* @param moveNext
|
|
733
|
+
* @returns {Array}
|
|
734
|
+
*/
|
|
735
|
+
getUint32Array( length, moveNext = true ) {
|
|
736
|
+
|
|
737
|
+
const currentOffset = this._offset
|
|
738
|
+
const array = []
|
|
739
|
+
|
|
740
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
741
|
+
|
|
742
|
+
array.push( this.getUint32() )
|
|
743
|
+
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
if ( !moveNext ) {
|
|
747
|
+
this._offset = currentOffset
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
return array
|
|
751
|
+
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
*
|
|
756
|
+
* @returns {number}
|
|
757
|
+
*/
|
|
758
|
+
getInt64( moveNext = true ) {
|
|
759
|
+
|
|
760
|
+
// From THREE.FBXLoader
|
|
761
|
+
// JavaScript doesn't support 64-bit integer so attempting to calculate by ourselves.
|
|
762
|
+
// 1 << 32 will return 1 so using multiply operation instead here.
|
|
763
|
+
// There'd be a possibility that this method returns wrong value if the value
|
|
764
|
+
// is out of the range between Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER.
|
|
765
|
+
// TODO: safely handle 64-bit integer
|
|
766
|
+
|
|
767
|
+
let low = null
|
|
768
|
+
let high = null
|
|
769
|
+
|
|
770
|
+
if ( this._endianness === Endianness.Little ) {
|
|
771
|
+
|
|
772
|
+
if ( moveNext ) {
|
|
773
|
+
low = this.getUint32()
|
|
774
|
+
high = this.getUint32()
|
|
775
|
+
} else {
|
|
776
|
+
const currentOffset = this._offset
|
|
777
|
+
low = this.getUint32()
|
|
778
|
+
high = this.getUint32()
|
|
779
|
+
this.skipOffsetTo( currentOffset )
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
} else {
|
|
783
|
+
|
|
784
|
+
if ( moveNext ) {
|
|
785
|
+
high = this.getUint32()
|
|
786
|
+
low = this.getUint32()
|
|
787
|
+
} else {
|
|
788
|
+
const currentOffset = this._offset
|
|
789
|
+
high = this.getUint32()
|
|
790
|
+
low = this.getUint32()
|
|
791
|
+
this.skipOffsetTo( currentOffset )
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// calculate negative value
|
|
797
|
+
if ( high & 0x80000000 ) {
|
|
798
|
+
|
|
799
|
+
high = ~high & 0xFFFFFFFF
|
|
800
|
+
low = ~low & 0xFFFFFFFF
|
|
801
|
+
|
|
802
|
+
if ( low === 0xFFFFFFFF ) {
|
|
803
|
+
high = ( high + 1 ) & 0xFFFFFFFF
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
low = ( low + 1 ) & 0xFFFFFFFF
|
|
807
|
+
|
|
808
|
+
return -( high * 0x100000000 + low )
|
|
809
|
+
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
return high * 0x100000000 + low
|
|
813
|
+
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
*
|
|
818
|
+
* @param length
|
|
819
|
+
* @param moveNext
|
|
820
|
+
* @returns {Array}
|
|
821
|
+
*/
|
|
822
|
+
getInt64Array( length, moveNext = true ) {
|
|
823
|
+
|
|
824
|
+
const currentOffset = this._offset
|
|
825
|
+
const array = []
|
|
826
|
+
|
|
827
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
828
|
+
|
|
829
|
+
array.push( this.getInt64() )
|
|
830
|
+
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
if ( !moveNext ) {
|
|
834
|
+
this._offset = currentOffset
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
return array
|
|
838
|
+
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
*
|
|
843
|
+
* @returns {number}
|
|
844
|
+
*/
|
|
845
|
+
getUint64( moveNext = true ) {
|
|
846
|
+
// Note: see getInt64() comment
|
|
847
|
+
|
|
848
|
+
let low = null
|
|
849
|
+
let high = null
|
|
850
|
+
|
|
851
|
+
if ( this._endianness === Endianness.Little ) {
|
|
852
|
+
|
|
853
|
+
if ( moveNext ) {
|
|
854
|
+
low = this.getUint32()
|
|
855
|
+
high = this.getUint32()
|
|
856
|
+
} else {
|
|
857
|
+
const currentOffset = this._offset
|
|
858
|
+
low = this.getUint32()
|
|
859
|
+
high = this.getUint32()
|
|
860
|
+
this.skipOffsetTo( currentOffset )
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
} else {
|
|
864
|
+
|
|
865
|
+
if ( moveNext ) {
|
|
866
|
+
high = this.getUint32()
|
|
867
|
+
low = this.getUint32()
|
|
868
|
+
} else {
|
|
869
|
+
const currentOffset = this._offset
|
|
870
|
+
high = this.getUint32()
|
|
871
|
+
low = this.getUint32()
|
|
872
|
+
this.skipOffsetTo( currentOffset )
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
return high * 0x100000000 + low
|
|
878
|
+
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
*
|
|
883
|
+
* @param length
|
|
884
|
+
* @param moveNext
|
|
885
|
+
* @returns {Array}
|
|
886
|
+
*/
|
|
887
|
+
getUint64Array( length, moveNext = true ) {
|
|
888
|
+
|
|
889
|
+
const currentOffset = this._offset
|
|
890
|
+
const array = []
|
|
891
|
+
|
|
892
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
893
|
+
|
|
894
|
+
array.push( this.getUint64() )
|
|
895
|
+
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
if ( !moveNext ) {
|
|
899
|
+
this._offset = currentOffset
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
return array
|
|
903
|
+
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
*
|
|
908
|
+
* @returns {number}
|
|
909
|
+
*/
|
|
910
|
+
getFloat32( moveNext = true ) {
|
|
911
|
+
|
|
912
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.Four ) : this._offset
|
|
913
|
+
return this._dataView.getFloat32( offset, this._endianness )
|
|
914
|
+
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
*
|
|
919
|
+
* @param length
|
|
920
|
+
* @param moveNext
|
|
921
|
+
* @returns {Array}
|
|
922
|
+
*/
|
|
923
|
+
getFloat32Array( length, moveNext = true ) {
|
|
924
|
+
|
|
925
|
+
const currentOffset = this._offset
|
|
926
|
+
const array = []
|
|
927
|
+
|
|
928
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
929
|
+
|
|
930
|
+
array.push( this.getFloat32() )
|
|
931
|
+
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
if ( !moveNext ) {
|
|
935
|
+
this._offset = currentOffset
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
return array
|
|
939
|
+
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
*
|
|
944
|
+
* @return {number}
|
|
945
|
+
*/
|
|
946
|
+
getFloat64( moveNext = true ) {
|
|
947
|
+
|
|
948
|
+
const offset = ( moveNext ) ? this._getAndUpdateOffsetBy( Byte.Eight ) : this._offset
|
|
949
|
+
return this._dataView.getFloat64( offset, this._endianness )
|
|
950
|
+
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
*
|
|
955
|
+
* @param length
|
|
956
|
+
* @param moveNext
|
|
957
|
+
* @returns {Array}
|
|
958
|
+
*/
|
|
959
|
+
getFloat64Array( length, moveNext = true ) {
|
|
960
|
+
|
|
961
|
+
const currentOffset = this._offset
|
|
962
|
+
const array = []
|
|
963
|
+
|
|
964
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
965
|
+
|
|
966
|
+
array.push( this.getFloat64() )
|
|
967
|
+
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
if ( !moveNext ) {
|
|
971
|
+
this._offset = currentOffset
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
return array
|
|
975
|
+
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
*
|
|
980
|
+
* @returns {string}
|
|
981
|
+
*/
|
|
982
|
+
getChar( moveNext = true ) {
|
|
983
|
+
|
|
984
|
+
return String.fromCharCode( this.getUint8( moveNext ) )
|
|
985
|
+
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
*
|
|
990
|
+
* @param length
|
|
991
|
+
* @param moveNext
|
|
992
|
+
* @return {string}
|
|
993
|
+
*/
|
|
994
|
+
getString( length, moveNext = true ) {
|
|
995
|
+
|
|
996
|
+
const currentOffset = this._offset
|
|
997
|
+
let string = ''
|
|
998
|
+
|
|
999
|
+
for ( let i = 0 ; i < length ; i++ ) {
|
|
1000
|
+
string += String.fromCharCode( this.getUint8() )
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if ( !moveNext ) {
|
|
1004
|
+
this._offset = currentOffset
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
return string
|
|
1008
|
+
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
*
|
|
1013
|
+
* @param size
|
|
1014
|
+
* @returns {ArrayBuffer}
|
|
1015
|
+
*/
|
|
1016
|
+
getArrayBuffer( size ) {
|
|
1017
|
+
|
|
1018
|
+
const offset = this._getAndUpdateOffsetBy( size )
|
|
1019
|
+
return this._dataView.buffer.slice( offset, offset + size )
|
|
1020
|
+
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
export {
|
|
1026
|
+
TBinaryReader,
|
|
1027
|
+
Endianness,
|
|
1028
|
+
Byte
|
|
1029
|
+
}
|