Socket
Socket
Sign inDemoInstall

flatbuffers

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flatbuffers - npm Package Compare versions

Comparing version 23.1.21 to 23.3.3

LICENSE

38

mjs/builder.js

@@ -1,7 +0,4 @@

"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 {
import { ByteBuffer } from "./byte-buffer.js";
import { SIZEOF_SHORT, SIZE_PREFIX_LENGTH, SIZEOF_INT, FILE_IDENTIFIER_LENGTH } from "./constants.js";
export class Builder {
/**

@@ -40,3 +37,3 @@ * Create a FlatBufferBuilder.

*/
this.bb = byte_buffer_js_1.ByteBuffer.allocate(initial_size);
this.bb = ByteBuffer.allocate(initial_size);
this.space = initial_size;

@@ -280,3 +277,3 @@ }

const new_buf_size = old_buf_size << 1;
const nbb = byte_buffer_js_1.ByteBuffer.allocate(new_buf_size);
const nbb = ByteBuffer.allocate(new_buf_size);
nbb.setPosition(new_buf_size - old_buf_size);

@@ -292,4 +289,4 @@ nbb.bytes().set(bb.bytes(), new_buf_size - old_buf_size);

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);
this.prep(SIZEOF_INT, 0); // Ensure alignment is already done.
this.writeInt32(this.offset() - offset + SIZEOF_INT);
}

@@ -336,3 +333,3 @@ /**

this.addInt16(vtableloc - this.object_start);
const len = (trimmed_size + standard_fields) * constants_js_1.SIZEOF_SHORT;
const len = (trimmed_size + standard_fields) * SIZEOF_SHORT;
this.addInt16(len);

@@ -345,3 +342,3 @@ // Search for an existing vtable that matches the current one.

if (len == this.bb.readInt16(vt2)) {
for (let j = constants_js_1.SIZEOF_SHORT; j < len; j += constants_js_1.SIZEOF_SHORT) {
for (let j = SIZEOF_SHORT; j < len; j += SIZEOF_SHORT) {
if (this.bb.readInt16(vt1 + j) != this.bb.readInt16(vt2 + j)) {

@@ -376,16 +373,16 @@ continue outer_loop;

finish(root_table, opt_file_identifier, opt_size_prefix) {
const size_prefix = opt_size_prefix ? constants_js_1.SIZE_PREFIX_LENGTH : 0;
const size_prefix = opt_size_prefix ? SIZE_PREFIX_LENGTH : 0;
if (opt_file_identifier) {
const file_identifier = opt_file_identifier;
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) {
this.prep(this.minalign, SIZEOF_INT +
FILE_IDENTIFIER_LENGTH + size_prefix);
if (file_identifier.length != FILE_IDENTIFIER_LENGTH) {
throw new Error('FlatBuffers: file identifier must be length ' +
constants_js_1.FILE_IDENTIFIER_LENGTH);
FILE_IDENTIFIER_LENGTH);
}
for (let i = constants_js_1.FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) {
for (let i = FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) {
this.writeInt8(file_identifier.charCodeAt(i));
}
}
this.prep(this.minalign, constants_js_1.SIZEOF_INT + size_prefix);
this.prep(this.minalign, SIZEOF_INT + size_prefix);
this.addOffset(root_table);

@@ -429,3 +426,3 @@ if (size_prefix) {

this.vector_num_elems = num_elems;
this.prep(constants_js_1.SIZEOF_INT, elem_size * num_elems);
this.prep(SIZEOF_INT, elem_size * num_elems);
this.prep(alignment, elem_size * num_elems); // Just in case alignment > int.

@@ -531,2 +528,1 @@ }

}
exports.Builder = Builder;

@@ -1,8 +0,5 @@

"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 {
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 {
/**

@@ -74,9 +71,9 @@ * Create a new ByteBuffer with a given array of bytes (`Uint8Array`)

readFloat32(offset) {
utils_js_1.int32[0] = this.readInt32(offset);
return utils_js_1.float32[0];
int32[0] = this.readInt32(offset);
return float32[0];
}
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];
int32[isLittleEndian ? 0 : 1] = this.readInt32(offset);
int32[isLittleEndian ? 1 : 0] = this.readInt32(offset + 4);
return float64[0];
}

@@ -118,9 +115,9 @@ writeInt8(offset, value) {

writeFloat32(offset, value) {
utils_js_1.float32[0] = value;
this.writeInt32(offset, utils_js_1.int32[0]);
float32[0] = value;
this.writeInt32(offset, int32[0]);
}
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]);
float64[0] = value;
this.writeInt32(offset, int32[isLittleEndian ? 0 : 1]);
this.writeInt32(offset + 4, int32[isLittleEndian ? 1 : 0]);
}

@@ -133,9 +130,9 @@ /**

getBufferIdentifier() {
if (this.bytes_.length < this.position_ + constants_js_1.SIZEOF_INT +
constants_js_1.FILE_IDENTIFIER_LENGTH) {
if (this.bytes_.length < this.position_ + SIZEOF_INT +
FILE_IDENTIFIER_LENGTH) {
throw new Error('FlatBuffers: ByteBuffer is too short to contain an identifier.');
}
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));
for (let i = 0; i < FILE_IDENTIFIER_LENGTH; i++) {
result += String.fromCharCode(this.readInt8(this.position_ + SIZEOF_INT + i));
}

@@ -174,5 +171,5 @@ return result;

const length = this.readInt32(offset);
offset += constants_js_1.SIZEOF_INT;
offset += SIZEOF_INT;
const utf8bytes = this.bytes_.subarray(offset, offset + length);
if (opt_encoding === encoding_js_1.Encoding.UTF8_BYTES)
if (opt_encoding === Encoding.UTF8_BYTES)
return utf8bytes;

@@ -205,3 +202,3 @@ else

__vector(offset) {
return offset + this.readInt32(offset) + constants_js_1.SIZEOF_INT; // data starts after the length
return offset + this.readInt32(offset) + SIZEOF_INT; // data starts after the length
}

@@ -215,8 +212,8 @@ /**

__has_identifier(ident) {
if (ident.length != constants_js_1.FILE_IDENTIFIER_LENGTH) {
if (ident.length != FILE_IDENTIFIER_LENGTH) {
throw new Error('FlatBuffers: file identifier must be length ' +
constants_js_1.FILE_IDENTIFIER_LENGTH);
FILE_IDENTIFIER_LENGTH);
}
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)) {
for (let i = 0; i < FILE_IDENTIFIER_LENGTH; i++) {
if (ident.charCodeAt(i) != this.readInt8(this.position() + SIZEOF_INT + i)) {
return false;

@@ -257,2 +254,1 @@ }

}
exports.ByteBuffer = ByteBuffer;

@@ -1,7 +0,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;
export const SIZEOF_SHORT = 2;
export const SIZEOF_INT = 4;
export const FILE_IDENTIFIER_LENGTH = 4;
export const SIZE_PREFIX_LENGTH = 4;

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Encoding = void 0;
var Encoding;
export var Encoding;
(function (Encoding) {
Encoding[Encoding["UTF8_BYTES"] = 1] = "UTF8_BYTES";
Encoding[Encoding["UTF16_STRING"] = 2] = "UTF16_STRING";
})(Encoding = exports.Encoding || (exports.Encoding = {}));
})(Encoding || (Encoding = {}));

@@ -1,22 +0,8 @@

"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; } });
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 { int32, float32, float64, isLittleEndian } from './utils.js';
export { Encoding } from './encoding.js';
export { Builder } from './builder.js';
export { ByteBuffer } from './byte-buffer.js';

@@ -1,22 +0,15 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encode = exports.toObject = exports.builder = exports.toReference = void 0;
/* eslint-disable @typescript-eslint/no-namespace */
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();
import { Builder } from './flexbuffers/builder.js';
import { toReference } from './flexbuffers/reference.js';
export { toReference } from './flexbuffers/reference.js';
export function builder() {
return new Builder();
}
exports.builder = builder;
function toObject(buffer) {
return (0, reference_js_1.toReference)(buffer).toObject();
export function toObject(buffer) {
return toReference(buffer).toObject();
}
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);
export function encode(object, size = 2048, deduplicateStrings = true, deduplicateKeys = true, deduplicateKeyVectors = true) {
const builder = new Builder(size > 0 ? size : 2048, deduplicateStrings, deduplicateKeys, deduplicateKeyVectors);
builder.add(object);
return builder.finish();
}
exports.encode = encode;

@@ -1,46 +0,37 @@

"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) {
import { BitWidth } from './bit-width.js';
export function toByteWidth(bitWidth) {
return 1 << bitWidth;
}
exports.toByteWidth = toByteWidth;
function iwidth(value) {
export function iwidth(value) {
if (value >= -128 && value <= 127)
return bit_width_js_1.BitWidth.WIDTH8;
return BitWidth.WIDTH8;
if (value >= -32768 && value <= 32767)
return bit_width_js_1.BitWidth.WIDTH16;
return BitWidth.WIDTH16;
if (value >= -2147483648 && value <= 2147483647)
return bit_width_js_1.BitWidth.WIDTH32;
return bit_width_js_1.BitWidth.WIDTH64;
return BitWidth.WIDTH32;
return 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 fwidth(value) {
return value === Math.fround(value) ? BitWidth.WIDTH32 : BitWidth.WIDTH64;
}
exports.fwidth = fwidth;
function uwidth(value) {
export function uwidth(value) {
if (value <= 255)
return bit_width_js_1.BitWidth.WIDTH8;
return BitWidth.WIDTH8;
if (value <= 65535)
return bit_width_js_1.BitWidth.WIDTH16;
return BitWidth.WIDTH16;
if (value <= 4294967295)
return bit_width_js_1.BitWidth.WIDTH32;
return bit_width_js_1.BitWidth.WIDTH64;
return BitWidth.WIDTH32;
return BitWidth.WIDTH64;
}
exports.uwidth = uwidth;
function fromByteWidth(value) {
export function fromByteWidth(value) {
if (value === 1)
return bit_width_js_1.BitWidth.WIDTH8;
return BitWidth.WIDTH8;
if (value === 2)
return bit_width_js_1.BitWidth.WIDTH16;
return BitWidth.WIDTH16;
if (value === 4)
return bit_width_js_1.BitWidth.WIDTH32;
return bit_width_js_1.BitWidth.WIDTH64;
return BitWidth.WIDTH32;
return BitWidth.WIDTH64;
}
exports.fromByteWidth = fromByteWidth;
function paddingSize(bufSize, scalarSize) {
export function paddingSize(bufSize, scalarSize) {
return (~bufSize + 1) & (scalarSize - 1);
}
exports.paddingSize = paddingSize;

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitWidth = void 0;
var BitWidth;
export var BitWidth;
(function (BitWidth) {

@@ -10,2 +7,2 @@ BitWidth[BitWidth["WIDTH8"] = 0] = "WIDTH8";

BitWidth[BitWidth["WIDTH64"] = 3] = "WIDTH64";
})(BitWidth = exports.BitWidth || (exports.BitWidth = {}));
})(BitWidth || (BitWidth = {}));

@@ -1,11 +0,8 @@

"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 {
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 {
constructor(size = 2048, dedupStrings = true, dedupKeys = true, dedupKeyVectors = true) {

@@ -29,4 +26,4 @@ this.dedupStrings = dedupStrings;

align(width) {
const byteWidth = (0, bit_width_util_js_1.toByteWidth)(width);
this.offset += (0, bit_width_util_js_1.paddingSize)(this.offset, byteWidth);
const byteWidth = toByteWidth(width);
this.offset += paddingSize(this.offset, byteWidth);
return byteWidth;

@@ -50,12 +47,12 @@ }

pushInt(value, width) {
if (width === bit_width_js_1.BitWidth.WIDTH8) {
if (width === BitWidth.WIDTH8) {
this.view.setInt8(this.offset, value);
}
else if (width === bit_width_js_1.BitWidth.WIDTH16) {
else if (width === BitWidth.WIDTH16) {
this.view.setInt16(this.offset, value, true);
}
else if (width === bit_width_js_1.BitWidth.WIDTH32) {
else if (width === BitWidth.WIDTH32) {
this.view.setInt32(this.offset, value, true);
}
else if (width === bit_width_js_1.BitWidth.WIDTH64) {
else if (width === BitWidth.WIDTH64) {
this.view.setBigInt64(this.offset, BigInt(value), true);

@@ -68,12 +65,12 @@ }

pushUInt(value, width) {
if (width === bit_width_js_1.BitWidth.WIDTH8) {
if (width === BitWidth.WIDTH8) {
this.view.setUint8(this.offset, value);
}
else if (width === bit_width_js_1.BitWidth.WIDTH16) {
else if (width === BitWidth.WIDTH16) {
this.view.setUint16(this.offset, value, true);
}
else if (width === bit_width_js_1.BitWidth.WIDTH32) {
else if (width === BitWidth.WIDTH32) {
this.view.setUint32(this.offset, value, true);
}
else if (width === bit_width_js_1.BitWidth.WIDTH64) {
else if (width === BitWidth.WIDTH64) {
this.view.setBigUint64(this.offset, BigInt(value), true);

@@ -87,3 +84,3 @@ }

const newOffset = this.computeOffset(byteWidth);
this.pushInt(value, (0, bit_width_util_js_1.fromByteWidth)(byteWidth));
this.pushInt(value, fromByteWidth(byteWidth));
this.offset = newOffset;

@@ -93,3 +90,3 @@ }

const newOffset = this.computeOffset(byteWidth);
this.pushUInt(value, (0, bit_width_util_js_1.fromByteWidth)(byteWidth));
this.pushUInt(value, fromByteWidth(byteWidth));
this.offset = newOffset;

@@ -99,3 +96,3 @@ }

const length = arrayBuffer.byteLength;
const bitWidth = (0, bit_width_util_js_1.uwidth)(length);
const bitWidth = uwidth(length);
const byteWidth = this.align(bitWidth);

@@ -106,3 +103,3 @@ this.writeUInt(length, byteWidth);

new Uint8Array(this.buffer).set(new Uint8Array(arrayBuffer), blobOffset);
this.stack.push(this.offsetStackValue(blobOffset, value_type_js_1.ValueType.BLOB, bitWidth));
this.stack.push(this.offsetStackValue(blobOffset, ValueType.BLOB, bitWidth));
this.offset = newOffset;

@@ -115,5 +112,5 @@ }

}
const utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str);
const utf8 = toUTF8Array(str);
const length = utf8.length;
const bitWidth = (0, bit_width_util_js_1.uwidth)(length);
const bitWidth = uwidth(length);
const byteWidth = this.align(bitWidth);

@@ -124,3 +121,3 @@ this.writeUInt(length, byteWidth);

new Uint8Array(this.buffer).set(utf8, stringOffset);
const stackValue = this.offsetStackValue(stringOffset, value_type_js_1.ValueType.STRING, bitWidth);
const stackValue = this.offsetStackValue(stringOffset, ValueType.STRING, bitWidth);
this.stack.push(stackValue);

@@ -137,7 +134,7 @@ if (this.dedupStrings) {

}
const utf8 = (0, flexbuffers_util_js_1.toUTF8Array)(str);
const utf8 = 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, value_type_js_1.ValueType.KEY, bit_width_js_1.BitWidth.WIDTH8);
const stackValue = this.offsetStackValue(this.offset, ValueType.KEY, BitWidth.WIDTH8);
this.stack.push(stackValue);

@@ -170,3 +167,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 !== value_type_js_1.ValueType.KEY) {
if (this.stack[this.stack.length - 1].type !== ValueType.KEY) {
throw "Adding value to a map before adding a key is prohibited";

@@ -217,3 +214,3 @@ }

function shouldFlip(v1, v2) {
if (v1.type !== value_type_js_1.ValueType.KEY || v2.type !== value_type_js_1.ValueType.KEY) {
if (v1.type !== ValueType.KEY || v2.type !== ValueType.KEY) {
throw `Stack values are not keys ${v1} | ${v2}. Check if you combined [addKey] with add... method calls properly.`;

@@ -258,3 +255,3 @@ }

function smaller(v1, v2) {
if (v1.type !== value_type_js_1.ValueType.KEY || v2.type !== value_type_js_1.ValueType.KEY) {
if (v1.type !== ValueType.KEY || v2.type !== ValueType.KEY) {
throw `Stack values are not keys ${v1} | ${v2}. Check if you combined [addKey] with add... method calls properly.`;

@@ -329,3 +326,3 @@ }

createVector(start, vecLength, step, keys = null) {
let bitWidth = (0, bit_width_util_js_1.uwidth)(vecLength);
let bitWidth = uwidth(vecLength);
let prefixElements = 1;

@@ -339,3 +336,3 @@ if (keys !== null) {

}
let vectorType = value_type_js_1.ValueType.KEY;
let vectorType = ValueType.KEY;
let typed = keys === null;

@@ -349,3 +346,3 @@ for (let i = start; i < this.stack.length; i += step) {

vectorType = this.stack[i].type;
typed = typed && (0, value_type_util_js_1.isTypedVectorElement)(vectorType);
typed = typed && isTypedVectorElement(vectorType);
}

@@ -359,3 +356,3 @@ else {

const byteWidth = this.align(bitWidth);
const fix = typed && (0, value_type_util_js_1.isNumber)(vectorType) && vecLength >= 2 && vecLength <= 4;
const fix = typed && isNumber(vectorType) && vecLength >= 2 && vecLength <= 4;
if (keys !== null) {

@@ -378,27 +375,27 @@ this.writeStackValue(keys, byteWidth);

if (keys !== null) {
return this.offsetStackValue(vecOffset, value_type_js_1.ValueType.MAP, bitWidth);
return this.offsetStackValue(vecOffset, ValueType.MAP, bitWidth);
}
if (typed) {
const vType = (0, value_type_util_js_1.toTypedVector)(vectorType, fix ? vecLength : 0);
const vType = toTypedVector(vectorType, fix ? vecLength : 0);
return this.offsetStackValue(vecOffset, vType, bitWidth);
}
return this.offsetStackValue(vecOffset, value_type_js_1.ValueType.VECTOR, bitWidth);
return this.offsetStackValue(vecOffset, ValueType.VECTOR, bitWidth);
}
nullStackValue() {
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.NULL, bit_width_js_1.BitWidth.WIDTH8);
return new StackValue(this, ValueType.NULL, BitWidth.WIDTH8);
}
boolStackValue(value) {
return new stack_value_js_1.StackValue(this, value_type_js_1.ValueType.BOOL, bit_width_js_1.BitWidth.WIDTH8, value);
return new StackValue(this, ValueType.BOOL, BitWidth.WIDTH8, 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);
return new StackValue(this, ValueType.INT, iwidth(value), 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);
return new StackValue(this, ValueType.UINT, uwidth(value), 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);
return new StackValue(this, ValueType.FLOAT, fwidth(value), value);
}
offsetStackValue(offset, valueType, bitWidth) {
return new stack_value_js_1.StackValue(this, valueType, bitWidth, null, offset);
return new StackValue(this, valueType, bitWidth, null, offset);
}

@@ -494,3 +491,3 @@ finishBuffer() {

stackValue.writeToBuffer(byteWidth);
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_INT, stackValue.width);
const stackOffset = this.offsetStackValue(valueOffset, ValueType.INDIRECT_INT, stackValue.width);
this.stack.push(stackOffset);

@@ -517,3 +514,3 @@ this.offset = newOffset;

stackValue.writeToBuffer(byteWidth);
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_UINT, stackValue.width);
const stackOffset = this.offsetStackValue(valueOffset, ValueType.INDIRECT_UINT, stackValue.width);
this.stack.push(stackOffset);

@@ -540,3 +537,3 @@ this.offset = newOffset;

stackValue.writeToBuffer(byteWidth);
const stackOffset = this.offsetStackValue(valueOffset, value_type_js_1.ValueType.INDIRECT_FLOAT, stackValue.width);
const stackOffset = this.offsetStackValue(valueOffset, ValueType.INDIRECT_FLOAT, stackValue.width);
this.stack.push(stackOffset);

@@ -549,2 +546,1 @@ this.offset = newOffset;

}
exports.Builder = Builder;

@@ -1,13 +0,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUTF8Array = exports.fromUTF8Array = void 0;
function fromUTF8Array(data) {
export function fromUTF8Array(data) {
const decoder = new TextDecoder();
return decoder.decode(data);
}
exports.fromUTF8Array = fromUTF8Array;
function toUTF8Array(str) {
export function toUTF8Array(str) {
const encoder = new TextEncoder();
return encoder.encode(str);
}
exports.toUTF8Array = toUTF8Array;

@@ -1,14 +0,10 @@

"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) {
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) {
throw "Bad offset: " + offset + ", width: " + width;
}
}
exports.validateOffset = validateOffset;
function readInt(dataView, offset, width) {
export function readInt(dataView, offset, width) {
if (width < 2) {

@@ -34,4 +30,3 @@ if (width < 1) {

}
exports.readInt = readInt;
function readUInt(dataView, offset, width) {
export function readUInt(dataView, offset, width) {
if (width < 2) {

@@ -57,8 +52,7 @@ if (width < 1) {

}
exports.readUInt = readUInt;
function readFloat(dataView, offset, width) {
if (width < bit_width_js_1.BitWidth.WIDTH32) {
export function readFloat(dataView, offset, width) {
if (width < BitWidth.WIDTH32) {
throw "Bad width: " + width;
}
if (width === bit_width_js_1.BitWidth.WIDTH32) {
if (width === BitWidth.WIDTH32) {
return dataView.getFloat32(offset, true);

@@ -68,12 +62,10 @@ }

}
exports.readFloat = readFloat;
function indirect(dataView, offset, width) {
export function indirect(dataView, offset, width) {
const step = readUInt(dataView, offset, width);
return offset - step;
}
exports.indirect = indirect;
function keyIndex(key, dataView, offset, parentWidth, byteWidth, length) {
const input = (0, flexbuffers_util_js_1.toUTF8Array)(key);
export function keyIndex(key, dataView, offset, parentWidth, byteWidth, length) {
const input = toUTF8Array(key);
const keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3;
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth);
const bitWidth = fromByteWidth(byteWidth);
const indirectOffset = keysVectorOffset - Number(readUInt(dataView, keysVectorOffset, bitWidth));

@@ -97,6 +89,5 @@ const _byteWidth = Number(readUInt(dataView, keysVectorOffset + byteWidth, bitWidth));

}
exports.keyIndex = keyIndex;
function diffKeys(input, index, dataView, offset, width) {
export function diffKeys(input, index, dataView, offset, width) {
const keyOffset = offset + index * width;
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, (0, bit_width_util_js_1.fromByteWidth)(width)));
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, fromByteWidth(width)));
for (let i = 0; i < input.length; i++) {

@@ -110,10 +101,9 @@ const dif = input[i] - dataView.getUint8(keyIndirectOffset + i);

}
exports.diffKeys = diffKeys;
function keyForIndex(index, dataView, offset, parentWidth, byteWidth) {
export function keyForIndex(index, dataView, offset, parentWidth, byteWidth) {
const keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3;
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth);
const bitWidth = 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)));
const keyIndirectOffset = keyOffset - Number(readUInt(dataView, keyOffset, fromByteWidth(_byteWidth)));
let length = 0;

@@ -123,4 +113,3 @@ while (dataView.getUint8(keyIndirectOffset + length) !== 0) {

}
return (0, flexbuffers_util_js_1.fromUTF8Array)(new Uint8Array(dataView.buffer, keyIndirectOffset, length));
return fromUTF8Array(new Uint8Array(dataView.buffer, keyIndirectOffset, length));
}
exports.keyForIndex = keyForIndex;

@@ -1,11 +0,8 @@

"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) {
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) {
const len = buffer.byteLength;

@@ -18,14 +15,13 @@ if (len < 3) {

const packedType = dataView.getUint8(len - 2);
const parentWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth);
const parentWidth = 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 = (0, reference_util_js_1.indirect)(dataView, offset, parentWidth);
const _indirect = 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}`);
return new Reference(dataView, elementOffset, fromByteWidth(byteWidth), packedType, `${path}/${key}`);
}
class Reference {
export class Reference {
constructor(dataView, offset, parentWidth, packedType, path) {

@@ -41,14 +37,14 @@ this.dataView = dataView;

}
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; }
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; }
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; }
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; }
boolValue() {
if (this.isBool()) {
return (0, reference_util_js_1.readInt)(this.dataView, this.offset, this.parentWidth) > 0;
return readInt(this.dataView, this.offset, this.parentWidth) > 0;
}

@@ -58,13 +54,13 @@ return null;

intValue() {
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.INT) {
return readInt(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.UINT) {
return readUInt(this.dataView, this.offset, this.parentWidth);
}
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_INT) {
return readInt(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));
if (this.valueType === ValueType.INDIRECT_UINT) {
return readUInt(this.dataView, indirect(this.dataView, this.offset, this.parentWidth), fromByteWidth(this.byteWidth));
}

@@ -74,7 +70,7 @@ return null;

floatValue() {
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.FLOAT) {
return readFloat(this.dataView, this.offset, this.parentWidth);
}
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));
if (this.valueType === ValueType.INDIRECT_FLOAT) {
return readFloat(this.dataView, indirect(this.dataView, this.offset, this.parentWidth), fromByteWidth(this.byteWidth));
}

@@ -85,5 +81,5 @@ return null;

stringValue() {
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()));
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()));
}

@@ -94,3 +90,3 @@ return null;

if (this.isBlob()) {
const begin = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth);
const begin = indirect(this.dataView, this.offset, this.parentWidth);
return new Uint8Array(this.dataView.buffer, begin, this.length());

@@ -102,21 +98,21 @@ }

const length = this.length();
if (Number.isInteger(key) && (0, value_type_util_js_1.isAVector)(this.valueType)) {
if (Number.isInteger(key) && isAVector(this.valueType)) {
if (key >= length || key < 0) {
throw `Key: [${key}] is not applicable on ${this.path} of ${this.valueType} length: ${length}`;
}
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth);
const _indirect = 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)) {
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);
if (isTypedVector(this.valueType)) {
const _valueType = typedVectorElementType(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);
else if (isFixedTypedVector(this.valueType)) {
const _valueType = fixedTypedVectorElementType(this.valueType);
_packedType = packedType(_valueType, BitWidth.WIDTH8);
}
return new Reference(this.dataView, elementOffset, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth), _packedType, `${this.path}[${key}]`);
return new Reference(this.dataView, elementOffset, fromByteWidth(this.byteWidth), _packedType, `${this.path}[${key}]`);
}
if (typeof key === 'string') {
const index = (0, reference_util_js_1.keyIndex)(key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length);
const index = keyIndex(key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length);
if (index !== null) {

@@ -133,25 +129,25 @@ return valueForIndexWithKey(index, key, this.dataView, this.offset, this.parentWidth, this.byteWidth, length, this.path);

}
if ((0, value_type_util_js_1.isFixedTypedVector)(this.valueType)) {
this._length = (0, value_type_util_js_1.fixedTypedVectorElementSize)(this.valueType);
if (isFixedTypedVector(this.valueType)) {
this._length = fixedTypedVectorElementSize(this.valueType);
}
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.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.NULL) {
else if (this.valueType === ValueType.NULL) {
this._length = 0;
}
else if (this.valueType === value_type_js_1.ValueType.STRING) {
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth);
else if (this.valueType === ValueType.STRING) {
const _indirect = 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));
size = readUInt(this.dataView, _indirect - sizeByteWidth, fromByteWidth(this.byteWidth));
while (this.dataView.getInt8(_indirect + size) !== 0) {
sizeByteWidth <<= 1;
size = (0, reference_util_js_1.readUInt)(this.dataView, _indirect - sizeByteWidth, (0, bit_width_util_js_1.fromByteWidth)(this.byteWidth));
size = readUInt(this.dataView, _indirect - sizeByteWidth, fromByteWidth(this.byteWidth));
}
this._length = size;
}
else if (this.valueType === value_type_js_1.ValueType.KEY) {
const _indirect = (0, reference_util_js_1.indirect)(this.dataView, this.offset, this.parentWidth);
else if (this.valueType === ValueType.KEY) {
const _indirect = indirect(this.dataView, this.offset, this.parentWidth);
size = 1;

@@ -180,3 +176,3 @@ while (this.dataView.getInt8(_indirect + size) !== 0) {

for (let i = 0; i < length; i++) {
const key = (0, reference_util_js_1.keyForIndex)(i, this.dataView, this.offset, this.parentWidth, this.byteWidth);
const key = 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();

@@ -198,2 +194,1 @@ }

}
exports.Reference = Reference;

@@ -1,9 +0,6 @@

"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 {
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 {
constructor(builder, type, width, value = null, offset = 0) {

@@ -17,9 +14,9 @@ this.builder = builder;

elementWidth(size, index) {
if ((0, value_type_util_js_1.isInline)(this.type))
if (isInline(this.type))
return this.width;
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 offsetLoc = size + paddingSize(size, width) + index * width;
const offset = offsetLoc - this.offset;
const bitWidth = (0, bit_width_util_js_1.uwidth)(offset);
const bitWidth = uwidth(offset);
if (1 << bitWidth === width) {

@@ -33,4 +30,4 @@ return bitWidth;

const newOffset = this.builder.computeOffset(byteWidth);
if (this.type === value_type_js_1.ValueType.FLOAT) {
if (this.width === bit_width_js_1.BitWidth.WIDTH32) {
if (this.type === ValueType.FLOAT) {
if (this.width === BitWidth.WIDTH32) {
this.builder.view.setFloat32(this.builder.offset, this.value, true);

@@ -42,14 +39,14 @@ }

}
else if (this.type === value_type_js_1.ValueType.INT) {
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth);
else if (this.type === ValueType.INT) {
const bitWidth = fromByteWidth(byteWidth);
this.builder.pushInt(this.value, bitWidth);
}
else if (this.type === value_type_js_1.ValueType.UINT) {
const bitWidth = (0, bit_width_util_js_1.fromByteWidth)(byteWidth);
else if (this.type === ValueType.UINT) {
const bitWidth = fromByteWidth(byteWidth);
this.builder.pushUInt(this.value, bitWidth);
}
else if (this.type === value_type_js_1.ValueType.NULL) {
else if (this.type === ValueType.NULL) {
this.builder.pushInt(0, this.width);
}
else if (this.type === value_type_js_1.ValueType.BOOL) {
else if (this.type === ValueType.BOOL) {
this.builder.pushInt(this.value ? 1 : 0, this.width);

@@ -62,12 +59,11 @@ }

}
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;
storedWidth(width = BitWidth.WIDTH8) {
return isInline(this.type) ? Math.max(width, this.width) : this.width;
}
storedPackedType(width = bit_width_js_1.BitWidth.WIDTH8) {
return (0, value_type_util_js_1.packedType)(this.type, this.storedWidth(width));
storedPackedType(width = BitWidth.WIDTH8) {
return packedType(this.type, this.storedWidth(width));
}
isOffset() {
return !(0, value_type_util_js_1.isInline)(this.type);
return !isInline(this.type);
}
}
exports.StackValue = StackValue;

@@ -1,71 +0,56 @@

"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;
import { ValueType } from './value-type.js';
export function isInline(value) {
return value === ValueType.BOOL
|| 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 isNumber(value) {
return value >= ValueType.INT
&& value <= ValueType.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 isIndirectNumber(value) {
return value >= ValueType.INDIRECT_INT
&& value <= ValueType.INDIRECT_FLOAT;
}
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 isTypedVectorElement(value) {
return value === ValueType.BOOL
|| (value >= ValueType.INT
&& value <= ValueType.STRING);
}
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 isTypedVector(value) {
return value === ValueType.VECTOR_BOOL
|| (value >= ValueType.VECTOR_INT
&& value <= ValueType.VECTOR_STRING_DEPRECATED);
}
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 isFixedTypedVector(value) {
return value >= ValueType.VECTOR_INT2
&& value <= ValueType.VECTOR_FLOAT4;
}
exports.isFixedTypedVector = isFixedTypedVector;
function isAVector(value) {
export function isAVector(value) {
return isTypedVector(value)
|| isFixedTypedVector(value)
|| value === value_type_js_1.ValueType.VECTOR;
|| value === ValueType.VECTOR;
}
exports.isAVector = isAVector;
function toTypedVector(valueType, length) {
export function toTypedVector(valueType, length) {
if (length === 0)
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT;
return valueType - ValueType.INT + ValueType.VECTOR_INT;
if (length === 2)
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT2;
return valueType - ValueType.INT + ValueType.VECTOR_INT2;
if (length === 3)
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT3;
return valueType - ValueType.INT + ValueType.VECTOR_INT3;
if (length === 4)
return valueType - value_type_js_1.ValueType.INT + value_type_js_1.ValueType.VECTOR_INT4;
return valueType - ValueType.INT + ValueType.VECTOR_INT4;
throw "Unexpected length " + length;
}
exports.toTypedVector = toTypedVector;
function typedVectorElementType(valueType) {
return valueType - value_type_js_1.ValueType.VECTOR_INT + value_type_js_1.ValueType.INT;
export function typedVectorElementType(valueType) {
return valueType - ValueType.VECTOR_INT + 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 fixedTypedVectorElementType(valueType) {
return ((valueType - ValueType.VECTOR_INT2) % 3) + ValueType.INT;
}
exports.fixedTypedVectorElementType = fixedTypedVectorElementType;
function fixedTypedVectorElementSize(valueType) {
export function fixedTypedVectorElementSize(valueType) {
// The x / y >> 0 trick is to have an int division. Suppose to be faster than Math.floor()
return (((valueType - value_type_js_1.ValueType.VECTOR_INT2) / 3) >> 0) + 2;
return (((valueType - ValueType.VECTOR_INT2) / 3) >> 0) + 2;
}
exports.fixedTypedVectorElementSize = fixedTypedVectorElementSize;
function packedType(valueType, bitWidth) {
export function packedType(valueType, bitWidth) {
return bitWidth | (valueType << 2);
}
exports.packedType = packedType;

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValueType = void 0;
var ValueType;
export var ValueType;
(function (ValueType) {

@@ -34,2 +31,2 @@ ValueType[ValueType["NULL"] = 0] = "NULL";

ValueType[ValueType["VECTOR_BOOL"] = 36] = "VECTOR_BOOL";
})(ValueType = exports.ValueType || (exports.ValueType = {}));
})(ValueType || (ValueType = {}));

@@ -1,2 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

@@ -1,7 +0,4 @@

"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;
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;
{
"name": "flatbuffers",
"version": "23.1.21",
"version": "23.3.3",
"description": "Memory Efficient Serialization Library",

@@ -14,14 +14,2 @@ "files": [

"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": {

@@ -28,0 +16,0 @@ "doc": "docs",

@@ -80,2 +80,2 @@ ![logo](http://google.github.io/flatbuffers/fpl_logo_small.png) FlatBuffers

[landing page]: https://google.github.io/flatbuffers
[LICENSE]: https://github.com/google/flatbuffers/blob/master/LICENSE.txt
[LICENSE]: https://github.com/google/flatbuffers/blob/master/LICENSE
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc