| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- var flatbuffers = {};
- var json = json || require('./json');
- flatbuffers.get = (name) => {
- flatbuffers._map = flatbuffers._map || new Map();
- if (!flatbuffers._map.has(name)) {
- flatbuffers._map.set(name, {});
- }
- return flatbuffers._map.get(name);
- };
- flatbuffers.BinaryReader = class {
- static open(data) {
- return data ? new flatbuffers.BinaryReader(data) : null;
- }
- constructor(data) {
- const buffer = data instanceof Uint8Array ? data : data.peek();
- this._buffer = buffer;
- this._position = 0;
- this._dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
- }
- get root() {
- return this.int32(this._position) + this._position;
- }
- get identifier() {
- if (this._buffer.length >= 8) {
- const buffer = this._buffer.slice(4, 8);
- if (buffer.every((c) => c >= 32 && c <= 128)) {
- return String.fromCharCode(...buffer);
- }
- }
- return '';
- }
- bool(offset) {
- return !!this.int8(offset);
- }
- bool_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.bool(position + offset) : defaultValue;
- }
- int8(offset) {
- return this.uint8(offset) << 24 >> 24;
- }
- int8_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.int8(position + offset) : defaultValue;
- }
- uint8(offset) {
- return this._buffer[offset];
- }
- uint8_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.uint8(position + offset) : defaultValue;
- }
- int16(offset) {
- return this._dataView.getInt16(offset, true);
- }
- int16_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.int16(position + offset) : defaultValue;
- }
- uint16(offset) {
- return this._dataView.getUint16(offset, true);
- }
- uint16_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.uint16(position + offset) : defaultValue;
- }
- int32(offset) {
- return this._dataView.getInt32(offset, true);
- }
- int32_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.int32(position + offset) : defaultValue;
- }
- uint32(offset) {
- return this._dataView.getUint32(offset, true);
- }
- uint32_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.int32(position + offset) : defaultValue;
- }
- int64(offset) {
- return this._dataView.getInt64(offset, true);
- }
- int64_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.int64(position + offset) : defaultValue;
- }
- uint64(offset) {
- return this._dataView.getUint64(offset, true);
- }
- uint64_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.uint64(position + offset) : defaultValue;
- }
- float32(offset) {
- return this._dataView.getFloat32(offset, true);
- }
- float32_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.float32(position + offset) : defaultValue;
- }
- float64(offset) {
- return this._dataView.getFloat64(offset, true);
- }
- float64_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.float64(position + offset) : defaultValue;
- }
- string(offset, encoding) {
- offset += this.int32(offset);
- const length = this.int32(offset);
- var result = '';
- var i = 0;
- offset += 4;
- if (encoding === 1) {
- return this._buffer.subarray(offset, offset + length);
- }
- while (i < length) {
- var codePoint;
- // Decode UTF-8
- const a = this.uint8(offset + i++);
- if (a < 0xC0) {
- codePoint = a;
- }
- else {
- const b = this.uint8(offset + i++);
- if (a < 0xE0) {
- codePoint = ((a & 0x1F) << 6) | (b & 0x3F);
- }
- else {
- const c = this.uint8(offset + i++);
- if (a < 0xF0) {
- codePoint = ((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F);
- }
- else {
- const d = this.uint8(offset + i++);
- codePoint = ((a & 0x07) << 18) | ((b & 0x3F) << 12) | ((c & 0x3F) << 6) | (d & 0x3F);
- }
- }
- }
- // Encode UTF-16
- if (codePoint < 0x10000) {
- result += String.fromCharCode(codePoint);
- }
- else {
- codePoint -= 0x10000;
- result += String.fromCharCode((codePoint >> 10) + 0xD800, (codePoint & ((1 << 10) - 1)) + 0xDC00);
- }
- }
- return result;
- }
- string_(position, offset, defaultValue) {
- offset = this._offset(position, offset);
- return offset ? this.string(position + offset) : defaultValue;
- }
- bools_(position, offset) {
- offset = this._offset(position, offset);
- if (offset) {
- const length = this._length(position + offset);
- offset = this._vector(position + offset);
- const array = new Array(length);
- for (let i = 0; i < length; i++) {
- array[i] = this.uint8(offset + i + 4) ? true : false;
- }
- return array;
- }
- return [];
- }
- int64s_(position, offset) {
- offset = this._offset(position, offset);
- if (offset) {
- const length = this._length(position + offset);
- offset = this._vector(position + offset);
- const array = new Array(length);
- for (let i = 0; i < length; i++) {
- array[i] = this.int64(offset + (i << 3));
- }
- return array;
- }
- return [];
- }
- uint64s_(position, offset) {
- offset = this._offset(position, offset);
- if (offset) {
- const length = this._length(position + offset);
- offset = this._vector(position + offset);
- const array = new Array(length);
- for (let i = 0; i < length; i++) {
- array[i] = this.uint64(offset + (i << 3));
- }
- return array;
- }
- return [];
- }
- strings_(position, offset) {
- offset = this._offset(position, offset);
- if (offset) {
- const length = this._length(position + offset);
- offset = this._vector(position + offset);
- const array = new Array(length);
- for (let i = 0; i < length; i++) {
- array[i] = this.string(offset + i * 4);
- }
- return array;
- }
- return [];
- }
- struct(position, offset, decode) {
- offset = this._offset(position, offset);
- return offset ? decode(this, position + offset) : null;
- }
- table(position, offset, decode) {
- offset = this._offset(position, offset);
- return offset ? decode(this, this._indirect(position + offset)) : null;
- }
- union(position, offset, decode) {
- const type_offset = this._offset(position, offset);
- const type = type_offset ? this.uint8(position + type_offset) : 0;
- offset = this._offset(position, offset + 2);
- return offset ? decode(this, this._union(position + offset), type) : null;
- }
- typedArray(position, offset, type) {
- offset = this._offset(position, offset);
- return offset ? new type(this._buffer.buffer, this._buffer.byteOffset + this._vector(position + offset), this._length(position + offset)) : new type(0);
- }
- unionArray(/* position, offset, decode */) {
- throw new flatbuffers.Error('Not implemented.');
- }
- structArray(position, offset, size, decode) {
- offset = this._offset(position, offset);
- const length = offset ? this._length(position + offset) : 0;
- const list = new Array(length);
- for (let i = 0; i < length; i++) {
- list[i] = decode(this, this._indirect(this._vector(position + offset) + i * 4));
- }
- return list;
- }
- tableArray(position, offset, decode) {
- offset = this._offset(position, offset);
- const length = offset ? this._length(position + offset) : 0;
- const list = new Array(length);
- for (let i = 0; i < length; i++) {
- list[i] = decode(this, this._indirect(this._vector(position + offset) + i * 4));
- }
- return list;
- }
- _offset(bb_pos, vtableOffset) {
- var vtable = bb_pos - this.int32(bb_pos);
- return vtableOffset < this.int16(vtable) ? this.int16(vtable + vtableOffset) : 0;
- }
- _indirect(offset) {
- return offset + this.int32(offset);
- }
- _vector(offset) {
- return offset + this.int32(offset) + 4;
- }
- _length(offset) {
- return this.int32(offset + this.int32(offset));
- }
- _union(offset) {
- return offset + this.int32(offset);
- }
- };
- flatbuffers.TextReader = class {
- static open(obj) {
- return new flatbuffers.TextReader(obj);
- }
- constructor(obj) {
- this._root = obj;
- }
- get root() {
- return this._root;
- }
- value(obj, defaultValue) {
- return obj !== undefined ? obj : defaultValue;
- }
- object(obj, decode) {
- return obj !== undefined ? decode(this, obj) : obj;
- }
- array(obj) {
- if (Array.isArray(obj)) {
- const target = new Array(obj.length);
- for (let i = 0; i < obj.length; i++) {
- target[i] = obj[i];
- }
- return target;
- }
- if (!obj) {
- return [];
- }
- throw new flatbuffers.Error('Inalid value array.');
- }
- typedArray(obj, type) {
- if (Array.isArray(obj)) {
- const target = new type(obj.length);
- for (let i = 0; i < obj.length; i++) {
- target[i] = obj[i];
- }
- return target;
- }
- if (!obj) {
- return new type(0);
- }
- throw new flatbuffers.Error('Inalid typed array.');
- }
- objectArray(obj, decode) {
- if (Array.isArray(obj)) {
- const target = new Array(obj.length);
- for (let i = 0; i < obj.length; i++) {
- target[i] = decode(this, obj[i]);
- }
- return target;
- }
- if (!obj) {
- return [];
- }
- throw new flatbuffers.Error('Inalid object array.');
- }
- };
- flatbuffers.Error = class extends Error {
- constructor(message) {
- super(message);
- this.name = 'FlatBuffers Error';
- this.message = message;
- }
- };
- if (typeof module !== "undefined" && typeof module.exports === "object") {
- module.exports.BinaryReader = flatbuffers.BinaryReader;
- module.exports.TextReader = flatbuffers.TextReader;
- module.exports.get = flatbuffers.get;
- }
|