flatbuffers
Advanced tools
Comparing version 23.1.20 to 23.1.21
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Builder = void 0; | ||
var byte_buffer_js_1 = require("./byte-buffer.js"); | ||
var constants_js_1 = require("./constants.js"); | ||
var Builder = /** @class */ (function () { | ||
const byte_buffer_js_1 = require("./byte-buffer.js"); | ||
const constants_js_1 = require("./constants.js"); | ||
class Builder { | ||
/** | ||
* Create a FlatBufferBuilder. | ||
*/ | ||
function Builder(opt_initial_size) { | ||
constructor(opt_initial_size) { | ||
/** Minimum alignment encountered so far. */ | ||
@@ -29,3 +29,3 @@ this.minalign = 1; | ||
this.text_encoder = new TextEncoder(); | ||
var initial_size; | ||
let initial_size; | ||
if (!opt_initial_size) { | ||
@@ -44,3 +44,3 @@ initial_size = 1024; | ||
} | ||
Builder.prototype.clear = function () { | ||
clear() { | ||
this.bb.clear(); | ||
@@ -57,3 +57,3 @@ this.space = this.bb.capacity(); | ||
this.string_maps = null; | ||
}; | ||
} | ||
/** | ||
@@ -66,5 +66,5 @@ * In order to save space, fields that are set to their default value | ||
*/ | ||
Builder.prototype.forceDefaults = function (forceDefaults) { | ||
forceDefaults(forceDefaults) { | ||
this.force_defaults = forceDefaults; | ||
}; | ||
} | ||
/** | ||
@@ -75,5 +75,5 @@ * Get the ByteBuffer representing the FlatBuffer. Only call this after you've | ||
*/ | ||
Builder.prototype.dataBuffer = function () { | ||
dataBuffer() { | ||
return this.bb; | ||
}; | ||
} | ||
/** | ||
@@ -83,5 +83,5 @@ * Get the bytes representing the FlatBuffer. Only call this after you've | ||
*/ | ||
Builder.prototype.asUint8Array = function () { | ||
asUint8Array() { | ||
return this.bb.bytes().subarray(this.bb.position(), this.bb.position() + this.offset()); | ||
}; | ||
} | ||
/** | ||
@@ -96,3 +96,3 @@ * Prepare to write an element of `size` after `additional_bytes` have been | ||
*/ | ||
Builder.prototype.prep = function (size, additional_bytes) { | ||
prep(size, additional_bytes) { | ||
// Track the biggest thing we've ever aligned to. | ||
@@ -104,6 +104,6 @@ if (size > this.minalign) { | ||
// aligned after `additional_bytes` | ||
var align_size = ((~(this.bb.capacity() - this.space + additional_bytes)) + 1) & (size - 1); | ||
const align_size = ((~(this.bb.capacity() - this.space + additional_bytes)) + 1) & (size - 1); | ||
// Reallocate the buffer if needed. | ||
while (this.space < align_size + size + additional_bytes) { | ||
var old_buf_size = this.bb.capacity(); | ||
const old_buf_size = this.bb.capacity(); | ||
this.bb = Builder.growByteBuffer(this.bb); | ||
@@ -113,26 +113,26 @@ this.space += this.bb.capacity() - old_buf_size; | ||
this.pad(align_size); | ||
}; | ||
Builder.prototype.pad = function (byte_size) { | ||
for (var i = 0; i < byte_size; i++) { | ||
} | ||
pad(byte_size) { | ||
for (let i = 0; i < byte_size; i++) { | ||
this.bb.writeInt8(--this.space, 0); | ||
} | ||
}; | ||
Builder.prototype.writeInt8 = function (value) { | ||
} | ||
writeInt8(value) { | ||
this.bb.writeInt8(this.space -= 1, value); | ||
}; | ||
Builder.prototype.writeInt16 = function (value) { | ||
} | ||
writeInt16(value) { | ||
this.bb.writeInt16(this.space -= 2, value); | ||
}; | ||
Builder.prototype.writeInt32 = function (value) { | ||
} | ||
writeInt32(value) { | ||
this.bb.writeInt32(this.space -= 4, value); | ||
}; | ||
Builder.prototype.writeInt64 = function (value) { | ||
} | ||
writeInt64(value) { | ||
this.bb.writeInt64(this.space -= 8, value); | ||
}; | ||
Builder.prototype.writeFloat32 = function (value) { | ||
} | ||
writeFloat32(value) { | ||
this.bb.writeFloat32(this.space -= 4, value); | ||
}; | ||
Builder.prototype.writeFloat64 = function (value) { | ||
} | ||
writeFloat64(value) { | ||
this.bb.writeFloat64(this.space -= 8, value); | ||
}; | ||
} | ||
/** | ||
@@ -142,6 +142,6 @@ * Add an `int8` to the buffer, properly aligned, and grows the buffer (if necessary). | ||
*/ | ||
Builder.prototype.addInt8 = function (value) { | ||
addInt8(value) { | ||
this.prep(1, 0); | ||
this.writeInt8(value); | ||
}; | ||
} | ||
/** | ||
@@ -151,6 +151,6 @@ * Add an `int16` to the buffer, properly aligned, and grows the buffer (if necessary). | ||
*/ | ||
Builder.prototype.addInt16 = function (value) { | ||
addInt16(value) { | ||
this.prep(2, 0); | ||
this.writeInt16(value); | ||
}; | ||
} | ||
/** | ||
@@ -160,6 +160,6 @@ * Add an `int32` to the buffer, properly aligned, and grows the buffer (if necessary). | ||
*/ | ||
Builder.prototype.addInt32 = function (value) { | ||
addInt32(value) { | ||
this.prep(4, 0); | ||
this.writeInt32(value); | ||
}; | ||
} | ||
/** | ||
@@ -169,6 +169,6 @@ * Add an `int64` to the buffer, properly aligned, and grows the buffer (if necessary). | ||
*/ | ||
Builder.prototype.addInt64 = function (value) { | ||
addInt64(value) { | ||
this.prep(8, 0); | ||
this.writeInt64(value); | ||
}; | ||
} | ||
/** | ||
@@ -178,6 +178,6 @@ * Add a `float32` to the buffer, properly aligned, and grows the buffer (if necessary). | ||
*/ | ||
Builder.prototype.addFloat32 = function (value) { | ||
addFloat32(value) { | ||
this.prep(4, 0); | ||
this.writeFloat32(value); | ||
}; | ||
} | ||
/** | ||
@@ -187,7 +187,7 @@ * Add a `float64` to the buffer, properly aligned, and grows the buffer (if necessary). | ||
*/ | ||
Builder.prototype.addFloat64 = function (value) { | ||
addFloat64(value) { | ||
this.prep(8, 0); | ||
this.writeFloat64(value); | ||
}; | ||
Builder.prototype.addFieldInt8 = function (voffset, value, defaultValue) { | ||
} | ||
addFieldInt8(voffset, value, defaultValue) { | ||
if (this.force_defaults || value != defaultValue) { | ||
@@ -197,4 +197,4 @@ this.addInt8(value); | ||
} | ||
}; | ||
Builder.prototype.addFieldInt16 = function (voffset, value, defaultValue) { | ||
} | ||
addFieldInt16(voffset, value, defaultValue) { | ||
if (this.force_defaults || value != defaultValue) { | ||
@@ -204,4 +204,4 @@ this.addInt16(value); | ||
} | ||
}; | ||
Builder.prototype.addFieldInt32 = function (voffset, value, defaultValue) { | ||
} | ||
addFieldInt32(voffset, value, defaultValue) { | ||
if (this.force_defaults || value != defaultValue) { | ||
@@ -211,4 +211,4 @@ this.addInt32(value); | ||
} | ||
}; | ||
Builder.prototype.addFieldInt64 = function (voffset, value, defaultValue) { | ||
} | ||
addFieldInt64(voffset, value, defaultValue) { | ||
if (this.force_defaults || value !== defaultValue) { | ||
@@ -218,4 +218,4 @@ this.addInt64(value); | ||
} | ||
}; | ||
Builder.prototype.addFieldFloat32 = function (voffset, value, defaultValue) { | ||
} | ||
addFieldFloat32(voffset, value, defaultValue) { | ||
if (this.force_defaults || value != defaultValue) { | ||
@@ -225,4 +225,4 @@ this.addFloat32(value); | ||
} | ||
}; | ||
Builder.prototype.addFieldFloat64 = function (voffset, value, defaultValue) { | ||
} | ||
addFieldFloat64(voffset, value, defaultValue) { | ||
if (this.force_defaults || value != defaultValue) { | ||
@@ -232,4 +232,4 @@ this.addFloat64(value); | ||
} | ||
}; | ||
Builder.prototype.addFieldOffset = function (voffset, value, defaultValue) { | ||
} | ||
addFieldOffset(voffset, value, defaultValue) { | ||
if (this.force_defaults || value != defaultValue) { | ||
@@ -239,7 +239,7 @@ this.addOffset(value); | ||
} | ||
}; | ||
} | ||
/** | ||
* Structs are stored inline, so nothing additional is being added. `d` is always 0. | ||
*/ | ||
Builder.prototype.addFieldStruct = function (voffset, value, defaultValue) { | ||
addFieldStruct(voffset, value, defaultValue) { | ||
if (value != defaultValue) { | ||
@@ -249,3 +249,3 @@ this.nested(value); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -256,7 +256,7 @@ * Structures are always stored inline, they need to be created right | ||
*/ | ||
Builder.prototype.nested = function (obj) { | ||
nested(obj) { | ||
if (obj != this.offset()) { | ||
throw new Error('FlatBuffers: struct must be serialized inline.'); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -266,20 +266,20 @@ * Should not be creating any other object, string or vector | ||
*/ | ||
Builder.prototype.notNested = function () { | ||
notNested() { | ||
if (this.isNested) { | ||
throw new Error('FlatBuffers: object serialization must not be nested.'); | ||
} | ||
}; | ||
} | ||
/** | ||
* Set the current vtable at `voffset` to the current location in the buffer. | ||
*/ | ||
Builder.prototype.slot = function (voffset) { | ||
slot(voffset) { | ||
if (this.vtable !== null) | ||
this.vtable[voffset] = this.offset(); | ||
}; | ||
} | ||
/** | ||
* @returns Offset relative to the end of the buffer. | ||
*/ | ||
Builder.prototype.offset = function () { | ||
offset() { | ||
return this.bb.capacity() - this.space; | ||
}; | ||
} | ||
/** | ||
@@ -297,4 +297,4 @@ * Doubles the size of the backing ByteBuffer and copies the old data towards | ||
*/ | ||
Builder.growByteBuffer = function (bb) { | ||
var old_buf_size = bb.capacity(); | ||
static growByteBuffer(bb) { | ||
const old_buf_size = bb.capacity(); | ||
// Ensure we don't grow beyond what fits in an int. | ||
@@ -304,8 +304,8 @@ if (old_buf_size & 0xC0000000) { | ||
} | ||
var new_buf_size = old_buf_size << 1; | ||
var nbb = byte_buffer_js_1.ByteBuffer.allocate(new_buf_size); | ||
const new_buf_size = old_buf_size << 1; | ||
const nbb = byte_buffer_js_1.ByteBuffer.allocate(new_buf_size); | ||
nbb.setPosition(new_buf_size - old_buf_size); | ||
nbb.bytes().set(bb.bytes(), new_buf_size - old_buf_size); | ||
return nbb; | ||
}; | ||
} | ||
/** | ||
@@ -316,6 +316,6 @@ * Adds on offset, relative to where it will be written. | ||
*/ | ||
Builder.prototype.addOffset = function (offset) { | ||
addOffset(offset) { | ||
this.prep(constants_js_1.SIZEOF_INT, 0); // Ensure alignment is already done. | ||
this.writeInt32(this.offset() - offset + constants_js_1.SIZEOF_INT); | ||
}; | ||
} | ||
/** | ||
@@ -326,3 +326,3 @@ * Start encoding a new object in the buffer. Users will not usually need to | ||
*/ | ||
Builder.prototype.startObject = function (numfields) { | ||
startObject(numfields) { | ||
this.notNested(); | ||
@@ -333,3 +333,3 @@ if (this.vtable == null) { | ||
this.vtable_in_use = numfields; | ||
for (var i = 0; i < numfields; i++) { | ||
for (let i = 0; i < numfields; i++) { | ||
this.vtable[i] = 0; // This will push additional elements as needed | ||
@@ -339,3 +339,3 @@ } | ||
this.object_start = this.offset(); | ||
}; | ||
} | ||
/** | ||
@@ -346,3 +346,3 @@ * Finish off writing the object that is under construction. | ||
*/ | ||
Builder.prototype.endObject = function () { | ||
endObject() { | ||
if (this.vtable == null || !this.isNested) { | ||
@@ -352,8 +352,8 @@ throw new Error('FlatBuffers: endObject called without startObject'); | ||
this.addInt32(0); | ||
var vtableloc = this.offset(); | ||
const vtableloc = this.offset(); | ||
// Trim trailing zeroes. | ||
var i = this.vtable_in_use - 1; | ||
let i = this.vtable_in_use - 1; | ||
// eslint-disable-next-line no-empty | ||
for (; i >= 0 && this.vtable[i] == 0; i--) { } | ||
var trimmed_size = i + 1; | ||
const trimmed_size = i + 1; | ||
// Write out the current vtable. | ||
@@ -364,13 +364,13 @@ for (; i >= 0; i--) { | ||
} | ||
var standard_fields = 2; // The fields below: | ||
const standard_fields = 2; // The fields below: | ||
this.addInt16(vtableloc - this.object_start); | ||
var len = (trimmed_size + standard_fields) * constants_js_1.SIZEOF_SHORT; | ||
const len = (trimmed_size + standard_fields) * constants_js_1.SIZEOF_SHORT; | ||
this.addInt16(len); | ||
// Search for an existing vtable that matches the current one. | ||
var existing_vtable = 0; | ||
var vt1 = this.space; | ||
let existing_vtable = 0; | ||
const vt1 = this.space; | ||
outer_loop: for (i = 0; i < this.vtables.length; i++) { | ||
var vt2 = this.bb.capacity() - this.vtables[i]; | ||
const vt2 = this.bb.capacity() - this.vtables[i]; | ||
if (len == this.bb.readInt16(vt2)) { | ||
for (var j = constants_js_1.SIZEOF_SHORT; j < len; j += constants_js_1.SIZEOF_SHORT) { | ||
for (let j = constants_js_1.SIZEOF_SHORT; j < len; j += constants_js_1.SIZEOF_SHORT) { | ||
if (this.bb.readInt16(vt1 + j) != this.bb.readInt16(vt2 + j)) { | ||
@@ -400,10 +400,10 @@ continue outer_loop; | ||
return vtableloc; | ||
}; | ||
} | ||
/** | ||
* Finalize a buffer, poiting to the given `root_table`. | ||
*/ | ||
Builder.prototype.finish = function (root_table, opt_file_identifier, opt_size_prefix) { | ||
var size_prefix = opt_size_prefix ? constants_js_1.SIZE_PREFIX_LENGTH : 0; | ||
finish(root_table, opt_file_identifier, opt_size_prefix) { | ||
const size_prefix = opt_size_prefix ? constants_js_1.SIZE_PREFIX_LENGTH : 0; | ||
if (opt_file_identifier) { | ||
var file_identifier = opt_file_identifier; | ||
const file_identifier = opt_file_identifier; | ||
this.prep(this.minalign, constants_js_1.SIZEOF_INT + | ||
@@ -415,3 +415,3 @@ constants_js_1.FILE_IDENTIFIER_LENGTH + size_prefix); | ||
} | ||
for (var i = constants_js_1.FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) { | ||
for (let i = constants_js_1.FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) { | ||
this.writeInt8(file_identifier.charCodeAt(i)); | ||
@@ -426,9 +426,9 @@ } | ||
this.bb.setPosition(this.space); | ||
}; | ||
} | ||
/** | ||
* Finalize a size prefixed buffer, pointing to the given `root_table`. | ||
*/ | ||
Builder.prototype.finishSizePrefixed = function (root_table, opt_file_identifier) { | ||
finishSizePrefixed(root_table, opt_file_identifier) { | ||
this.finish(root_table, opt_file_identifier, true); | ||
}; | ||
} | ||
/** | ||
@@ -438,6 +438,6 @@ * This checks a required field has been set in a given table that has | ||
*/ | ||
Builder.prototype.requiredField = function (table, field) { | ||
var table_start = this.bb.capacity() - table; | ||
var vtable_start = table_start - this.bb.readInt32(table_start); | ||
var ok = field < this.bb.readInt16(vtable_start) && | ||
requiredField(table, field) { | ||
const table_start = this.bb.capacity() - table; | ||
const vtable_start = table_start - this.bb.readInt32(table_start); | ||
const ok = field < this.bb.readInt16(vtable_start) && | ||
this.bb.readInt16(vtable_start + field) != 0; | ||
@@ -448,3 +448,3 @@ // If this fails, the caller will show what field needs to be set. | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -459,3 +459,3 @@ * Start a new array/vector of objects. Users usually will not call | ||
*/ | ||
Builder.prototype.startVector = function (elem_size, num_elems, alignment) { | ||
startVector(elem_size, num_elems, alignment) { | ||
this.notNested(); | ||
@@ -465,3 +465,3 @@ this.vector_num_elems = num_elems; | ||
this.prep(alignment, elem_size * num_elems); // Just in case alignment > int. | ||
}; | ||
} | ||
/** | ||
@@ -474,6 +474,6 @@ * Finish off the creation of an array and all its elements. The array must be | ||
*/ | ||
Builder.prototype.endVector = function () { | ||
endVector() { | ||
this.writeInt32(this.vector_num_elems); | ||
return this.offset(); | ||
}; | ||
} | ||
/** | ||
@@ -486,3 +486,3 @@ * Encode the string `s` in the buffer using UTF-8. If the string passed has | ||
*/ | ||
Builder.prototype.createSharedString = function (s) { | ||
createSharedString(s) { | ||
if (!s) { | ||
@@ -497,6 +497,6 @@ return 0; | ||
} | ||
var offset = this.createString(s); | ||
const offset = this.createString(s); | ||
this.string_maps.set(s, offset); | ||
return offset; | ||
}; | ||
} | ||
/** | ||
@@ -509,7 +509,7 @@ * Encode the string `s` in the buffer using UTF-8. If a Uint8Array is passed | ||
*/ | ||
Builder.prototype.createString = function (s) { | ||
createString(s) { | ||
if (s === null || s === undefined) { | ||
return 0; | ||
} | ||
var utf8; | ||
let utf8; | ||
if (s instanceof Uint8Array) { | ||
@@ -524,7 +524,7 @@ utf8 = s; | ||
this.bb.setPosition(this.space -= utf8.length); | ||
for (var i = 0, offset = this.space, bytes = this.bb.bytes(); i < utf8.length; i++) { | ||
for (let i = 0, offset = this.space, bytes = this.bb.bytes(); i < utf8.length; i++) { | ||
bytes[offset++] = utf8[i]; | ||
} | ||
return this.endVector(); | ||
}; | ||
} | ||
/** | ||
@@ -535,3 +535,3 @@ * A helper function to pack an object | ||
*/ | ||
Builder.prototype.createObjectOffset = function (obj) { | ||
createObjectOffset(obj) { | ||
if (obj === null) { | ||
@@ -546,3 +546,3 @@ return 0; | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -553,6 +553,6 @@ * A helper function to pack a list of object | ||
*/ | ||
Builder.prototype.createObjectOffsetList = function (list) { | ||
var ret = []; | ||
for (var i = 0; i < list.length; ++i) { | ||
var val = list[i]; | ||
createObjectOffsetList(list) { | ||
const ret = []; | ||
for (let i = 0; i < list.length; ++i) { | ||
const val = list[i]; | ||
if (val !== null) { | ||
@@ -566,10 +566,9 @@ ret.push(this.createObjectOffset(val)); | ||
return ret; | ||
}; | ||
Builder.prototype.createStructOffsetList = function (list, startFunc) { | ||
} | ||
createStructOffsetList(list, startFunc) { | ||
startFunc(this, list.length); | ||
this.createObjectOffsetList(list.slice().reverse()); | ||
return this.endVector(); | ||
}; | ||
return Builder; | ||
}()); | ||
} | ||
} | ||
exports.Builder = Builder; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ByteBuffer = void 0; | ||
var constants_js_1 = require("./constants.js"); | ||
var utils_js_1 = require("./utils.js"); | ||
var encoding_js_1 = require("./encoding.js"); | ||
var ByteBuffer = /** @class */ (function () { | ||
const constants_js_1 = require("./constants.js"); | ||
const utils_js_1 = require("./utils.js"); | ||
const encoding_js_1 = require("./encoding.js"); | ||
class ByteBuffer { | ||
/** | ||
* Create a new ByteBuffer with a given array of bytes (`Uint8Array`) | ||
*/ | ||
function ByteBuffer(bytes_) { | ||
constructor(bytes_) { | ||
this.bytes_ = bytes_; | ||
@@ -19,80 +19,80 @@ this.position_ = 0; | ||
*/ | ||
ByteBuffer.allocate = function (byte_size) { | ||
static allocate(byte_size) { | ||
return new ByteBuffer(new Uint8Array(byte_size)); | ||
}; | ||
ByteBuffer.prototype.clear = function () { | ||
} | ||
clear() { | ||
this.position_ = 0; | ||
}; | ||
} | ||
/** | ||
* Get the underlying `Uint8Array`. | ||
*/ | ||
ByteBuffer.prototype.bytes = function () { | ||
bytes() { | ||
return this.bytes_; | ||
}; | ||
} | ||
/** | ||
* Get the buffer's position. | ||
*/ | ||
ByteBuffer.prototype.position = function () { | ||
position() { | ||
return this.position_; | ||
}; | ||
} | ||
/** | ||
* Set the buffer's position. | ||
*/ | ||
ByteBuffer.prototype.setPosition = function (position) { | ||
setPosition(position) { | ||
this.position_ = position; | ||
}; | ||
} | ||
/** | ||
* Get the buffer's capacity. | ||
*/ | ||
ByteBuffer.prototype.capacity = function () { | ||
capacity() { | ||
return this.bytes_.length; | ||
}; | ||
ByteBuffer.prototype.readInt8 = function (offset) { | ||
} | ||
readInt8(offset) { | ||
return this.readUint8(offset) << 24 >> 24; | ||
}; | ||
ByteBuffer.prototype.readUint8 = function (offset) { | ||
} | ||
readUint8(offset) { | ||
return this.bytes_[offset]; | ||
}; | ||
ByteBuffer.prototype.readInt16 = function (offset) { | ||
} | ||
readInt16(offset) { | ||
return this.readUint16(offset) << 16 >> 16; | ||
}; | ||
ByteBuffer.prototype.readUint16 = function (offset) { | ||
} | ||
readUint16(offset) { | ||
return this.bytes_[offset] | this.bytes_[offset + 1] << 8; | ||
}; | ||
ByteBuffer.prototype.readInt32 = function (offset) { | ||
} | ||
readInt32(offset) { | ||
return this.bytes_[offset] | this.bytes_[offset + 1] << 8 | this.bytes_[offset + 2] << 16 | this.bytes_[offset + 3] << 24; | ||
}; | ||
ByteBuffer.prototype.readUint32 = function (offset) { | ||
} | ||
readUint32(offset) { | ||
return this.readInt32(offset) >>> 0; | ||
}; | ||
ByteBuffer.prototype.readInt64 = function (offset) { | ||
} | ||
readInt64(offset) { | ||
return BigInt.asIntN(64, BigInt(this.readUint32(offset)) + (BigInt(this.readUint32(offset + 4)) << BigInt(32))); | ||
}; | ||
ByteBuffer.prototype.readUint64 = function (offset) { | ||
} | ||
readUint64(offset) { | ||
return BigInt.asUintN(64, BigInt(this.readUint32(offset)) + (BigInt(this.readUint32(offset + 4)) << BigInt(32))); | ||
}; | ||
ByteBuffer.prototype.readFloat32 = function (offset) { | ||
} | ||
readFloat32(offset) { | ||
utils_js_1.int32[0] = this.readInt32(offset); | ||
return utils_js_1.float32[0]; | ||
}; | ||
ByteBuffer.prototype.readFloat64 = function (offset) { | ||
} | ||
readFloat64(offset) { | ||
utils_js_1.int32[utils_js_1.isLittleEndian ? 0 : 1] = this.readInt32(offset); | ||
utils_js_1.int32[utils_js_1.isLittleEndian ? 1 : 0] = this.readInt32(offset + 4); | ||
return utils_js_1.float64[0]; | ||
}; | ||
ByteBuffer.prototype.writeInt8 = function (offset, value) { | ||
} | ||
writeInt8(offset, value) { | ||
this.bytes_[offset] = value; | ||
}; | ||
ByteBuffer.prototype.writeUint8 = function (offset, value) { | ||
} | ||
writeUint8(offset, value) { | ||
this.bytes_[offset] = value; | ||
}; | ||
ByteBuffer.prototype.writeInt16 = function (offset, value) { | ||
} | ||
writeInt16(offset, value) { | ||
this.bytes_[offset] = value; | ||
this.bytes_[offset + 1] = value >> 8; | ||
}; | ||
ByteBuffer.prototype.writeUint16 = function (offset, value) { | ||
} | ||
writeUint16(offset, value) { | ||
this.bytes_[offset] = value; | ||
this.bytes_[offset + 1] = value >> 8; | ||
}; | ||
ByteBuffer.prototype.writeInt32 = function (offset, value) { | ||
} | ||
writeInt32(offset, value) { | ||
this.bytes_[offset] = value; | ||
@@ -102,4 +102,4 @@ this.bytes_[offset + 1] = value >> 8; | ||
this.bytes_[offset + 3] = value >> 24; | ||
}; | ||
ByteBuffer.prototype.writeUint32 = function (offset, value) { | ||
} | ||
writeUint32(offset, value) { | ||
this.bytes_[offset] = value; | ||
@@ -109,20 +109,20 @@ this.bytes_[offset + 1] = value >> 8; | ||
this.bytes_[offset + 3] = value >> 24; | ||
}; | ||
ByteBuffer.prototype.writeInt64 = function (offset, value) { | ||
} | ||
writeInt64(offset, value) { | ||
this.writeInt32(offset, Number(BigInt.asIntN(32, value))); | ||
this.writeInt32(offset + 4, Number(BigInt.asIntN(32, value >> BigInt(32)))); | ||
}; | ||
ByteBuffer.prototype.writeUint64 = function (offset, value) { | ||
} | ||
writeUint64(offset, value) { | ||
this.writeUint32(offset, Number(BigInt.asUintN(32, value))); | ||
this.writeUint32(offset + 4, Number(BigInt.asUintN(32, value >> BigInt(32)))); | ||
}; | ||
ByteBuffer.prototype.writeFloat32 = function (offset, value) { | ||
} | ||
writeFloat32(offset, value) { | ||
utils_js_1.float32[0] = value; | ||
this.writeInt32(offset, utils_js_1.int32[0]); | ||
}; | ||
ByteBuffer.prototype.writeFloat64 = function (offset, value) { | ||
} | ||
writeFloat64(offset, value) { | ||
utils_js_1.float64[0] = value; | ||
this.writeInt32(offset, utils_js_1.int32[utils_js_1.isLittleEndian ? 0 : 1]); | ||
this.writeInt32(offset + 4, utils_js_1.int32[utils_js_1.isLittleEndian ? 1 : 0]); | ||
}; | ||
} | ||
/** | ||
@@ -133,3 +133,3 @@ * Return the file identifier. Behavior is undefined for FlatBuffers whose | ||
*/ | ||
ByteBuffer.prototype.getBufferIdentifier = function () { | ||
getBufferIdentifier() { | ||
if (this.bytes_.length < this.position_ + constants_js_1.SIZEOF_INT + | ||
@@ -139,8 +139,8 @@ constants_js_1.FILE_IDENTIFIER_LENGTH) { | ||
} | ||
var result = ""; | ||
for (var i = 0; i < constants_js_1.FILE_IDENTIFIER_LENGTH; i++) { | ||
let result = ""; | ||
for (let i = 0; i < constants_js_1.FILE_IDENTIFIER_LENGTH; i++) { | ||
result += String.fromCharCode(this.readInt8(this.position_ + constants_js_1.SIZEOF_INT + i)); | ||
} | ||
return result; | ||
}; | ||
} | ||
/** | ||
@@ -150,14 +150,14 @@ * Look up a field in the vtable, return an offset into the object, or 0 if the | ||
*/ | ||
ByteBuffer.prototype.__offset = function (bb_pos, vtable_offset) { | ||
var vtable = bb_pos - this.readInt32(bb_pos); | ||
__offset(bb_pos, vtable_offset) { | ||
const vtable = bb_pos - this.readInt32(bb_pos); | ||
return vtable_offset < this.readInt16(vtable) ? this.readInt16(vtable + vtable_offset) : 0; | ||
}; | ||
} | ||
/** | ||
* Initialize any Table-derived type to point to the union at the given offset. | ||
*/ | ||
ByteBuffer.prototype.__union = function (t, offset) { | ||
__union(t, offset) { | ||
t.bb_pos = offset + this.readInt32(offset); | ||
t.bb = this; | ||
return t; | ||
}; | ||
} | ||
/** | ||
@@ -174,7 +174,7 @@ * Create a JavaScript string from UTF-8 data stored inside the FlatBuffer. | ||
*/ | ||
ByteBuffer.prototype.__string = function (offset, opt_encoding) { | ||
__string(offset, opt_encoding) { | ||
offset += this.readInt32(offset); | ||
var length = this.readInt32(offset); | ||
const length = this.readInt32(offset); | ||
offset += constants_js_1.SIZEOF_INT; | ||
var utf8bytes = this.bytes_.subarray(offset, offset + length); | ||
const utf8bytes = this.bytes_.subarray(offset, offset + length); | ||
if (opt_encoding === encoding_js_1.Encoding.UTF8_BYTES) | ||
@@ -184,3 +184,3 @@ return utf8bytes; | ||
return this.text_decoder_.decode(utf8bytes); | ||
}; | ||
} | ||
/** | ||
@@ -193,3 +193,3 @@ * Handle unions that can contain string as its member, if a Table-derived type then initialize it, | ||
*/ | ||
ByteBuffer.prototype.__union_with_string = function (o, offset) { | ||
__union_with_string(o, offset) { | ||
if (typeof o === 'string') { | ||
@@ -199,22 +199,22 @@ return this.__string(offset); | ||
return this.__union(o, offset); | ||
}; | ||
} | ||
/** | ||
* Retrieve the relative offset stored at "offset" | ||
*/ | ||
ByteBuffer.prototype.__indirect = function (offset) { | ||
__indirect(offset) { | ||
return offset + this.readInt32(offset); | ||
}; | ||
} | ||
/** | ||
* Get the start of data of a vector whose offset is stored at "offset" in this object. | ||
*/ | ||
ByteBuffer.prototype.__vector = function (offset) { | ||
__vector(offset) { | ||
return offset + this.readInt32(offset) + constants_js_1.SIZEOF_INT; // data starts after the length | ||
}; | ||
} | ||
/** | ||
* Get the length of a vector whose offset is stored at "offset" in this object. | ||
*/ | ||
ByteBuffer.prototype.__vector_len = function (offset) { | ||
__vector_len(offset) { | ||
return this.readInt32(offset + this.readInt32(offset)); | ||
}; | ||
ByteBuffer.prototype.__has_identifier = function (ident) { | ||
} | ||
__has_identifier(ident) { | ||
if (ident.length != constants_js_1.FILE_IDENTIFIER_LENGTH) { | ||
@@ -224,3 +224,3 @@ throw new Error('FlatBuffers: file identifier must be length ' + | ||
} | ||
for (var i = 0; i < constants_js_1.FILE_IDENTIFIER_LENGTH; i++) { | ||
for (let i = 0; i < constants_js_1.FILE_IDENTIFIER_LENGTH; i++) { | ||
if (ident.charCodeAt(i) != this.readInt8(this.position() + constants_js_1.SIZEOF_INT + i)) { | ||
@@ -231,10 +231,10 @@ return false; | ||
return true; | ||
}; | ||
} | ||
/** | ||
* A helper function for generating list for obj api | ||
*/ | ||
ByteBuffer.prototype.createScalarList = function (listAccessor, listLength) { | ||
var ret = []; | ||
for (var i = 0; i < listLength; ++i) { | ||
var val = listAccessor(i); | ||
createScalarList(listAccessor, listLength) { | ||
const ret = []; | ||
for (let i = 0; i < listLength; ++i) { | ||
const val = listAccessor(i); | ||
if (val !== null) { | ||
@@ -245,3 +245,3 @@ ret.push(val); | ||
return ret; | ||
}; | ||
} | ||
/** | ||
@@ -253,6 +253,6 @@ * A helper function for generating list for obj api | ||
*/ | ||
ByteBuffer.prototype.createObjList = function (listAccessor, listLength) { | ||
var ret = []; | ||
for (var i = 0; i < listLength; ++i) { | ||
var val = listAccessor(i); | ||
createObjList(listAccessor, listLength) { | ||
const ret = []; | ||
for (let i = 0; i < listLength; ++i) { | ||
const val = listAccessor(i); | ||
if (val !== null) { | ||
@@ -263,5 +263,4 @@ ret.push(val.unpack()); | ||
return ret; | ||
}; | ||
return ByteBuffer; | ||
}()); | ||
} | ||
} | ||
exports.ByteBuffer = ByteBuffer; |
@@ -1,1 +0,9 @@ | ||
export * as flatbuffers from './index.js'; | ||
export { SIZEOF_SHORT } from './constants.js'; | ||
export { SIZEOF_INT } from './constants.js'; | ||
export { FILE_IDENTIFIER_LENGTH } from './constants.js'; | ||
export { SIZE_PREFIX_LENGTH } from './constants.js'; | ||
export { Table, Offset, IGeneratedObject, IUnpackableObject } from './types.js'; | ||
export { int32, float32, float64, isLittleEndian } from './utils.js'; | ||
export { Encoding } from './encoding.js'; | ||
export { Builder } from './builder.js'; | ||
export { ByteBuffer } from './byte-buffer.js'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.flatbuffers = void 0; | ||
exports.flatbuffers = __importStar(require("./index.js")); | ||
exports.ByteBuffer = exports.Builder = exports.Encoding = exports.isLittleEndian = exports.float64 = exports.float32 = exports.int32 = exports.SIZE_PREFIX_LENGTH = exports.FILE_IDENTIFIER_LENGTH = exports.SIZEOF_INT = exports.SIZEOF_SHORT = void 0; | ||
var constants_js_1 = require("./constants.js"); | ||
Object.defineProperty(exports, "SIZEOF_SHORT", { enumerable: true, get: function () { return constants_js_1.SIZEOF_SHORT; } }); | ||
var constants_js_2 = require("./constants.js"); | ||
Object.defineProperty(exports, "SIZEOF_INT", { enumerable: true, get: function () { return constants_js_2.SIZEOF_INT; } }); | ||
var constants_js_3 = require("./constants.js"); | ||
Object.defineProperty(exports, "FILE_IDENTIFIER_LENGTH", { enumerable: true, get: function () { return constants_js_3.FILE_IDENTIFIER_LENGTH; } }); | ||
var constants_js_4 = require("./constants.js"); | ||
Object.defineProperty(exports, "SIZE_PREFIX_LENGTH", { enumerable: true, get: function () { return constants_js_4.SIZE_PREFIX_LENGTH; } }); | ||
var utils_js_1 = require("./utils.js"); | ||
Object.defineProperty(exports, "int32", { enumerable: true, get: function () { return utils_js_1.int32; } }); | ||
Object.defineProperty(exports, "float32", { enumerable: true, get: function () { return utils_js_1.float32; } }); | ||
Object.defineProperty(exports, "float64", { enumerable: true, get: function () { return utils_js_1.float64; } }); | ||
Object.defineProperty(exports, "isLittleEndian", { enumerable: true, get: function () { return utils_js_1.isLittleEndian; } }); | ||
var encoding_js_1 = require("./encoding.js"); | ||
Object.defineProperty(exports, "Encoding", { enumerable: true, get: function () { return encoding_js_1.Encoding; } }); | ||
var builder_js_1 = require("./builder.js"); | ||
Object.defineProperty(exports, "Builder", { enumerable: true, get: function () { return builder_js_1.Builder; } }); | ||
var byte_buffer_js_1 = require("./byte-buffer.js"); | ||
Object.defineProperty(exports, "ByteBuffer", { enumerable: true, get: function () { return byte_buffer_js_1.ByteBuffer; } }); |
@@ -5,4 +5,4 @@ "use strict"; | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
var builder_js_1 = require("./flexbuffers/builder.js"); | ||
var reference_js_1 = require("./flexbuffers/reference.js"); | ||
const builder_js_1 = require("./flexbuffers/builder.js"); | ||
const reference_js_1 = require("./flexbuffers/reference.js"); | ||
var reference_js_2 = require("./flexbuffers/reference.js"); | ||
@@ -18,8 +18,4 @@ Object.defineProperty(exports, "toReference", { enumerable: true, get: function () { return reference_js_2.toReference; } }); | ||
exports.toObject = toObject; | ||
function encode(object, size, deduplicateStrings, deduplicateKeys, deduplicateKeyVectors) { | ||
if (size === void 0) { size = 2048; } | ||
if (deduplicateStrings === void 0) { deduplicateStrings = true; } | ||
if (deduplicateKeys === void 0) { deduplicateKeys = true; } | ||
if (deduplicateKeyVectors === void 0) { deduplicateKeyVectors = true; } | ||
var builder = new builder_js_1.Builder(size > 0 ? size : 2048, deduplicateStrings, deduplicateKeys, deduplicateKeyVectors); | ||
function encode(object, size = 2048, deduplicateStrings = true, deduplicateKeys = true, deduplicateKeyVectors = true) { | ||
const builder = new builder_js_1.Builder(size > 0 ? size : 2048, deduplicateStrings, deduplicateKeys, deduplicateKeyVectors); | ||
builder.add(object); | ||
@@ -26,0 +22,0 @@ return builder.finish(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.paddingSize = exports.fromByteWidth = exports.uwidth = exports.fwidth = exports.iwidth = exports.toByteWidth = void 0; | ||
var bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
function toByteWidth(bitWidth) { | ||
@@ -6,0 +6,0 @@ return 1 << bitWidth; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Builder = void 0; | ||
var bit_width_js_1 = require("./bit-width.js"); | ||
var bit_width_util_js_1 = require("./bit-width-util.js"); | ||
var flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
var value_type_js_1 = require("./value-type.js"); | ||
var value_type_util_js_1 = require("./value-type-util.js"); | ||
var stack_value_js_1 = require("./stack-value.js"); | ||
var Builder = /** @class */ (function () { | ||
function Builder(size, dedupStrings, dedupKeys, dedupKeyVectors) { | ||
if (size === void 0) { size = 2048; } | ||
if (dedupStrings === void 0) { dedupStrings = true; } | ||
if (dedupKeys === void 0) { dedupKeys = true; } | ||
if (dedupKeyVectors === void 0) { dedupKeyVectors = true; } | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
const value_type_js_1 = require("./value-type.js"); | ||
const value_type_util_js_1 = require("./value-type-util.js"); | ||
const stack_value_js_1 = require("./stack-value.js"); | ||
class Builder { | ||
constructor(size = 2048, dedupStrings = true, dedupKeys = true, dedupKeyVectors = true) { | ||
this.dedupStrings = dedupStrings; | ||
@@ -32,11 +28,11 @@ this.dedupKeys = dedupKeys; | ||
} | ||
Builder.prototype.align = function (width) { | ||
var byteWidth = (0, bit_width_util_js_1.toByteWidth)(width); | ||
align(width) { | ||
const byteWidth = (0, bit_width_util_js_1.toByteWidth)(width); | ||
this.offset += (0, bit_width_util_js_1.paddingSize)(this.offset, byteWidth); | ||
return byteWidth; | ||
}; | ||
Builder.prototype.computeOffset = function (newValueSize) { | ||
var targetOffset = this.offset + newValueSize; | ||
var size = this.buffer.byteLength; | ||
var prevSize = size; | ||
} | ||
computeOffset(newValueSize) { | ||
const targetOffset = this.offset + newValueSize; | ||
let size = this.buffer.byteLength; | ||
const prevSize = size; | ||
while (size < targetOffset) { | ||
@@ -46,3 +42,3 @@ size <<= 1; | ||
if (prevSize < size) { | ||
var prevBuffer = this.buffer; | ||
const prevBuffer = this.buffer; | ||
this.buffer = new ArrayBuffer(size); | ||
@@ -53,4 +49,4 @@ this.view = new DataView(this.buffer); | ||
return targetOffset; | ||
}; | ||
Builder.prototype.pushInt = function (value, width) { | ||
} | ||
pushInt(value, width) { | ||
if (width === bit_width_js_1.BitWidth.WIDTH8) { | ||
@@ -69,6 +65,6 @@ this.view.setInt8(this.offset, value); | ||
else { | ||
throw "Unexpected width: ".concat(width, " for value: ").concat(value); | ||
throw `Unexpected width: ${width} for value: ${value}`; | ||
} | ||
}; | ||
Builder.prototype.pushUInt = function (value, width) { | ||
} | ||
pushUInt(value, width) { | ||
if (width === bit_width_js_1.BitWidth.WIDTH8) { | ||
@@ -87,27 +83,27 @@ this.view.setUint8(this.offset, value); | ||
else { | ||
throw "Unexpected width: ".concat(width, " for value: ").concat(value); | ||
throw `Unexpected width: ${width} for value: ${value}`; | ||
} | ||
}; | ||
Builder.prototype.writeInt = function (value, byteWidth) { | ||
var newOffset = this.computeOffset(byteWidth); | ||
} | ||
writeInt(value, byteWidth) { | ||
const newOffset = this.computeOffset(byteWidth); | ||
this.pushInt(value, (0, bit_width_util_js_1.fromByteWidth)(byteWidth)); | ||
this.offset = newOffset; | ||
}; | ||
Builder.prototype.writeUInt = function (value, byteWidth) { | ||
var newOffset = this.computeOffset(byteWidth); | ||
} | ||
writeUInt(value, byteWidth) { | ||
const newOffset = this.computeOffset(byteWidth); | ||
this.pushUInt(value, (0, bit_width_util_js_1.fromByteWidth)(byteWidth)); | ||
this.offset = newOffset; | ||
}; | ||
Builder.prototype.writeBlob = function (arrayBuffer) { | ||
var length = arrayBuffer.byteLength; | ||
var bitWidth = (0, bit_width_util_js_1.uwidth)(length); | ||
var byteWidth = this.align(bitWidth); | ||
} | ||
writeBlob(arrayBuffer) { | ||
const length = arrayBuffer.byteLength; | ||
const bitWidth = (0, bit_width_util_js_1.uwidth)(length); | ||
const byteWidth = this.align(bitWidth); | ||
this.writeUInt(length, byteWidth); | ||
var blobOffset = this.offset; | ||
var newOffset = this.computeOffset(length); | ||
const blobOffset = this.offset; | ||
const newOffset = this.computeOffset(length); | ||
new Uint8Array(this.buffer).set(new Uint8Array(arrayBuffer), blobOffset); | ||
this.stack.push(this.offsetStackValue(blobOffset, value_type_js_1.ValueType.BLOB, bitWidth)); | ||
this.offset = newOffset; | ||
}; | ||
Builder.prototype.writeString = function (str) { | ||
} | ||
writeString(str) { | ||
if (this.dedupStrings && Object.prototype.hasOwnProperty.call(this.stringLookup, str)) { | ||
@@ -117,11 +113,11 @@ this.stack.push(this.stringLookup[str]); | ||
} | ||
var utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str); | ||
var length = utf8.length; | ||
var bitWidth = (0, bit_width_util_js_1.uwidth)(length); | ||
var byteWidth = this.align(bitWidth); | ||
const utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str); | ||
const length = utf8.length; | ||
const bitWidth = (0, bit_width_util_js_1.uwidth)(length); | ||
const byteWidth = this.align(bitWidth); | ||
this.writeUInt(length, byteWidth); | ||
var stringOffset = this.offset; | ||
var newOffset = this.computeOffset(length + 1); | ||
const stringOffset = this.offset; | ||
const newOffset = this.computeOffset(length + 1); | ||
new Uint8Array(this.buffer).set(utf8, stringOffset); | ||
var stackValue = this.offsetStackValue(stringOffset, value_type_js_1.ValueType.STRING, bitWidth); | ||
const stackValue = this.offsetStackValue(stringOffset, value_type_js_1.ValueType.STRING, bitWidth); | ||
this.stack.push(stackValue); | ||
@@ -132,4 +128,4 @@ if (this.dedupStrings) { | ||
this.offset = newOffset; | ||
}; | ||
Builder.prototype.writeKey = function (str) { | ||
} | ||
writeKey(str) { | ||
if (this.dedupKeys && Object.prototype.hasOwnProperty.call(this.keyLookup, str)) { | ||
@@ -139,7 +135,7 @@ this.stack.push(this.keyLookup[str]); | ||
} | ||
var utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str); | ||
var length = utf8.length; | ||
var newOffset = this.computeOffset(length + 1); | ||
const utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str); | ||
const length = utf8.length; | ||
const newOffset = this.computeOffset(length + 1); | ||
new Uint8Array(this.buffer).set(utf8, this.offset); | ||
var stackValue = this.offsetStackValue(this.offset, value_type_js_1.ValueType.KEY, bit_width_js_1.BitWidth.WIDTH8); | ||
const stackValue = this.offsetStackValue(this.offset, value_type_js_1.ValueType.KEY, bit_width_js_1.BitWidth.WIDTH8); | ||
this.stack.push(stackValue); | ||
@@ -150,7 +146,7 @@ if (this.dedupKeys) { | ||
this.offset = newOffset; | ||
}; | ||
Builder.prototype.writeStackValue = function (value, byteWidth) { | ||
var newOffset = this.computeOffset(byteWidth); | ||
} | ||
writeStackValue(value, byteWidth) { | ||
const newOffset = this.computeOffset(byteWidth); | ||
if (value.isOffset()) { | ||
var relativeOffset = this.offset - value.offset; | ||
const relativeOffset = this.offset - value.offset; | ||
if (byteWidth === 8 || BigInt(relativeOffset) < (BigInt(1) << BigInt(byteWidth * 8))) { | ||
@@ -160,3 +156,3 @@ this.writeUInt(relativeOffset, byteWidth); | ||
else { | ||
throw "Unexpected size ".concat(byteWidth, ". This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new"); | ||
throw `Unexpected size ${byteWidth}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`; | ||
} | ||
@@ -168,4 +164,4 @@ } | ||
this.offset = newOffset; | ||
}; | ||
Builder.prototype.integrityCheckOnValueAddition = function () { | ||
} | ||
integrityCheckOnValueAddition() { | ||
if (this.finished) { | ||
@@ -179,4 +175,4 @@ throw "Adding values after finish is prohibited"; | ||
} | ||
}; | ||
Builder.prototype.integrityCheckOnKeyAddition = function () { | ||
} | ||
integrityCheckOnKeyAddition() { | ||
if (this.finished) { | ||
@@ -188,42 +184,41 @@ throw "Adding values after finish is prohibited"; | ||
} | ||
}; | ||
Builder.prototype.startVector = function () { | ||
} | ||
startVector() { | ||
this.stackPointers.push({ stackPosition: this.stack.length, isVector: true }); | ||
}; | ||
Builder.prototype.startMap = function (presorted) { | ||
if (presorted === void 0) { presorted = false; } | ||
} | ||
startMap(presorted = false) { | ||
this.stackPointers.push({ stackPosition: this.stack.length, isVector: false, presorted: presorted }); | ||
}; | ||
Builder.prototype.endVector = function (stackPointer) { | ||
var vecLength = this.stack.length - stackPointer.stackPosition; | ||
var vec = this.createVector(stackPointer.stackPosition, vecLength, 1); | ||
} | ||
endVector(stackPointer) { | ||
const vecLength = this.stack.length - stackPointer.stackPosition; | ||
const vec = this.createVector(stackPointer.stackPosition, vecLength, 1); | ||
this.stack.splice(stackPointer.stackPosition, vecLength); | ||
this.stack.push(vec); | ||
}; | ||
Builder.prototype.endMap = function (stackPointer) { | ||
} | ||
endMap(stackPointer) { | ||
if (!stackPointer.presorted) { | ||
this.sort(stackPointer); | ||
} | ||
var keyVectorHash = ""; | ||
for (var i = stackPointer.stackPosition; i < this.stack.length; i += 2) { | ||
keyVectorHash += ",".concat(this.stack[i].offset); | ||
let keyVectorHash = ""; | ||
for (let i = stackPointer.stackPosition; i < this.stack.length; i += 2) { | ||
keyVectorHash += `,${this.stack[i].offset}`; | ||
} | ||
var vecLength = (this.stack.length - stackPointer.stackPosition) >> 1; | ||
const vecLength = (this.stack.length - stackPointer.stackPosition) >> 1; | ||
if (this.dedupKeyVectors && !Object.prototype.hasOwnProperty.call(this.keyVectorLookup, keyVectorHash)) { | ||
this.keyVectorLookup[keyVectorHash] = this.createVector(stackPointer.stackPosition, vecLength, 2); | ||
} | ||
var keysStackValue = this.dedupKeyVectors ? this.keyVectorLookup[keyVectorHash] : this.createVector(stackPointer.stackPosition, vecLength, 2); | ||
var valuesStackValue = this.createVector(stackPointer.stackPosition + 1, vecLength, 2, keysStackValue); | ||
const keysStackValue = this.dedupKeyVectors ? this.keyVectorLookup[keyVectorHash] : this.createVector(stackPointer.stackPosition, vecLength, 2); | ||
const valuesStackValue = this.createVector(stackPointer.stackPosition + 1, vecLength, 2, keysStackValue); | ||
this.stack.splice(stackPointer.stackPosition, vecLength << 1); | ||
this.stack.push(valuesStackValue); | ||
}; | ||
Builder.prototype.sort = function (stackPointer) { | ||
var view = this.view; | ||
var stack = this.stack; | ||
} | ||
sort(stackPointer) { | ||
const view = this.view; | ||
const stack = this.stack; | ||
function shouldFlip(v1, v2) { | ||
if (v1.type !== value_type_js_1.ValueType.KEY || v2.type !== value_type_js_1.ValueType.KEY) { | ||
throw "Stack values are not keys ".concat(v1, " | ").concat(v2, ". Check if you combined [addKey] with add... method calls properly."); | ||
throw `Stack values are not keys ${v1} | ${v2}. Check if you combined [addKey] with add... method calls properly.`; | ||
} | ||
var c1, c2; | ||
var index = 0; | ||
let c1, c2; | ||
let index = 0; | ||
do { | ||
@@ -243,4 +238,4 @@ c1 = view.getUint8(v1.offset + index); | ||
return; | ||
var k = stack[flipIndex]; | ||
var v = stack[flipIndex + 1]; | ||
const k = stack[flipIndex]; | ||
const v = stack[flipIndex + 1]; | ||
stack[flipIndex] = stack[i]; | ||
@@ -252,5 +247,5 @@ stack[flipIndex + 1] = stack[i + 1]; | ||
function selectionSort() { | ||
for (var i = stackPointer.stackPosition; i < stack.length; i += 2) { | ||
var flipIndex = i; | ||
for (var j = i + 2; j < stack.length; j += 2) { | ||
for (let i = stackPointer.stackPosition; i < stack.length; i += 2) { | ||
let flipIndex = i; | ||
for (let j = i + 2; j < stack.length; j += 2) { | ||
if (shouldFlip(stack[flipIndex], stack[j])) { | ||
@@ -267,3 +262,3 @@ flipIndex = j; | ||
if (v1.type !== value_type_js_1.ValueType.KEY || v2.type !== value_type_js_1.ValueType.KEY) { | ||
throw "Stack values are not keys ".concat(v1, " | ").concat(v2, ". Check if you combined [addKey] with add... method calls properly."); | ||
throw `Stack values are not keys ${v1} | ${v2}. Check if you combined [addKey] with add... method calls properly.`; | ||
} | ||
@@ -273,4 +268,4 @@ if (v1.offset === v2.offset) { | ||
} | ||
var c1, c2; | ||
var index = 0; | ||
let c1, c2; | ||
let index = 0; | ||
do { | ||
@@ -289,6 +284,6 @@ c1 = view.getUint8(v1.offset + index); | ||
if (left < right) { | ||
var mid = left + (((right - left) >> 2)) * 2; | ||
var pivot = stack[mid]; | ||
var left_new = left; | ||
var right_new = right; | ||
const mid = left + (((right - left) >> 2)) * 2; | ||
const pivot = stack[mid]; | ||
let left_new = left; | ||
let right_new = right; | ||
do { | ||
@@ -311,4 +306,4 @@ while (smaller(stack[left_new], pivot)) { | ||
} | ||
var sorted = true; | ||
for (var i = stackPointer.stackPosition; i < this.stack.length - 2; i += 2) { | ||
let sorted = true; | ||
for (let i = stackPointer.stackPosition; i < this.stack.length - 2; i += 2) { | ||
if (shouldFlip(this.stack[i], this.stack[i + 2])) { | ||
@@ -327,7 +322,7 @@ sorted = false; | ||
} | ||
}; | ||
Builder.prototype.end = function () { | ||
} | ||
end() { | ||
if (this.stackPointers.length < 1) | ||
return; | ||
var pointer = this.stackPointers.pop(); | ||
const pointer = this.stackPointers.pop(); | ||
if (pointer.isVector) { | ||
@@ -339,9 +334,8 @@ this.endVector(pointer); | ||
} | ||
}; | ||
Builder.prototype.createVector = function (start, vecLength, step, keys) { | ||
if (keys === void 0) { keys = null; } | ||
var bitWidth = (0, bit_width_util_js_1.uwidth)(vecLength); | ||
var prefixElements = 1; | ||
} | ||
createVector(start, vecLength, step, keys = null) { | ||
let bitWidth = (0, bit_width_util_js_1.uwidth)(vecLength); | ||
let prefixElements = 1; | ||
if (keys !== null) { | ||
var elementWidth = keys.elementWidth(this.offset, 0); | ||
const elementWidth = keys.elementWidth(this.offset, 0); | ||
if (elementWidth > bitWidth) { | ||
@@ -352,6 +346,6 @@ bitWidth = elementWidth; | ||
} | ||
var vectorType = value_type_js_1.ValueType.KEY; | ||
var typed = keys === null; | ||
for (var i = start; i < this.stack.length; i += step) { | ||
var elementWidth = this.stack[i].elementWidth(this.offset, i + prefixElements); | ||
let vectorType = value_type_js_1.ValueType.KEY; | ||
let typed = keys === null; | ||
for (let i = start; i < this.stack.length; i += step) { | ||
const elementWidth = this.stack[i].elementWidth(this.offset, i + prefixElements); | ||
if (elementWidth > bitWidth) { | ||
@@ -370,4 +364,4 @@ bitWidth = elementWidth; | ||
} | ||
var byteWidth = this.align(bitWidth); | ||
var fix = typed && (0, value_type_util_js_1.isNumber)(vectorType) && vecLength >= 2 && vecLength <= 4; | ||
const byteWidth = this.align(bitWidth); | ||
const fix = typed && (0, value_type_util_js_1.isNumber)(vectorType) && vecLength >= 2 && vecLength <= 4; | ||
if (keys !== null) { | ||
@@ -380,8 +374,8 @@ this.writeStackValue(keys, byteWidth); | ||
} | ||
var vecOffset = this.offset; | ||
for (var i = start; i < this.stack.length; i += step) { | ||
const vecOffset = this.offset; | ||
for (let i = start; i < this.stack.length; i += step) { | ||
this.writeStackValue(this.stack[i], byteWidth); | ||
} | ||
if (!typed) { | ||
for (var i = start; i < this.stack.length; i += step) { | ||
for (let i = start; i < this.stack.length; i += step) { | ||
this.writeUInt(this.stack[i].storedPackedType(), 1); | ||
@@ -394,31 +388,31 @@ } | ||
if (typed) { | ||
var vType = (0, value_type_util_js_1.toTypedVector)(vectorType, fix ? vecLength : 0); | ||
const vType = (0, value_type_util_js_1.toTypedVector)(vectorType, fix ? vecLength : 0); | ||
return this.offsetStackValue(vecOffset, vType, bitWidth); | ||
} | ||
return this.offsetStackValue(vecOffset, value_type_js_1.ValueType.VECTOR, bitWidth); | ||
}; | ||
Builder.prototype.nullStackValue = function () { | ||
} | ||
nullStackValue() { | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.NULL, bit_width_js_1.BitWidth.WIDTH8); | ||
}; | ||
Builder.prototype.boolStackValue = function (value) { | ||
} | ||
boolStackValue(value) { | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.BOOL, bit_width_js_1.BitWidth.WIDTH8, value); | ||
}; | ||
Builder.prototype.intStackValue = function (value) { | ||
} | ||
intStackValue(value) { | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.INT, (0, bit_width_util_js_1.iwidth)(value), value); | ||
}; | ||
Builder.prototype.uintStackValue = function (value) { | ||
} | ||
uintStackValue(value) { | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.UINT, (0, bit_width_util_js_1.uwidth)(value), value); | ||
}; | ||
Builder.prototype.floatStackValue = function (value) { | ||
} | ||
floatStackValue(value) { | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.FLOAT, (0, bit_width_util_js_1.fwidth)(value), value); | ||
}; | ||
Builder.prototype.offsetStackValue = function (offset, valueType, bitWidth) { | ||
} | ||
offsetStackValue(offset, valueType, bitWidth) { | ||
return new stack_value_js_1.StackValue(this, valueType, bitWidth, null, offset); | ||
}; | ||
Builder.prototype.finishBuffer = function () { | ||
} | ||
finishBuffer() { | ||
if (this.stack.length !== 1) { | ||
throw "Stack has to be exactly 1, but it is ".concat(this.stack.length, ". You have to end all started vectors and maps before calling [finish]"); | ||
throw `Stack has to be exactly 1, but it is ${this.stack.length}. You have to end all started vectors and maps before calling [finish]`; | ||
} | ||
var value = this.stack[0]; | ||
var byteWidth = this.align(value.elementWidth(this.offset, 0)); | ||
const value = this.stack[0]; | ||
const byteWidth = this.align(value.elementWidth(this.offset, 0)); | ||
this.writeStackValue(value, byteWidth); | ||
@@ -428,4 +422,4 @@ this.writeUInt(value.storedPackedType(), 1); | ||
this.finished = true; | ||
}; | ||
Builder.prototype.add = function (value) { | ||
} | ||
add(value) { | ||
this.integrityCheckOnValueAddition(); | ||
@@ -460,3 +454,3 @@ if (typeof value === 'undefined') { | ||
this.startVector(); | ||
for (var i = 0; i < value.length; i++) { | ||
for (let i = 0; i < value.length; i++) { | ||
this.add(value[i]); | ||
@@ -467,6 +461,6 @@ } | ||
else if (typeof value === 'object') { | ||
var properties = Object.getOwnPropertyNames(value).sort(); | ||
const properties = Object.getOwnPropertyNames(value).sort(); | ||
this.startMap(true); | ||
for (var i = 0; i < properties.length; i++) { | ||
var key = properties[i]; | ||
for (let i = 0; i < properties.length; i++) { | ||
const key = properties[i]; | ||
this.addKey(key); | ||
@@ -478,22 +472,20 @@ this.add(value[key]); | ||
else { | ||
throw "Unexpected value input ".concat(value); | ||
throw `Unexpected value input ${value}`; | ||
} | ||
}; | ||
Builder.prototype.finish = function () { | ||
} | ||
finish() { | ||
if (!this.finished) { | ||
this.finishBuffer(); | ||
} | ||
var result = this.buffer.slice(0, this.offset); | ||
const result = this.buffer.slice(0, this.offset); | ||
return new Uint8Array(result); | ||
}; | ||
Builder.prototype.isFinished = function () { | ||
} | ||
isFinished() { | ||
return this.finished; | ||
}; | ||
Builder.prototype.addKey = function (key) { | ||
} | ||
addKey(key) { | ||
this.integrityCheckOnKeyAddition(); | ||
this.writeKey(key); | ||
}; | ||
Builder.prototype.addInt = function (value, indirect, deduplicate) { | ||
if (indirect === void 0) { indirect = false; } | ||
if (deduplicate === void 0) { deduplicate = false; } | ||
} | ||
addInt(value, indirect = false, deduplicate = false) { | ||
this.integrityCheckOnValueAddition(); | ||
@@ -508,8 +500,8 @@ if (!indirect) { | ||
} | ||
var stackValue = this.intStackValue(value); | ||
var byteWidth = this.align(stackValue.width); | ||
var newOffset = this.computeOffset(byteWidth); | ||
var valueOffset = this.offset; | ||
const stackValue = this.intStackValue(value); | ||
const byteWidth = this.align(stackValue.width); | ||
const newOffset = this.computeOffset(byteWidth); | ||
const valueOffset = this.offset; | ||
stackValue.writeToBuffer(byteWidth); | ||
var stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_INT, stackValue.width); | ||
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_INT, stackValue.width); | ||
this.stack.push(stackOffset); | ||
@@ -520,6 +512,4 @@ this.offset = newOffset; | ||
} | ||
}; | ||
Builder.prototype.addUInt = function (value, indirect, deduplicate) { | ||
if (indirect === void 0) { indirect = false; } | ||
if (deduplicate === void 0) { deduplicate = false; } | ||
} | ||
addUInt(value, indirect = false, deduplicate = false) { | ||
this.integrityCheckOnValueAddition(); | ||
@@ -534,8 +524,8 @@ if (!indirect) { | ||
} | ||
var stackValue = this.uintStackValue(value); | ||
var byteWidth = this.align(stackValue.width); | ||
var newOffset = this.computeOffset(byteWidth); | ||
var valueOffset = this.offset; | ||
const stackValue = this.uintStackValue(value); | ||
const byteWidth = this.align(stackValue.width); | ||
const newOffset = this.computeOffset(byteWidth); | ||
const valueOffset = this.offset; | ||
stackValue.writeToBuffer(byteWidth); | ||
var stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_UINT, stackValue.width); | ||
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_UINT, stackValue.width); | ||
this.stack.push(stackOffset); | ||
@@ -546,6 +536,4 @@ this.offset = newOffset; | ||
} | ||
}; | ||
Builder.prototype.addFloat = function (value, indirect, deduplicate) { | ||
if (indirect === void 0) { indirect = false; } | ||
if (deduplicate === void 0) { deduplicate = false; } | ||
} | ||
addFloat(value, indirect = false, deduplicate = false) { | ||
this.integrityCheckOnValueAddition(); | ||
@@ -560,8 +548,8 @@ if (!indirect) { | ||
} | ||
var stackValue = this.floatStackValue(value); | ||
var byteWidth = this.align(stackValue.width); | ||
var newOffset = this.computeOffset(byteWidth); | ||
var valueOffset = this.offset; | ||
const stackValue = this.floatStackValue(value); | ||
const byteWidth = this.align(stackValue.width); | ||
const newOffset = this.computeOffset(byteWidth); | ||
const valueOffset = this.offset; | ||
stackValue.writeToBuffer(byteWidth); | ||
var stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_FLOAT, stackValue.width); | ||
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_FLOAT, stackValue.width); | ||
this.stack.push(stackOffset); | ||
@@ -572,5 +560,4 @@ this.offset = newOffset; | ||
} | ||
}; | ||
return Builder; | ||
}()); | ||
} | ||
} | ||
exports.Builder = Builder; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function fromUTF8Array(data) { | ||
var decoder = new TextDecoder(); | ||
const decoder = new TextDecoder(); | ||
return decoder.decode(data); | ||
@@ -11,5 +11,5 @@ } | ||
function toUTF8Array(str) { | ||
var encoder = new TextEncoder(); | ||
const encoder = new TextEncoder(); | ||
return encoder.encode(str); | ||
} | ||
exports.toUTF8Array = toUTF8Array; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.keyForIndex = exports.diffKeys = exports.keyIndex = exports.indirect = exports.readFloat = exports.readUInt = exports.readInt = exports.validateOffset = void 0; | ||
var bit_width_js_1 = require("./bit-width.js"); | ||
var bit_width_util_js_1 = require("./bit-width-util.js"); | ||
var flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
function validateOffset(dataView, offset, width) { | ||
@@ -68,3 +68,3 @@ if (dataView.byteLength <= offset + width || (offset & ((0, bit_width_util_js_1.toByteWidth)(width) - 1)) !== 0) { | ||
function indirect(dataView, offset, width) { | ||
var step = readUInt(dataView, offset, width); | ||
const step = readUInt(dataView, offset, width); | ||
return offset - step; | ||
@@ -74,12 +74,12 @@ } | ||
function keyIndex(key, dataView, offset, parentWidth, byteWidth, length) { | ||
var input = (0, flexbuffers_util_js_1.toUTF8Array)(key); | ||
var keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3; | ||
var bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
var indirectOffset = keysVectorOffset - Number(readUInt(dataView, keysVectorOffset, bitWidth)); | ||
var _byteWidth = Number(readUInt(dataView, keysVectorOffset + byteWidth, bitWidth)); | ||
var low = 0; | ||
var high = length - 1; | ||
const input = (0, flexbuffers_util_js_1.toUTF8Array)(key); | ||
const keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3; | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const indirectOffset = keysVectorOffset - Number(readUInt(dataView, keysVectorOffset, bitWidth)); | ||
const _byteWidth = Number(readUInt(dataView, keysVectorOffset + byteWidth, bitWidth)); | ||
let low = 0; | ||
let high = length - 1; | ||
while (low <= high) { | ||
var mid = (high + low) >> 1; | ||
var dif = diffKeys(input, mid, dataView, indirectOffset, _byteWidth); | ||
const mid = (high + low) >> 1; | ||
const dif = diffKeys(input, mid, dataView, indirectOffset, _byteWidth); | ||
if (dif === 0) | ||
@@ -98,6 +98,6 @@ return mid; | ||
function diffKeys(input, index, dataView, offset, width) { | ||
var keyOffset = offset + index * width; | ||
var keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, (0, bit_width_util_js_1.fromByteWidth)(width))); | ||
for (var i = 0; i < input.length; i++) { | ||
var dif = input[i] - dataView.getUint8(keyIndirectOffset + i); | ||
const keyOffset = offset + index * width; | ||
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, (0, bit_width_util_js_1.fromByteWidth)(width))); | ||
for (let i = 0; i < input.length; i++) { | ||
const dif = input[i] - dataView.getUint8(keyIndirectOffset + i); | ||
if (dif !== 0) { | ||
@@ -111,9 +111,9 @@ return dif; | ||
function keyForIndex(index, dataView, offset, parentWidth, byteWidth) { | ||
var keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3; | ||
var bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
var indirectOffset = keysVectorOffset - Number(readUInt(dataView, keysVectorOffset, bitWidth)); | ||
var _byteWidth = Number(readUInt(dataView, keysVectorOffset + byteWidth, bitWidth)); | ||
var keyOffset = indirectOffset + index * _byteWidth; | ||
var keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, (0, bit_width_util_js_1.fromByteWidth)(_byteWidth))); | ||
var length = 0; | ||
const keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3; | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const indirectOffset = keysVectorOffset - Number(readUInt(dataView, keysVectorOffset, bitWidth)); | ||
const _byteWidth = Number(readUInt(dataView, keysVectorOffset + byteWidth, bitWidth)); | ||
const keyOffset = indirectOffset + index * _byteWidth; | ||
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, (0, bit_width_util_js_1.fromByteWidth)(_byteWidth))); | ||
let length = 0; | ||
while (dataView.getUint8(keyIndirectOffset + length) !== 0) { | ||
@@ -120,0 +120,0 @@ length++; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Reference = exports.toReference = void 0; | ||
var bit_width_util_js_1 = require("./bit-width-util.js"); | ||
var value_type_js_1 = require("./value-type.js"); | ||
var value_type_util_js_1 = require("./value-type-util.js"); | ||
var reference_util_js_1 = require("./reference-util.js"); | ||
var flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
var bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const value_type_js_1 = require("./value-type.js"); | ||
const value_type_util_js_1 = require("./value-type-util.js"); | ||
const reference_util_js_1 = require("./reference-util.js"); | ||
const flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
function toReference(buffer) { | ||
var len = buffer.byteLength; | ||
const len = buffer.byteLength; | ||
if (len < 3) { | ||
throw "Buffer needs to be bigger than 3"; | ||
} | ||
var dataView = new DataView(buffer); | ||
var byteWidth = dataView.getUint8(len - 1); | ||
var packedType = dataView.getUint8(len - 2); | ||
var parentWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
var offset = len - byteWidth - 2; | ||
const dataView = new DataView(buffer); | ||
const byteWidth = dataView.getUint8(len - 1); | ||
const packedType = dataView.getUint8(len - 2); | ||
const parentWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const offset = len - byteWidth - 2; | ||
return new Reference(dataView, offset, parentWidth, packedType, "/"); | ||
@@ -24,9 +24,9 @@ } | ||
function valueForIndexWithKey(index, key, dataView, offset, parentWidth, byteWidth, length, path) { | ||
var _indirect = (0, reference_util_js_1.indirect)(dataView, offset, parentWidth); | ||
var elementOffset = _indirect + index * byteWidth; | ||
var packedType = dataView.getUint8(_indirect + length * byteWidth + index); | ||
return new Reference(dataView, elementOffset, (0, bit_width_util_js_1.fromByteWidth)(byteWidth), packedType, "".concat(path, "/").concat(key)); | ||
const _indirect = (0, reference_util_js_1.indirect)(dataView, offset, parentWidth); | ||
const elementOffset = _indirect + index * byteWidth; | ||
const packedType = dataView.getUint8(_indirect + length * byteWidth + index); | ||
return new Reference(dataView, elementOffset, (0, bit_width_util_js_1.fromByteWidth)(byteWidth), packedType, `${path}/${key}`); | ||
} | ||
var Reference = /** @class */ (function () { | ||
function Reference(dataView, offset, parentWidth, packedType, path) { | ||
class Reference { | ||
constructor(dataView, offset, parentWidth, packedType, path) { | ||
this.dataView = dataView; | ||
@@ -41,12 +41,12 @@ this.offset = offset; | ||
} | ||
Reference.prototype.isNull = function () { return this.valueType === value_type_js_1.ValueType.NULL; }; | ||
Reference.prototype.isNumber = function () { return (0, value_type_util_js_1.isNumber)(this.valueType) || (0, value_type_util_js_1.isIndirectNumber)(this.valueType); }; | ||
Reference.prototype.isFloat = function () { return value_type_js_1.ValueType.FLOAT === this.valueType || value_type_js_1.ValueType.INDIRECT_FLOAT === this.valueType; }; | ||
Reference.prototype.isInt = function () { return this.isNumber() && !this.isFloat(); }; | ||
Reference.prototype.isString = function () { return value_type_js_1.ValueType.STRING === this.valueType || value_type_js_1.ValueType.KEY === this.valueType; }; | ||
Reference.prototype.isBool = function () { return value_type_js_1.ValueType.BOOL === this.valueType; }; | ||
Reference.prototype.isBlob = function () { return value_type_js_1.ValueType.BLOB === this.valueType; }; | ||
Reference.prototype.isVector = function () { return (0, value_type_util_js_1.isAVector)(this.valueType); }; | ||
Reference.prototype.isMap = function () { return value_type_js_1.ValueType.MAP === this.valueType; }; | ||
Reference.prototype.boolValue = function () { | ||
isNull() { return this.valueType === value_type_js_1.ValueType.NULL; } | ||
isNumber() { return (0, value_type_util_js_1.isNumber)(this.valueType) || (0, value_type_util_js_1.isIndirectNumber)(this.valueType); } | ||
isFloat() { return value_type_js_1.ValueType.FLOAT === this.valueType || value_type_js_1.ValueType.INDIRECT_FLOAT === this.valueType; } | ||
isInt() { return this.isNumber() && !this.isFloat(); } | ||
isString() { return value_type_js_1.ValueType.STRING === this.valueType || value_type_js_1.ValueType.KEY === this.valueType; } | ||
isBool() { return value_type_js_1.ValueType.BOOL === this.valueType; } | ||
isBlob() { return value_type_js_1.ValueType.BLOB === this.valueType; } | ||
isVector() { return (0, value_type_util_js_1.isAVector)(this.valueType); } | ||
isMap() { return value_type_js_1.ValueType.MAP === this.valueType; } | ||
boolValue() { | ||
if (this.isBool()) { | ||
@@ -56,4 +56,4 @@ return (0, reference_util_js_1.readInt)(this.dataView, this.offset, this.parentWidth) > 0; | ||
return null; | ||
}; | ||
Reference.prototype.intValue = function () { | ||
} | ||
intValue() { | ||
if (this.valueType === value_type_js_1.ValueType.INT) { | ||
@@ -72,4 +72,4 @@ return (0, reference_util_js_1.readInt)(this.dataView, this.offset, this.parentWidth); | ||
return null; | ||
}; | ||
Reference.prototype.floatValue = function () { | ||
} | ||
floatValue() { | ||
if (this.valueType === value_type_js_1.ValueType.FLOAT) { | ||
@@ -82,39 +82,39 @@ return (0, reference_util_js_1.readFloat)(this.dataView, this.offset, this.parentWidth); | ||
return null; | ||
}; | ||
Reference.prototype.numericValue = function () { return this.floatValue() || this.intValue(); }; | ||
Reference.prototype.stringValue = function () { | ||
} | ||
numericValue() { return this.floatValue() || this.intValue(); } | ||
stringValue() { | ||
if (this.valueType === value_type_js_1.ValueType.STRING || this.valueType === value_type_js_1.ValueType.KEY) { | ||
var begin = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
const begin = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
return (0, flexbuffers_util_js_1.fromUTF8Array)(new Uint8Array(this.dataView.buffer, begin, this.length())); | ||
} | ||
return null; | ||
}; | ||
Reference.prototype.blobValue = function () { | ||
} | ||
blobValue() { | ||
if (this.isBlob()) { | ||
var begin = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
const begin = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
return new Uint8Array(this.dataView.buffer, begin, this.length()); | ||
} | ||
return null; | ||
}; | ||
Reference.prototype.get = function (key) { | ||
var length = this.length(); | ||
} | ||
get(key) { | ||
const length = this.length(); | ||
if (Number.isInteger(key) && (0, value_type_util_js_1.isAVector)(this.valueType)) { | ||
if (key >= length || key < 0) { | ||
throw "Key: [".concat(key, "] is not applicable on ").concat(this.path, " of ").concat(this.valueType, " length: ").concat(length); | ||
throw `Key: [${key}] is not applicable on ${this.path} of ${this.valueType} length: ${length}`; | ||
} | ||
var _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
var elementOffset = _indirect + key * this.byteWidth; | ||
var _packedType = this.dataView.getUint8(_indirect + length * this.byteWidth + key); | ||
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
const elementOffset = _indirect + key * this.byteWidth; | ||
let _packedType = this.dataView.getUint8(_indirect + length * this.byteWidth + key); | ||
if ((0, value_type_util_js_1.isTypedVector)(this.valueType)) { | ||
var _valueType = (0, value_type_util_js_1.typedVectorElementType)(this.valueType); | ||
const _valueType = (0, value_type_util_js_1.typedVectorElementType)(this.valueType); | ||
_packedType = (0, value_type_util_js_1.packedType)(_valueType, bit_width_js_1.BitWidth.WIDTH8); | ||
} | ||
else if ((0, value_type_util_js_1.isFixedTypedVector)(this.valueType)) { | ||
var _valueType = (0, value_type_util_js_1.fixedTypedVectorElementType)(this.valueType); | ||
const _valueType = (0, value_type_util_js_1.fixedTypedVectorElementType)(this.valueType); | ||
_packedType = (0, value_type_util_js_1.packedType)(_valueType, bit_width_js_1.BitWidth.WIDTH8); | ||
} | ||
return new Reference(this.dataView, elementOffset, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth), _packedType, "".concat(this.path, "[").concat(key, "]")); | ||
return new Reference(this.dataView, elementOffset, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth), _packedType, `${this.path}[${key}]`); | ||
} | ||
if (typeof key === 'string') { | ||
var index = (0, reference_util_js_1.keyIndex)(key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length); | ||
const index = (0, reference_util_js_1.keyIndex)(key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length); | ||
if (index !== null) { | ||
@@ -124,6 +124,6 @@ return valueForIndexWithKey(index, key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length, this.path); | ||
} | ||
throw "Key [".concat(key, "] is not applicable on ").concat(this.path, " of ").concat(this.valueType); | ||
}; | ||
Reference.prototype.length = function () { | ||
var size; | ||
throw `Key [${key}] is not applicable on ${this.path} of ${this.valueType}`; | ||
} | ||
length() { | ||
let size; | ||
if (this._length > -1) { | ||
@@ -144,4 +144,4 @@ return this._length; | ||
else if (this.valueType === value_type_js_1.ValueType.STRING) { | ||
var _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
var sizeByteWidth = this.byteWidth; | ||
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
let sizeByteWidth = this.byteWidth; | ||
size = (0, reference_util_js_1.readUInt)(this.dataView, _indirect - sizeByteWidth, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth)); | ||
@@ -155,3 +155,3 @@ while (this.dataView.getInt8(_indirect + size) !== 0) { | ||
else if (this.valueType === value_type_js_1.ValueType.KEY) { | ||
var _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
size = 1; | ||
@@ -167,8 +167,8 @@ while (this.dataView.getInt8(_indirect + size) !== 0) { | ||
return Number(this._length); | ||
}; | ||
Reference.prototype.toObject = function () { | ||
var length = this.length(); | ||
} | ||
toObject() { | ||
const length = this.length(); | ||
if (this.isVector()) { | ||
var result = []; | ||
for (var i = 0; i < length; i++) { | ||
const result = []; | ||
for (let i = 0; i < length; i++) { | ||
result.push(this.get(i).toObject()); | ||
@@ -179,5 +179,5 @@ } | ||
if (this.isMap()) { | ||
var result = {}; | ||
for (var i = 0; i < length; i++) { | ||
var key = (0, reference_util_js_1.keyForIndex)(i, this.dataView, this.offset, this.parentWidth, this.byteWidth); | ||
const result = {}; | ||
for (let i = 0; i < length; i++) { | ||
const key = (0, reference_util_js_1.keyForIndex)(i, this.dataView, this.offset, this.parentWidth, this.byteWidth); | ||
result[key] = valueForIndexWithKey(i, key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length, this.path).toObject(); | ||
@@ -197,5 +197,4 @@ } | ||
return this.blobValue() || this.stringValue(); | ||
}; | ||
return Reference; | ||
}()); | ||
} | ||
} | ||
exports.Reference = Reference; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StackValue = void 0; | ||
var bit_width_js_1 = require("./bit-width.js"); | ||
var bit_width_util_js_1 = require("./bit-width-util.js"); | ||
var value_type_js_1 = require("./value-type.js"); | ||
var value_type_util_js_1 = require("./value-type-util.js"); | ||
var StackValue = /** @class */ (function () { | ||
function StackValue(builder, type, width, value, offset) { | ||
if (value === void 0) { value = null; } | ||
if (offset === void 0) { offset = 0; } | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const value_type_js_1 = require("./value-type.js"); | ||
const value_type_util_js_1 = require("./value-type-util.js"); | ||
class StackValue { | ||
constructor(builder, type, width, value = null, offset = 0) { | ||
this.builder = builder; | ||
@@ -18,10 +16,10 @@ this.type = type; | ||
} | ||
StackValue.prototype.elementWidth = function (size, index) { | ||
elementWidth(size, index) { | ||
if ((0, value_type_util_js_1.isInline)(this.type)) | ||
return this.width; | ||
for (var i = 0; i < 4; i++) { | ||
var width = 1 << i; | ||
var offsetLoc = size + (0, bit_width_util_js_1.paddingSize)(size, width) + index * width; | ||
var offset = offsetLoc - this.offset; | ||
var bitWidth = (0, bit_width_util_js_1.uwidth)(offset); | ||
for (let i = 0; i < 4; i++) { | ||
const width = 1 << i; | ||
const offsetLoc = size + (0, bit_width_util_js_1.paddingSize)(size, width) + index * width; | ||
const offset = offsetLoc - this.offset; | ||
const bitWidth = (0, bit_width_util_js_1.uwidth)(offset); | ||
if (1 << bitWidth === width) { | ||
@@ -31,6 +29,6 @@ return bitWidth; | ||
} | ||
throw "Element is unknown. Size: ".concat(size, " at index: ").concat(index, ". This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new"); | ||
}; | ||
StackValue.prototype.writeToBuffer = function (byteWidth) { | ||
var newOffset = this.builder.computeOffset(byteWidth); | ||
throw `Element is unknown. Size: ${size} at index: ${index}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`; | ||
} | ||
writeToBuffer(byteWidth) { | ||
const newOffset = this.builder.computeOffset(byteWidth); | ||
if (this.type === value_type_js_1.ValueType.FLOAT) { | ||
@@ -45,7 +43,7 @@ if (this.width === bit_width_js_1.BitWidth.WIDTH32) { | ||
else if (this.type === value_type_js_1.ValueType.INT) { | ||
var bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
this.builder.pushInt(this.value, bitWidth); | ||
} | ||
else if (this.type === value_type_js_1.ValueType.UINT) { | ||
var bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
this.builder.pushUInt(this.value, bitWidth); | ||
@@ -60,19 +58,16 @@ } | ||
else { | ||
throw "Unexpected type: ".concat(this.type, ". This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new"); | ||
throw `Unexpected type: ${this.type}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`; | ||
} | ||
this.offset = newOffset; | ||
}; | ||
StackValue.prototype.storedWidth = function (width) { | ||
if (width === void 0) { width = bit_width_js_1.BitWidth.WIDTH8; } | ||
} | ||
storedWidth(width = bit_width_js_1.BitWidth.WIDTH8) { | ||
return (0, value_type_util_js_1.isInline)(this.type) ? Math.max(width, this.width) : this.width; | ||
}; | ||
StackValue.prototype.storedPackedType = function (width) { | ||
if (width === void 0) { width = bit_width_js_1.BitWidth.WIDTH8; } | ||
} | ||
storedPackedType(width = bit_width_js_1.BitWidth.WIDTH8) { | ||
return (0, value_type_util_js_1.packedType)(this.type, this.storedWidth(width)); | ||
}; | ||
StackValue.prototype.isOffset = function () { | ||
} | ||
isOffset() { | ||
return !(0, value_type_util_js_1.isInline)(this.type); | ||
}; | ||
return StackValue; | ||
}()); | ||
} | ||
} | ||
exports.StackValue = StackValue; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.packedType = exports.fixedTypedVectorElementSize = exports.fixedTypedVectorElementType = exports.typedVectorElementType = exports.toTypedVector = exports.isAVector = exports.isFixedTypedVector = exports.isTypedVector = exports.isTypedVectorElement = exports.isIndirectNumber = exports.isNumber = exports.isInline = void 0; | ||
var value_type_js_1 = require("./value-type.js"); | ||
const value_type_js_1 = require("./value-type.js"); | ||
function isInline(value) { | ||
@@ -6,0 +6,0 @@ return value === value_type_js_1.ValueType.BOOL |
@@ -1,4 +0,7 @@ | ||
import { ByteBuffer } from "./byte-buffer.js"; | ||
import { SIZEOF_SHORT, SIZE_PREFIX_LENGTH, SIZEOF_INT, FILE_IDENTIFIER_LENGTH } from "./constants.js"; | ||
export class Builder { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Builder = void 0; | ||
const byte_buffer_js_1 = require("./byte-buffer.js"); | ||
const constants_js_1 = require("./constants.js"); | ||
class Builder { | ||
/** | ||
@@ -37,3 +40,3 @@ * Create a FlatBufferBuilder. | ||
*/ | ||
this.bb = ByteBuffer.allocate(initial_size); | ||
this.bb = byte_buffer_js_1.ByteBuffer.allocate(initial_size); | ||
this.space = initial_size; | ||
@@ -277,3 +280,3 @@ } | ||
const new_buf_size = old_buf_size << 1; | ||
const nbb = ByteBuffer.allocate(new_buf_size); | ||
const nbb = byte_buffer_js_1.ByteBuffer.allocate(new_buf_size); | ||
nbb.setPosition(new_buf_size - old_buf_size); | ||
@@ -289,4 +292,4 @@ nbb.bytes().set(bb.bytes(), new_buf_size - old_buf_size); | ||
addOffset(offset) { | ||
this.prep(SIZEOF_INT, 0); // Ensure alignment is already done. | ||
this.writeInt32(this.offset() - offset + SIZEOF_INT); | ||
this.prep(constants_js_1.SIZEOF_INT, 0); // Ensure alignment is already done. | ||
this.writeInt32(this.offset() - offset + constants_js_1.SIZEOF_INT); | ||
} | ||
@@ -333,3 +336,3 @@ /** | ||
this.addInt16(vtableloc - this.object_start); | ||
const len = (trimmed_size + standard_fields) * SIZEOF_SHORT; | ||
const len = (trimmed_size + standard_fields) * constants_js_1.SIZEOF_SHORT; | ||
this.addInt16(len); | ||
@@ -342,3 +345,3 @@ // Search for an existing vtable that matches the current one. | ||
if (len == this.bb.readInt16(vt2)) { | ||
for (let j = SIZEOF_SHORT; j < len; j += SIZEOF_SHORT) { | ||
for (let j = constants_js_1.SIZEOF_SHORT; j < len; j += constants_js_1.SIZEOF_SHORT) { | ||
if (this.bb.readInt16(vt1 + j) != this.bb.readInt16(vt2 + j)) { | ||
@@ -373,16 +376,16 @@ continue outer_loop; | ||
finish(root_table, opt_file_identifier, opt_size_prefix) { | ||
const size_prefix = opt_size_prefix ? SIZE_PREFIX_LENGTH : 0; | ||
const size_prefix = opt_size_prefix ? constants_js_1.SIZE_PREFIX_LENGTH : 0; | ||
if (opt_file_identifier) { | ||
const file_identifier = opt_file_identifier; | ||
this.prep(this.minalign, SIZEOF_INT + | ||
FILE_IDENTIFIER_LENGTH + size_prefix); | ||
if (file_identifier.length != FILE_IDENTIFIER_LENGTH) { | ||
this.prep(this.minalign, constants_js_1.SIZEOF_INT + | ||
constants_js_1.FILE_IDENTIFIER_LENGTH + size_prefix); | ||
if (file_identifier.length != constants_js_1.FILE_IDENTIFIER_LENGTH) { | ||
throw new Error('FlatBuffers: file identifier must be length ' + | ||
FILE_IDENTIFIER_LENGTH); | ||
constants_js_1.FILE_IDENTIFIER_LENGTH); | ||
} | ||
for (let i = FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) { | ||
for (let i = constants_js_1.FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) { | ||
this.writeInt8(file_identifier.charCodeAt(i)); | ||
} | ||
} | ||
this.prep(this.minalign, SIZEOF_INT + size_prefix); | ||
this.prep(this.minalign, constants_js_1.SIZEOF_INT + size_prefix); | ||
this.addOffset(root_table); | ||
@@ -426,3 +429,3 @@ if (size_prefix) { | ||
this.vector_num_elems = num_elems; | ||
this.prep(SIZEOF_INT, elem_size * num_elems); | ||
this.prep(constants_js_1.SIZEOF_INT, elem_size * num_elems); | ||
this.prep(alignment, elem_size * num_elems); // Just in case alignment > int. | ||
@@ -528,1 +531,2 @@ } | ||
} | ||
exports.Builder = Builder; |
@@ -1,5 +0,8 @@ | ||
import { FILE_IDENTIFIER_LENGTH, SIZEOF_INT } from "./constants.js"; | ||
import { int32, isLittleEndian, float32, float64 } from "./utils.js"; | ||
import { Encoding } from "./encoding.js"; | ||
export class ByteBuffer { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ByteBuffer = void 0; | ||
const constants_js_1 = require("./constants.js"); | ||
const utils_js_1 = require("./utils.js"); | ||
const encoding_js_1 = require("./encoding.js"); | ||
class ByteBuffer { | ||
/** | ||
@@ -71,9 +74,9 @@ * Create a new ByteBuffer with a given array of bytes (`Uint8Array`) | ||
readFloat32(offset) { | ||
int32[0] = this.readInt32(offset); | ||
return float32[0]; | ||
utils_js_1.int32[0] = this.readInt32(offset); | ||
return utils_js_1.float32[0]; | ||
} | ||
readFloat64(offset) { | ||
int32[isLittleEndian ? 0 : 1] = this.readInt32(offset); | ||
int32[isLittleEndian ? 1 : 0] = this.readInt32(offset + 4); | ||
return float64[0]; | ||
utils_js_1.int32[utils_js_1.isLittleEndian ? 0 : 1] = this.readInt32(offset); | ||
utils_js_1.int32[utils_js_1.isLittleEndian ? 1 : 0] = this.readInt32(offset + 4); | ||
return utils_js_1.float64[0]; | ||
} | ||
@@ -115,9 +118,9 @@ writeInt8(offset, value) { | ||
writeFloat32(offset, value) { | ||
float32[0] = value; | ||
this.writeInt32(offset, int32[0]); | ||
utils_js_1.float32[0] = value; | ||
this.writeInt32(offset, utils_js_1.int32[0]); | ||
} | ||
writeFloat64(offset, value) { | ||
float64[0] = value; | ||
this.writeInt32(offset, int32[isLittleEndian ? 0 : 1]); | ||
this.writeInt32(offset + 4, int32[isLittleEndian ? 1 : 0]); | ||
utils_js_1.float64[0] = value; | ||
this.writeInt32(offset, utils_js_1.int32[utils_js_1.isLittleEndian ? 0 : 1]); | ||
this.writeInt32(offset + 4, utils_js_1.int32[utils_js_1.isLittleEndian ? 1 : 0]); | ||
} | ||
@@ -130,9 +133,9 @@ /** | ||
getBufferIdentifier() { | ||
if (this.bytes_.length < this.position_ + SIZEOF_INT + | ||
FILE_IDENTIFIER_LENGTH) { | ||
if (this.bytes_.length < this.position_ + constants_js_1.SIZEOF_INT + | ||
constants_js_1.FILE_IDENTIFIER_LENGTH) { | ||
throw new Error('FlatBuffers: ByteBuffer is too short to contain an identifier.'); | ||
} | ||
let result = ""; | ||
for (let i = 0; i < FILE_IDENTIFIER_LENGTH; i++) { | ||
result += String.fromCharCode(this.readInt8(this.position_ + SIZEOF_INT + i)); | ||
for (let i = 0; i < constants_js_1.FILE_IDENTIFIER_LENGTH; i++) { | ||
result += String.fromCharCode(this.readInt8(this.position_ + constants_js_1.SIZEOF_INT + i)); | ||
} | ||
@@ -171,5 +174,5 @@ return result; | ||
const length = this.readInt32(offset); | ||
offset += SIZEOF_INT; | ||
offset += constants_js_1.SIZEOF_INT; | ||
const utf8bytes = this.bytes_.subarray(offset, offset + length); | ||
if (opt_encoding === Encoding.UTF8_BYTES) | ||
if (opt_encoding === encoding_js_1.Encoding.UTF8_BYTES) | ||
return utf8bytes; | ||
@@ -202,3 +205,3 @@ else | ||
__vector(offset) { | ||
return offset + this.readInt32(offset) + SIZEOF_INT; // data starts after the length | ||
return offset + this.readInt32(offset) + constants_js_1.SIZEOF_INT; // data starts after the length | ||
} | ||
@@ -212,8 +215,8 @@ /** | ||
__has_identifier(ident) { | ||
if (ident.length != FILE_IDENTIFIER_LENGTH) { | ||
if (ident.length != constants_js_1.FILE_IDENTIFIER_LENGTH) { | ||
throw new Error('FlatBuffers: file identifier must be length ' + | ||
FILE_IDENTIFIER_LENGTH); | ||
constants_js_1.FILE_IDENTIFIER_LENGTH); | ||
} | ||
for (let i = 0; i < FILE_IDENTIFIER_LENGTH; i++) { | ||
if (ident.charCodeAt(i) != this.readInt8(this.position() + SIZEOF_INT + i)) { | ||
for (let i = 0; i < constants_js_1.FILE_IDENTIFIER_LENGTH; i++) { | ||
if (ident.charCodeAt(i) != this.readInt8(this.position() + constants_js_1.SIZEOF_INT + i)) { | ||
return false; | ||
@@ -254,1 +257,2 @@ } | ||
} | ||
exports.ByteBuffer = ByteBuffer; |
@@ -1,4 +0,7 @@ | ||
export const SIZEOF_SHORT = 2; | ||
export const SIZEOF_INT = 4; | ||
export const FILE_IDENTIFIER_LENGTH = 4; | ||
export const SIZE_PREFIX_LENGTH = 4; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SIZE_PREFIX_LENGTH = exports.FILE_IDENTIFIER_LENGTH = exports.SIZEOF_INT = exports.SIZEOF_SHORT = void 0; | ||
exports.SIZEOF_SHORT = 2; | ||
exports.SIZEOF_INT = 4; | ||
exports.FILE_IDENTIFIER_LENGTH = 4; | ||
exports.SIZE_PREFIX_LENGTH = 4; |
@@ -1,5 +0,8 @@ | ||
export var Encoding; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Encoding = void 0; | ||
var Encoding; | ||
(function (Encoding) { | ||
Encoding[Encoding["UTF8_BYTES"] = 1] = "UTF8_BYTES"; | ||
Encoding[Encoding["UTF16_STRING"] = 2] = "UTF16_STRING"; | ||
})(Encoding || (Encoding = {})); | ||
})(Encoding = exports.Encoding || (exports.Encoding = {})); |
@@ -1,1 +0,9 @@ | ||
export * as flatbuffers from './index.js'; | ||
export { SIZEOF_SHORT } from './constants.js'; | ||
export { SIZEOF_INT } from './constants.js'; | ||
export { FILE_IDENTIFIER_LENGTH } from './constants.js'; | ||
export { SIZE_PREFIX_LENGTH } from './constants.js'; | ||
export { Table, Offset, IGeneratedObject, IUnpackableObject } from './types.js'; | ||
export { int32, float32, float64, isLittleEndian } from './utils.js'; | ||
export { Encoding } from './encoding.js'; | ||
export { Builder } from './builder.js'; | ||
export { ByteBuffer } from './byte-buffer.js'; |
@@ -1,2 +0,22 @@ | ||
import * as flatbuffers_1 from './index.js'; | ||
export { flatbuffers_1 as flatbuffers }; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ByteBuffer = exports.Builder = exports.Encoding = exports.isLittleEndian = exports.float64 = exports.float32 = exports.int32 = exports.SIZE_PREFIX_LENGTH = exports.FILE_IDENTIFIER_LENGTH = exports.SIZEOF_INT = exports.SIZEOF_SHORT = void 0; | ||
var constants_js_1 = require("./constants.js"); | ||
Object.defineProperty(exports, "SIZEOF_SHORT", { enumerable: true, get: function () { return constants_js_1.SIZEOF_SHORT; } }); | ||
var constants_js_2 = require("./constants.js"); | ||
Object.defineProperty(exports, "SIZEOF_INT", { enumerable: true, get: function () { return constants_js_2.SIZEOF_INT; } }); | ||
var constants_js_3 = require("./constants.js"); | ||
Object.defineProperty(exports, "FILE_IDENTIFIER_LENGTH", { enumerable: true, get: function () { return constants_js_3.FILE_IDENTIFIER_LENGTH; } }); | ||
var constants_js_4 = require("./constants.js"); | ||
Object.defineProperty(exports, "SIZE_PREFIX_LENGTH", { enumerable: true, get: function () { return constants_js_4.SIZE_PREFIX_LENGTH; } }); | ||
var utils_js_1 = require("./utils.js"); | ||
Object.defineProperty(exports, "int32", { enumerable: true, get: function () { return utils_js_1.int32; } }); | ||
Object.defineProperty(exports, "float32", { enumerable: true, get: function () { return utils_js_1.float32; } }); | ||
Object.defineProperty(exports, "float64", { enumerable: true, get: function () { return utils_js_1.float64; } }); | ||
Object.defineProperty(exports, "isLittleEndian", { enumerable: true, get: function () { return utils_js_1.isLittleEndian; } }); | ||
var encoding_js_1 = require("./encoding.js"); | ||
Object.defineProperty(exports, "Encoding", { enumerable: true, get: function () { return encoding_js_1.Encoding; } }); | ||
var builder_js_1 = require("./builder.js"); | ||
Object.defineProperty(exports, "Builder", { enumerable: true, get: function () { return builder_js_1.Builder; } }); | ||
var byte_buffer_js_1 = require("./byte-buffer.js"); | ||
Object.defineProperty(exports, "ByteBuffer", { enumerable: true, get: function () { return byte_buffer_js_1.ByteBuffer; } }); |
@@ -0,15 +1,22 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.encode = exports.toObject = exports.builder = exports.toReference = void 0; | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
import { Builder } from './flexbuffers/builder.js'; | ||
import { toReference } from './flexbuffers/reference.js'; | ||
export { toReference } from './flexbuffers/reference.js'; | ||
export function builder() { | ||
return new Builder(); | ||
const builder_js_1 = require("./flexbuffers/builder.js"); | ||
const reference_js_1 = require("./flexbuffers/reference.js"); | ||
var reference_js_2 = require("./flexbuffers/reference.js"); | ||
Object.defineProperty(exports, "toReference", { enumerable: true, get: function () { return reference_js_2.toReference; } }); | ||
function builder() { | ||
return new builder_js_1.Builder(); | ||
} | ||
export function toObject(buffer) { | ||
return toReference(buffer).toObject(); | ||
exports.builder = builder; | ||
function toObject(buffer) { | ||
return (0, reference_js_1.toReference)(buffer).toObject(); | ||
} | ||
export function encode(object, size = 2048, deduplicateStrings = true, deduplicateKeys = true, deduplicateKeyVectors = true) { | ||
const builder = new Builder(size > 0 ? size : 2048, deduplicateStrings, deduplicateKeys, deduplicateKeyVectors); | ||
exports.toObject = toObject; | ||
function encode(object, size = 2048, deduplicateStrings = true, deduplicateKeys = true, deduplicateKeyVectors = true) { | ||
const builder = new builder_js_1.Builder(size > 0 ? size : 2048, deduplicateStrings, deduplicateKeys, deduplicateKeyVectors); | ||
builder.add(object); | ||
return builder.finish(); | ||
} | ||
exports.encode = encode; |
@@ -1,37 +0,46 @@ | ||
import { BitWidth } from './bit-width.js'; | ||
export function toByteWidth(bitWidth) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.paddingSize = exports.fromByteWidth = exports.uwidth = exports.fwidth = exports.iwidth = exports.toByteWidth = void 0; | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
function toByteWidth(bitWidth) { | ||
return 1 << bitWidth; | ||
} | ||
export function iwidth(value) { | ||
exports.toByteWidth = toByteWidth; | ||
function iwidth(value) { | ||
if (value >= -128 && value <= 127) | ||
return BitWidth.WIDTH8; | ||
return bit_width_js_1.BitWidth.WIDTH8; | ||
if (value >= -32768 && value <= 32767) | ||
return BitWidth.WIDTH16; | ||
return bit_width_js_1.BitWidth.WIDTH16; | ||
if (value >= -2147483648 && value <= 2147483647) | ||
return BitWidth.WIDTH32; | ||
return BitWidth.WIDTH64; | ||
return bit_width_js_1.BitWidth.WIDTH32; | ||
return bit_width_js_1.BitWidth.WIDTH64; | ||
} | ||
export function fwidth(value) { | ||
return value === Math.fround(value) ? BitWidth.WIDTH32 : BitWidth.WIDTH64; | ||
exports.iwidth = iwidth; | ||
function fwidth(value) { | ||
return value === Math.fround(value) ? bit_width_js_1.BitWidth.WIDTH32 : bit_width_js_1.BitWidth.WIDTH64; | ||
} | ||
export function uwidth(value) { | ||
exports.fwidth = fwidth; | ||
function uwidth(value) { | ||
if (value <= 255) | ||
return BitWidth.WIDTH8; | ||
return bit_width_js_1.BitWidth.WIDTH8; | ||
if (value <= 65535) | ||
return BitWidth.WIDTH16; | ||
return bit_width_js_1.BitWidth.WIDTH16; | ||
if (value <= 4294967295) | ||
return BitWidth.WIDTH32; | ||
return BitWidth.WIDTH64; | ||
return bit_width_js_1.BitWidth.WIDTH32; | ||
return bit_width_js_1.BitWidth.WIDTH64; | ||
} | ||
export function fromByteWidth(value) { | ||
exports.uwidth = uwidth; | ||
function fromByteWidth(value) { | ||
if (value === 1) | ||
return BitWidth.WIDTH8; | ||
return bit_width_js_1.BitWidth.WIDTH8; | ||
if (value === 2) | ||
return BitWidth.WIDTH16; | ||
return bit_width_js_1.BitWidth.WIDTH16; | ||
if (value === 4) | ||
return BitWidth.WIDTH32; | ||
return BitWidth.WIDTH64; | ||
return bit_width_js_1.BitWidth.WIDTH32; | ||
return bit_width_js_1.BitWidth.WIDTH64; | ||
} | ||
export function paddingSize(bufSize, scalarSize) { | ||
exports.fromByteWidth = fromByteWidth; | ||
function paddingSize(bufSize, scalarSize) { | ||
return (~bufSize + 1) & (scalarSize - 1); | ||
} | ||
exports.paddingSize = paddingSize; |
@@ -1,2 +0,5 @@ | ||
export var BitWidth; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BitWidth = void 0; | ||
var BitWidth; | ||
(function (BitWidth) { | ||
@@ -7,2 +10,2 @@ BitWidth[BitWidth["WIDTH8"] = 0] = "WIDTH8"; | ||
BitWidth[BitWidth["WIDTH64"] = 3] = "WIDTH64"; | ||
})(BitWidth || (BitWidth = {})); | ||
})(BitWidth = exports.BitWidth || (exports.BitWidth = {})); |
@@ -1,8 +0,11 @@ | ||
import { BitWidth } from './bit-width.js'; | ||
import { paddingSize, iwidth, uwidth, fwidth, toByteWidth, fromByteWidth } from './bit-width-util.js'; | ||
import { toUTF8Array } from './flexbuffers-util.js'; | ||
import { ValueType } from './value-type.js'; | ||
import { isNumber, isTypedVectorElement, toTypedVector } from './value-type-util.js'; | ||
import { StackValue } from './stack-value.js'; | ||
export class Builder { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Builder = void 0; | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
const value_type_js_1 = require("./value-type.js"); | ||
const value_type_util_js_1 = require("./value-type-util.js"); | ||
const stack_value_js_1 = require("./stack-value.js"); | ||
class Builder { | ||
constructor(size = 2048, dedupStrings = true, dedupKeys = true, dedupKeyVectors = true) { | ||
@@ -26,4 +29,4 @@ this.dedupStrings = dedupStrings; | ||
align(width) { | ||
const byteWidth = toByteWidth(width); | ||
this.offset += paddingSize(this.offset, byteWidth); | ||
const byteWidth = (0, bit_width_util_js_1.toByteWidth)(width); | ||
this.offset += (0, bit_width_util_js_1.paddingSize)(this.offset, byteWidth); | ||
return byteWidth; | ||
@@ -47,12 +50,12 @@ } | ||
pushInt(value, width) { | ||
if (width === BitWidth.WIDTH8) { | ||
if (width === bit_width_js_1.BitWidth.WIDTH8) { | ||
this.view.setInt8(this.offset, value); | ||
} | ||
else if (width === BitWidth.WIDTH16) { | ||
else if (width === bit_width_js_1.BitWidth.WIDTH16) { | ||
this.view.setInt16(this.offset, value, true); | ||
} | ||
else if (width === BitWidth.WIDTH32) { | ||
else if (width === bit_width_js_1.BitWidth.WIDTH32) { | ||
this.view.setInt32(this.offset, value, true); | ||
} | ||
else if (width === BitWidth.WIDTH64) { | ||
else if (width === bit_width_js_1.BitWidth.WIDTH64) { | ||
this.view.setBigInt64(this.offset, BigInt(value), true); | ||
@@ -65,12 +68,12 @@ } | ||
pushUInt(value, width) { | ||
if (width === BitWidth.WIDTH8) { | ||
if (width === bit_width_js_1.BitWidth.WIDTH8) { | ||
this.view.setUint8(this.offset, value); | ||
} | ||
else if (width === BitWidth.WIDTH16) { | ||
else if (width === bit_width_js_1.BitWidth.WIDTH16) { | ||
this.view.setUint16(this.offset, value, true); | ||
} | ||
else if (width === BitWidth.WIDTH32) { | ||
else if (width === bit_width_js_1.BitWidth.WIDTH32) { | ||
this.view.setUint32(this.offset, value, true); | ||
} | ||
else if (width === BitWidth.WIDTH64) { | ||
else if (width === bit_width_js_1.BitWidth.WIDTH64) { | ||
this.view.setBigUint64(this.offset, BigInt(value), true); | ||
@@ -84,3 +87,3 @@ } | ||
const newOffset = this.computeOffset(byteWidth); | ||
this.pushInt(value, fromByteWidth(byteWidth)); | ||
this.pushInt(value, (0, bit_width_util_js_1.fromByteWidth)(byteWidth)); | ||
this.offset = newOffset; | ||
@@ -90,3 +93,3 @@ } | ||
const newOffset = this.computeOffset(byteWidth); | ||
this.pushUInt(value, fromByteWidth(byteWidth)); | ||
this.pushUInt(value, (0, bit_width_util_js_1.fromByteWidth)(byteWidth)); | ||
this.offset = newOffset; | ||
@@ -96,3 +99,3 @@ } | ||
const length = arrayBuffer.byteLength; | ||
const bitWidth = uwidth(length); | ||
const bitWidth = (0, bit_width_util_js_1.uwidth)(length); | ||
const byteWidth = this.align(bitWidth); | ||
@@ -103,3 +106,3 @@ this.writeUInt(length, byteWidth); | ||
new Uint8Array(this.buffer).set(new Uint8Array(arrayBuffer), blobOffset); | ||
this.stack.push(this.offsetStackValue(blobOffset, ValueType.BLOB, bitWidth)); | ||
this.stack.push(this.offsetStackValue(blobOffset, value_type_js_1.ValueType.BLOB, bitWidth)); | ||
this.offset = newOffset; | ||
@@ -112,5 +115,5 @@ } | ||
} | ||
const utf8 = toUTF8Array(str); | ||
const utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str); | ||
const length = utf8.length; | ||
const bitWidth = uwidth(length); | ||
const bitWidth = (0, bit_width_util_js_1.uwidth)(length); | ||
const byteWidth = this.align(bitWidth); | ||
@@ -121,3 +124,3 @@ this.writeUInt(length, byteWidth); | ||
new Uint8Array(this.buffer).set(utf8, stringOffset); | ||
const stackValue = this.offsetStackValue(stringOffset, ValueType.STRING, bitWidth); | ||
const stackValue = this.offsetStackValue(stringOffset, value_type_js_1.ValueType.STRING, bitWidth); | ||
this.stack.push(stackValue); | ||
@@ -134,7 +137,7 @@ if (this.dedupStrings) { | ||
} | ||
const utf8 = toUTF8Array(str); | ||
const utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str); | ||
const length = utf8.length; | ||
const newOffset = this.computeOffset(length + 1); | ||
new Uint8Array(this.buffer).set(utf8, this.offset); | ||
const stackValue = this.offsetStackValue(this.offset, ValueType.KEY, BitWidth.WIDTH8); | ||
const stackValue = this.offsetStackValue(this.offset, value_type_js_1.ValueType.KEY, bit_width_js_1.BitWidth.WIDTH8); | ||
this.stack.push(stackValue); | ||
@@ -167,3 +170,3 @@ if (this.dedupKeys) { | ||
if (this.stackPointers.length !== 0 && this.stackPointers[this.stackPointers.length - 1].isVector === false) { | ||
if (this.stack[this.stack.length - 1].type !== ValueType.KEY) { | ||
if (this.stack[this.stack.length - 1].type !== value_type_js_1.ValueType.KEY) { | ||
throw "Adding value to a map before adding a key is prohibited"; | ||
@@ -214,3 +217,3 @@ } | ||
function shouldFlip(v1, v2) { | ||
if (v1.type !== ValueType.KEY || v2.type !== ValueType.KEY) { | ||
if (v1.type !== value_type_js_1.ValueType.KEY || v2.type !== value_type_js_1.ValueType.KEY) { | ||
throw `Stack values are not keys ${v1} | ${v2}. Check if you combined [addKey] with add... method calls properly.`; | ||
@@ -255,3 +258,3 @@ } | ||
function smaller(v1, v2) { | ||
if (v1.type !== ValueType.KEY || v2.type !== ValueType.KEY) { | ||
if (v1.type !== value_type_js_1.ValueType.KEY || v2.type !== value_type_js_1.ValueType.KEY) { | ||
throw `Stack values are not keys ${v1} | ${v2}. Check if you combined [addKey] with add... method calls properly.`; | ||
@@ -326,3 +329,3 @@ } | ||
createVector(start, vecLength, step, keys = null) { | ||
let bitWidth = uwidth(vecLength); | ||
let bitWidth = (0, bit_width_util_js_1.uwidth)(vecLength); | ||
let prefixElements = 1; | ||
@@ -336,3 +339,3 @@ if (keys !== null) { | ||
} | ||
let vectorType = ValueType.KEY; | ||
let vectorType = value_type_js_1.ValueType.KEY; | ||
let typed = keys === null; | ||
@@ -346,3 +349,3 @@ for (let i = start; i < this.stack.length; i += step) { | ||
vectorType = this.stack[i].type; | ||
typed = typed && isTypedVectorElement(vectorType); | ||
typed = typed && (0, value_type_util_js_1.isTypedVectorElement)(vectorType); | ||
} | ||
@@ -356,3 +359,3 @@ else { | ||
const byteWidth = this.align(bitWidth); | ||
const fix = typed && isNumber(vectorType) && vecLength >= 2 && vecLength <= 4; | ||
const fix = typed && (0, value_type_util_js_1.isNumber)(vectorType) && vecLength >= 2 && vecLength <= 4; | ||
if (keys !== null) { | ||
@@ -375,27 +378,27 @@ this.writeStackValue(keys, byteWidth); | ||
if (keys !== null) { | ||
return this.offsetStackValue(vecOffset, ValueType.MAP, bitWidth); | ||
return this.offsetStackValue(vecOffset, value_type_js_1.ValueType.MAP, bitWidth); | ||
} | ||
if (typed) { | ||
const vType = toTypedVector(vectorType, fix ? vecLength : 0); | ||
const vType = (0, value_type_util_js_1.toTypedVector)(vectorType, fix ? vecLength : 0); | ||
return this.offsetStackValue(vecOffset, vType, bitWidth); | ||
} | ||
return this.offsetStackValue(vecOffset, ValueType.VECTOR, bitWidth); | ||
return this.offsetStackValue(vecOffset, value_type_js_1.ValueType.VECTOR, bitWidth); | ||
} | ||
nullStackValue() { | ||
return new StackValue(this, ValueType.NULL, BitWidth.WIDTH8); | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.NULL, bit_width_js_1.BitWidth.WIDTH8); | ||
} | ||
boolStackValue(value) { | ||
return new StackValue(this, ValueType.BOOL, BitWidth.WIDTH8, value); | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.BOOL, bit_width_js_1.BitWidth.WIDTH8, value); | ||
} | ||
intStackValue(value) { | ||
return new StackValue(this, ValueType.INT, iwidth(value), value); | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.INT, (0, bit_width_util_js_1.iwidth)(value), value); | ||
} | ||
uintStackValue(value) { | ||
return new StackValue(this, ValueType.UINT, uwidth(value), value); | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.UINT, (0, bit_width_util_js_1.uwidth)(value), value); | ||
} | ||
floatStackValue(value) { | ||
return new StackValue(this, ValueType.FLOAT, fwidth(value), value); | ||
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.FLOAT, (0, bit_width_util_js_1.fwidth)(value), value); | ||
} | ||
offsetStackValue(offset, valueType, bitWidth) { | ||
return new StackValue(this, valueType, bitWidth, null, offset); | ||
return new stack_value_js_1.StackValue(this, valueType, bitWidth, null, offset); | ||
} | ||
@@ -491,3 +494,3 @@ finishBuffer() { | ||
stackValue.writeToBuffer(byteWidth); | ||
const stackOffset = this.offsetStackValue(valueOffset, ValueType.INDIRECT_INT, stackValue.width); | ||
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_INT, stackValue.width); | ||
this.stack.push(stackOffset); | ||
@@ -514,3 +517,3 @@ this.offset = newOffset; | ||
stackValue.writeToBuffer(byteWidth); | ||
const stackOffset = this.offsetStackValue(valueOffset, ValueType.INDIRECT_UINT, stackValue.width); | ||
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_UINT, stackValue.width); | ||
this.stack.push(stackOffset); | ||
@@ -537,3 +540,3 @@ this.offset = newOffset; | ||
stackValue.writeToBuffer(byteWidth); | ||
const stackOffset = this.offsetStackValue(valueOffset, ValueType.INDIRECT_FLOAT, stackValue.width); | ||
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_FLOAT, stackValue.width); | ||
this.stack.push(stackOffset); | ||
@@ -546,1 +549,2 @@ this.offset = newOffset; | ||
} | ||
exports.Builder = Builder; |
@@ -1,8 +0,13 @@ | ||
export function fromUTF8Array(data) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toUTF8Array = exports.fromUTF8Array = void 0; | ||
function fromUTF8Array(data) { | ||
const decoder = new TextDecoder(); | ||
return decoder.decode(data); | ||
} | ||
export function toUTF8Array(str) { | ||
exports.fromUTF8Array = fromUTF8Array; | ||
function toUTF8Array(str) { | ||
const encoder = new TextEncoder(); | ||
return encoder.encode(str); | ||
} | ||
exports.toUTF8Array = toUTF8Array; |
@@ -1,10 +0,14 @@ | ||
import { BitWidth } from './bit-width.js'; | ||
import { toByteWidth, fromByteWidth } from './bit-width-util.js'; | ||
import { toUTF8Array, fromUTF8Array } from './flexbuffers-util.js'; | ||
export function validateOffset(dataView, offset, width) { | ||
if (dataView.byteLength <= offset + width || (offset & (toByteWidth(width) - 1)) !== 0) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.keyForIndex = exports.diffKeys = exports.keyIndex = exports.indirect = exports.readFloat = exports.readUInt = exports.readInt = exports.validateOffset = void 0; | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
function validateOffset(dataView, offset, width) { | ||
if (dataView.byteLength <= offset + width || (offset & ((0, bit_width_util_js_1.toByteWidth)(width) - 1)) !== 0) { | ||
throw "Bad offset: " + offset + ", width: " + width; | ||
} | ||
} | ||
export function readInt(dataView, offset, width) { | ||
exports.validateOffset = validateOffset; | ||
function readInt(dataView, offset, width) { | ||
if (width < 2) { | ||
@@ -30,3 +34,4 @@ if (width < 1) { | ||
} | ||
export function readUInt(dataView, offset, width) { | ||
exports.readInt = readInt; | ||
function readUInt(dataView, offset, width) { | ||
if (width < 2) { | ||
@@ -52,7 +57,8 @@ if (width < 1) { | ||
} | ||
export function readFloat(dataView, offset, width) { | ||
if (width < BitWidth.WIDTH32) { | ||
exports.readUInt = readUInt; | ||
function readFloat(dataView, offset, width) { | ||
if (width < bit_width_js_1.BitWidth.WIDTH32) { | ||
throw "Bad width: " + width; | ||
} | ||
if (width === BitWidth.WIDTH32) { | ||
if (width === bit_width_js_1.BitWidth.WIDTH32) { | ||
return dataView.getFloat32(offset, true); | ||
@@ -62,10 +68,12 @@ } | ||
} | ||
export function indirect(dataView, offset, width) { | ||
exports.readFloat = readFloat; | ||
function indirect(dataView, offset, width) { | ||
const step = readUInt(dataView, offset, width); | ||
return offset - step; | ||
} | ||
export function keyIndex(key, dataView, offset, parentWidth, byteWidth, length) { | ||
const input = toUTF8Array(key); | ||
exports.indirect = indirect; | ||
function keyIndex(key, dataView, offset, parentWidth, byteWidth, length) { | ||
const input = (0, flexbuffers_util_js_1.toUTF8Array)(key); | ||
const keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3; | ||
const bitWidth = fromByteWidth(byteWidth); | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const indirectOffset = keysVectorOffset - Number(readUInt(dataView, keysVectorOffset, bitWidth)); | ||
@@ -89,5 +97,6 @@ const _byteWidth = Number(readUInt(dataView, keysVectorOffset + byteWidth, bitWidth)); | ||
} | ||
export function diffKeys(input, index, dataView, offset, width) { | ||
exports.keyIndex = keyIndex; | ||
function diffKeys(input, index, dataView, offset, width) { | ||
const keyOffset = offset + index * width; | ||
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, fromByteWidth(width))); | ||
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, (0, bit_width_util_js_1.fromByteWidth)(width))); | ||
for (let i = 0; i < input.length; i++) { | ||
@@ -101,9 +110,10 @@ const dif = input[i] - dataView.getUint8(keyIndirectOffset + i); | ||
} | ||
export function keyForIndex(index, dataView, offset, parentWidth, byteWidth) { | ||
exports.diffKeys = diffKeys; | ||
function keyForIndex(index, dataView, offset, parentWidth, byteWidth) { | ||
const keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3; | ||
const bitWidth = fromByteWidth(byteWidth); | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const indirectOffset = keysVectorOffset - Number(readUInt(dataView, keysVectorOffset, bitWidth)); | ||
const _byteWidth = Number(readUInt(dataView, keysVectorOffset + byteWidth, bitWidth)); | ||
const keyOffset = indirectOffset + index * _byteWidth; | ||
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, fromByteWidth(_byteWidth))); | ||
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, (0, bit_width_util_js_1.fromByteWidth)(_byteWidth))); | ||
let length = 0; | ||
@@ -113,3 +123,4 @@ while (dataView.getUint8(keyIndirectOffset + length) !== 0) { | ||
} | ||
return fromUTF8Array(new Uint8Array(dataView.buffer, keyIndirectOffset, length)); | ||
return (0, flexbuffers_util_js_1.fromUTF8Array)(new Uint8Array(dataView.buffer, keyIndirectOffset, length)); | ||
} | ||
exports.keyForIndex = keyForIndex; |
@@ -1,8 +0,11 @@ | ||
import { fromByteWidth } from './bit-width-util.js'; | ||
import { ValueType } from './value-type.js'; | ||
import { isNumber, isIndirectNumber, isAVector, fixedTypedVectorElementSize, isFixedTypedVector, isTypedVector, typedVectorElementType, packedType, fixedTypedVectorElementType } from './value-type-util.js'; | ||
import { indirect, keyForIndex, keyIndex, readFloat, readInt, readUInt } from './reference-util.js'; | ||
import { fromUTF8Array } from './flexbuffers-util.js'; | ||
import { BitWidth } from './bit-width.js'; | ||
export function toReference(buffer) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Reference = exports.toReference = void 0; | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const value_type_js_1 = require("./value-type.js"); | ||
const value_type_util_js_1 = require("./value-type-util.js"); | ||
const reference_util_js_1 = require("./reference-util.js"); | ||
const flexbuffers_util_js_1 = require("./flexbuffers-util.js"); | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
function toReference(buffer) { | ||
const len = buffer.byteLength; | ||
@@ -15,13 +18,14 @@ if (len < 3) { | ||
const packedType = dataView.getUint8(len - 2); | ||
const parentWidth = fromByteWidth(byteWidth); | ||
const parentWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
const offset = len - byteWidth - 2; | ||
return new Reference(dataView, offset, parentWidth, packedType, "/"); | ||
} | ||
exports.toReference = toReference; | ||
function valueForIndexWithKey(index, key, dataView, offset, parentWidth, byteWidth, length, path) { | ||
const _indirect = indirect(dataView, offset, parentWidth); | ||
const _indirect = (0, reference_util_js_1.indirect)(dataView, offset, parentWidth); | ||
const elementOffset = _indirect + index * byteWidth; | ||
const packedType = dataView.getUint8(_indirect + length * byteWidth + index); | ||
return new Reference(dataView, elementOffset, fromByteWidth(byteWidth), packedType, `${path}/${key}`); | ||
return new Reference(dataView, elementOffset, (0, bit_width_util_js_1.fromByteWidth)(byteWidth), packedType, `${path}/${key}`); | ||
} | ||
export class Reference { | ||
class Reference { | ||
constructor(dataView, offset, parentWidth, packedType, path) { | ||
@@ -37,14 +41,14 @@ this.dataView = dataView; | ||
} | ||
isNull() { return this.valueType === ValueType.NULL; } | ||
isNumber() { return isNumber(this.valueType) || isIndirectNumber(this.valueType); } | ||
isFloat() { return ValueType.FLOAT === this.valueType || ValueType.INDIRECT_FLOAT === this.valueType; } | ||
isNull() { return this.valueType === value_type_js_1.ValueType.NULL; } | ||
isNumber() { return (0, value_type_util_js_1.isNumber)(this.valueType) || (0, value_type_util_js_1.isIndirectNumber)(this.valueType); } | ||
isFloat() { return value_type_js_1.ValueType.FLOAT === this.valueType || value_type_js_1.ValueType.INDIRECT_FLOAT === this.valueType; } | ||
isInt() { return this.isNumber() && !this.isFloat(); } | ||
isString() { return ValueType.STRING === this.valueType || ValueType.KEY === this.valueType; } | ||
isBool() { return ValueType.BOOL === this.valueType; } | ||
isBlob() { return ValueType.BLOB === this.valueType; } | ||
isVector() { return isAVector(this.valueType); } | ||
isMap() { return ValueType.MAP === this.valueType; } | ||
isString() { return value_type_js_1.ValueType.STRING === this.valueType || value_type_js_1.ValueType.KEY === this.valueType; } | ||
isBool() { return value_type_js_1.ValueType.BOOL === this.valueType; } | ||
isBlob() { return value_type_js_1.ValueType.BLOB === this.valueType; } | ||
isVector() { return (0, value_type_util_js_1.isAVector)(this.valueType); } | ||
isMap() { return value_type_js_1.ValueType.MAP === this.valueType; } | ||
boolValue() { | ||
if (this.isBool()) { | ||
return readInt(this.dataView, this.offset, this.parentWidth) > 0; | ||
return (0, reference_util_js_1.readInt)(this.dataView, this.offset, this.parentWidth) > 0; | ||
} | ||
@@ -54,13 +58,13 @@ return null; | ||
intValue() { | ||
if (this.valueType === ValueType.INT) { | ||
return readInt(this.dataView, this.offset, this.parentWidth); | ||
if (this.valueType === value_type_js_1.ValueType.INT) { | ||
return (0, reference_util_js_1.readInt)(this.dataView, this.offset, this.parentWidth); | ||
} | ||
if (this.valueType === ValueType.UINT) { | ||
return readUInt(this.dataView, this.offset, this.parentWidth); | ||
if (this.valueType === value_type_js_1.ValueType.UINT) { | ||
return (0, reference_util_js_1.readUInt)(this.dataView, this.offset, this.parentWidth); | ||
} | ||
if (this.valueType === ValueType.INDIRECT_INT) { | ||
return readInt(this.dataView, indirect(this.dataView, this.offset, this.parentWidth), fromByteWidth(this.byteWidth)); | ||
if (this.valueType === value_type_js_1.ValueType.INDIRECT_INT) { | ||
return (0, reference_util_js_1.readInt)(this.dataView, (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth), (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth)); | ||
} | ||
if (this.valueType === ValueType.INDIRECT_UINT) { | ||
return readUInt(this.dataView, indirect(this.dataView, this.offset, this.parentWidth), fromByteWidth(this.byteWidth)); | ||
if (this.valueType === value_type_js_1.ValueType.INDIRECT_UINT) { | ||
return (0, reference_util_js_1.readUInt)(this.dataView, (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth), (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth)); | ||
} | ||
@@ -70,7 +74,7 @@ return null; | ||
floatValue() { | ||
if (this.valueType === ValueType.FLOAT) { | ||
return readFloat(this.dataView, this.offset, this.parentWidth); | ||
if (this.valueType === value_type_js_1.ValueType.FLOAT) { | ||
return (0, reference_util_js_1.readFloat)(this.dataView, this.offset, this.parentWidth); | ||
} | ||
if (this.valueType === ValueType.INDIRECT_FLOAT) { | ||
return readFloat(this.dataView, indirect(this.dataView, this.offset, this.parentWidth), fromByteWidth(this.byteWidth)); | ||
if (this.valueType === value_type_js_1.ValueType.INDIRECT_FLOAT) { | ||
return (0, reference_util_js_1.readFloat)(this.dataView, (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth), (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth)); | ||
} | ||
@@ -81,5 +85,5 @@ return null; | ||
stringValue() { | ||
if (this.valueType === ValueType.STRING || this.valueType === ValueType.KEY) { | ||
const begin = indirect(this.dataView, this.offset, this.parentWidth); | ||
return fromUTF8Array(new Uint8Array(this.dataView.buffer, begin, this.length())); | ||
if (this.valueType === value_type_js_1.ValueType.STRING || this.valueType === value_type_js_1.ValueType.KEY) { | ||
const begin = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
return (0, flexbuffers_util_js_1.fromUTF8Array)(new Uint8Array(this.dataView.buffer, begin, this.length())); | ||
} | ||
@@ -90,3 +94,3 @@ return null; | ||
if (this.isBlob()) { | ||
const begin = indirect(this.dataView, this.offset, this.parentWidth); | ||
const begin = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
return new Uint8Array(this.dataView.buffer, begin, this.length()); | ||
@@ -98,21 +102,21 @@ } | ||
const length = this.length(); | ||
if (Number.isInteger(key) && isAVector(this.valueType)) { | ||
if (Number.isInteger(key) && (0, value_type_util_js_1.isAVector)(this.valueType)) { | ||
if (key >= length || key < 0) { | ||
throw `Key: [${key}] is not applicable on ${this.path} of ${this.valueType} length: ${length}`; | ||
} | ||
const _indirect = indirect(this.dataView, this.offset, this.parentWidth); | ||
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
const elementOffset = _indirect + key * this.byteWidth; | ||
let _packedType = this.dataView.getUint8(_indirect + length * this.byteWidth + key); | ||
if (isTypedVector(this.valueType)) { | ||
const _valueType = typedVectorElementType(this.valueType); | ||
_packedType = packedType(_valueType, BitWidth.WIDTH8); | ||
if ((0, value_type_util_js_1.isTypedVector)(this.valueType)) { | ||
const _valueType = (0, value_type_util_js_1.typedVectorElementType)(this.valueType); | ||
_packedType = (0, value_type_util_js_1.packedType)(_valueType, bit_width_js_1.BitWidth.WIDTH8); | ||
} | ||
else if (isFixedTypedVector(this.valueType)) { | ||
const _valueType = fixedTypedVectorElementType(this.valueType); | ||
_packedType = packedType(_valueType, BitWidth.WIDTH8); | ||
else if ((0, value_type_util_js_1.isFixedTypedVector)(this.valueType)) { | ||
const _valueType = (0, value_type_util_js_1.fixedTypedVectorElementType)(this.valueType); | ||
_packedType = (0, value_type_util_js_1.packedType)(_valueType, bit_width_js_1.BitWidth.WIDTH8); | ||
} | ||
return new Reference(this.dataView, elementOffset, fromByteWidth(this.byteWidth), _packedType, `${this.path}[${key}]`); | ||
return new Reference(this.dataView, elementOffset, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth), _packedType, `${this.path}[${key}]`); | ||
} | ||
if (typeof key === 'string') { | ||
const index = keyIndex(key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length); | ||
const index = (0, reference_util_js_1.keyIndex)(key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length); | ||
if (index !== null) { | ||
@@ -129,25 +133,25 @@ return valueForIndexWithKey(index, key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length, this.path); | ||
} | ||
if (isFixedTypedVector(this.valueType)) { | ||
this._length = fixedTypedVectorElementSize(this.valueType); | ||
if ((0, value_type_util_js_1.isFixedTypedVector)(this.valueType)) { | ||
this._length = (0, value_type_util_js_1.fixedTypedVectorElementSize)(this.valueType); | ||
} | ||
else if (this.valueType === ValueType.BLOB | ||
|| this.valueType === ValueType.MAP | ||
|| isAVector(this.valueType)) { | ||
this._length = readUInt(this.dataView, indirect(this.dataView, this.offset, this.parentWidth) - this.byteWidth, fromByteWidth(this.byteWidth)); | ||
else if (this.valueType === value_type_js_1.ValueType.BLOB | ||
|| this.valueType === value_type_js_1.ValueType.MAP | ||
|| (0, value_type_util_js_1.isAVector)(this.valueType)) { | ||
this._length = (0, reference_util_js_1.readUInt)(this.dataView, (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth) - this.byteWidth, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth)); | ||
} | ||
else if (this.valueType === ValueType.NULL) { | ||
else if (this.valueType === value_type_js_1.ValueType.NULL) { | ||
this._length = 0; | ||
} | ||
else if (this.valueType === ValueType.STRING) { | ||
const _indirect = indirect(this.dataView, this.offset, this.parentWidth); | ||
else if (this.valueType === value_type_js_1.ValueType.STRING) { | ||
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
let sizeByteWidth = this.byteWidth; | ||
size = readUInt(this.dataView, _indirect - sizeByteWidth, fromByteWidth(this.byteWidth)); | ||
size = (0, reference_util_js_1.readUInt)(this.dataView, _indirect - sizeByteWidth, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth)); | ||
while (this.dataView.getInt8(_indirect + size) !== 0) { | ||
sizeByteWidth <<= 1; | ||
size = readUInt(this.dataView, _indirect - sizeByteWidth, fromByteWidth(this.byteWidth)); | ||
size = (0, reference_util_js_1.readUInt)(this.dataView, _indirect - sizeByteWidth, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth)); | ||
} | ||
this._length = size; | ||
} | ||
else if (this.valueType === ValueType.KEY) { | ||
const _indirect = indirect(this.dataView, this.offset, this.parentWidth); | ||
else if (this.valueType === value_type_js_1.ValueType.KEY) { | ||
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth); | ||
size = 1; | ||
@@ -176,3 +180,3 @@ while (this.dataView.getInt8(_indirect + size) !== 0) { | ||
for (let i = 0; i < length; i++) { | ||
const key = keyForIndex(i, this.dataView, this.offset, this.parentWidth, this.byteWidth); | ||
const key = (0, reference_util_js_1.keyForIndex)(i, this.dataView, this.offset, this.parentWidth, this.byteWidth); | ||
result[key] = valueForIndexWithKey(i, key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length, this.path).toObject(); | ||
@@ -194,1 +198,2 @@ } | ||
} | ||
exports.Reference = Reference; |
@@ -1,6 +0,9 @@ | ||
import { BitWidth } from './bit-width.js'; | ||
import { paddingSize, uwidth, fromByteWidth } from './bit-width-util.js'; | ||
import { ValueType } from './value-type.js'; | ||
import { isInline, packedType } from './value-type-util.js'; | ||
export class StackValue { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StackValue = void 0; | ||
const bit_width_js_1 = require("./bit-width.js"); | ||
const bit_width_util_js_1 = require("./bit-width-util.js"); | ||
const value_type_js_1 = require("./value-type.js"); | ||
const value_type_util_js_1 = require("./value-type-util.js"); | ||
class StackValue { | ||
constructor(builder, type, width, value = null, offset = 0) { | ||
@@ -14,9 +17,9 @@ this.builder = builder; | ||
elementWidth(size, index) { | ||
if (isInline(this.type)) | ||
if ((0, value_type_util_js_1.isInline)(this.type)) | ||
return this.width; | ||
for (let i = 0; i < 4; i++) { | ||
const width = 1 << i; | ||
const offsetLoc = size + paddingSize(size, width) + index * width; | ||
const offsetLoc = size + (0, bit_width_util_js_1.paddingSize)(size, width) + index * width; | ||
const offset = offsetLoc - this.offset; | ||
const bitWidth = uwidth(offset); | ||
const bitWidth = (0, bit_width_util_js_1.uwidth)(offset); | ||
if (1 << bitWidth === width) { | ||
@@ -30,4 +33,4 @@ return bitWidth; | ||
const newOffset = this.builder.computeOffset(byteWidth); | ||
if (this.type === ValueType.FLOAT) { | ||
if (this.width === BitWidth.WIDTH32) { | ||
if (this.type === value_type_js_1.ValueType.FLOAT) { | ||
if (this.width === bit_width_js_1.BitWidth.WIDTH32) { | ||
this.builder.view.setFloat32(this.builder.offset, this.value, true); | ||
@@ -39,14 +42,14 @@ } | ||
} | ||
else if (this.type === ValueType.INT) { | ||
const bitWidth = fromByteWidth(byteWidth); | ||
else if (this.type === value_type_js_1.ValueType.INT) { | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
this.builder.pushInt(this.value, bitWidth); | ||
} | ||
else if (this.type === ValueType.UINT) { | ||
const bitWidth = fromByteWidth(byteWidth); | ||
else if (this.type === value_type_js_1.ValueType.UINT) { | ||
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth); | ||
this.builder.pushUInt(this.value, bitWidth); | ||
} | ||
else if (this.type === ValueType.NULL) { | ||
else if (this.type === value_type_js_1.ValueType.NULL) { | ||
this.builder.pushInt(0, this.width); | ||
} | ||
else if (this.type === ValueType.BOOL) { | ||
else if (this.type === value_type_js_1.ValueType.BOOL) { | ||
this.builder.pushInt(this.value ? 1 : 0, this.width); | ||
@@ -59,11 +62,12 @@ } | ||
} | ||
storedWidth(width = BitWidth.WIDTH8) { | ||
return isInline(this.type) ? Math.max(width, this.width) : this.width; | ||
storedWidth(width = bit_width_js_1.BitWidth.WIDTH8) { | ||
return (0, value_type_util_js_1.isInline)(this.type) ? Math.max(width, this.width) : this.width; | ||
} | ||
storedPackedType(width = BitWidth.WIDTH8) { | ||
return packedType(this.type, this.storedWidth(width)); | ||
storedPackedType(width = bit_width_js_1.BitWidth.WIDTH8) { | ||
return (0, value_type_util_js_1.packedType)(this.type, this.storedWidth(width)); | ||
} | ||
isOffset() { | ||
return !isInline(this.type); | ||
return !(0, value_type_util_js_1.isInline)(this.type); | ||
} | ||
} | ||
exports.StackValue = StackValue; |
@@ -1,56 +0,71 @@ | ||
import { ValueType } from './value-type.js'; | ||
export function isInline(value) { | ||
return value === ValueType.BOOL | ||
|| value <= ValueType.FLOAT; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.packedType = exports.fixedTypedVectorElementSize = exports.fixedTypedVectorElementType = exports.typedVectorElementType = exports.toTypedVector = exports.isAVector = exports.isFixedTypedVector = exports.isTypedVector = exports.isTypedVectorElement = exports.isIndirectNumber = exports.isNumber = exports.isInline = void 0; | ||
const value_type_js_1 = require("./value-type.js"); | ||
function isInline(value) { | ||
return value === value_type_js_1.ValueType.BOOL | ||
|| value <= value_type_js_1.ValueType.FLOAT; | ||
} | ||
export function isNumber(value) { | ||
return value >= ValueType.INT | ||
&& value <= ValueType.FLOAT; | ||
exports.isInline = isInline; | ||
function isNumber(value) { | ||
return value >= value_type_js_1.ValueType.INT | ||
&& value <= value_type_js_1.ValueType.FLOAT; | ||
} | ||
export function isIndirectNumber(value) { | ||
return value >= ValueType.INDIRECT_INT | ||
&& value <= ValueType.INDIRECT_FLOAT; | ||
exports.isNumber = isNumber; | ||
function isIndirectNumber(value) { | ||
return value >= value_type_js_1.ValueType.INDIRECT_INT | ||
&& value <= value_type_js_1.ValueType.INDIRECT_FLOAT; | ||
} | ||
export function isTypedVectorElement(value) { | ||
return value === ValueType.BOOL | ||
|| (value >= ValueType.INT | ||
&& value <= ValueType.STRING); | ||
exports.isIndirectNumber = isIndirectNumber; | ||
function isTypedVectorElement(value) { | ||
return value === value_type_js_1.ValueType.BOOL | ||
|| (value >= value_type_js_1.ValueType.INT | ||
&& value <= value_type_js_1.ValueType.STRING); | ||
} | ||
export function isTypedVector(value) { | ||
return value === ValueType.VECTOR_BOOL | ||
|| (value >= ValueType.VECTOR_INT | ||
&& value <= ValueType.VECTOR_STRING_DEPRECATED); | ||
exports.isTypedVectorElement = isTypedVectorElement; | ||
function isTypedVector(value) { | ||
return value === value_type_js_1.ValueType.VECTOR_BOOL | ||
|| (value >= value_type_js_1.ValueType.VECTOR_INT | ||
&& value <= value_type_js_1.ValueType.VECTOR_STRING_DEPRECATED); | ||
} | ||
export function isFixedTypedVector(value) { | ||
return value >= ValueType.VECTOR_INT2 | ||
&& value <= ValueType.VECTOR_FLOAT4; | ||
exports.isTypedVector = isTypedVector; | ||
function isFixedTypedVector(value) { | ||
return value >= value_type_js_1.ValueType.VECTOR_INT2 | ||
&& value <= value_type_js_1.ValueType.VECTOR_FLOAT4; | ||
} | ||
export function isAVector(value) { | ||
exports.isFixedTypedVector = isFixedTypedVector; | ||
function isAVector(value) { | ||
return isTypedVector(value) | ||
|| isFixedTypedVector(value) | ||
|| value === ValueType.VECTOR; | ||
|| value === value_type_js_1.ValueType.VECTOR; | ||
} | ||
export function toTypedVector(valueType, length) { | ||
exports.isAVector = isAVector; | ||
function toTypedVector(valueType, length) { | ||
if (length === 0) | ||
return valueType - ValueType.INT + ValueType.VECTOR_INT; | ||
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT; | ||
if (length === 2) | ||
return valueType - ValueType.INT + ValueType.VECTOR_INT2; | ||
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT2; | ||
if (length === 3) | ||
return valueType - ValueType.INT + ValueType.VECTOR_INT3; | ||
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT3; | ||
if (length === 4) | ||
return valueType - ValueType.INT + ValueType.VECTOR_INT4; | ||
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT4; | ||
throw "Unexpected length " + length; | ||
} | ||
export function typedVectorElementType(valueType) { | ||
return valueType - ValueType.VECTOR_INT + ValueType.INT; | ||
exports.toTypedVector = toTypedVector; | ||
function typedVectorElementType(valueType) { | ||
return valueType - value_type_js_1.ValueType.VECTOR_INT + value_type_js_1.ValueType.INT; | ||
} | ||
export function fixedTypedVectorElementType(valueType) { | ||
return ((valueType - ValueType.VECTOR_INT2) % 3) + ValueType.INT; | ||
exports.typedVectorElementType = typedVectorElementType; | ||
function fixedTypedVectorElementType(valueType) { | ||
return ((valueType - value_type_js_1.ValueType.VECTOR_INT2) % 3) + value_type_js_1.ValueType.INT; | ||
} | ||
export function fixedTypedVectorElementSize(valueType) { | ||
exports.fixedTypedVectorElementType = fixedTypedVectorElementType; | ||
function fixedTypedVectorElementSize(valueType) { | ||
// The x / y >> 0 trick is to have an int division. Suppose to be faster than Math.floor() | ||
return (((valueType - ValueType.VECTOR_INT2) / 3) >> 0) + 2; | ||
return (((valueType - value_type_js_1.ValueType.VECTOR_INT2) / 3) >> 0) + 2; | ||
} | ||
export function packedType(valueType, bitWidth) { | ||
exports.fixedTypedVectorElementSize = fixedTypedVectorElementSize; | ||
function packedType(valueType, bitWidth) { | ||
return bitWidth | (valueType << 2); | ||
} | ||
exports.packedType = packedType; |
@@ -1,2 +0,5 @@ | ||
export var ValueType; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ValueType = void 0; | ||
var ValueType; | ||
(function (ValueType) { | ||
@@ -31,2 +34,2 @@ ValueType[ValueType["NULL"] = 0] = "NULL"; | ||
ValueType[ValueType["VECTOR_BOOL"] = 36] = "VECTOR_BOOL"; | ||
})(ValueType || (ValueType = {})); | ||
})(ValueType = exports.ValueType || (exports.ValueType = {})); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,4 +0,7 @@ | ||
export const int32 = new Int32Array(2); | ||
export const float32 = new Float32Array(int32.buffer); | ||
export const float64 = new Float64Array(int32.buffer); | ||
export const isLittleEndian = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLittleEndian = exports.float64 = exports.float32 = exports.int32 = void 0; | ||
exports.int32 = new Int32Array(2); | ||
exports.float32 = new Float32Array(exports.int32.buffer); | ||
exports.float64 = new Float64Array(exports.int32.buffer); | ||
exports.isLittleEndian = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; |
{ | ||
"name": "flatbuffers", | ||
"version": "23.1.20", | ||
"version": "23.1.21", | ||
"description": "Memory Efficient Serialization Library", | ||
@@ -12,4 +12,16 @@ "files": [ | ||
], | ||
"main": "js/index.js", | ||
"module": "mjs/index.js", | ||
"main": "js/flatbuffers.js", | ||
"module": "mjs/flatbuffers.js", | ||
"exports": { | ||
".": { | ||
"node": { | ||
"import": "./mjs/flatbuffers.js", | ||
"require": "./js/flatbuffers.js" | ||
}, | ||
"default": "./js/flatbuffers.js" | ||
}, | ||
"./js/flexbuffers.js": { | ||
"default": "./js/flexbuffers.js" | ||
} | ||
}, | ||
"directories": { | ||
@@ -22,3 +34,3 @@ "doc": "docs", | ||
"lint": "eslint ts", | ||
"compile": "tsc && tsc -p tsconfig.mjs.json && rollup -c", | ||
"compile": "tsc && tsc -p tsconfig.mjs.json && esbuild js/flatbuffers.js --minify --global-name=flatbuffers --bundle --outfile=js/flatbuffers.min.js", | ||
"prepublishOnly": "npm install --only=dev && npm run compile" | ||
@@ -43,8 +55,8 @@ }, | ||
"@types/node": "18.7.16", | ||
"@typescript-eslint/eslint-plugin": "^5.36.2", | ||
"@typescript-eslint/parser": "^5.36.2", | ||
"eslint": "^8.23.1", | ||
"rollup": "^2.79.0", | ||
"@typescript-eslint/eslint-plugin": "^5.46.0", | ||
"@typescript-eslint/parser": "^5.46.0", | ||
"esbuild": "^0.16.4", | ||
"eslint": "^8.29.0", | ||
"typescript": "^4.8.3" | ||
} | ||
} |
@@ -1,1 +0,12 @@ | ||
export * as flatbuffers from './index.js' | ||
export { SIZEOF_SHORT } from './constants.js' | ||
export { SIZEOF_INT } from './constants.js' | ||
export { FILE_IDENTIFIER_LENGTH } from './constants.js' | ||
export { SIZE_PREFIX_LENGTH } from './constants.js' | ||
export { Table, Offset, IGeneratedObject, IUnpackableObject } from './types.js' | ||
export { int32, float32, float64, isLittleEndian } from './utils.js' | ||
export { Encoding } from './encoding.js' | ||
export { Builder } from './builder.js' | ||
export { ByteBuffer } from './byte-buffer.js' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
294689
6730
89