[TS/JS] BigInt implementation (#6998)

* BigInt implementation

* Unit test reading long from existing bytebuffer

* Code review
This commit is contained in:
Alex E
2022-01-06 21:35:37 -05:00
committed by GitHub
parent f28c2b2936
commit ace4a37f22
22 changed files with 225 additions and 256 deletions

View File

@@ -184,7 +184,7 @@ export class Monster {
}
testhashs64Fnv1() {
const offset = this.bb.__offset(this.bb_pos, 40);
return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0);
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
}
mutate_testhashs64_fnv1(value) {
const offset = this.bb.__offset(this.bb_pos, 40);
@@ -196,7 +196,7 @@ export class Monster {
}
testhashu64Fnv1() {
const offset = this.bb.__offset(this.bb_pos, 42);
return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
}
mutate_testhashu64_fnv1(value) {
const offset = this.bb.__offset(this.bb_pos, 42);
@@ -232,7 +232,7 @@ export class Monster {
}
testhashs64Fnv1a() {
const offset = this.bb.__offset(this.bb_pos, 48);
return offset ? this.bb.readInt64(this.bb_pos + offset) : this.bb.createLong(0, 0);
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
}
mutate_testhashs64_fnv1a(value) {
const offset = this.bb.__offset(this.bb_pos, 48);
@@ -244,7 +244,7 @@ export class Monster {
}
testhashu64Fnv1a() {
const offset = this.bb.__offset(this.bb_pos, 50);
return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
}
mutate_testhashu64_fnv1a(value) {
const offset = this.bb.__offset(this.bb_pos, 50);
@@ -340,7 +340,7 @@ export class Monster {
}
vectorOfLongs(index) {
const offset = this.bb.__offset(this.bb_pos, 68);
return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : this.bb.createLong(0, 0);
return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0);
}
vectorOfLongsLength() {
const offset = this.bb.__offset(this.bb_pos, 68);
@@ -372,7 +372,7 @@ export class Monster {
}
singleWeakReference() {
const offset = this.bb.__offset(this.bb_pos, 76);
return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
}
mutate_single_weak_reference(value) {
const offset = this.bb.__offset(this.bb_pos, 76);
@@ -384,7 +384,7 @@ export class Monster {
}
vectorOfWeakReferences(index) {
const offset = this.bb.__offset(this.bb_pos, 78);
return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0);
}
vectorOfWeakReferencesLength() {
const offset = this.bb.__offset(this.bb_pos, 78);
@@ -400,7 +400,7 @@ export class Monster {
}
coOwningReference() {
const offset = this.bb.__offset(this.bb_pos, 82);
return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
}
mutate_co_owning_reference(value) {
const offset = this.bb.__offset(this.bb_pos, 82);
@@ -412,7 +412,7 @@ export class Monster {
}
vectorOfCoOwningReferences(index) {
const offset = this.bb.__offset(this.bb_pos, 84);
return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0);
}
vectorOfCoOwningReferencesLength() {
const offset = this.bb.__offset(this.bb_pos, 84);
@@ -420,7 +420,7 @@ export class Monster {
}
nonOwningReference() {
const offset = this.bb.__offset(this.bb_pos, 86);
return offset ? this.bb.readUint64(this.bb_pos + offset) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
}
mutate_non_owning_reference(value) {
const offset = this.bb.__offset(this.bb_pos, 86);
@@ -432,7 +432,7 @@ export class Monster {
}
vectorOfNonOwningReferences(index) {
const offset = this.bb.__offset(this.bb_pos, 88);
return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : this.bb.createLong(0, 0);
return offset ? this.bb.readUint64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0);
}
vectorOfNonOwningReferencesLength() {
const offset = this.bb.__offset(this.bb_pos, 88);
@@ -599,10 +599,10 @@ export class Monster {
builder.addFieldInt32(17, testhashu32Fnv1, 0);
}
static addTesthashs64Fnv1(builder, testhashs64Fnv1) {
builder.addFieldInt64(18, testhashs64Fnv1, builder.createLong(0, 0));
builder.addFieldInt64(18, testhashs64Fnv1, BigInt('0'));
}
static addTesthashu64Fnv1(builder, testhashu64Fnv1) {
builder.addFieldInt64(19, testhashu64Fnv1, builder.createLong(0, 0));
builder.addFieldInt64(19, testhashu64Fnv1, BigInt('0'));
}
static addTesthashs32Fnv1a(builder, testhashs32Fnv1a) {
builder.addFieldInt32(20, testhashs32Fnv1a, 0);
@@ -611,10 +611,10 @@ export class Monster {
builder.addFieldInt32(21, testhashu32Fnv1a, 0);
}
static addTesthashs64Fnv1a(builder, testhashs64Fnv1a) {
builder.addFieldInt64(22, testhashs64Fnv1a, builder.createLong(0, 0));
builder.addFieldInt64(22, testhashs64Fnv1a, BigInt('0'));
}
static addTesthashu64Fnv1a(builder, testhashu64Fnv1a) {
builder.addFieldInt64(23, testhashu64Fnv1a, builder.createLong(0, 0));
builder.addFieldInt64(23, testhashu64Fnv1a, BigInt('0'));
}
static addTestarrayofbools(builder, testarrayofboolsOffset) {
builder.addFieldOffset(24, testarrayofboolsOffset, 0);
@@ -719,7 +719,7 @@ export class Monster {
builder.startVector(4, numElems, 4);
}
static addSingleWeakReference(builder, singleWeakReference) {
builder.addFieldInt64(36, singleWeakReference, builder.createLong(0, 0));
builder.addFieldInt64(36, singleWeakReference, BigInt('0'));
}
static addVectorOfWeakReferences(builder, vectorOfWeakReferencesOffset) {
builder.addFieldOffset(37, vectorOfWeakReferencesOffset, 0);
@@ -748,7 +748,7 @@ export class Monster {
builder.startVector(4, numElems, 4);
}
static addCoOwningReference(builder, coOwningReference) {
builder.addFieldInt64(39, coOwningReference, builder.createLong(0, 0));
builder.addFieldInt64(39, coOwningReference, BigInt('0'));
}
static addVectorOfCoOwningReferences(builder, vectorOfCoOwningReferencesOffset) {
builder.addFieldOffset(40, vectorOfCoOwningReferencesOffset, 0);
@@ -764,7 +764,7 @@ export class Monster {
builder.startVector(8, numElems, 8);
}
static addNonOwningReference(builder, nonOwningReference) {
builder.addFieldInt64(41, nonOwningReference, builder.createLong(0, 0));
builder.addFieldInt64(41, nonOwningReference, BigInt('0'));
}
static addVectorOfNonOwningReferences(builder, vectorOfNonOwningReferencesOffset) {
builder.addFieldOffset(42, vectorOfNonOwningReferencesOffset, 0);
@@ -943,7 +943,7 @@ export class Monster {
}
}
export class MonsterT {
constructor(pos = null, mana = 150, hp = 100, name = null, inventory = [], color = Color.Blue, testType = Any.NONE, test = null, test4 = [], testarrayofstring = [], testarrayoftables = [], enemy = null, testnestedflatbuffer = [], testempty = null, testbool = false, testhashs32Fnv1 = 0, testhashu32Fnv1 = 0, testhashs64Fnv1 = flatbuffers.createLong(0, 0), testhashu64Fnv1 = flatbuffers.createLong(0, 0), testhashs32Fnv1a = 0, testhashu32Fnv1a = 0, testhashs64Fnv1a = flatbuffers.createLong(0, 0), testhashu64Fnv1a = flatbuffers.createLong(0, 0), testarrayofbools = [], testf = 3.14159, testf2 = 3.0, testf3 = 0.0, testarrayofstring2 = [], testarrayofsortedstruct = [], flex = [], test5 = [], vectorOfLongs = [], vectorOfDoubles = [], parentNamespaceTest = null, vectorOfReferrables = [], singleWeakReference = flatbuffers.createLong(0, 0), vectorOfWeakReferences = [], vectorOfStrongReferrables = [], coOwningReference = flatbuffers.createLong(0, 0), vectorOfCoOwningReferences = [], nonOwningReference = flatbuffers.createLong(0, 0), vectorOfNonOwningReferences = [], anyUniqueType = AnyUniqueAliases.NONE, anyUnique = null, anyAmbiguousType = AnyAmbiguousAliases.NONE, anyAmbiguous = null, vectorOfEnums = [], signedEnum = Race.None, testrequirednestedflatbuffer = [], scalarKeySortedTables = []) {
constructor(pos = null, mana = 150, hp = 100, name = null, inventory = [], color = Color.Blue, testType = Any.NONE, test = null, test4 = [], testarrayofstring = [], testarrayoftables = [], enemy = null, testnestedflatbuffer = [], testempty = null, testbool = false, testhashs32Fnv1 = 0, testhashu32Fnv1 = 0, testhashs64Fnv1 = BigInt('0'), testhashu64Fnv1 = BigInt('0'), testhashs32Fnv1a = 0, testhashu32Fnv1a = 0, testhashs64Fnv1a = BigInt('0'), testhashu64Fnv1a = BigInt('0'), testarrayofbools = [], testf = 3.14159, testf2 = 3.0, testf3 = 0.0, testarrayofstring2 = [], testarrayofsortedstruct = [], flex = [], test5 = [], vectorOfLongs = [], vectorOfDoubles = [], parentNamespaceTest = null, vectorOfReferrables = [], singleWeakReference = BigInt('0'), vectorOfWeakReferences = [], vectorOfStrongReferrables = [], coOwningReference = BigInt('0'), vectorOfCoOwningReferences = [], nonOwningReference = BigInt('0'), vectorOfNonOwningReferences = [], anyUniqueType = AnyUniqueAliases.NONE, anyUnique = null, anyAmbiguousType = AnyAmbiguousAliases.NONE, anyAmbiguous = null, vectorOfEnums = [], signedEnum = Race.None, testrequirednestedflatbuffer = [], scalarKeySortedTables = []) {
this.pos = pos;
this.mana = mana;
this.hp = hp;