| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822 |
- var base = base || {};
- base.Int64 = class Int64 {
- constructor(low, high) {
- this.low = low | 0;
- this.high = high | 0;
- }
- static create(value) {
- if (isNaN(value)) {
- return base.Int64.zero;
- }
- if (value <= -9223372036854776000) {
- return base.Int64.min;
- }
- if (value + 1 >= 9223372036854776000) {
- return base.Int64.max;
- }
- if (value < 0) {
- return base.Int64.create(-value).negate();
- }
- return new base.Int64((value % 4294967296) | 0, (value / 4294967296));
- }
- get isZero() {
- return this.low === 0 && this.high === 0;
- }
- get isNegative() {
- return this.high < 0;
- }
- negate() {
- if (this.equals(base.Int64.min)) {
- return base.Int64.min;
- }
- return this.not().add(base.Int64.one);
- }
- not() {
- return new Int64(~this.low, ~this.high);
- }
- equals(other) {
- if (!(other instanceof base.Int64) && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) {
- return false;
- }
- return this.high === other.high && this.low === other.low;
- }
- compare(other) {
- if (this.equals(other)) {
- return 0;
- }
- const thisNeg = this.isNegative;
- const otherNeg = other.isNegative;
- if (thisNeg && !otherNeg) {
- return -1;
- }
- if (!thisNeg && otherNeg) {
- return 1;
- }
- return this.subtract(other).isNegative ? -1 : 1;
- }
- add(other) {
- return base.Utility.add(this, other, false);
- }
- subtract(other) {
- return base.Utility.subtract(this, other, false);
- }
- multiply(other) {
- return base.Utility.multiply(this, other, false);
- }
- divide(other) {
- return base.Utility.divide(this, other, false);
- }
- toInteger() {
- return this.low;
- }
- toNumber() {
- if (this.high === 0) {
- return this.low >>> 0;
- }
- if (this.high === -1) {
- return this.low;
- }
- return (this.high * 4294967296) + (this.low >>> 0);
- }
- toString(radix) {
- const r = radix || 10;
- if (r < 2 || r > 16) {
- throw new RangeError('radix');
- }
- if (this.isZero) {
- return '0';
- }
- if (this.high < 0) {
- if (this.equals(base.Int64.min)) {
- const r = new Int64(radix, 0);
- const div = this.divide(r);
- const remainder = div.multiply(r).subtract(this);
- return div.toString(r) + (remainder.low >>> 0).toString(r);
- }
- return '-' + this.negate().toString(r);
- }
- if (this.high === 0) {
- return this.low.toString(radix);
- }
- return base.Utility.text(this, false, r);
- }
- };
- base.Int64.min = new base.Int64(0, -2147483648);
- base.Int64.zero = new base.Int64(0, 0);
- base.Int64.one = new base.Int64(1, 0);
- base.Int64.power24 = new base.Int64(1 << 24, 0);
- base.Int64.max = new base.Int64(0, 2147483647);
- base.Uint64 = class Uint64 {
- constructor(low, high) {
- this.low = low | 0;
- this.high = high | 0;
- }
- static create(value) {
- if (isNaN(value)) {
- return base.Uint64.zero;
- }
- if (value < 0) {
- return base.Uint64.zero;
- }
- if (value >= 18446744073709552000) {
- return base.Uint64.max;
- }
- if (value < 0) {
- return base.Uint64.create(-value).negate();
- }
- return new base.Uint64((value % 4294967296) | 0, (value / 4294967296));
- }
- get isZero() {
- return this.low === 0 && this.high === 0;
- }
- get isNegative() {
- return false;
- }
- negate() {
- return this.not().add(base.Int64.one);
- }
- not() {
- return new base.Uint64(~this.low, ~this.high);
- }
- equals(other) {
- if (!(other instanceof base.Uint64) && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) {
- return false;
- }
- return this.high === other.high && this.low === other.low;
- }
- compare(other) {
- if (this.equals(other)) {
- return 0;
- }
- const thisNeg = this.isNegative;
- const otherNeg = other.isNegative;
- if (thisNeg && !otherNeg) {
- return -1;
- }
- if (!thisNeg && otherNeg) {
- return 1;
- }
- return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
- }
- add(other) {
- return base.Utility.add(this, other, true);
- }
- subtract(other) {
- return base.Utility.subtract(this, other, true);
- }
- multiply(other) {
- return base.Utility.multiply(this, other, true);
- }
- divide(other) {
- return base.Utility.divide(this, other, true);
- }
- toInteger() {
- return this.low >>> 0;
- }
- toNumber() {
- if (this.high === 0) {
- return this.low >>> 0;
- }
- return ((this.high >>> 0) * 4294967296) + (this.low >>> 0);
- }
- toString(radix) {
- const r = radix || 10;
- if (r < 2 || 36 < r) {
- throw new RangeError('radix');
- }
- if (this.isZero) {
- return '0';
- }
- if (this.high === 0) {
- return this.low.toString(radix);
- }
- return base.Utility.text(this, true, r);
- }
- };
- base.Utility = class {
- static add(a, b, unsigned) {
- const a48 = a.high >>> 16;
- const a32 = a.high & 0xFFFF;
- const a16 = a.low >>> 16;
- const a00 = a.low & 0xFFFF;
- const b48 = b.high >>> 16;
- const b32 = b.high & 0xFFFF;
- const b16 = b.low >>> 16;
- const b00 = b.low & 0xFFFF;
- let c48 = 0;
- let c32 = 0;
- let c16 = 0;
- let c00 = 0;
- c00 += a00 + b00;
- c16 += c00 >>> 16;
- c00 &= 0xFFFF;
- c16 += a16 + b16;
- c32 += c16 >>> 16;
- c16 &= 0xFFFF;
- c32 += a32 + b32;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c48 += a48 + b48;
- c48 &= 0xFFFF;
- return base.Utility._create((c16 << 16) | c00, (c48 << 16) | c32, unsigned);
- }
- static subtract(a, b, unsigned) {
- return base.Utility.add(a, b.negate(), unsigned);
- }
- static multiply(a, b, unsigned) {
- if (a.isZero) {
- return base.Int64.zero;
- }
- if (b.isZero) {
- return base.Int64.zero;
- }
- if (a.equals(base.Int64.min)) {
- return b.isOdd() ? base.Int64.min : base.Int64.zero;
- }
- if (b.equals(base.Int64.min)) {
- return b.isOdd() ? base.Int64.min : base.Int64.zero;
- }
- if (a.isNegative) {
- if (b.isNegative) {
- return this.negate().multiply(b.negate());
- }
- return this.negate().multiply(b).negate();
- }
- else if (b.isNegative) {
- return this.multiply(b.negate()).negate();
- }
- if (a.compare(base.Int64.power24) < 0 && b.compare(base.Int64.power24) < 0) {
- return unsigned ? base.Uint64.create(a.toNumber() * b.toNumber()) : base.Int64.create(a.toNumber() * b.toNumber());
- }
- const a48 = a.high >>> 16;
- const a32 = a.high & 0xFFFF;
- const a16 = a.low >>> 16;
- const a00 = a.low & 0xFFFF;
- const b48 = b.high >>> 16;
- const b32 = b.high & 0xFFFF;
- const b16 = b.low >>> 16;
- const b00 = b.low & 0xFFFF;
- let c48 = 0;
- let c32 = 0;
- let c16 = 0;
- let c00 = 0;
- c00 += a00 * b00;
- c16 += c00 >>> 16;
- c00 &= 0xFFFF;
- c16 += a16 * b00;
- c32 += c16 >>> 16;
- c16 &= 0xFFFF;
- c16 += a00 * b16;
- c32 += c16 >>> 16;
- c16 &= 0xFFFF;
- c32 += a32 * b00;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c32 += a16 * b16;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c32 += a00 * b32;
- c48 += c32 >>> 16;
- c32 &= 0xFFFF;
- c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
- c48 &= 0xFFFF;
- return base.Utility._create((c16 << 16) | c00, (c48 << 16) | c32, unsigned);
- }
- static divide(a, b, unsigned) {
- if (b.isZero) {
- throw new Error('Division by zero.');
- }
- if (a.isZero) {
- return unsigned ? base.Uint64.zero : base.Int64.zero;
- }
- let approx;
- let remainder;
- let result;
- if (!unsigned) {
- if (a.equals(base.Int64.min)) {
- if (b.equals(base.Int64.one) || b.equals(base.Int64.negativeOne)) {
- return base.Int64.min;
- }
- else if (b.equals(base.Int64.min)) {
- return base.Int64.one;
- }
- const half = base.Utility._shiftRight(a, unsigned, 1);
- const halfDivide = half.divide(b);
- approx = base.Utility._shiftLeft(halfDivide, halfDivide instanceof base.Uint64, 1);
- if (approx.eq(base.Int64.zero)) {
- return b.isNegative ? base.Int64.one : base.Int64.negativeOne;
- }
- remainder = a.subtract(b.multiply(approx));
- result = approx.add(remainder.divide(b));
- return result;
- }
- else if (b.equals(base.Int64.min)) {
- return unsigned ? base.Uint64.zero : base.Int64.zero;
- }
- if (a.isNegative) {
- if (b.isNegative) {
- return this.negate().divide(b.negate());
- }
- return a.negate().divide(b).negate();
- }
- else if (b.isNegative) {
- return a.divide(b.negate()).negate();
- }
- result = base.Int64.zero;
- }
- else {
- if (!(b instanceof base.Uint64)) {
- b = new base.Uint64(b.low, b.high);
- }
- if (b.compare(a) > 0) {
- return base.Int64.zero;
- }
- if (b.compare(base.Utility._shiftRight(a, unsigned, 1)) > 0) {
- return base.Uint64.one;
- }
- result = base.Uint64.zero;
- }
- remainder = a;
- while (remainder.compare(b) >= 0) {
- let approx = Math.max(1, Math.floor(remainder.toNumber() / b.toNumber()));
- const log2 = Math.ceil(Math.log(approx) / Math.LN2);
- const delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48);
- let approxResult = base.Int64.create(approx);
- let approxRemainder = approxResult.multiply(b);
- while (approxRemainder.isNegative || approxRemainder.compare(remainder) > 0) {
- approx -= delta;
- approxResult = unsigned ? base.Uint64.create(approx) : base.Int64.create(approx);
- approxRemainder = approxResult.multiply(b);
- }
- if (approxResult.isZero) {
- approxResult = base.Int64.one;
- }
- result = result.add(approxResult);
- remainder = remainder.subtract(approxRemainder);
- }
- return result;
- }
- static text(value, unsigned, radix) {
- const power = unsigned ? base.Uint64.create(Math.pow(radix, 6)) : base.Int64.create(Math.pow(radix, 6));
- let remainder = value;
- let result = '';
- for (;;) {
- const remainderDiv = remainder.divide(power);
- const intval = remainder.subtract(remainderDiv.multiply(power)).toInteger() >>> 0;
- let digits = intval.toString(radix);
- remainder = remainderDiv;
- if (remainder.low === 0 && remainder.high === 0) {
- return digits + result;
- }
- while (digits.length < 6) {
- digits = '0' + digits;
- }
- result = '' + digits + result;
- }
- }
- static _shiftLeft(value, unsigned, shift) {
- return base.Utility._create(value.low << shift, (value.high << shift) | (value.low >>> (32 - shift)), unsigned);
- }
- static _shiftRight(value, unsigned, shift) {
- return base.Utility._create((value.low >>> shift) | (value.high << (32 - shift)), value.high >> shift, unsigned);
- }
- static _create(low, high, unsigned) {
- return unsigned ? new base.Uint64(low, high) : new base.Int64(low, high);
- }
- };
- base.Uint64.zero = new base.Uint64(0, 0);
- base.Uint64.one = new base.Uint64(1, 0);
- base.Uint64.max = new base.Uint64(-1, -1);
- base.Complex = class Complex {
- constructor(real, imaginary) {
- this.real = real;
- this.imaginary = imaginary;
- }
- static create(real, imaginary) {
- return new base.Complex(real, imaginary);
- }
- toString(/* radix */) {
- return this.real + ' + ' + this.imaginary + 'i';
- }
- };
- if (!DataView.prototype.getFloat16) {
- DataView.prototype.getFloat16 = function(byteOffset, littleEndian) {
- const value = this.getUint16(byteOffset, littleEndian);
- const e = (value & 0x7C00) >> 10;
- let f = value & 0x03FF;
- if (e == 0) {
- f = 0.00006103515625 * (f / 1024);
- }
- else if (e == 0x1F) {
- f = f ? NaN : Infinity;
- }
- else {
- f = DataView.__float16_pow[e] * (1 + (f / 1024));
- }
- return value & 0x8000 ? -f : f;
- };
- DataView.__float16_pow = {
- 1: 1/16384, 2: 1/8192, 3: 1/4096, 4: 1/2048, 5: 1/1024, 6: 1/512, 7: 1/256, 8: 1/128,
- 9: 1/64, 10: 1/32, 11: 1/16, 12: 1/8, 13: 1/4, 14: 1/2, 15: 1, 16: 2,
- 17: 4, 18: 8, 19: 16, 20: 32, 21: 64, 22: 128, 23: 256, 24: 512,
- 25: 1024, 26: 2048, 27: 4096, 28: 8192, 29: 16384, 30: 32768, 31: 65536
- };
- }
- if (!DataView.prototype.setFloat16) {
- DataView.prototype.setFloat16 = function(byteOffset, value, littleEndian) {
- DataView.__float16_float[0] = value;
- value = DataView.__float16_int[0];
- const s = (value >>> 16) & 0x8000;
- const e = (value >>> 23) & 0xff;
- const f = value & 0x7fffff;
- const v = s | DataView.__float16_base[e] | (f >> DataView.__float16_shift[e]);
- this.setUint16(byteOffset, v, littleEndian);
- };
- DataView.__float16_float = new Float32Array(1);
- DataView.__float16_int = new Uint32Array(DataView.__float16_float.buffer, 0, DataView.__float16_float.length);
- DataView.__float16_base = new Uint32Array(256);
- DataView.__float16_shift = new Uint32Array(256);
- for (let i = 0; i < 256; ++i) {
- const e = i - 127;
- if (e < -27) {
- DataView.__float16_base[i] = 0x0000;
- DataView.__float16_shift[i] = 24;
- }
- else if (e < -14) {
- DataView.__float16_base[i] = 0x0400 >> -e - 14;
- DataView.__float16_shift[i] = -e - 1;
- }
- else if (e <= 15) {
- DataView.__float16_base[i] = e + 15 << 10;
- DataView.__float16_shift[i] = 13;
- }
- else if (e < 128) {
- DataView.__float16_base[i] = 0x7c00;
- DataView.__float16_shift[i] = 24;
- }
- else {
- DataView.__float16_base[i] = 0x7c00;
- DataView.__float16_shift[i] = 13;
- }
- }
- }
- if (!DataView.prototype.getBfloat16) {
- DataView.prototype.getBfloat16 = function(byteOffset, littleEndian) {
- if (littleEndian) {
- DataView.__bfloat16_get_uint16_le[1] = this.getUint16(byteOffset, littleEndian);
- return DataView.__bfloat16_get_float32_le[0];
- }
- DataView.__bfloat16_uint16_be[0] = this.getUint16(byteOffset, littleEndian);
- return DataView.__bfloat16_get_float32_be[0];
- };
- DataView.__bfloat16_get_float32_le = new Float32Array(1);
- DataView.__bfloat16_get_float32_be = new Float32Array(1);
- DataView.__bfloat16_get_uint16_le = new Uint16Array(DataView.__bfloat16_get_float32_le.buffer, DataView.__bfloat16_get_float32_le.byteOffset, 2);
- DataView.__bfloat16_get_uint16_be = new Uint16Array(DataView.__bfloat16_get_float32_be.buffer, DataView.__bfloat16_get_float32_be.byteOffset, 2);
- }
- DataView.prototype.getInt64 = DataView.prototype.getInt64 || function(byteOffset, littleEndian) {
- return littleEndian ?
- new base.Int64(this.getUint32(byteOffset, true), this.getUint32(byteOffset + 4, true)) :
- new base.Int64(this.getUint32(byteOffset + 4, true), this.getUint32(byteOffset, true));
- };
- DataView.prototype.setInt64 = DataView.prototype.setInt64 || function(byteOffset, value, littleEndian) {
- if (littleEndian) {
- this.setUint32(byteOffset, value.low, true);
- this.setUint32(byteOffset + 4, value.high, true);
- }
- else {
- this.setUint32(byteOffset + 4, value.low, false);
- this.setUint32(byteOffset, value.high, false);
- }
- };
- DataView.prototype.getUint64 = DataView.prototype.getUint64 || function(byteOffset, littleEndian) {
- return littleEndian ?
- new base.Uint64(this.getUint32(byteOffset, true), this.getUint32(byteOffset + 4, true)) :
- new base.Uint64(this.getUint32(byteOffset + 4, true), this.getUint32(byteOffset, true));
- };
- DataView.prototype.setUint64 = DataView.prototype.setUint64 || function(byteOffset, value, littleEndian) {
- if (littleEndian) {
- this.setUint32(byteOffset, value.low, true);
- this.setUint32(byteOffset + 4, value.high, true);
- }
- else {
- this.setUint32(byteOffset + 4, value.low, false);
- this.setUint32(byteOffset, value.high, false);
- }
- };
- DataView.prototype.getComplex64 = DataView.prototype.getComplex64 || function(byteOffset, littleEndian) {
- const real = littleEndian ? this.getFloat32(byteOffset, littleEndian) : this.getFloat32(byteOffset + 4, littleEndian);
- const imaginary = littleEndian ? this.getFloat32(byteOffset + 4, littleEndian) : this.getFloat32(byteOffset, littleEndian);
- return base.Complex.create(real, imaginary);
- };
- DataView.prototype.setComplex64 = DataView.prototype.setComplex64 || function(byteOffset, value, littleEndian) {
- if (littleEndian) {
- this.setFloat32(byteOffset, value.real, littleEndian);
- this.setFloat32(byteOffset + 4, value.imaginary, littleEndian);
- }
- else {
- this.setFloat32(byteOffset + 4, value.real, littleEndian);
- this.setFloat32(byteOffset, value.imaginary, littleEndian);
- }
- };
- DataView.prototype.getComplex128 = DataView.prototype.getComplex128 || function(byteOffset, littleEndian) {
- const real = littleEndian ? this.getFloat64(byteOffset, littleEndian) : this.getFloat64(byteOffset + 8, littleEndian);
- const imaginary = littleEndian ? this.getFloat64(byteOffset + 8, littleEndian) : this.getFloat64(byteOffset, littleEndian);
- return base.Complex.create(real, imaginary);
- };
- DataView.prototype.setComplex128 = DataView.prototype.setComplex128 || function(byteOffset, value, littleEndian) {
- if (littleEndian) {
- this.setFloat64(byteOffset, value.real, littleEndian);
- this.setFloat64(byteOffset + 8, value.imaginary, littleEndian);
- }
- else {
- this.setFloat64(byteOffset + 8, value.real, littleEndian);
- this.setFloat64(byteOffset, value.imaginary, littleEndian);
- }
- };
- DataView.prototype.getBits = DataView.prototype.getBits || function(offset, bits /*, signed */) {
- offset = offset * bits;
- const available = (this.byteLength << 3) - offset;
- if (bits > available) {
- throw new RangeError();
- }
- let value = 0;
- let index = 0;
- while (index < bits) {
- const remainder = offset & 7;
- const size = Math.min(bits - index, 8 - remainder);
- value <<= size;
- value |= (this.getUint8(offset >> 3) >> (8 - size - remainder)) & ~(0xff << size);
- offset += size;
- index += size;
- }
- return value;
- };
- base.BinaryReader = class {
- constructor(data) {
- this._buffer = data instanceof Uint8Array ? data : data.peek();
- this._position = 0;
- this._length = this._buffer.length;
- this._view = new DataView(this._buffer.buffer, this._buffer.byteOffset, this._buffer.byteLength);
- }
- get length() {
- return this._length;
- }
- get position() {
- return this._position;
- }
- seek(position) {
- this._position = position >= 0 ? position : this._length + position;
- if (this._position > this._length || this._position < 0) {
- throw new Error('Expected ' + (this._position - this._length) + ' more bytes. The file might be corrupted. Unexpected end of file.');
- }
- }
- skip(offset) {
- this._position += offset;
- if (this._position > this._length) {
- throw new Error('Expected ' + (this._position - this._length) + ' more bytes. The file might be corrupted. Unexpected end of file.');
- }
- }
- align(mod) {
- if (this._position % mod != 0) {
- this.skip(mod - (this._position % mod));
- }
- }
- peek(length) {
- if (this._position === 0 && length === undefined) {
- return this._buffer;
- }
- const position = this._position;
- this.skip(length !== undefined ? length : this._length - this._position);
- const end = this._position;
- this._position = position;
- return this._buffer.slice(position, end);
- }
- read(length) {
- if (this._position === 0 && length === undefined) {
- this._position = this._length;
- return this._buffer;
- }
- const position = this._position;
- this.skip(length !== undefined ? length : this._length - this._position);
- return this._buffer.slice(position, this._position);
- }
- byte() {
- const position = this._position;
- this.skip(1);
- return this._buffer[position];
- }
- int8() {
- const position = this._position;
- this.skip(1);
- return this._view.getInt8(position, true);
- }
- int16() {
- const position = this._position;
- this.skip(2);
- return this._view.getInt16(position, true);
- }
- int32() {
- const position = this._position;
- this.skip(4);
- return this._view.getInt32(position, true);
- }
- int64() {
- const position = this._position;
- this.skip(8);
- return this._view.getInt64(position, true).toNumber();
- }
- uint16() {
- const position = this._position;
- this.skip(2);
- return this._view.getUint16(position, true);
- }
- uint32() {
- const position = this._position;
- this.skip(4);
- return this._view.getUint32(position, true);
- }
- uint64() {
- const position = this._position;
- this.skip(8);
- const low = this._view.getUint32(position, true);
- const high = this._view.getUint32(position + 4, true);
- if (high === 0) {
- return low;
- }
- const value = (high * 4294967296) + low;
- if (Number.isSafeInteger(value)) {
- return value;
- }
- throw new Error("Unsigned 64-bit value exceeds safe integer.");
- }
- float32() {
- const position = this._position;
- this.skip(4);
- return this._view.getFloat32(position, true);
- }
- float64() {
- const position = this._position;
- this.skip(8);
- return this._view.getFloat64(position, true);
- }
- string() {
- const length = this.uint32();
- const position = this._position;
- this.skip(length);
- const data = this._buffer.subarray(position, this._position);
- this._decoder = this._decoder || new TextDecoder('utf-8');
- return this._decoder.decode(data);
- }
- boolean() {
- return this.byte() !== 0 ? true : false;
- }
- };
- base.Metadata = class {
- static open(context, name) {
- base.Metadata._metadata = base.Metadata._metadata || new Map();
- if (base.Metadata._metadata.has(name)) {
- return Promise.resolve(base.Metadata._metadata.get(name));
- }
- return context.request(name, 'utf-8', null).then((data) => {
- const library = new base.Metadata(data);
- base.Metadata._metadata.set(name, library);
- return library;
- }).catch(() => {
- const library = new base.Metadata(null);
- base.Metadata._metadata.set(name, library);
- return library;
- });
- }
- constructor(data) {
- this._types = new Map();
- this._attributes = new Map();
- if (data) {
- const metadata = JSON.parse(data);
- for (const entry of metadata) {
- this._types.set(entry.name, entry);
- if (entry.identifier !== undefined) {
- this._types.set(entry.identifier, entry);
- }
- }
- }
- }
- type(name) {
- if (!this._types.has(name)) {
- this._types.set(name, { name: name.toString() });
- }
- return this._types.get(name);
- }
- attribute(type, name) {
- const key = type + ':' + name;
- if (!this._attributes.has(key)) {
- this._attributes.set(key, null);
- const metadata = this.type(type);
- if (metadata && Array.isArray(metadata.attributes)) {
- for (const attribute of metadata.attributes) {
- this._attributes.set(type + ':' + attribute.name, attribute);
- }
- }
- }
- return this._attributes.get(key);
- }
- };
- if (typeof window !== 'undefined' && typeof window.Long != 'undefined') {
- window.long = { Long: window.Long };
- window.Int64 = base.Int64;
- window.Uint64 = base.Uint64;
- }
- if (typeof module !== 'undefined' && typeof module.exports === 'object') {
- module.exports.Int64 = base.Int64;
- module.exports.Uint64 = base.Uint64;
- module.exports.BinaryReader = base.BinaryReader;
- module.exports.Metadata = base.Metadata;
- }
|