mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 17:22:03 +00:00
Fix 64-bit numeric enum values in typescript (#7135)
* Fix 64-bit default numeric enum values in typescript If you had a default value that wasn't a valid enum value (e.g., a zero if you used a bit_flag setting, like you get with AdvancedFeatures in reflection.fbs), we weren't using BigInt. * Run generate_code.py * [DART] Handle deprecated fields & invalid enum defaults * Update .NET test
This commit is contained in:
8
tests/my-game/example/long-enum.ts
Normal file
8
tests/my-game/example/long-enum.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export enum LongEnum{
|
||||
LongOne = '2',
|
||||
LongTwo = '4',
|
||||
LongBig = '1099511627776'
|
||||
}
|
||||
|
||||
@@ -651,12 +651,44 @@ nativeInline(obj?:Test):Test|null {
|
||||
return offset ? (obj || new Test()).__init(this.bb_pos + offset, this.bb!) : null;
|
||||
}
|
||||
|
||||
longEnumNonEnumDefault():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 108);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
mutate_long_enum_non_enum_default(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 108);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
longEnumNormalDefault():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 110);
|
||||
return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('2');
|
||||
}
|
||||
|
||||
mutate_long_enum_normal_default(value:bigint):boolean {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 110);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeUint64(this.bb_pos + offset, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static getFullyQualifiedName():string {
|
||||
return 'MyGame.Example.Monster';
|
||||
}
|
||||
|
||||
static startMonster(builder:flatbuffers.Builder) {
|
||||
builder.startObject(52);
|
||||
builder.startObject(54);
|
||||
}
|
||||
|
||||
static addPos(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset) {
|
||||
@@ -1084,6 +1116,14 @@ static addNativeInline(builder:flatbuffers.Builder, nativeInlineOffset:flatbuffe
|
||||
builder.addFieldStruct(51, nativeInlineOffset, 0);
|
||||
}
|
||||
|
||||
static addLongEnumNonEnumDefault(builder:flatbuffers.Builder, longEnumNonEnumDefault:bigint) {
|
||||
builder.addFieldInt64(52, longEnumNonEnumDefault, BigInt('0'));
|
||||
}
|
||||
|
||||
static addLongEnumNormalDefault(builder:flatbuffers.Builder, longEnumNormalDefault:bigint) {
|
||||
builder.addFieldInt64(53, longEnumNormalDefault, BigInt('2'));
|
||||
}
|
||||
|
||||
static endMonster(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 10) // name
|
||||
@@ -1171,7 +1211,9 @@ unpack(): MonsterT {
|
||||
this.signedEnum(),
|
||||
this.bb!.createScalarList(this.testrequirednestedflatbuffer.bind(this), this.testrequirednestedflatbufferLength()),
|
||||
this.bb!.createObjList(this.scalarKeySortedTables.bind(this), this.scalarKeySortedTablesLength()),
|
||||
(this.nativeInline() !== null ? this.nativeInline()!.unpack() : null)
|
||||
(this.nativeInline() !== null ? this.nativeInline()!.unpack() : null),
|
||||
this.longEnumNonEnumDefault(),
|
||||
this.longEnumNormalDefault()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1240,6 +1282,8 @@ unpackTo(_o: MonsterT): void {
|
||||
_o.testrequirednestedflatbuffer = this.bb!.createScalarList(this.testrequirednestedflatbuffer.bind(this), this.testrequirednestedflatbufferLength());
|
||||
_o.scalarKeySortedTables = this.bb!.createObjList(this.scalarKeySortedTables.bind(this), this.scalarKeySortedTablesLength());
|
||||
_o.nativeInline = (this.nativeInline() !== null ? this.nativeInline()!.unpack() : null);
|
||||
_o.longEnumNonEnumDefault = this.longEnumNonEnumDefault();
|
||||
_o.longEnumNormalDefault = this.longEnumNormalDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1295,7 +1339,9 @@ constructor(
|
||||
public signedEnum: Race = Race.None,
|
||||
public testrequirednestedflatbuffer: (number)[] = [],
|
||||
public scalarKeySortedTables: (StatT)[] = [],
|
||||
public nativeInline: TestT|null = null
|
||||
public nativeInline: TestT|null = null,
|
||||
public longEnumNonEnumDefault: bigint = BigInt('0'),
|
||||
public longEnumNormalDefault: bigint = BigInt('2')
|
||||
){}
|
||||
|
||||
|
||||
@@ -1380,6 +1426,8 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
Monster.addTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer);
|
||||
Monster.addScalarKeySortedTables(builder, scalarKeySortedTables);
|
||||
Monster.addNativeInline(builder, (this.nativeInline !== null ? this.nativeInline!.pack(builder) : 0));
|
||||
Monster.addLongEnumNonEnumDefault(builder, this.longEnumNonEnumDefault);
|
||||
Monster.addLongEnumNormalDefault(builder, this.longEnumNormalDefault);
|
||||
|
||||
return Monster.endMonster(builder);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user