From 496f10525b54ed4e82e939f6c5a93c6d43a6cb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Wed, 8 Apr 2026 05:42:18 +0200 Subject: [PATCH] Improve TS types to support isolatedModules and isolatedDeclarations --- src/idl_gen_ts.cpp | 10 +- tests/ts/TypeScriptTest.py | 5 + tests/ts/abc.ts | 9 + .../arrays_test_complex/my-game/example.d.ts | 12 +- .../ts/arrays_test_complex/my-game/example.js | 15 +- .../ts/arrays_test_complex/my-game/example.ts | 12 +- .../my-game/example/array-struct.d.ts | 76 +- .../my-game/example/array-struct.js | 195 +- .../my-game/example/array-struct.ts | 298 +- .../my-game/example/array-table.d.ts | 68 +- .../my-game/example/array-table.js | 151 +- .../my-game/example/array-table.ts | 175 +- .../my-game/example/inner-struct.d.ts | 46 +- .../my-game/example/inner-struct.js | 113 +- .../my-game/example/inner-struct.ts | 149 +- .../my-game/example/nested-struct.d.ts | 61 +- .../my-game/example/nested-struct.js | 155 +- .../my-game/example/nested-struct.ts | 230 +- .../my-game/example/outer-struct.d.ts | 71 +- .../my-game/example/outer-struct.js | 188 +- .../my-game/example/outer-struct.ts | 264 +- .../my-game/example/test-enum.d.ts | 6 +- .../my-game/example/test-enum.js | 11 +- .../my-game/example/test-enum.ts | 2 +- tests/ts/com/company/test.ts | 2 +- tests/ts/com/company/test/person.ts | 143 +- tests/ts/even-more-defaults.ts | 473 +++ tests/ts/even-more-struct.ts | 64 + tests/ts/even_more_defaults.ts | 7 + tests/ts/foobar.d.ts | 2 +- tests/ts/foobar.js | 5 +- tests/ts/foobar.ts | 2 +- tests/ts/foobar/abc.d.ts | 2 +- tests/ts/foobar/abc.js | 7 +- tests/ts/foobar/abc.ts | 2 +- tests/ts/foobar/class.d.ts | 2 +- tests/ts/foobar/class.js | 7 +- tests/ts/foobar/class.ts | 2 +- tests/ts/foobar/tab.ts | 214 +- tests/ts/longer-namespace/a/b/c.d.ts | 2 +- tests/ts/longer-namespace/a/b/c.js | 5 +- tests/ts/longer-namespace/a/b/c.ts | 2 +- tests/ts/longer-namespace/a/b/c/person.d.ts | 46 +- tests/ts/longer-namespace/a/b/c/person.js | 104 +- tests/ts/longer-namespace/a/b/c/person.ts | 143 +- tests/ts/monster_test.d.ts | 2 +- tests/ts/monster_test.js | 5 +- tests/ts/monster_test_generated.cjs | 4 +- tests/ts/my-game.d.ts | 5 +- tests/ts/my-game.js | 5 +- tests/ts/my-game/example.d.ts | 41 +- tests/ts/my-game/example.js | 35 +- tests/ts/my-game/example/ability.d.ts | 40 +- tests/ts/my-game/example/ability.js | 98 +- tests/ts/my-game/example/ability.ts | 2 +- .../example/any-ambiguous-aliases.d.ts | 21 +- .../my-game/example/any-ambiguous-aliases.js | 53 +- .../my-game/example/any-unique-aliases.d.ts | 30 +- .../ts/my-game/example/any-unique-aliases.js | 58 +- tests/ts/my-game/example/any.d.ts | 30 +- tests/ts/my-game/example/any.js | 58 +- tests/ts/my-game/example/color.d.ts | 20 +- tests/ts/my-game/example/color.js | 25 +- tests/ts/my-game/example/long-enum.d.ts | 6 +- tests/ts/my-game/example/long-enum.js | 11 +- tests/ts/my-game/example/monster.d.ts | 985 ++---- tests/ts/my-game/example/monster.js | 2714 ++++++++--------- tests/ts/my-game/example/monster.ts | 170 +- tests/ts/my-game/example/race.d.ts | 8 +- tests/ts/my-game/example/race.js | 13 +- tests/ts/my-game/example/referrable.d.ts | 51 +- tests/ts/my-game/example/referrable.js | 131 +- tests/ts/my-game/example/referrable.ts | 6 +- tests/ts/my-game/example/stat.d.ts | 65 +- tests/ts/my-game/example/stat.js | 188 +- tests/ts/my-game/example/stat.ts | 10 +- .../example/struct-of-structs-of-structs.d.ts | 45 +- .../example/struct-of-structs-of-structs.js | 97 +- .../example/struct-of-structs-of-structs.ts | 2 +- .../ts/my-game/example/struct-of-structs.d.ts | 48 +- tests/ts/my-game/example/struct-of-structs.js | 118 +- tests/ts/my-game/example/struct-of-structs.ts | 2 +- .../example/test-simple-table-with-enum.d.ts | 59 +- .../example/test-simple-table-with-enum.js | 137 +- .../example/test-simple-table-with-enum.ts | 6 +- tests/ts/my-game/example/test.d.ts | 36 +- tests/ts/my-game/example/test.js | 100 +- tests/ts/my-game/example/test.ts | 2 +- tests/ts/my-game/example/type-aliases.d.ts | 209 +- tests/ts/my-game/example/type-aliases.js | 573 ++-- tests/ts/my-game/example/type-aliases.ts | 32 +- tests/ts/my-game/example/vec3.d.ts | 74 +- tests/ts/my-game/example/vec3.js | 191 +- tests/ts/my-game/example/vec3.ts | 2 +- tests/ts/my-game/example2.d.ts | 2 +- tests/ts/my-game/example2.js | 5 +- tests/ts/my-game/example2/monster.d.ts | 37 +- tests/ts/my-game/example2/monster.js | 93 +- tests/ts/my-game/example2/monster.ts | 4 +- tests/ts/my-game/in-parent-namespace.d.ts | 46 +- tests/ts/my-game/in-parent-namespace.js | 94 +- tests/ts/my-game/in-parent-namespace.ts | 4 +- tests/ts/my-game/other-name-space.d.ts | 6 +- tests/ts/my-game/other-name-space.js | 9 +- .../other-name-space/from-include.d.ts | 2 +- .../my-game/other-name-space/from-include.js | 7 +- .../my-game/other-name-space/from-include.ts | 2 +- .../ts/my-game/other-name-space/table-b.d.ts | 44 +- tests/ts/my-game/other-name-space/table-b.js | 126 +- tests/ts/my-game/other-name-space/table-b.ts | 134 +- tests/ts/my-game/other-name-space/unused.d.ts | 29 +- tests/ts/my-game/other-name-space/unused.js | 78 +- tests/ts/my-game/other-name-space/unused.ts | 84 +- tests/ts/no_import_ext/optional-scalars.d.ts | 4 +- tests/ts/no_import_ext/optional-scalars.js | 7 +- tests/ts/no_import_ext/optional-scalars.ts | 4 +- .../optional-scalars/optional-byte.d.ts | 6 +- .../optional-scalars/optional-byte.js | 11 +- .../optional-scalars/optional-byte.ts | 2 +- .../optional-scalars/scalar-stuff.d.ts | 232 +- .../optional-scalars/scalar-stuff.js | 681 ++--- .../optional-scalars/scalar-stuff.ts | 886 +++--- tests/ts/no_import_ext/optional_scalars.js | 3 +- tests/ts/non-zero-vector-table.ts | 113 + tests/ts/non-zero.ts | 7 + tests/ts/non_zero_enum.ts | 6 + tests/ts/optional-scalars/scalar-stuff.ts | 80 +- tests/ts/reflection.d.ts | 24 +- tests/ts/reflection.js | 27 +- tests/ts/reflection.ts | 24 +- tests/ts/reflection/advanced-features.d.ts | 8 +- tests/ts/reflection/advanced-features.js | 13 +- tests/ts/reflection/advanced-features.ts | 2 +- tests/ts/reflection/base-type.d.ts | 40 +- tests/ts/reflection/base-type.js | 45 +- tests/ts/reflection/base-type.ts | 2 +- tests/ts/reflection/enum-val.d.ts | 116 +- tests/ts/reflection/enum-val.js | 288 +- tests/ts/reflection/enum-val.ts | 382 +-- tests/ts/reflection/enum.d.ts | 156 +- tests/ts/reflection/enum.js | 381 +-- tests/ts/reflection/enum.ts | 514 ++-- tests/ts/reflection/field.d.ts | 211 +- tests/ts/reflection/field.js | 610 ++-- tests/ts/reflection/field.ts | 772 +++-- tests/ts/reflection/key-value.d.ts | 65 +- tests/ts/reflection/key-value.js | 133 +- tests/ts/reflection/key-value.ts | 163 +- tests/ts/reflection/object.d.ts | 178 +- tests/ts/reflection/object.js | 425 ++- tests/ts/reflection/object.ts | 596 ++-- tests/ts/reflection/rpccall.d.ts | 117 +- tests/ts/reflection/rpccall.js | 281 +- tests/ts/reflection/rpccall.ts | 344 +-- tests/ts/reflection/schema-file.d.ts | 92 +- tests/ts/reflection/schema-file.js | 167 +- tests/ts/reflection/schema-file.ts | 232 +- tests/ts/reflection/schema.d.ts | 187 +- tests/ts/reflection/schema.js | 461 ++- tests/ts/reflection/schema.ts | 616 ++-- tests/ts/reflection/service.d.ts | 145 +- tests/ts/reflection/service.js | 318 +- tests/ts/reflection/service.ts | 417 +-- tests/ts/reflection/type.d.ts | 112 +- tests/ts/reflection/type.js | 312 +- tests/ts/reflection/type.ts | 377 ++- tests/ts/relative_imports/transit/one.d.ts | 1 + tests/ts/relative_imports/transit/one.js | 3 + tests/ts/relative_imports/transit/one.ts | 5 + .../ts/relative_imports/transit/one/info.d.ts | 21 + tests/ts/relative_imports/transit/one/info.js | 57 + tests/ts/relative_imports/transit/one/info.ts | 78 + tests/ts/relative_imports/transit/three.d.ts | 1 + tests/ts/relative_imports/transit/three.js | 3 + tests/ts/relative_imports/transit/three.ts | 5 + .../transit/three/header.d.ts | 27 + .../relative_imports/transit/three/header.js | 74 + .../relative_imports/transit/three/header.ts | 100 + tests/ts/relative_imports/transit/two.d.ts | 1 + tests/ts/relative_imports/transit/two.js | 3 + tests/ts/relative_imports/transit/two.ts | 5 + .../transit/two/identity.d.ts | 21 + .../relative_imports/transit/two/identity.js | 57 + .../relative_imports/transit/two/identity.ts | 78 + tests/ts/table-a.d.ts | 44 +- tests/ts/table-a.js | 126 +- tests/ts/table-a.ts | 134 +- .../optional-scalars/scalar-stuff.ts | 82 +- tests/ts/tsconfig.isolated.json | 8 + tests/ts/tsconfig.json | 6 +- tests/ts/typescript.d.ts | 4 +- tests/ts/typescript.js | 7 +- tests/ts/typescript.ts | 4 +- tests/ts/typescript/class.d.ts | 4 +- tests/ts/typescript/class.js | 9 +- tests/ts/typescript/class.ts | 2 +- tests/ts/typescript/object.d.ts | 104 +- tests/ts/typescript/object.js | 324 +- tests/ts/typescript/object.ts | 375 ++- tests/ts/typescript_keywords.js | 3 +- tests/ts/typescript_keywords_generated.cjs | 16 +- tests/ts/union-underlying-type.d.ts | 10 +- tests/ts/union-underlying-type.js | 13 +- tests/ts/union-underlying-type.ts | 10 +- tests/ts/union-underlying-type/a.d.ts | 34 +- tests/ts/union-underlying-type/a.js | 119 +- tests/ts/union-underlying-type/a.ts | 130 +- tests/ts/union-underlying-type/abc.d.ts | 25 +- tests/ts/union-underlying-type/abc.js | 57 +- tests/ts/union-underlying-type/abc.ts | 55 +- tests/ts/union-underlying-type/b.d.ts | 37 +- tests/ts/union-underlying-type/b.js | 108 +- tests/ts/union-underlying-type/b.ts | 119 +- tests/ts/union-underlying-type/c.d.ts | 34 +- tests/ts/union-underlying-type/c.js | 119 +- tests/ts/union-underlying-type/c.ts | 130 +- tests/ts/union-underlying-type/d.d.ts | 107 +- tests/ts/union-underlying-type/d.js | 341 +-- tests/ts/union-underlying-type/d.ts | 435 ++- tests/ts/union_underlying_type_test.js | 3 +- tests/ts/union_vector/attacker.d.ts | 50 +- tests/ts/union_vector/attacker.js | 119 +- tests/ts/union_vector/attacker.ts | 6 +- tests/ts/union_vector/book-reader.d.ts | 33 +- tests/ts/union_vector/book-reader.js | 78 +- tests/ts/union_vector/book-reader.ts | 2 +- tests/ts/union_vector/character.d.ts | 36 +- tests/ts/union_vector/character.js | 81 +- tests/ts/union_vector/falling-tub.d.ts | 33 +- tests/ts/union_vector/falling-tub.js | 78 +- tests/ts/union_vector/falling-tub.ts | 2 +- tests/ts/union_vector/gadget.d.ts | 24 +- tests/ts/union_vector/gadget.js | 47 +- tests/ts/union_vector/hand-fan.d.ts | 44 +- tests/ts/union_vector/hand-fan.js | 119 +- tests/ts/union_vector/hand-fan.ts | 6 +- tests/ts/union_vector/movie.d.ts | 124 +- tests/ts/union_vector/movie.js | 382 ++- tests/ts/union_vector/movie.ts | 20 +- tests/ts/union_vector/rapunzel.d.ts | 33 +- tests/ts/union_vector/rapunzel.js | 78 +- tests/ts/union_vector/rapunzel.ts | 2 +- tests/ts/union_vector/union_vector.d.ts | 16 +- tests/ts/union_vector/union_vector.js | 19 +- .../union_vector/union_vector_generated.cjs | 2 +- ts/flatbuffers.ts | 2 +- ts/flexbuffers/stack-value.ts | 4 +- ts/utils.ts | 8 +- tsconfig.json | 4 +- 249 files changed, 12736 insertions(+), 14776 deletions(-) create mode 100644 tests/ts/abc.ts create mode 100644 tests/ts/even-more-defaults.ts create mode 100644 tests/ts/even-more-struct.ts create mode 100644 tests/ts/even_more_defaults.ts create mode 100644 tests/ts/non-zero-vector-table.ts create mode 100644 tests/ts/non-zero.ts create mode 100644 tests/ts/non_zero_enum.ts create mode 100644 tests/ts/relative_imports/transit/one.d.ts create mode 100644 tests/ts/relative_imports/transit/one.js create mode 100644 tests/ts/relative_imports/transit/one.ts create mode 100644 tests/ts/relative_imports/transit/one/info.d.ts create mode 100644 tests/ts/relative_imports/transit/one/info.js create mode 100644 tests/ts/relative_imports/transit/one/info.ts create mode 100644 tests/ts/relative_imports/transit/three.d.ts create mode 100644 tests/ts/relative_imports/transit/three.js create mode 100644 tests/ts/relative_imports/transit/three.ts create mode 100644 tests/ts/relative_imports/transit/three/header.d.ts create mode 100644 tests/ts/relative_imports/transit/three/header.js create mode 100644 tests/ts/relative_imports/transit/three/header.ts create mode 100644 tests/ts/relative_imports/transit/two.d.ts create mode 100644 tests/ts/relative_imports/transit/two.js create mode 100644 tests/ts/relative_imports/transit/two.ts create mode 100644 tests/ts/relative_imports/transit/two/identity.d.ts create mode 100644 tests/ts/relative_imports/transit/two/identity.js create mode 100644 tests/ts/relative_imports/transit/two/identity.ts create mode 100644 tests/ts/tsconfig.isolated.json diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index 8d02b8eb4..7a50cbe64 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -818,7 +818,7 @@ class TsGenerator : public BaseGenerator { code += "static finish" + (size_prefixed ? sizePrefixed : "") + GetPrefixedName(struct_def) + "Buffer"; - code += "(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {\n"; + code += "(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void {\n"; code += " builder.finish(offset"; if (!parser_.file_identifier_.empty()) { code += ", '" + parser_.file_identifier_ + "'"; @@ -1703,7 +1703,7 @@ class TsGenerator : public BaseGenerator { } code += " bb: flatbuffers.ByteBuffer|" + null_keyword_ + " = " + null_keyword_ + ";\n"; - code += " bb_pos = 0;\n"; + code += " bb_pos: number = 0;\n"; // Generate the __init method that sets the field in a pre-existing // accessor object. This is to allow object reuse. @@ -2156,7 +2156,7 @@ class TsGenerator : public BaseGenerator { GenDocComment(code_ptr); code += "static start" + GetPrefixedName(struct_def) + - "(builder:flatbuffers.Builder) {\n"; + "(builder:flatbuffers.Builder):void {\n"; code += " builder.startObject(" + NumToString(struct_def.fields.vec.size()) + ");\n"; @@ -2173,7 +2173,7 @@ class TsGenerator : public BaseGenerator { GenDocComment(code_ptr); code += "static " + namer_.Method("add", field); code += "(builder:flatbuffers.Builder, " + argname + ":" + - GetArgType(imports, struct_def, field, false) + ") {\n"; + GetArgType(imports, struct_def, field, false) + "):void {\n"; code += " builder.addField" + GenWriteMethod(field.value.type) + "("; code += NumToString(it - struct_def.fields.vec.begin()) + ", "; if (field.value.type.base_type == BASE_TYPE_BOOL) { @@ -2245,7 +2245,7 @@ class TsGenerator : public BaseGenerator { code += "static "; code += namer_.Method("start", field, "Vector"); - code += "(builder:flatbuffers.Builder, numElems:number) {\n"; + code += "(builder:flatbuffers.Builder, numElems:number):void {\n"; code += " builder.startVector(" + NumToString(elem_size); code += ", numElems, " + NumToString(alignment) + ");\n"; code += "}\n\n"; diff --git a/tests/ts/TypeScriptTest.py b/tests/ts/TypeScriptTest.py index 7bf4317f0..27120814e 100755 --- a/tests/ts/TypeScriptTest.py +++ b/tests/ts/TypeScriptTest.py @@ -228,6 +228,11 @@ print( " no_import_ext..." ) check_call(["../../node_modules/.bin/tsc", "-p", "./tsconfig.node.json"]) +print( + "Running TypeScript Compiler with isolatedDeclarations and" + " isolatedModules..." +) +check_call(["../../node_modules/.bin/tsc", "-p", "./tsconfig.isolated.json"]) NODE_CMD = ["node"] diff --git a/tests/ts/abc.ts b/tests/ts/abc.ts new file mode 100644 index 000000000..ddf7ad356 --- /dev/null +++ b/tests/ts/abc.ts @@ -0,0 +1,9 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +export enum ABC { + A = 0, + B = 1, + C = 2 +} diff --git a/tests/ts/arrays_test_complex/my-game/example.d.ts b/tests/ts/arrays_test_complex/my-game/example.d.ts index 9f165bda4..a3c1a81e1 100644 --- a/tests/ts/arrays_test_complex/my-game/example.d.ts +++ b/tests/ts/arrays_test_complex/my-game/example.d.ts @@ -1,6 +1,6 @@ -export {ArrayStruct, ArrayStructT} from './example/array-struct.js'; -export {ArrayTable, ArrayTableT} from './example/array-table.js'; -export {InnerStruct, InnerStructT} from './example/inner-struct.js'; -export {NestedStruct, NestedStructT} from './example/nested-struct.js'; -export {OuterStruct, OuterStructT} from './example/outer-struct.js'; -export {TestEnum} from './example/test-enum.js'; +export { ArrayStruct, ArrayStructT } from './example/array-struct.js'; +export { ArrayTable, ArrayTableT } from './example/array-table.js'; +export { InnerStruct, InnerStructT } from './example/inner-struct.js'; +export { NestedStruct, NestedStructT } from './example/nested-struct.js'; +export { OuterStruct, OuterStructT } from './example/outer-struct.js'; +export { TestEnum } from './example/test-enum.js'; diff --git a/tests/ts/arrays_test_complex/my-game/example.js b/tests/ts/arrays_test_complex/my-game/example.js index 90f6f0c88..d9405e142 100644 --- a/tests/ts/arrays_test_complex/my-game/example.js +++ b/tests/ts/arrays_test_complex/my-game/example.js @@ -1,9 +1,8 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {ArrayStruct, ArrayStructT} from './example/array-struct.js'; -export {ArrayTable, ArrayTableT} from './example/array-table.js'; -export {InnerStruct, InnerStructT} from './example/inner-struct.js'; -export {NestedStruct, NestedStructT} from './example/nested-struct.js'; -export {OuterStruct, OuterStructT} from './example/outer-struct.js'; -export {TestEnum} from './example/test-enum.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { ArrayStruct, ArrayStructT } from './example/array-struct.js'; +export { ArrayTable, ArrayTableT } from './example/array-table.js'; +export { InnerStruct, InnerStructT } from './example/inner-struct.js'; +export { NestedStruct, NestedStructT } from './example/nested-struct.js'; +export { OuterStruct, OuterStructT } from './example/outer-struct.js'; +export { TestEnum } from './example/test-enum.js'; diff --git a/tests/ts/arrays_test_complex/my-game/example.ts b/tests/ts/arrays_test_complex/my-game/example.ts index eb01ee15d..4f1d63b4e 100644 --- a/tests/ts/arrays_test_complex/my-game/example.ts +++ b/tests/ts/arrays_test_complex/my-game/example.ts @@ -2,9 +2,9 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {ArrayStruct, ArrayStructT} from './example/array-struct.js'; -export {ArrayTable, ArrayTableT} from './example/array-table.js'; -export {InnerStruct, InnerStructT} from './example/inner-struct.js'; -export {NestedStruct, NestedStructT} from './example/nested-struct.js'; -export {OuterStruct, OuterStructT} from './example/outer-struct.js'; -export {TestEnum} from './example/test-enum.js'; +export { ArrayStruct, ArrayStructT } from './example/array-struct.js'; +export { ArrayTable, ArrayTableT } from './example/array-table.js'; +export { InnerStruct, InnerStructT } from './example/inner-struct.js'; +export { NestedStruct, NestedStructT } from './example/nested-struct.js'; +export { OuterStruct, OuterStructT } from './example/outer-struct.js'; +export { TestEnum } from './example/test-enum.js'; diff --git a/tests/ts/arrays_test_complex/my-game/example/array-struct.d.ts b/tests/ts/arrays_test_complex/my-game/example/array-struct.d.ts index b8b8703b1..51b261cb8 100644 --- a/tests/ts/arrays_test_complex/my-game/example/array-struct.d.ts +++ b/tests/ts/arrays_test_complex/my-game/example/array-struct.d.ts @@ -1,53 +1,31 @@ import * as flatbuffers from 'flatbuffers'; -import { - NestedStruct, - NestedStructT, -} from '../../my-game/example/nested-struct.js'; -import {OuterStruct, OuterStructT} from '../../my-game/example/outer-struct.js'; -export declare class ArrayStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): ArrayStruct; - aUnderscore(): number; - bUnderscore(index: number): number | null; - c(): number; - d(index: number, obj?: NestedStruct): NestedStruct | null; - e(): number; - f(index: number, obj?: OuterStruct): OuterStruct | null; - g(index: number): bigint | null; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createArrayStruct( - builder: flatbuffers.Builder, - a_underscore: number, - b_underscore: number[] | null, - c: number, - d: (any | NestedStructT)[] | null, - e: number, - f: (any | OuterStructT)[] | null, - g: bigint[] | null, - ): flatbuffers.Offset; - unpack(): ArrayStructT; - unpackTo(_o: ArrayStructT): void; +import { NestedStruct, NestedStructT } from './nested-struct.js'; +import { OuterStruct, OuterStructT } from './outer-struct.js'; +export declare class ArrayStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): ArrayStruct; + aUnderscore(): number; + bUnderscore(index: number): number | null; + c(): number; + d(index: number, obj?: NestedStruct): NestedStruct | null; + e(): number; + f(index: number, obj?: OuterStruct): OuterStruct | null; + g(index: number): bigint | null; + static getFullyQualifiedName(): "MyGame.Example.ArrayStruct"; + static sizeOf(): number; + static createArrayStruct(builder: flatbuffers.Builder, a_underscore: number, b_underscore: number[], c: number, d: (any | NestedStructT)[], e: number, f: (any | OuterStructT)[], g: bigint[]): flatbuffers.Offset; + unpack(): ArrayStructT; + unpackTo(_o: ArrayStructT): void; } export declare class ArrayStructT implements flatbuffers.IGeneratedObject { - aUnderscore: number; - bUnderscore: number[]; - c: number; - d: NestedStructT[]; - e: number; - f: OuterStructT[]; - g: bigint[]; - constructor( - aUnderscore?: number, - bUnderscore?: number[], - c?: number, - d?: NestedStructT[], - e?: number, - f?: OuterStructT[], - g?: bigint[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + aUnderscore: number; + bUnderscore: (number)[]; + c: number; + d: (NestedStructT)[]; + e: number; + f: (OuterStructT)[]; + g: (bigint)[]; + constructor(aUnderscore?: number, bUnderscore?: (number)[], c?: number, d?: (NestedStructT)[], e?: number, f?: (OuterStructT)[], g?: (bigint)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/arrays_test_complex/my-game/example/array-struct.js b/tests/ts/arrays_test_complex/my-game/example/array-struct.js index 9a62528f0..6300dcd2a 100644 --- a/tests/ts/arrays_test_complex/my-game/example/array-struct.js +++ b/tests/ts/arrays_test_complex/my-game/example/array-struct.js @@ -1,115 +1,98 @@ // automatically generated by the FlatBuffers compiler, do not modify -import {NestedStruct, NestedStructT} from '../../my-game/example/nested-struct.js'; -import {OuterStruct, OuterStructT} from '../../my-game/example/outer-struct.js'; +import { NestedStruct, NestedStructT } from './nested-struct.js'; +import { OuterStruct, OuterStructT } from './outer-struct.js'; export class ArrayStruct { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - aUnderscore() { - return this.bb.readFloat32(this.bb_pos); - } - bUnderscore(index) { - return this.bb.readInt32(this.bb_pos + 4 + index * 4); - } - c() { - return this.bb.readInt8(this.bb_pos + 64); - } - d(index, obj) { - return (obj || new NestedStruct()) - .__init(this.bb_pos + 72 + index * 1072, this.bb); - } - e() { - return this.bb.readInt32(this.bb_pos + 2216); - } - f(index, obj) { - return (obj || new OuterStruct()) - .__init(this.bb_pos + 2224 + index * 208, this.bb); - } - g(index) { - return this.bb.readInt64(this.bb_pos + 2640 + index * 8); - } - static getFullyQualifiedName() { - return 'MyGame.Example.ArrayStruct'; - } - static sizeOf() { - return 2656; - } - static createArrayStruct(builder, a_underscore, b_underscore, c, d, e, f, g) { - builder.prep(8, 2656); - for (let i = 1; i >= 0; --i) { - builder.writeInt64(BigInt(g?.[i] ?? 0)); + constructor() { + this.bb = null; + this.bb_pos = 0; } - for (let i = 1; i >= 0; --i) { - const item = f?.[i]; - if (item instanceof OuterStructT) { - item.pack(builder); - continue; - } - OuterStruct.createOuterStruct( - builder, item?.a, item?.b, (item?.cUnderscore?.a ?? 0), - (item?.cUnderscore?.b ?? []), (item?.cUnderscore?.c ?? 0), - (item?.cUnderscore?.dUnderscore ?? BigInt(0)), item?.d, - (item?.e?.a ?? 0), (item?.e?.b ?? []), (item?.e?.c ?? 0), - (item?.e?.dUnderscore ?? BigInt(0)), item?.f); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - builder.pad(4); - builder.writeInt32(e); - for (let i = 1; i >= 0; --i) { - const item = d?.[i]; - if (item instanceof NestedStructT) { - item.pack(builder); - continue; - } - NestedStruct.createNestedStruct( - builder, item?.a, item?.b, item?.cUnderscore, item?.dOuter, item?.e); + aUnderscore() { + return this.bb.readFloat32(this.bb_pos); } - builder.pad(7); - builder.writeInt8(c); - for (let i = 14; i >= 0; --i) { - builder.writeInt32((b_underscore?.[i] ?? 0)); + bUnderscore(index) { + return this.bb.readInt32(this.bb_pos + 4 + index * 4); + } + c() { + return this.bb.readInt8(this.bb_pos + 64); + } + d(index, obj) { + return (obj || new NestedStruct()).__init(this.bb_pos + 72 + index * 1072, this.bb); + } + e() { + return this.bb.readInt32(this.bb_pos + 2216); + } + f(index, obj) { + return (obj || new OuterStruct()).__init(this.bb_pos + 2224 + index * 208, this.bb); + } + g(index) { + return this.bb.readInt64(this.bb_pos + 2640 + index * 8); + } + static getFullyQualifiedName() { + return 'MyGame.Example.ArrayStruct'; + } + static sizeOf() { + return 2656; + } + static createArrayStruct(builder, a_underscore, b_underscore, c, d, e, f, g) { + builder.prep(8, 2656); + for (let i = 1; i >= 0; --i) { + builder.writeInt64(BigInt(g?.[i] ?? 0)); + } + for (let i = 1; i >= 0; --i) { + const item = f?.[i]; + if (item instanceof OuterStructT) { + item.pack(builder); + continue; + } + OuterStruct.createOuterStruct(builder, item?.a, item?.b, (item?.cUnderscore?.a ?? 0), (item?.cUnderscore?.b ?? []), (item?.cUnderscore?.c ?? 0), (item?.cUnderscore?.dUnderscore ?? BigInt(0)), item?.d, (item?.e?.a ?? 0), (item?.e?.b ?? []), (item?.e?.c ?? 0), (item?.e?.dUnderscore ?? BigInt(0)), item?.f); + } + builder.pad(4); + builder.writeInt32(e); + for (let i = 1; i >= 0; --i) { + const item = d?.[i]; + if (item instanceof NestedStructT) { + item.pack(builder); + continue; + } + NestedStruct.createNestedStruct(builder, item?.a, item?.b, item?.cUnderscore, item?.dOuter, item?.e); + } + builder.pad(7); + builder.writeInt8(c); + for (let i = 14; i >= 0; --i) { + builder.writeInt32((b_underscore?.[i] ?? 0)); + } + builder.writeFloat32(a_underscore); + return builder.offset(); + } + unpack() { + return new ArrayStructT(this.aUnderscore(), this.bb.createScalarList(this.bUnderscore.bind(this), 15), this.c(), this.bb.createObjList(this.d.bind(this), 2), this.e(), this.bb.createObjList(this.f.bind(this), 2), this.bb.createScalarList(this.g.bind(this), 2)); + } + unpackTo(_o) { + _o.aUnderscore = this.aUnderscore(); + _o.bUnderscore = this.bb.createScalarList(this.bUnderscore.bind(this), 15); + _o.c = this.c(); + _o.d = this.bb.createObjList(this.d.bind(this), 2); + _o.e = this.e(); + _o.f = this.bb.createObjList(this.f.bind(this), 2); + _o.g = this.bb.createScalarList(this.g.bind(this), 2); } - builder.writeFloat32(a_underscore); - return builder.offset(); - } - unpack() { - return new ArrayStructT( - this.aUnderscore(), - this.bb.createScalarList(this.bUnderscore.bind(this), 15), this.c(), - this.bb.createObjList(this.d.bind(this), 2), this.e(), - this.bb.createObjList(this.f.bind(this), 2), - this.bb.createScalarList(this.g.bind(this), 2)); - } - unpackTo(_o) { - _o.aUnderscore = this.aUnderscore(); - _o.bUnderscore = this.bb.createScalarList(this.bUnderscore.bind(this), 15); - _o.c = this.c(); - _o.d = this.bb.createObjList(this.d.bind(this), 2); - _o.e = this.e(); - _o.f = this.bb.createObjList(this.f.bind(this), 2); - _o.g = this.bb.createScalarList(this.g.bind(this), 2); - } } export class ArrayStructT { - constructor( - aUnderscore = 0.0, bUnderscore = [], c = 0, d = [], e = 0, f = [], - g = []) { - this.aUnderscore = aUnderscore; - this.bUnderscore = bUnderscore; - this.c = c; - this.d = d; - this.e = e; - this.f = f; - this.g = g; - } - pack(builder) { - return ArrayStruct.createArrayStruct( - builder, this.aUnderscore, this.bUnderscore, this.c, this.d, this.e, - this.f, this.g); - } + constructor(aUnderscore = 0.0, bUnderscore = [], c = 0, d = [], e = 0, f = [], g = []) { + this.aUnderscore = aUnderscore; + this.bUnderscore = bUnderscore; + this.c = c; + this.d = d; + this.e = e; + this.f = f; + this.g = g; + } + pack(builder) { + return ArrayStruct.createArrayStruct(builder, this.aUnderscore, this.bUnderscore, this.c, this.d, this.e, this.f, this.g); + } } diff --git a/tests/ts/arrays_test_complex/my-game/example/array-struct.ts b/tests/ts/arrays_test_complex/my-game/example/array-struct.ts index bfb65df22..9d0359704 100644 --- a/tests/ts/arrays_test_complex/my-game/example/array-struct.ts +++ b/tests/ts/arrays_test_complex/my-game/example/array-struct.ts @@ -4,191 +4,165 @@ import * as flatbuffers from 'flatbuffers'; -import { - NestedStruct, - NestedStructT, -} from '../../my-game/example/nested-struct.js'; -import {OuterStruct, OuterStructT} from '../../my-game/example/outer-struct.js'; +import { NestedStruct, NestedStructT } from './nested-struct.js'; +import { OuterStruct, OuterStructT } from './outer-struct.js'; -export class ArrayStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): ArrayStruct { - this.bb_pos = i; - this.bb = bb; - return this; - } - aUnderscore(): number { - return this.bb!.readFloat32(this.bb_pos); - } +export class ArrayStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):ArrayStruct { + this.bb_pos = i; + this.bb = bb; + return this; +} - bUnderscore(index: number): number | null { +aUnderscore():number { + return this.bb!.readFloat32(this.bb_pos); +} + +bUnderscore(index: number):number|null { return this.bb!.readInt32(this.bb_pos + 4 + index * 4); - } +} - c(): number { - return this.bb!.readInt8(this.bb_pos + 64); - } +c():number { + return this.bb!.readInt8(this.bb_pos + 64); +} - d(index: number, obj?: NestedStruct): NestedStruct | null { - return (obj || new NestedStruct()).__init( - this.bb_pos + 72 + index * 1072, - this.bb!, - ); - } +d(index: number, obj?:NestedStruct):NestedStruct|null { + return (obj || new NestedStruct()).__init(this.bb_pos + 72 + index * 1072, this.bb!); +} - e(): number { - return this.bb!.readInt32(this.bb_pos + 2216); - } +e():number { + return this.bb!.readInt32(this.bb_pos + 2216); +} - f(index: number, obj?: OuterStruct): OuterStruct | null { - return (obj || new OuterStruct()).__init( - this.bb_pos + 2224 + index * 208, - this.bb!, - ); - } +f(index: number, obj?:OuterStruct):OuterStruct|null { + return (obj || new OuterStruct()).__init(this.bb_pos + 2224 + index * 208, this.bb!); +} - g(index: number): bigint | null { +g(index: number):bigint|null { return this.bb!.readInt64(this.bb_pos + 2640 + index * 8); +} + +static getFullyQualifiedName(): "MyGame.Example.ArrayStruct" { + return 'MyGame.Example.ArrayStruct'; +} + +static sizeOf():number { + return 2656; +} + +static createArrayStruct(builder:flatbuffers.Builder, a_underscore: number, b_underscore: number[], c: number, d: (any|NestedStructT)[], e: number, f: (any|OuterStructT)[], g: bigint[]):flatbuffers.Offset { + builder.prep(8, 2656); + + for (let i = 1; i >= 0; --i) { + builder.writeInt64(BigInt(g?.[i] ?? 0)); } - static getFullyQualifiedName(): string { - return 'MyGame.Example.ArrayStruct'; - } - static sizeOf(): number { - return 2656; - } + for (let i = 1; i >= 0; --i) { + const item = f?.[i]; - static createArrayStruct( - builder: flatbuffers.Builder, - a_underscore: number, - b_underscore: number[] | null, - c: number, - d: (any | NestedStructT)[] | null, - e: number, - f: (any | OuterStructT)[] | null, - g: bigint[] | null, - ): flatbuffers.Offset { - builder.prep(8, 2656); - - for (let i = 1; i >= 0; --i) { - builder.writeInt64(BigInt(g?.[i] ?? 0)); + if (item instanceof OuterStructT) { + item.pack(builder); + continue; } - for (let i = 1; i >= 0; --i) { - const item = f?.[i]; - - if (item instanceof OuterStructT) { - item.pack(builder); - continue; - } - - OuterStruct.createOuterStruct( - builder, - item?.a, - item?.b, - item?.cUnderscore?.a ?? 0, - item?.cUnderscore?.b ?? [], - item?.cUnderscore?.c ?? 0, - item?.cUnderscore?.dUnderscore ?? BigInt(0), - item?.d, - item?.e?.a ?? 0, - item?.e?.b ?? [], - item?.e?.c ?? 0, - item?.e?.dUnderscore ?? BigInt(0), - item?.f, - ); - } - - builder.pad(4); - builder.writeInt32(e); - - for (let i = 1; i >= 0; --i) { - const item = d?.[i]; - - if (item instanceof NestedStructT) { - item.pack(builder); - continue; - } - - NestedStruct.createNestedStruct( - builder, - item?.a, - item?.b, - item?.cUnderscore, - item?.dOuter, - item?.e, - ); - } - - builder.pad(7); - builder.writeInt8(c); - - for (let i = 14; i >= 0; --i) { - builder.writeInt32(b_underscore?.[i] ?? 0); - } - - builder.writeFloat32(a_underscore); - return builder.offset(); - } - - unpack(): ArrayStructT { - return new ArrayStructT( - this.aUnderscore(), - this.bb!.createScalarList(this.bUnderscore.bind(this), 15), - this.c(), - this.bb!.createObjList(this.d.bind(this), 2), - this.e(), - this.bb!.createObjList(this.f.bind(this), 2), - this.bb!.createScalarList(this.g.bind(this), 2), + OuterStruct.createOuterStruct(builder, + item?.a, + item?.b, + (item?.cUnderscore?.a ?? 0), + (item?.cUnderscore?.b ?? []), + (item?.cUnderscore?.c ?? 0), + (item?.cUnderscore?.dUnderscore ?? BigInt(0)), + item?.d, + (item?.e?.a ?? 0), + (item?.e?.b ?? []), + (item?.e?.c ?? 0), + (item?.e?.dUnderscore ?? BigInt(0)), + item?.f ); } - unpackTo(_o: ArrayStructT): void { - _o.aUnderscore = this.aUnderscore(); - _o.bUnderscore = this.bb!.createScalarList( - this.bUnderscore.bind(this), - 15, + builder.pad(4); + builder.writeInt32(e); + + for (let i = 1; i >= 0; --i) { + const item = d?.[i]; + + if (item instanceof NestedStructT) { + item.pack(builder); + continue; + } + + NestedStruct.createNestedStruct(builder, + item?.a, + item?.b, + item?.cUnderscore, + item?.dOuter, + item?.e ); - _o.c = this.c(); - _o.d = this.bb!.createObjList( - this.d.bind(this), - 2, - ); - _o.e = this.e(); - _o.f = this.bb!.createObjList( - this.f.bind(this), - 2, - ); - _o.g = this.bb!.createScalarList(this.g.bind(this), 2); } + + builder.pad(7); + builder.writeInt8(c); + + for (let i = 14; i >= 0; --i) { + builder.writeInt32((b_underscore?.[i] ?? 0)); + + } + + builder.writeFloat32(a_underscore); + return builder.offset(); +} + + +unpack(): ArrayStructT { + return new ArrayStructT( + this.aUnderscore(), + this.bb!.createScalarList(this.bUnderscore.bind(this), 15), + this.c(), + this.bb!.createObjList(this.d.bind(this), 2), + this.e(), + this.bb!.createObjList(this.f.bind(this), 2), + this.bb!.createScalarList(this.g.bind(this), 2) + ); +} + + +unpackTo(_o: ArrayStructT): void { + _o.aUnderscore = this.aUnderscore(); + _o.bUnderscore = this.bb!.createScalarList(this.bUnderscore.bind(this), 15); + _o.c = this.c(); + _o.d = this.bb!.createObjList(this.d.bind(this), 2); + _o.e = this.e(); + _o.f = this.bb!.createObjList(this.f.bind(this), 2); + _o.g = this.bb!.createScalarList(this.g.bind(this), 2); +} } export class ArrayStructT implements flatbuffers.IGeneratedObject { - constructor( - public aUnderscore: number = 0.0, - public bUnderscore: number[] = [], - public c: number = 0, - public d: NestedStructT[] = [], - public e: number = 0, - public f: OuterStructT[] = [], - public g: bigint[] = [], - ) {} +constructor( + public aUnderscore: number = 0.0, + public bUnderscore: (number)[] = [], + public c: number = 0, + public d: (NestedStructT)[] = [], + public e: number = 0, + public f: (OuterStructT)[] = [], + public g: (bigint)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return ArrayStruct.createArrayStruct( - builder, - this.aUnderscore, - this.bUnderscore, - this.c, - this.d, - this.e, - this.f, - this.g, - ); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return ArrayStruct.createArrayStruct(builder, + this.aUnderscore, + this.bUnderscore, + this.c, + this.d, + this.e, + this.f, + this.g + ); +} } diff --git a/tests/ts/arrays_test_complex/my-game/example/array-table.d.ts b/tests/ts/arrays_test_complex/my-game/example/array-table.d.ts index 86668d9f7..7b7b94ef1 100644 --- a/tests/ts/arrays_test_complex/my-game/example/array-table.d.ts +++ b/tests/ts/arrays_test_complex/my-game/example/array-table.d.ts @@ -1,48 +1,28 @@ import * as flatbuffers from 'flatbuffers'; -import {ArrayStruct, ArrayStructT} from '../../my-game/example/array-struct.js'; -export declare class ArrayTable - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): ArrayTable; - static getRootAsArrayTable( - bb: flatbuffers.ByteBuffer, - obj?: ArrayTable, - ): ArrayTable; - static getSizePrefixedRootAsArrayTable( - bb: flatbuffers.ByteBuffer, - obj?: ArrayTable, - ): ArrayTable; - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; - a(): string | null; - a(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - cUnderscore(obj?: ArrayStruct): ArrayStruct | null; - static getFullyQualifiedName(): string; - static startArrayTable(builder: flatbuffers.Builder): void; - static addA(builder: flatbuffers.Builder, aOffset: flatbuffers.Offset): void; - static addCUnderscore( - builder: flatbuffers.Builder, - cUnderscoreOffset: flatbuffers.Offset, - ): void; - static endArrayTable(builder: flatbuffers.Builder): flatbuffers.Offset; - static finishArrayTableBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static finishSizePrefixedArrayTableBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - unpack(): ArrayTableT; - unpackTo(_o: ArrayTableT): void; +import { ArrayStruct, ArrayStructT } from './array-struct.js'; +export declare class ArrayTable implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): ArrayTable; + static getRootAsArrayTable(bb: flatbuffers.ByteBuffer, obj?: ArrayTable): ArrayTable; + static getSizePrefixedRootAsArrayTable(bb: flatbuffers.ByteBuffer, obj?: ArrayTable): ArrayTable; + static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; + a(): string | null; + a(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + cUnderscore(obj?: ArrayStruct): ArrayStruct | null; + static getFullyQualifiedName(): "MyGame.Example.ArrayTable"; + static startArrayTable(builder: flatbuffers.Builder): void; + static addA(builder: flatbuffers.Builder, aOffset: flatbuffers.Offset): void; + static addCUnderscore(builder: flatbuffers.Builder, cUnderscoreOffset: flatbuffers.Offset): void; + static endArrayTable(builder: flatbuffers.Builder): flatbuffers.Offset; + static finishArrayTableBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static finishSizePrefixedArrayTableBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + unpack(): ArrayTableT; + unpackTo(_o: ArrayTableT): void; } export declare class ArrayTableT implements flatbuffers.IGeneratedObject { - a: string | Uint8Array | null; - cUnderscore: ArrayStructT | null; - constructor( - a?: string | Uint8Array | null, - cUnderscore?: ArrayStructT | null, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: string | Uint8Array | null; + cUnderscore: ArrayStructT | null; + constructor(a?: string | Uint8Array | null, cUnderscore?: ArrayStructT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/arrays_test_complex/my-game/example/array-table.js b/tests/ts/arrays_test_complex/my-game/example/array-table.js index 01457b733..bbbf79e60 100644 --- a/tests/ts/arrays_test_complex/my-game/example/array-table.js +++ b/tests/ts/arrays_test_complex/my-game/example/array-table.js @@ -1,88 +1,75 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {ArrayStruct} from '../../my-game/example/array-struct.js'; - +import { ArrayStruct } from './array-struct.js'; export class ArrayTable { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsArrayTable(bb, obj) { - return (obj || new ArrayTable()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsArrayTable(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new ArrayTable()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static bufferHasIdentifier(bb) { - return bb.__has_identifier('RHUB'); - } - a(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - cUnderscore(obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? - (obj || new ArrayStruct()).__init(this.bb_pos + offset, this.bb) : - null; - } - static getFullyQualifiedName() { - return 'MyGame.Example.ArrayTable'; - } - static startArrayTable(builder) { - builder.startObject(2); - } - static addA(builder, aOffset) { - builder.addFieldOffset(0, aOffset, 0); - } - static addCUnderscore(builder, cUnderscoreOffset) { - builder.addFieldStruct(1, cUnderscoreOffset, 0); - } - static endArrayTable(builder) { - const offset = builder.endObject(); - return offset; - } - static finishArrayTableBuffer(builder, offset) { - builder.finish(offset, 'RHUB'); - } - static finishSizePrefixedArrayTableBuffer(builder, offset) { - builder.finish(offset, 'RHUB', true); - } - unpack() { - return new ArrayTableT( - this.a(), - (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null)); - } - unpackTo(_o) { - _o.a = this.a(); - _o.cUnderscore = - (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsArrayTable(bb, obj) { + return (obj || new ArrayTable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsArrayTable(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new ArrayTable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static bufferHasIdentifier(bb) { + return bb.__has_identifier('RHUB'); + } + a(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + cUnderscore(obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new ArrayStruct()).__init(this.bb_pos + offset, this.bb) : null; + } + static getFullyQualifiedName() { + return 'MyGame.Example.ArrayTable'; + } + static startArrayTable(builder) { + builder.startObject(2); + } + static addA(builder, aOffset) { + builder.addFieldOffset(0, aOffset, 0); + } + static addCUnderscore(builder, cUnderscoreOffset) { + builder.addFieldStruct(1, cUnderscoreOffset, 0); + } + static endArrayTable(builder) { + const offset = builder.endObject(); + return offset; + } + static finishArrayTableBuffer(builder, offset) { + builder.finish(offset, 'RHUB'); + } + static finishSizePrefixedArrayTableBuffer(builder, offset) { + builder.finish(offset, 'RHUB', true); + } + unpack() { + return new ArrayTableT(this.a(), (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null)); + } + unpackTo(_o) { + _o.a = this.a(); + _o.cUnderscore = (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null); + } } export class ArrayTableT { - constructor(a = null, cUnderscore = null) { - this.a = a; - this.cUnderscore = cUnderscore; - } - pack(builder) { - const a = (this.a !== null ? builder.createString(this.a) : 0); - ArrayTable.startArrayTable(builder); - ArrayTable.addA(builder, a); - ArrayTable.addCUnderscore( - builder, - (this.cUnderscore !== null ? this.cUnderscore.pack(builder) : 0)); - return ArrayTable.endArrayTable(builder); - } + constructor(a = null, cUnderscore = null) { + this.a = a; + this.cUnderscore = cUnderscore; + } + pack(builder) { + const a = (this.a !== null ? builder.createString(this.a) : 0); + ArrayTable.startArrayTable(builder); + ArrayTable.addA(builder, a); + ArrayTable.addCUnderscore(builder, (this.cUnderscore !== null ? this.cUnderscore.pack(builder) : 0)); + return ArrayTable.endArrayTable(builder); + } } diff --git a/tests/ts/arrays_test_complex/my-game/example/array-table.ts b/tests/ts/arrays_test_complex/my-game/example/array-table.ts index 1128fc3d9..94148c660 100644 --- a/tests/ts/arrays_test_complex/my-game/example/array-table.ts +++ b/tests/ts/arrays_test_complex/my-game/example/array-table.ts @@ -4,126 +4,101 @@ import * as flatbuffers from 'flatbuffers'; -import {ArrayStruct, ArrayStructT} from '../../my-game/example/array-struct.js'; +import { ArrayStruct, ArrayStructT } from './array-struct.js'; + export class ArrayTable implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): ArrayTable { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):ArrayTable { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsArrayTable( - bb: flatbuffers.ByteBuffer, - obj?: ArrayTable, - ): ArrayTable { - return (obj || new ArrayTable()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsArrayTable(bb:flatbuffers.ByteBuffer, obj?:ArrayTable):ArrayTable { + return (obj || new ArrayTable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsArrayTable( - bb: flatbuffers.ByteBuffer, - obj?: ArrayTable, - ): ArrayTable { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new ArrayTable()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsArrayTable(bb:flatbuffers.ByteBuffer, obj?:ArrayTable):ArrayTable { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new ArrayTable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean { - return bb.__has_identifier('RHUB'); - } +static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean { + return bb.__has_identifier('RHUB'); +} - a(): string | null; - a(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - a(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +a():string|null +a(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +a(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} - cUnderscore(obj?: ArrayStruct): ArrayStruct | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? (obj || new ArrayStruct()).__init(this.bb_pos + offset, this.bb!) - : null; - } +cUnderscore(obj?:ArrayStruct):ArrayStruct|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new ArrayStruct()).__init(this.bb_pos + offset, this.bb!) : null; +} - static getFullyQualifiedName(): string { - return 'MyGame.Example.ArrayTable'; - } +static getFullyQualifiedName(): "MyGame.Example.ArrayTable" { + return 'MyGame.Example.ArrayTable'; +} - static startArrayTable(builder: flatbuffers.Builder) { - builder.startObject(2); - } +static startArrayTable(builder:flatbuffers.Builder):void { + builder.startObject(2); +} - static addA(builder: flatbuffers.Builder, aOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, aOffset, 0); - } +static addA(builder:flatbuffers.Builder, aOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, aOffset, 0); +} - static addCUnderscore( - builder: flatbuffers.Builder, - cUnderscoreOffset: flatbuffers.Offset, - ) { - builder.addFieldStruct(1, cUnderscoreOffset, 0); - } +static addCUnderscore(builder:flatbuffers.Builder, cUnderscoreOffset:flatbuffers.Offset):void { + builder.addFieldStruct(1, cUnderscoreOffset, 0); +} - static endArrayTable(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } +static endArrayTable(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - static finishArrayTableBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, 'RHUB'); - } +static finishArrayTableBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, 'RHUB'); +} - static finishSizePrefixedArrayTableBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, 'RHUB', true); - } +static finishSizePrefixedArrayTableBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, 'RHUB', true); +} - unpack(): ArrayTableT { - return new ArrayTableT( - this.a(), - this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null, - ); - } - unpackTo(_o: ArrayTableT): void { - _o.a = this.a(); - _o.cUnderscore = - this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null; - } +unpack(): ArrayTableT { + return new ArrayTableT( + this.a(), + (this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null) + ); +} + + +unpackTo(_o: ArrayTableT): void { + _o.a = this.a(); + _o.cUnderscore = (this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null); +} } export class ArrayTableT implements flatbuffers.IGeneratedObject { - constructor( - public a: string | Uint8Array | null = null, - public cUnderscore: ArrayStructT | null = null, - ) {} +constructor( + public a: string|Uint8Array|null = null, + public cUnderscore: ArrayStructT|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const a = this.a !== null ? builder.createString(this.a!) : 0; - ArrayTable.startArrayTable(builder); - ArrayTable.addA(builder, a); - ArrayTable.addCUnderscore( - builder, - this.cUnderscore !== null ? this.cUnderscore!.pack(builder) : 0, - ); +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const a = (this.a !== null ? builder.createString(this.a!) : 0); - return ArrayTable.endArrayTable(builder); - } + ArrayTable.startArrayTable(builder); + ArrayTable.addA(builder, a); + ArrayTable.addCUnderscore(builder, (this.cUnderscore !== null ? this.cUnderscore!.pack(builder) : 0)); + + return ArrayTable.endArrayTable(builder); +} } diff --git a/tests/ts/arrays_test_complex/my-game/example/inner-struct.d.ts b/tests/ts/arrays_test_complex/my-game/example/inner-struct.d.ts index b1a47eadc..c93a2061c 100644 --- a/tests/ts/arrays_test_complex/my-game/example/inner-struct.d.ts +++ b/tests/ts/arrays_test_complex/my-game/example/inner-struct.d.ts @@ -1,31 +1,23 @@ import * as flatbuffers from 'flatbuffers'; -export declare class InnerStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): InnerStruct; - a(): number; - b(index: number): number | null; - c(): number; - dUnderscore(): bigint; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createInnerStruct( - builder: flatbuffers.Builder, - a: number, - b: number[] | null, - c: number, - d_underscore: bigint, - ): flatbuffers.Offset; - unpack(): InnerStructT; - unpackTo(_o: InnerStructT): void; +export declare class InnerStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): InnerStruct; + a(): number; + b(index: number): number | null; + c(): number; + dUnderscore(): bigint; + static getFullyQualifiedName(): "MyGame.Example.InnerStruct"; + static sizeOf(): number; + static createInnerStruct(builder: flatbuffers.Builder, a: number, b: number[], c: number, d_underscore: bigint): flatbuffers.Offset; + unpack(): InnerStructT; + unpackTo(_o: InnerStructT): void; } export declare class InnerStructT implements flatbuffers.IGeneratedObject { - a: number; - b: number[]; - c: number; - dUnderscore: bigint; - constructor(a?: number, b?: number[], c?: number, dUnderscore?: bigint); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: number; + b: (number)[]; + c: number; + dUnderscore: bigint; + constructor(a?: number, b?: (number)[], c?: number, dUnderscore?: bigint); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/arrays_test_complex/my-game/example/inner-struct.js b/tests/ts/arrays_test_complex/my-game/example/inner-struct.js index 4af8c1e16..e8ed97362 100644 --- a/tests/ts/arrays_test_complex/my-game/example/inner-struct.js +++ b/tests/ts/arrays_test_complex/my-game/example/inner-struct.js @@ -1,64 +1,61 @@ // automatically generated by the FlatBuffers compiler, do not modify export class InnerStruct { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - a() { - return this.bb.readFloat64(this.bb_pos); - } - b(index) { - return this.bb.readUint8(this.bb_pos + 8 + index); - } - c() { - return this.bb.readInt8(this.bb_pos + 21); - } - dUnderscore() { - return this.bb.readInt64(this.bb_pos + 24); - } - static getFullyQualifiedName() { - return 'MyGame.Example.InnerStruct'; - } - static sizeOf() { - return 32; - } - static createInnerStruct(builder, a, b, c, d_underscore) { - builder.prep(8, 32); - builder.writeInt64(BigInt(d_underscore ?? 0)); - builder.pad(2); - builder.writeInt8(c); - for (let i = 12; i >= 0; --i) { - builder.writeInt8((b?.[i] ?? 0)); + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + a() { + return this.bb.readFloat64(this.bb_pos); + } + b(index) { + return this.bb.readUint8(this.bb_pos + 8 + index); + } + c() { + return this.bb.readInt8(this.bb_pos + 21); + } + dUnderscore() { + return this.bb.readInt64(this.bb_pos + 24); + } + static getFullyQualifiedName() { + return 'MyGame.Example.InnerStruct'; + } + static sizeOf() { + return 32; + } + static createInnerStruct(builder, a, b, c, d_underscore) { + builder.prep(8, 32); + builder.writeInt64(BigInt(d_underscore ?? 0)); + builder.pad(2); + builder.writeInt8(c); + for (let i = 12; i >= 0; --i) { + builder.writeInt8((b?.[i] ?? 0)); + } + builder.writeFloat64(a); + return builder.offset(); + } + unpack() { + return new InnerStructT(this.a(), this.bb.createScalarList(this.b.bind(this), 13), this.c(), this.dUnderscore()); + } + unpackTo(_o) { + _o.a = this.a(); + _o.b = this.bb.createScalarList(this.b.bind(this), 13); + _o.c = this.c(); + _o.dUnderscore = this.dUnderscore(); } - builder.writeFloat64(a); - return builder.offset(); - } - unpack() { - return new InnerStructT( - this.a(), this.bb.createScalarList(this.b.bind(this), 13), this.c(), - this.dUnderscore()); - } - unpackTo(_o) { - _o.a = this.a(); - _o.b = this.bb.createScalarList(this.b.bind(this), 13); - _o.c = this.c(); - _o.dUnderscore = this.dUnderscore(); - } } export class InnerStructT { - constructor(a = 0.0, b = [], c = 0, dUnderscore = BigInt('0')) { - this.a = a; - this.b = b; - this.c = c; - this.dUnderscore = dUnderscore; - } - pack(builder) { - return InnerStruct.createInnerStruct( - builder, this.a, this.b, this.c, this.dUnderscore); - } + constructor(a = 0.0, b = [], c = 0, dUnderscore = BigInt('0')) { + this.a = a; + this.b = b; + this.c = c; + this.dUnderscore = dUnderscore; + } + pack(builder) { + return InnerStruct.createInnerStruct(builder, this.a, this.b, this.c, this.dUnderscore); + } } diff --git a/tests/ts/arrays_test_complex/my-game/example/inner-struct.ts b/tests/ts/arrays_test_complex/my-game/example/inner-struct.ts index dcc0e29ce..84271784a 100644 --- a/tests/ts/arrays_test_complex/my-game/example/inner-struct.ts +++ b/tests/ts/arrays_test_complex/my-game/example/inner-struct.ts @@ -4,93 +4,90 @@ import * as flatbuffers from 'flatbuffers'; -export class InnerStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): InnerStruct { - this.bb_pos = i; - this.bb = bb; - return this; - } - a(): number { - return this.bb!.readFloat64(this.bb_pos); - } - b(index: number): number | null { +export class InnerStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):InnerStruct { + this.bb_pos = i; + this.bb = bb; + return this; +} + +a():number { + return this.bb!.readFloat64(this.bb_pos); +} + +b(index: number):number|null { return this.bb!.readUint8(this.bb_pos + 8 + index); +} + +c():number { + return this.bb!.readInt8(this.bb_pos + 21); +} + +dUnderscore():bigint { + return this.bb!.readInt64(this.bb_pos + 24); +} + +static getFullyQualifiedName(): "MyGame.Example.InnerStruct" { + return 'MyGame.Example.InnerStruct'; +} + +static sizeOf():number { + return 32; +} + +static createInnerStruct(builder:flatbuffers.Builder, a: number, b: number[], c: number, d_underscore: bigint):flatbuffers.Offset { + builder.prep(8, 32); + builder.writeInt64(BigInt(d_underscore ?? 0)); + builder.pad(2); + builder.writeInt8(c); + + for (let i = 12; i >= 0; --i) { + builder.writeInt8((b?.[i] ?? 0)); + } - c(): number { - return this.bb!.readInt8(this.bb_pos + 21); - } + builder.writeFloat64(a); + return builder.offset(); +} - dUnderscore(): bigint { - return this.bb!.readInt64(this.bb_pos + 24); - } - static getFullyQualifiedName(): string { - return 'MyGame.Example.InnerStruct'; - } +unpack(): InnerStructT { + return new InnerStructT( + this.a(), + this.bb!.createScalarList(this.b.bind(this), 13), + this.c(), + this.dUnderscore() + ); +} - static sizeOf(): number { - return 32; - } - static createInnerStruct( - builder: flatbuffers.Builder, - a: number, - b: number[] | null, - c: number, - d_underscore: bigint, - ): flatbuffers.Offset { - builder.prep(8, 32); - builder.writeInt64(BigInt(d_underscore ?? 0)); - builder.pad(2); - builder.writeInt8(c); - - for (let i = 12; i >= 0; --i) { - builder.writeInt8(b?.[i] ?? 0); - } - - builder.writeFloat64(a); - return builder.offset(); - } - - unpack(): InnerStructT { - return new InnerStructT( - this.a(), - this.bb!.createScalarList(this.b.bind(this), 13), - this.c(), - this.dUnderscore(), - ); - } - - unpackTo(_o: InnerStructT): void { - _o.a = this.a(); - _o.b = this.bb!.createScalarList(this.b.bind(this), 13); - _o.c = this.c(); - _o.dUnderscore = this.dUnderscore(); - } +unpackTo(_o: InnerStructT): void { + _o.a = this.a(); + _o.b = this.bb!.createScalarList(this.b.bind(this), 13); + _o.c = this.c(); + _o.dUnderscore = this.dUnderscore(); +} } export class InnerStructT implements flatbuffers.IGeneratedObject { - constructor( - public a: number = 0.0, - public b: number[] = [], - public c: number = 0, - public dUnderscore: bigint = BigInt('0'), - ) {} +constructor( + public a: number = 0.0, + public b: (number)[] = [], + public c: number = 0, + public dUnderscore: bigint = BigInt('0') +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return InnerStruct.createInnerStruct( - builder, - this.a, - this.b, - this.c, - this.dUnderscore, - ); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return InnerStruct.createInnerStruct(builder, + this.a, + this.b, + this.c, + this.dUnderscore + ); +} } diff --git a/tests/ts/arrays_test_complex/my-game/example/nested-struct.d.ts b/tests/ts/arrays_test_complex/my-game/example/nested-struct.d.ts index 8e3facad9..6c8fd00a2 100644 --- a/tests/ts/arrays_test_complex/my-game/example/nested-struct.d.ts +++ b/tests/ts/arrays_test_complex/my-game/example/nested-struct.d.ts @@ -1,42 +1,27 @@ import * as flatbuffers from 'flatbuffers'; -import {OuterStruct, OuterStructT} from '../../my-game/example/outer-struct.js'; -import {TestEnum} from '../../my-game/example/test-enum.js'; -export declare class NestedStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): NestedStruct; - a(index: number): number | null; - b(): TestEnum; - cUnderscore(index: number): TestEnum | null; - dOuter(index: number, obj?: OuterStruct): OuterStruct | null; - e(index: number): bigint | null; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createNestedStruct( - builder: flatbuffers.Builder, - a: number[] | null, - b: TestEnum, - c_underscore: number[] | null, - d_outer: (any | OuterStructT)[] | null, - e: bigint[] | null, - ): flatbuffers.Offset; - unpack(): NestedStructT; - unpackTo(_o: NestedStructT): void; +import { OuterStruct, OuterStructT } from './outer-struct.js'; +import { TestEnum } from './test-enum.js'; +export declare class NestedStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): NestedStruct; + a(index: number): number | null; + b(): TestEnum; + cUnderscore(index: number): TestEnum | null; + dOuter(index: number, obj?: OuterStruct): OuterStruct | null; + e(index: number): bigint | null; + static getFullyQualifiedName(): "MyGame.Example.NestedStruct"; + static sizeOf(): number; + static createNestedStruct(builder: flatbuffers.Builder, a: number[], b: TestEnum, c_underscore: number[], d_outer: (any | OuterStructT)[], e: bigint[]): flatbuffers.Offset; + unpack(): NestedStructT; + unpackTo(_o: NestedStructT): void; } export declare class NestedStructT implements flatbuffers.IGeneratedObject { - a: number[]; - b: TestEnum; - cUnderscore: TestEnum[]; - dOuter: OuterStructT[]; - e: bigint[]; - constructor( - a?: number[], - b?: TestEnum, - cUnderscore?: TestEnum[], - dOuter?: OuterStructT[], - e?: bigint[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: (number)[]; + b: TestEnum; + cUnderscore: (TestEnum)[]; + dOuter: (OuterStructT)[]; + e: (bigint)[]; + constructor(a?: (number)[], b?: TestEnum, cUnderscore?: (TestEnum)[], dOuter?: (OuterStructT)[], e?: (bigint)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/arrays_test_complex/my-game/example/nested-struct.js b/tests/ts/arrays_test_complex/my-game/example/nested-struct.js index 4c57081e4..44faa6918 100644 --- a/tests/ts/arrays_test_complex/my-game/example/nested-struct.js +++ b/tests/ts/arrays_test_complex/my-game/example/nested-struct.js @@ -1,93 +1,80 @@ // automatically generated by the FlatBuffers compiler, do not modify -import {OuterStruct, OuterStructT} from '../../my-game/example/outer-struct.js'; -import {TestEnum} from '../../my-game/example/test-enum.js'; +import { OuterStruct, OuterStructT } from './outer-struct.js'; +import { TestEnum } from './test-enum.js'; export class NestedStruct { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - a(index) { - return this.bb.readInt32(this.bb_pos + 0 + index * 4); - } - b() { - return this.bb.readInt8(this.bb_pos + 8); - } - cUnderscore(index) { - return this.bb.readInt8(this.bb_pos + 9 + index); - } - dOuter(index, obj) { - return (obj || new OuterStruct()) - .__init(this.bb_pos + 16 + index * 208, this.bb); - } - e(index) { - return this.bb.readInt64(this.bb_pos + 1056 + index * 8); - } - static getFullyQualifiedName() { - return 'MyGame.Example.NestedStruct'; - } - static sizeOf() { - return 1072; - } - static createNestedStruct(builder, a, b, c_underscore, d_outer, e) { - builder.prep(8, 1072); - for (let i = 1; i >= 0; --i) { - builder.writeInt64(BigInt(e?.[i] ?? 0)); + constructor() { + this.bb = null; + this.bb_pos = 0; } - for (let i = 4; i >= 0; --i) { - const item = d_outer?.[i]; - if (item instanceof OuterStructT) { - item.pack(builder); - continue; - } - OuterStruct.createOuterStruct( - builder, item?.a, item?.b, (item?.cUnderscore?.a ?? 0), - (item?.cUnderscore?.b ?? []), (item?.cUnderscore?.c ?? 0), - (item?.cUnderscore?.dUnderscore ?? BigInt(0)), item?.d, - (item?.e?.a ?? 0), (item?.e?.b ?? []), (item?.e?.c ?? 0), - (item?.e?.dUnderscore ?? BigInt(0)), item?.f); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - builder.pad(5); - for (let i = 1; i >= 0; --i) { - builder.writeInt8((c_underscore?.[i] ?? 0)); + a(index) { + return this.bb.readInt32(this.bb_pos + 0 + index * 4); } - builder.writeInt8(b); - for (let i = 1; i >= 0; --i) { - builder.writeInt32((a?.[i] ?? 0)); + b() { + return this.bb.readInt8(this.bb_pos + 8); + } + cUnderscore(index) { + return this.bb.readInt8(this.bb_pos + 9 + index); + } + dOuter(index, obj) { + return (obj || new OuterStruct()).__init(this.bb_pos + 16 + index * 208, this.bb); + } + e(index) { + return this.bb.readInt64(this.bb_pos + 1056 + index * 8); + } + static getFullyQualifiedName() { + return 'MyGame.Example.NestedStruct'; + } + static sizeOf() { + return 1072; + } + static createNestedStruct(builder, a, b, c_underscore, d_outer, e) { + builder.prep(8, 1072); + for (let i = 1; i >= 0; --i) { + builder.writeInt64(BigInt(e?.[i] ?? 0)); + } + for (let i = 4; i >= 0; --i) { + const item = d_outer?.[i]; + if (item instanceof OuterStructT) { + item.pack(builder); + continue; + } + OuterStruct.createOuterStruct(builder, item?.a, item?.b, (item?.cUnderscore?.a ?? 0), (item?.cUnderscore?.b ?? []), (item?.cUnderscore?.c ?? 0), (item?.cUnderscore?.dUnderscore ?? BigInt(0)), item?.d, (item?.e?.a ?? 0), (item?.e?.b ?? []), (item?.e?.c ?? 0), (item?.e?.dUnderscore ?? BigInt(0)), item?.f); + } + builder.pad(5); + for (let i = 1; i >= 0; --i) { + builder.writeInt8((c_underscore?.[i] ?? 0)); + } + builder.writeInt8(b); + for (let i = 1; i >= 0; --i) { + builder.writeInt32((a?.[i] ?? 0)); + } + return builder.offset(); + } + unpack() { + return new NestedStructT(this.bb.createScalarList(this.a.bind(this), 2), this.b(), this.bb.createScalarList(this.cUnderscore.bind(this), 2), this.bb.createObjList(this.dOuter.bind(this), 5), this.bb.createScalarList(this.e.bind(this), 2)); + } + unpackTo(_o) { + _o.a = this.bb.createScalarList(this.a.bind(this), 2); + _o.b = this.b(); + _o.cUnderscore = this.bb.createScalarList(this.cUnderscore.bind(this), 2); + _o.dOuter = this.bb.createObjList(this.dOuter.bind(this), 5); + _o.e = this.bb.createScalarList(this.e.bind(this), 2); } - return builder.offset(); - } - unpack() { - return new NestedStructT( - this.bb.createScalarList(this.a.bind(this), 2), this.b(), - this.bb.createScalarList(this.cUnderscore.bind(this), 2), - this.bb.createObjList(this.dOuter.bind(this), 5), - this.bb.createScalarList(this.e.bind(this), 2)); - } - unpackTo(_o) { - _o.a = this.bb.createScalarList(this.a.bind(this), 2); - _o.b = this.b(); - _o.cUnderscore = this.bb.createScalarList(this.cUnderscore.bind(this), 2); - _o.dOuter = this.bb.createObjList(this.dOuter.bind(this), 5); - _o.e = this.bb.createScalarList(this.e.bind(this), 2); - } } export class NestedStructT { - constructor( - a = [], b = TestEnum.A, cUnderscore = [TestEnum.A, TestEnum.A], - dOuter = [], e = []) { - this.a = a; - this.b = b; - this.cUnderscore = cUnderscore; - this.dOuter = dOuter; - this.e = e; - } - pack(builder) { - return NestedStruct.createNestedStruct( - builder, this.a, this.b, this.cUnderscore, this.dOuter, this.e); - } + constructor(a = [], b = TestEnum.A, cUnderscore = [TestEnum.A, TestEnum.A], dOuter = [], e = []) { + this.a = a; + this.b = b; + this.cUnderscore = cUnderscore; + this.dOuter = dOuter; + this.e = e; + } + pack(builder) { + return NestedStruct.createNestedStruct(builder, this.a, this.b, this.cUnderscore, this.dOuter, this.e); + } } diff --git a/tests/ts/arrays_test_complex/my-game/example/nested-struct.ts b/tests/ts/arrays_test_complex/my-game/example/nested-struct.ts index 711eaa7fd..c707f9228 100644 --- a/tests/ts/arrays_test_complex/my-game/example/nested-struct.ts +++ b/tests/ts/arrays_test_complex/my-game/example/nested-struct.ts @@ -4,150 +4,134 @@ import * as flatbuffers from 'flatbuffers'; -import {OuterStruct, OuterStructT} from '../../my-game/example/outer-struct.js'; -import {TestEnum} from '../../my-game/example/test-enum.js'; +import { OuterStruct, OuterStructT } from './outer-struct.js'; +import { TestEnum } from './test-enum.js'; -export class NestedStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): NestedStruct { - this.bb_pos = i; - this.bb = bb; - return this; - } - a(index: number): number | null { +export class NestedStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):NestedStruct { + this.bb_pos = i; + this.bb = bb; + return this; +} + +a(index: number):number|null { return this.bb!.readInt32(this.bb_pos + 0 + index * 4); - } +} - b(): TestEnum { - return this.bb!.readInt8(this.bb_pos + 8); - } +b():TestEnum { + return this.bb!.readInt8(this.bb_pos + 8); +} - cUnderscore(index: number): TestEnum | null { +cUnderscore(index: number):TestEnum|null { return this.bb!.readInt8(this.bb_pos + 9 + index); - } +} - dOuter(index: number, obj?: OuterStruct): OuterStruct | null { - return (obj || new OuterStruct()).__init( - this.bb_pos + 16 + index * 208, - this.bb!, - ); - } +dOuter(index: number, obj?:OuterStruct):OuterStruct|null { + return (obj || new OuterStruct()).__init(this.bb_pos + 16 + index * 208, this.bb!); +} - e(index: number): bigint | null { +e(index: number):bigint|null { return this.bb!.readInt64(this.bb_pos + 1056 + index * 8); +} + +static getFullyQualifiedName(): "MyGame.Example.NestedStruct" { + return 'MyGame.Example.NestedStruct'; +} + +static sizeOf():number { + return 1072; +} + +static createNestedStruct(builder:flatbuffers.Builder, a: number[], b: TestEnum, c_underscore: number[], d_outer: (any|OuterStructT)[], e: bigint[]):flatbuffers.Offset { + builder.prep(8, 1072); + + for (let i = 1; i >= 0; --i) { + builder.writeInt64(BigInt(e?.[i] ?? 0)); } - static getFullyQualifiedName(): string { - return 'MyGame.Example.NestedStruct'; - } - static sizeOf(): number { - return 1072; - } + for (let i = 4; i >= 0; --i) { + const item = d_outer?.[i]; - static createNestedStruct( - builder: flatbuffers.Builder, - a: number[] | null, - b: TestEnum, - c_underscore: number[] | null, - d_outer: (any | OuterStructT)[] | null, - e: bigint[] | null, - ): flatbuffers.Offset { - builder.prep(8, 1072); - - for (let i = 1; i >= 0; --i) { - builder.writeInt64(BigInt(e?.[i] ?? 0)); + if (item instanceof OuterStructT) { + item.pack(builder); + continue; } - for (let i = 4; i >= 0; --i) { - const item = d_outer?.[i]; - - if (item instanceof OuterStructT) { - item.pack(builder); - continue; - } - - OuterStruct.createOuterStruct( - builder, - item?.a, - item?.b, - item?.cUnderscore?.a ?? 0, - item?.cUnderscore?.b ?? [], - item?.cUnderscore?.c ?? 0, - item?.cUnderscore?.dUnderscore ?? BigInt(0), - item?.d, - item?.e?.a ?? 0, - item?.e?.b ?? [], - item?.e?.c ?? 0, - item?.e?.dUnderscore ?? BigInt(0), - item?.f, - ); - } - - builder.pad(5); - - for (let i = 1; i >= 0; --i) { - builder.writeInt8(c_underscore?.[i] ?? 0); - } - - builder.writeInt8(b); - - for (let i = 1; i >= 0; --i) { - builder.writeInt32(a?.[i] ?? 0); - } - - return builder.offset(); - } - - unpack(): NestedStructT { - return new NestedStructT( - this.bb!.createScalarList(this.a.bind(this), 2), - this.b(), - this.bb!.createScalarList(this.cUnderscore.bind(this), 2), - this.bb!.createObjList( - this.dOuter.bind(this), - 5, - ), - this.bb!.createScalarList(this.e.bind(this), 2), + OuterStruct.createOuterStruct(builder, + item?.a, + item?.b, + (item?.cUnderscore?.a ?? 0), + (item?.cUnderscore?.b ?? []), + (item?.cUnderscore?.c ?? 0), + (item?.cUnderscore?.dUnderscore ?? BigInt(0)), + item?.d, + (item?.e?.a ?? 0), + (item?.e?.b ?? []), + (item?.e?.c ?? 0), + (item?.e?.dUnderscore ?? BigInt(0)), + item?.f ); } - unpackTo(_o: NestedStructT): void { - _o.a = this.bb!.createScalarList(this.a.bind(this), 2); - _o.b = this.b(); - _o.cUnderscore = this.bb!.createScalarList( - this.cUnderscore.bind(this), - 2, - ); - _o.dOuter = this.bb!.createObjList( - this.dOuter.bind(this), - 5, - ); - _o.e = this.bb!.createScalarList(this.e.bind(this), 2); + builder.pad(5); + + for (let i = 1; i >= 0; --i) { + builder.writeInt8((c_underscore?.[i] ?? 0)); + } + + builder.writeInt8(b); + + for (let i = 1; i >= 0; --i) { + builder.writeInt32((a?.[i] ?? 0)); + + } + + return builder.offset(); +} + + +unpack(): NestedStructT { + return new NestedStructT( + this.bb!.createScalarList(this.a.bind(this), 2), + this.b(), + this.bb!.createScalarList(this.cUnderscore.bind(this), 2), + this.bb!.createObjList(this.dOuter.bind(this), 5), + this.bb!.createScalarList(this.e.bind(this), 2) + ); +} + + +unpackTo(_o: NestedStructT): void { + _o.a = this.bb!.createScalarList(this.a.bind(this), 2); + _o.b = this.b(); + _o.cUnderscore = this.bb!.createScalarList(this.cUnderscore.bind(this), 2); + _o.dOuter = this.bb!.createObjList(this.dOuter.bind(this), 5); + _o.e = this.bb!.createScalarList(this.e.bind(this), 2); +} } export class NestedStructT implements flatbuffers.IGeneratedObject { - constructor( - public a: number[] = [], - public b: TestEnum = TestEnum.A, - public cUnderscore: TestEnum[] = [TestEnum.A, TestEnum.A], - public dOuter: OuterStructT[] = [], - public e: bigint[] = [], - ) {} +constructor( + public a: (number)[] = [], + public b: TestEnum = TestEnum.A, + public cUnderscore: (TestEnum)[] = [TestEnum.A, TestEnum.A], + public dOuter: (OuterStructT)[] = [], + public e: (bigint)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return NestedStruct.createNestedStruct( - builder, - this.a, - this.b, - this.cUnderscore, - this.dOuter, - this.e, - ); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return NestedStruct.createNestedStruct(builder, + this.a, + this.b, + this.cUnderscore, + this.dOuter, + this.e + ); +} } diff --git a/tests/ts/arrays_test_complex/my-game/example/outer-struct.d.ts b/tests/ts/arrays_test_complex/my-game/example/outer-struct.d.ts index e02653a3a..3ea7db59f 100644 --- a/tests/ts/arrays_test_complex/my-game/example/outer-struct.d.ts +++ b/tests/ts/arrays_test_complex/my-game/example/outer-struct.d.ts @@ -1,51 +1,28 @@ import * as flatbuffers from 'flatbuffers'; -import {InnerStruct, InnerStructT} from '../../my-game/example/inner-struct.js'; -export declare class OuterStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): OuterStruct; - a(): boolean; - b(): number; - cUnderscore(obj?: InnerStruct): InnerStruct | null; - d(index: number, obj?: InnerStruct): InnerStruct | null; - e(obj?: InnerStruct): InnerStruct | null; - f(index: number): number | null; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createOuterStruct( - builder: flatbuffers.Builder, - a: boolean, - b: number, - c_underscore_a: number, - c_underscore_b: number[] | null, - c_underscore_c: number, - c_underscore_d_underscore: bigint, - d: (any | InnerStructT)[] | null, - e_a: number, - e_b: number[] | null, - e_c: number, - e_d_underscore: bigint, - f: number[] | null, - ): flatbuffers.Offset; - unpack(): OuterStructT; - unpackTo(_o: OuterStructT): void; +import { InnerStruct, InnerStructT } from './inner-struct.js'; +export declare class OuterStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): OuterStruct; + a(): boolean; + b(): number; + cUnderscore(obj?: InnerStruct): InnerStruct | null; + d(index: number, obj?: InnerStruct): InnerStruct | null; + e(obj?: InnerStruct): InnerStruct | null; + f(index: number): number | null; + static getFullyQualifiedName(): "MyGame.Example.OuterStruct"; + static sizeOf(): number; + static createOuterStruct(builder: flatbuffers.Builder, a: boolean, b: number, c_underscore_a: number, c_underscore_b: number[], c_underscore_c: number, c_underscore_d_underscore: bigint, d: (any | InnerStructT)[], e_a: number, e_b: number[], e_c: number, e_d_underscore: bigint, f: number[]): flatbuffers.Offset; + unpack(): OuterStructT; + unpackTo(_o: OuterStructT): void; } export declare class OuterStructT implements flatbuffers.IGeneratedObject { - a: boolean; - b: number; - cUnderscore: InnerStructT | null; - d: InnerStructT[]; - e: InnerStructT | null; - f: number[]; - constructor( - a?: boolean, - b?: number, - cUnderscore?: InnerStructT | null, - d?: InnerStructT[], - e?: InnerStructT | null, - f?: number[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: boolean; + b: number; + cUnderscore: InnerStructT | null; + d: (InnerStructT)[]; + e: InnerStructT | null; + f: (number)[]; + constructor(a?: boolean, b?: number, cUnderscore?: InnerStructT | null, d?: (InnerStructT)[], e?: InnerStructT | null, f?: (number)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/arrays_test_complex/my-game/example/outer-struct.js b/tests/ts/arrays_test_complex/my-game/example/outer-struct.js index 9a93faad4..50c384bf2 100644 --- a/tests/ts/arrays_test_complex/my-game/example/outer-struct.js +++ b/tests/ts/arrays_test_complex/my-game/example/outer-struct.js @@ -1,111 +1,95 @@ // automatically generated by the FlatBuffers compiler, do not modify -import {InnerStruct, InnerStructT} from '../../my-game/example/inner-struct.js'; +import { InnerStruct, InnerStructT } from './inner-struct.js'; export class OuterStruct { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - a() { - return !!this.bb.readInt8(this.bb_pos); - } - b() { - return this.bb.readFloat64(this.bb_pos + 8); - } - cUnderscore(obj) { - return (obj || new InnerStruct()).__init(this.bb_pos + 16, this.bb); - } - d(index, obj) { - return (obj || new InnerStruct()) - .__init(this.bb_pos + 48 + index * 32, this.bb); - } - e(obj) { - return (obj || new InnerStruct()).__init(this.bb_pos + 144, this.bb); - } - f(index) { - return this.bb.readFloat64(this.bb_pos + 176 + index * 8); - } - static getFullyQualifiedName() { - return 'MyGame.Example.OuterStruct'; - } - static sizeOf() { - return 208; - } - static createOuterStruct( - builder, a, b, c_underscore_a, c_underscore_b, c_underscore_c, - c_underscore_d_underscore, d, e_a, e_b, e_c, e_d_underscore, f) { - builder.prep(8, 208); - for (let i = 3; i >= 0; --i) { - builder.writeFloat64((f?.[i] ?? 0)); + constructor() { + this.bb = null; + this.bb_pos = 0; } - builder.prep(8, 32); - builder.writeInt64(BigInt(e_d_underscore ?? 0)); - builder.pad(2); - builder.writeInt8(e_c); - for (let i = 12; i >= 0; --i) { - builder.writeInt8((e_b?.[i] ?? 0)); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - builder.writeFloat64(e_a); - for (let i = 2; i >= 0; --i) { - const item = d?.[i]; - if (item instanceof InnerStructT) { - item.pack(builder); - continue; - } - InnerStruct.createInnerStruct( - builder, item?.a, item?.b, item?.c, item?.dUnderscore); + a() { + return !!this.bb.readInt8(this.bb_pos); } - builder.prep(8, 32); - builder.writeInt64(BigInt(c_underscore_d_underscore ?? 0)); - builder.pad(2); - builder.writeInt8(c_underscore_c); - for (let i = 12; i >= 0; --i) { - builder.writeInt8((c_underscore_b?.[i] ?? 0)); + b() { + return this.bb.readFloat64(this.bb_pos + 8); + } + cUnderscore(obj) { + return (obj || new InnerStruct()).__init(this.bb_pos + 16, this.bb); + } + d(index, obj) { + return (obj || new InnerStruct()).__init(this.bb_pos + 48 + index * 32, this.bb); + } + e(obj) { + return (obj || new InnerStruct()).__init(this.bb_pos + 144, this.bb); + } + f(index) { + return this.bb.readFloat64(this.bb_pos + 176 + index * 8); + } + static getFullyQualifiedName() { + return 'MyGame.Example.OuterStruct'; + } + static sizeOf() { + return 208; + } + static createOuterStruct(builder, a, b, c_underscore_a, c_underscore_b, c_underscore_c, c_underscore_d_underscore, d, e_a, e_b, e_c, e_d_underscore, f) { + builder.prep(8, 208); + for (let i = 3; i >= 0; --i) { + builder.writeFloat64((f?.[i] ?? 0)); + } + builder.prep(8, 32); + builder.writeInt64(BigInt(e_d_underscore ?? 0)); + builder.pad(2); + builder.writeInt8(e_c); + for (let i = 12; i >= 0; --i) { + builder.writeInt8((e_b?.[i] ?? 0)); + } + builder.writeFloat64(e_a); + for (let i = 2; i >= 0; --i) { + const item = d?.[i]; + if (item instanceof InnerStructT) { + item.pack(builder); + continue; + } + InnerStruct.createInnerStruct(builder, item?.a, item?.b, item?.c, item?.dUnderscore); + } + builder.prep(8, 32); + builder.writeInt64(BigInt(c_underscore_d_underscore ?? 0)); + builder.pad(2); + builder.writeInt8(c_underscore_c); + for (let i = 12; i >= 0; --i) { + builder.writeInt8((c_underscore_b?.[i] ?? 0)); + } + builder.writeFloat64(c_underscore_a); + builder.writeFloat64(b); + builder.pad(7); + builder.writeInt8(Number(Boolean(a))); + return builder.offset(); + } + unpack() { + return new OuterStructT(this.a(), this.b(), (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null), this.bb.createObjList(this.d.bind(this), 3), (this.e() !== null ? this.e().unpack() : null), this.bb.createScalarList(this.f.bind(this), 4)); + } + unpackTo(_o) { + _o.a = this.a(); + _o.b = this.b(); + _o.cUnderscore = (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null); + _o.d = this.bb.createObjList(this.d.bind(this), 3); + _o.e = (this.e() !== null ? this.e().unpack() : null); + _o.f = this.bb.createScalarList(this.f.bind(this), 4); } - builder.writeFloat64(c_underscore_a); - builder.writeFloat64(b); - builder.pad(7); - builder.writeInt8(Number(Boolean(a))); - return builder.offset(); - } - unpack() { - return new OuterStructT( - this.a(), this.b(), - (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null), - this.bb.createObjList(this.d.bind(this), 3), - (this.e() !== null ? this.e().unpack() : null), - this.bb.createScalarList(this.f.bind(this), 4)); - } - unpackTo(_o) { - _o.a = this.a(); - _o.b = this.b(); - _o.cUnderscore = - (this.cUnderscore() !== null ? this.cUnderscore().unpack() : null); - _o.d = this.bb.createObjList(this.d.bind(this), 3); - _o.e = (this.e() !== null ? this.e().unpack() : null); - _o.f = this.bb.createScalarList(this.f.bind(this), 4); - } } export class OuterStructT { - constructor( - a = false, b = 0.0, cUnderscore = null, d = [], e = null, f = []) { - this.a = a; - this.b = b; - this.cUnderscore = cUnderscore; - this.d = d; - this.e = e; - this.f = f; - } - pack(builder) { - return OuterStruct.createOuterStruct( - builder, this.a, this.b, (this.cUnderscore?.a ?? 0), - (this.cUnderscore?.b ?? []), (this.cUnderscore?.c ?? 0), - (this.cUnderscore?.dUnderscore ?? BigInt(0)), this.d, (this.e?.a ?? 0), - (this.e?.b ?? []), (this.e?.c ?? 0), (this.e?.dUnderscore ?? BigInt(0)), - this.f); - } + constructor(a = false, b = 0.0, cUnderscore = null, d = [], e = null, f = []) { + this.a = a; + this.b = b; + this.cUnderscore = cUnderscore; + this.d = d; + this.e = e; + this.f = f; + } + pack(builder) { + return OuterStruct.createOuterStruct(builder, this.a, this.b, (this.cUnderscore?.a ?? 0), (this.cUnderscore?.b ?? []), (this.cUnderscore?.c ?? 0), (this.cUnderscore?.dUnderscore ?? BigInt(0)), this.d, (this.e?.a ?? 0), (this.e?.b ?? []), (this.e?.c ?? 0), (this.e?.dUnderscore ?? BigInt(0)), this.f); + } } diff --git a/tests/ts/arrays_test_complex/my-game/example/outer-struct.ts b/tests/ts/arrays_test_complex/my-game/example/outer-struct.ts index baad94b25..bba38aefa 100644 --- a/tests/ts/arrays_test_complex/my-game/example/outer-struct.ts +++ b/tests/ts/arrays_test_complex/my-game/example/outer-struct.ts @@ -4,169 +4,151 @@ import * as flatbuffers from 'flatbuffers'; -import {InnerStruct, InnerStructT} from '../../my-game/example/inner-struct.js'; +import { InnerStruct, InnerStructT } from './inner-struct.js'; -export class OuterStruct - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): OuterStruct { - this.bb_pos = i; - this.bb = bb; - return this; - } - a(): boolean { - return !!this.bb!.readInt8(this.bb_pos); - } +export class OuterStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):OuterStruct { + this.bb_pos = i; + this.bb = bb; + return this; +} - b(): number { - return this.bb!.readFloat64(this.bb_pos + 8); - } +a():boolean { + return !!this.bb!.readInt8(this.bb_pos); +} - cUnderscore(obj?: InnerStruct): InnerStruct | null { - return (obj || new InnerStruct()).__init(this.bb_pos + 16, this.bb!); - } +b():number { + return this.bb!.readFloat64(this.bb_pos + 8); +} - d(index: number, obj?: InnerStruct): InnerStruct | null { - return (obj || new InnerStruct()).__init( - this.bb_pos + 48 + index * 32, - this.bb!, - ); - } +cUnderscore(obj?:InnerStruct):InnerStruct|null { + return (obj || new InnerStruct()).__init(this.bb_pos + 16, this.bb!); +} - e(obj?: InnerStruct): InnerStruct | null { - return (obj || new InnerStruct()).__init(this.bb_pos + 144, this.bb!); - } +d(index: number, obj?:InnerStruct):InnerStruct|null { + return (obj || new InnerStruct()).__init(this.bb_pos + 48 + index * 32, this.bb!); +} - f(index: number): number | null { +e(obj?:InnerStruct):InnerStruct|null { + return (obj || new InnerStruct()).__init(this.bb_pos + 144, this.bb!); +} + +f(index: number):number|null { return this.bb!.readFloat64(this.bb_pos + 176 + index * 8); +} + +static getFullyQualifiedName(): "MyGame.Example.OuterStruct" { + return 'MyGame.Example.OuterStruct'; +} + +static sizeOf():number { + return 208; +} + +static createOuterStruct(builder:flatbuffers.Builder, a: boolean, b: number, c_underscore_a: number, c_underscore_b: number[], c_underscore_c: number, c_underscore_d_underscore: bigint, d: (any|InnerStructT)[], e_a: number, e_b: number[], e_c: number, e_d_underscore: bigint, f: number[]):flatbuffers.Offset { + builder.prep(8, 208); + + for (let i = 3; i >= 0; --i) { + builder.writeFloat64((f?.[i] ?? 0)); + } - static getFullyQualifiedName(): string { - return 'MyGame.Example.OuterStruct'; + builder.prep(8, 32); + builder.writeInt64(BigInt(e_d_underscore ?? 0)); + builder.pad(2); + builder.writeInt8(e_c); + + for (let i = 12; i >= 0; --i) { + builder.writeInt8((e_b?.[i] ?? 0)); + } - static sizeOf(): number { - return 208; - } + builder.writeFloat64(e_a); - static createOuterStruct( - builder: flatbuffers.Builder, - a: boolean, - b: number, - c_underscore_a: number, - c_underscore_b: number[] | null, - c_underscore_c: number, - c_underscore_d_underscore: bigint, - d: (any | InnerStructT)[] | null, - e_a: number, - e_b: number[] | null, - e_c: number, - e_d_underscore: bigint, - f: number[] | null, - ): flatbuffers.Offset { - builder.prep(8, 208); + for (let i = 2; i >= 0; --i) { + const item = d?.[i]; - for (let i = 3; i >= 0; --i) { - builder.writeFloat64(f?.[i] ?? 0); + if (item instanceof InnerStructT) { + item.pack(builder); + continue; } - builder.prep(8, 32); - builder.writeInt64(BigInt(e_d_underscore ?? 0)); - builder.pad(2); - builder.writeInt8(e_c); - - for (let i = 12; i >= 0; --i) { - builder.writeInt8(e_b?.[i] ?? 0); - } - - builder.writeFloat64(e_a); - - for (let i = 2; i >= 0; --i) { - const item = d?.[i]; - - if (item instanceof InnerStructT) { - item.pack(builder); - continue; - } - - InnerStruct.createInnerStruct( - builder, - item?.a, - item?.b, - item?.c, - item?.dUnderscore, - ); - } - - builder.prep(8, 32); - builder.writeInt64(BigInt(c_underscore_d_underscore ?? 0)); - builder.pad(2); - builder.writeInt8(c_underscore_c); - - for (let i = 12; i >= 0; --i) { - builder.writeInt8(c_underscore_b?.[i] ?? 0); - } - - builder.writeFloat64(c_underscore_a); - builder.writeFloat64(b); - builder.pad(7); - builder.writeInt8(Number(Boolean(a))); - return builder.offset(); - } - - unpack(): OuterStructT { - return new OuterStructT( - this.a(), - this.b(), - this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null, - this.bb!.createObjList(this.d.bind(this), 3), - this.e() !== null ? this.e()!.unpack() : null, - this.bb!.createScalarList(this.f.bind(this), 4), + InnerStruct.createInnerStruct(builder, + item?.a, + item?.b, + item?.c, + item?.dUnderscore ); } - unpackTo(_o: OuterStructT): void { - _o.a = this.a(); - _o.b = this.b(); - _o.cUnderscore = - this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null; - _o.d = this.bb!.createObjList( - this.d.bind(this), - 3, - ); - _o.e = this.e() !== null ? this.e()!.unpack() : null; - _o.f = this.bb!.createScalarList(this.f.bind(this), 4); + builder.prep(8, 32); + builder.writeInt64(BigInt(c_underscore_d_underscore ?? 0)); + builder.pad(2); + builder.writeInt8(c_underscore_c); + + for (let i = 12; i >= 0; --i) { + builder.writeInt8((c_underscore_b?.[i] ?? 0)); + } + + builder.writeFloat64(c_underscore_a); + builder.writeFloat64(b); + builder.pad(7); + builder.writeInt8(Number(Boolean(a))); + return builder.offset(); +} + + +unpack(): OuterStructT { + return new OuterStructT( + this.a(), + this.b(), + (this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null), + this.bb!.createObjList(this.d.bind(this), 3), + (this.e() !== null ? this.e()!.unpack() : null), + this.bb!.createScalarList(this.f.bind(this), 4) + ); +} + + +unpackTo(_o: OuterStructT): void { + _o.a = this.a(); + _o.b = this.b(); + _o.cUnderscore = (this.cUnderscore() !== null ? this.cUnderscore()!.unpack() : null); + _o.d = this.bb!.createObjList(this.d.bind(this), 3); + _o.e = (this.e() !== null ? this.e()!.unpack() : null); + _o.f = this.bb!.createScalarList(this.f.bind(this), 4); +} } export class OuterStructT implements flatbuffers.IGeneratedObject { - constructor( - public a: boolean = false, - public b: number = 0.0, - public cUnderscore: InnerStructT | null = null, - public d: InnerStructT[] = [], - public e: InnerStructT | null = null, - public f: number[] = [], - ) {} +constructor( + public a: boolean = false, + public b: number = 0.0, + public cUnderscore: InnerStructT|null = null, + public d: (InnerStructT)[] = [], + public e: InnerStructT|null = null, + public f: (number)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return OuterStruct.createOuterStruct( - builder, - this.a, - this.b, - this.cUnderscore?.a ?? 0, - this.cUnderscore?.b ?? [], - this.cUnderscore?.c ?? 0, - this.cUnderscore?.dUnderscore ?? BigInt(0), - this.d, - this.e?.a ?? 0, - this.e?.b ?? [], - this.e?.c ?? 0, - this.e?.dUnderscore ?? BigInt(0), - this.f, - ); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return OuterStruct.createOuterStruct(builder, + this.a, + this.b, + (this.cUnderscore?.a ?? 0), + (this.cUnderscore?.b ?? []), + (this.cUnderscore?.c ?? 0), + (this.cUnderscore?.dUnderscore ?? BigInt(0)), + this.d, + (this.e?.a ?? 0), + (this.e?.b ?? []), + (this.e?.c ?? 0), + (this.e?.dUnderscore ?? BigInt(0)), + this.f + ); +} } diff --git a/tests/ts/arrays_test_complex/my-game/example/test-enum.d.ts b/tests/ts/arrays_test_complex/my-game/example/test-enum.d.ts index 6422dd2c3..291e04971 100644 --- a/tests/ts/arrays_test_complex/my-game/example/test-enum.d.ts +++ b/tests/ts/arrays_test_complex/my-game/example/test-enum.d.ts @@ -1,5 +1,5 @@ export declare enum TestEnum { - A = 0, - B = 1, - C = 2, + A = 0, + B = 1, + C = 2 } diff --git a/tests/ts/arrays_test_complex/my-game/example/test-enum.js b/tests/ts/arrays_test_complex/my-game/example/test-enum.js index 7adf3a2cb..abe18369f 100644 --- a/tests/ts/arrays_test_complex/my-game/example/test-enum.js +++ b/tests/ts/arrays_test_complex/my-game/example/test-enum.js @@ -1,9 +1,8 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var TestEnum; -(function(TestEnum) { -TestEnum[TestEnum['A'] = 0] = 'A'; -TestEnum[TestEnum['B'] = 1] = 'B'; -TestEnum[TestEnum['C'] = 2] = 'C'; +(function (TestEnum) { + TestEnum[TestEnum["A"] = 0] = "A"; + TestEnum[TestEnum["B"] = 1] = "B"; + TestEnum[TestEnum["C"] = 2] = "C"; })(TestEnum || (TestEnum = {})); diff --git a/tests/ts/arrays_test_complex/my-game/example/test-enum.ts b/tests/ts/arrays_test_complex/my-game/example/test-enum.ts index 52c64eba5..d07713911 100644 --- a/tests/ts/arrays_test_complex/my-game/example/test-enum.ts +++ b/tests/ts/arrays_test_complex/my-game/example/test-enum.ts @@ -5,5 +5,5 @@ export enum TestEnum { A = 0, B = 1, - C = 2, + C = 2 } diff --git a/tests/ts/com/company/test.ts b/tests/ts/com/company/test.ts index 4aa9c55ec..87f26d217 100644 --- a/tests/ts/com/company/test.ts +++ b/tests/ts/com/company/test.ts @@ -2,4 +2,4 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {Person} from './test/person.js'; +export { Person } from './test/person.js'; diff --git a/tests/ts/com/company/test/person.ts b/tests/ts/com/company/test/person.ts index 9ac360c0e..f4d3472cd 100644 --- a/tests/ts/com/company/test/person.ts +++ b/tests/ts/com/company/test/person.ts @@ -4,86 +4,67 @@ import * as flatbuffers from 'flatbuffers'; + + export class Person { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Person { - this.bb_pos = i; - this.bb = bb; - return this; - } - - static getRootAsPerson(bb: flatbuffers.ByteBuffer, obj?: Person): Person { - return (obj || new Person()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } - - static getSizePrefixedRootAsPerson( - bb: flatbuffers.ByteBuffer, - obj?: Person, - ): Person { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Person()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } - - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } - - age(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0; - } - - static startPerson(builder: flatbuffers.Builder) { - builder.startObject(2); - } - - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } - - static addAge(builder: flatbuffers.Builder, age: number) { - builder.addFieldInt16(1, age, 0); - } - - static endPerson(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static finishPersonBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset); - } - - static finishSizePrefixedPersonBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, undefined, true); - } - - static createPerson( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - age: number, - ): flatbuffers.Offset { - Person.startPerson(builder); - Person.addName(builder, nameOffset); - Person.addAge(builder, age); - return Person.endPerson(builder); - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Person { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsPerson(bb:flatbuffers.ByteBuffer, obj?:Person):Person { + return (obj || new Person()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsPerson(bb:flatbuffers.ByteBuffer, obj?:Person):Person { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Person()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +name():string|null +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +name(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} + +age():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0; +} + +static startPerson(builder:flatbuffers.Builder):void { + builder.startObject(2); +} + +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} + +static addAge(builder:flatbuffers.Builder, age:number):void { + builder.addFieldInt16(1, age, 0); +} + +static endPerson(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static finishPersonBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset); +} + +static finishSizePrefixedPersonBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, undefined, true); +} + +static createPerson(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset, age:number):flatbuffers.Offset { + Person.startPerson(builder); + Person.addName(builder, nameOffset); + Person.addAge(builder, age); + return Person.endPerson(builder); +} } diff --git a/tests/ts/even-more-defaults.ts b/tests/ts/even-more-defaults.ts new file mode 100644 index 000000000..3603964bf --- /dev/null +++ b/tests/ts/even-more-defaults.ts @@ -0,0 +1,473 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +import * as flatbuffers from 'flatbuffers'; + +import { ABC } from './abc.js'; +import { EvenMoreStruct, EvenMoreStructT } from './even-more-struct.js'; + + +export class EvenMoreDefaults implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):EvenMoreDefaults { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsEvenMoreDefaults(bb:flatbuffers.ByteBuffer, obj?:EvenMoreDefaults):EvenMoreDefaults { + return (obj || new EvenMoreDefaults()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsEvenMoreDefaults(bb:flatbuffers.ByteBuffer, obj?:EvenMoreDefaults):EvenMoreDefaults { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new EvenMoreDefaults()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +str(obj?:EvenMoreStruct):EvenMoreStruct|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new EvenMoreStruct()).__init(this.bb_pos + offset, this.bb!) : null; +} + +ints(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt32(this.bb!.__vector(this.bb_pos + offset) + index * 4) : 0; +} + +intsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +intsArray():Int32Array { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? new Int32Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : new Int32Array(); +} + +floats(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readFloat32(this.bb!.__vector(this.bb_pos + offset) + index * 4) : 0; +} + +floatsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +floatsArray():Float32Array { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? new Float32Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : new Float32Array(); +} + +floatOptional(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.readFloat32(this.bb!.__vector(this.bb_pos + offset) + index * 4) : 0; +} + +floatOptionalLength():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +floatOptionalArray():Float32Array|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? new Float32Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null; +} + +bytesOptional(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0; +} + +bytesOptionalLength():number { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +bytesOptionalArray():Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null; +} + +floatsRequired(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.readFloat32(this.bb!.__vector(this.bb_pos + offset) + index * 4) : 0; +} + +floatsRequiredLength():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +floatsRequiredArray():Float32Array { + const offset = this.bb!.__offset(this.bb_pos, 14); + return new Float32Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)); +} + +emptyString():string +emptyString(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +emptyString(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : ""; +} + +someString():string +someString(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +someString(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : "some"; +} + +zeroString():string|null +zeroString(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +zeroString(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 20); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} + +aString():string +aString(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +aString(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 22); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} + +requiredString():string +requiredString(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +requiredString(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 24); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} + +abcs(index: number):ABC|null { + const offset = this.bb!.__offset(this.bb_pos, 26); + return offset ? this.bb!.readInt32(this.bb!.__vector(this.bb_pos + offset) + index * 4) : null; +} + +abcsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 26); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +abcsArray():Int32Array { + const offset = this.bb!.__offset(this.bb_pos, 26); + return offset ? new Int32Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : new Int32Array(); +} + +bools(index: number):boolean|null { + const offset = this.bb!.__offset(this.bb_pos, 28); + return offset ? !!this.bb!.readInt8(this.bb!.__vector(this.bb_pos + offset) + index) : false; +} + +boolsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 28); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +boolsArray():Int8Array { + const offset = this.bb!.__offset(this.bb_pos, 28); + return offset ? new Int8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : new Int8Array(); +} + +oneBool():boolean { + const offset = this.bb!.__offset(this.bb_pos, 30); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : true; +} + +mutate_one_bool(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 30); + + if (offset === 0) { + return false; + } + + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} + +static getFullyQualifiedName(): "EvenMoreDefaults" { + return 'EvenMoreDefaults'; +} + +static startEvenMoreDefaults(builder:flatbuffers.Builder):void { + builder.startObject(14); +} + +static addStr(builder:flatbuffers.Builder, strOffset:flatbuffers.Offset):void { + builder.addFieldStruct(0, strOffset, 0); +} + +static addInts(builder:flatbuffers.Builder, intsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, intsOffset, 0); +} + +static createIntsVector(builder:flatbuffers.Builder, data:number[]|Int32Array):flatbuffers.Offset; +/** + * @deprecated This Uint8Array overload will be removed in the future. + */ +static createIntsVector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset; +static createIntsVector(builder:flatbuffers.Builder, data:number[]|Int32Array|Uint8Array):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt32(data[i]!); + } + return builder.endVector(); +} + +static startIntsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addFloats(builder:flatbuffers.Builder, floatsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(2, floatsOffset, 0); +} + +static createFloatsVector(builder:flatbuffers.Builder, data:number[]|Float32Array):flatbuffers.Offset; +/** + * @deprecated This Uint8Array overload will be removed in the future. + */ +static createFloatsVector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset; +static createFloatsVector(builder:flatbuffers.Builder, data:number[]|Float32Array|Uint8Array):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addFloat32(data[i]!); + } + return builder.endVector(); +} + +static startFloatsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addFloatOptional(builder:flatbuffers.Builder, floatOptionalOffset:flatbuffers.Offset):void { + builder.addFieldOffset(3, floatOptionalOffset, 0); +} + +static createFloatOptionalVector(builder:flatbuffers.Builder, data:number[]|Float32Array):flatbuffers.Offset; +/** + * @deprecated This Uint8Array overload will be removed in the future. + */ +static createFloatOptionalVector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset; +static createFloatOptionalVector(builder:flatbuffers.Builder, data:number[]|Float32Array|Uint8Array):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addFloat32(data[i]!); + } + return builder.endVector(); +} + +static startFloatOptionalVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addBytesOptional(builder:flatbuffers.Builder, bytesOptionalOffset:flatbuffers.Offset):void { + builder.addFieldOffset(4, bytesOptionalOffset, 0); +} + +static createBytesOptionalVector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]!); + } + return builder.endVector(); +} + +static startBytesOptionalVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(1, numElems, 1); +} + +static addFloatsRequired(builder:flatbuffers.Builder, floatsRequiredOffset:flatbuffers.Offset):void { + builder.addFieldOffset(5, floatsRequiredOffset, 0); +} + +static createFloatsRequiredVector(builder:flatbuffers.Builder, data:number[]|Float32Array):flatbuffers.Offset; +/** + * @deprecated This Uint8Array overload will be removed in the future. + */ +static createFloatsRequiredVector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset; +static createFloatsRequiredVector(builder:flatbuffers.Builder, data:number[]|Float32Array|Uint8Array):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addFloat32(data[i]!); + } + return builder.endVector(); +} + +static startFloatsRequiredVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addEmptyString(builder:flatbuffers.Builder, emptyStringOffset:flatbuffers.Offset):void { + builder.addFieldOffset(6, emptyStringOffset, 0); +} + +static addSomeString(builder:flatbuffers.Builder, someStringOffset:flatbuffers.Offset):void { + builder.addFieldOffset(7, someStringOffset, 0); +} + +static addZeroString(builder:flatbuffers.Builder, zeroStringOffset:flatbuffers.Offset):void { + builder.addFieldOffset(8, zeroStringOffset, 0); +} + +static addAString(builder:flatbuffers.Builder, aStringOffset:flatbuffers.Offset):void { + builder.addFieldOffset(9, aStringOffset, 0); +} + +static addRequiredString(builder:flatbuffers.Builder, requiredStringOffset:flatbuffers.Offset):void { + builder.addFieldOffset(10, requiredStringOffset, 0); +} + +static addAbcs(builder:flatbuffers.Builder, abcsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(11, abcsOffset, 0); +} + +static createAbcsVector(builder:flatbuffers.Builder, data:ABC[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt32(data[i]!); + } + return builder.endVector(); +} + +static startAbcsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addBools(builder:flatbuffers.Builder, boolsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(12, boolsOffset, 0); +} + +static createBoolsVector(builder:flatbuffers.Builder, data:boolean[]):flatbuffers.Offset { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(+data[i]!); + } + return builder.endVector(); +} + +static startBoolsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(1, numElems, 1); +} + +static addOneBool(builder:flatbuffers.Builder, oneBool:boolean):void { + builder.addFieldInt8(13, +oneBool, +true); +} + +static endEvenMoreDefaults(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 14) // floats_required + builder.requiredField(offset, 22) // a_string + builder.requiredField(offset, 24) // required_string + return offset; +} + +static createEvenMoreDefaults(builder:flatbuffers.Builder, strOffset:flatbuffers.Offset, intsOffset:flatbuffers.Offset, floatsOffset:flatbuffers.Offset, floatOptionalOffset:flatbuffers.Offset, bytesOptionalOffset:flatbuffers.Offset, floatsRequiredOffset:flatbuffers.Offset, emptyStringOffset:flatbuffers.Offset, someStringOffset:flatbuffers.Offset, zeroStringOffset:flatbuffers.Offset, aStringOffset:flatbuffers.Offset, requiredStringOffset:flatbuffers.Offset, abcsOffset:flatbuffers.Offset, boolsOffset:flatbuffers.Offset, oneBool:boolean):flatbuffers.Offset { + EvenMoreDefaults.startEvenMoreDefaults(builder); + EvenMoreDefaults.addStr(builder, strOffset); + EvenMoreDefaults.addInts(builder, intsOffset); + EvenMoreDefaults.addFloats(builder, floatsOffset); + EvenMoreDefaults.addFloatOptional(builder, floatOptionalOffset); + EvenMoreDefaults.addBytesOptional(builder, bytesOptionalOffset); + EvenMoreDefaults.addFloatsRequired(builder, floatsRequiredOffset); + EvenMoreDefaults.addEmptyString(builder, emptyStringOffset); + EvenMoreDefaults.addSomeString(builder, someStringOffset); + EvenMoreDefaults.addZeroString(builder, zeroStringOffset); + EvenMoreDefaults.addAString(builder, aStringOffset); + EvenMoreDefaults.addRequiredString(builder, requiredStringOffset); + EvenMoreDefaults.addAbcs(builder, abcsOffset); + EvenMoreDefaults.addBools(builder, boolsOffset); + EvenMoreDefaults.addOneBool(builder, oneBool); + return EvenMoreDefaults.endEvenMoreDefaults(builder); +} + +unpack(): EvenMoreDefaultsT { + return new EvenMoreDefaultsT( + (this.str() !== null ? this.str()!.unpack() : null), + this.bb!.createScalarList(this.ints.bind(this), this.intsLength()), + this.bb!.createScalarList(this.floats.bind(this), this.floatsLength()), + this.bb!.createScalarList(this.floatOptional.bind(this), this.floatOptionalLength()), + this.bb!.createScalarList(this.bytesOptional.bind(this), this.bytesOptionalLength()), + this.bb!.createScalarList(this.floatsRequired.bind(this), this.floatsRequiredLength()), + this.emptyString(), + this.someString(), + this.zeroString(), + this.aString(), + this.requiredString(), + this.bb!.createScalarList(this.abcs.bind(this), this.abcsLength()), + this.bb!.createScalarList(this.bools.bind(this), this.boolsLength()), + this.oneBool() + ); +} + + +unpackTo(_o: EvenMoreDefaultsT): void { + _o.str = (this.str() !== null ? this.str()!.unpack() : null); + _o.ints = this.bb!.createScalarList(this.ints.bind(this), this.intsLength()); + _o.floats = this.bb!.createScalarList(this.floats.bind(this), this.floatsLength()); + _o.floatOptional = this.bb!.createScalarList(this.floatOptional.bind(this), this.floatOptionalLength()); + _o.bytesOptional = this.bb!.createScalarList(this.bytesOptional.bind(this), this.bytesOptionalLength()); + _o.floatsRequired = this.bb!.createScalarList(this.floatsRequired.bind(this), this.floatsRequiredLength()); + _o.emptyString = this.emptyString(); + _o.someString = this.someString(); + _o.zeroString = this.zeroString(); + _o.aString = this.aString(); + _o.requiredString = this.requiredString(); + _o.abcs = this.bb!.createScalarList(this.abcs.bind(this), this.abcsLength()); + _o.bools = this.bb!.createScalarList(this.bools.bind(this), this.boolsLength()); + _o.oneBool = this.oneBool(); +} +} + +export class EvenMoreDefaultsT implements flatbuffers.IGeneratedObject { +constructor( + public str: EvenMoreStructT|null = null, + public ints: (number)[] = [], + public floats: (number)[] = [], + public floatOptional: (number)[] = [], + public bytesOptional: (number)[] = [], + public floatsRequired: (number)[] = [], + public emptyString: string|Uint8Array = "", + public someString: string|Uint8Array = "some", + public zeroString: string|Uint8Array|null = null, + public aString: string|Uint8Array|null = null, + public requiredString: string|Uint8Array|null = null, + public abcs: (ABC)[] = [], + public bools: (boolean)[] = [], + public oneBool: boolean = true +){} + + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const ints = EvenMoreDefaults.createIntsVector(builder, this.ints); + const floats = EvenMoreDefaults.createFloatsVector(builder, this.floats); + const floatOptional = EvenMoreDefaults.createFloatOptionalVector(builder, this.floatOptional); + const bytesOptional = EvenMoreDefaults.createBytesOptionalVector(builder, this.bytesOptional); + const floatsRequired = EvenMoreDefaults.createFloatsRequiredVector(builder, this.floatsRequired); + const emptyString = (this.emptyString !== null ? builder.createString(this.emptyString!) : 0); + const someString = (this.someString !== null ? builder.createString(this.someString!) : 0); + const zeroString = (this.zeroString !== null ? builder.createString(this.zeroString!) : 0); + const aString = (this.aString !== null ? builder.createString(this.aString!) : 0); + const requiredString = (this.requiredString !== null ? builder.createString(this.requiredString!) : 0); + const abcs = EvenMoreDefaults.createAbcsVector(builder, this.abcs); + const bools = EvenMoreDefaults.createBoolsVector(builder, this.bools); + + return EvenMoreDefaults.createEvenMoreDefaults(builder, + (this.str !== null ? this.str!.pack(builder) : 0), + ints, + floats, + floatOptional, + bytesOptional, + floatsRequired, + emptyString, + someString, + zeroString, + aString, + requiredString, + abcs, + bools, + this.oneBool + ); +} +} diff --git a/tests/ts/even-more-struct.ts b/tests/ts/even-more-struct.ts new file mode 100644 index 000000000..7c0a0d1a2 --- /dev/null +++ b/tests/ts/even-more-struct.ts @@ -0,0 +1,64 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +import * as flatbuffers from 'flatbuffers'; + + + +export class EvenMoreStruct implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):EvenMoreStruct { + this.bb_pos = i; + this.bb = bb; + return this; +} + +g(index: number):bigint|null { + return this.bb!.readInt64(this.bb_pos + 0 + index * 8); +} + +static getFullyQualifiedName(): "EvenMoreStruct" { + return 'EvenMoreStruct'; +} + +static sizeOf():number { + return 16; +} + +static createEvenMoreStruct(builder:flatbuffers.Builder, g: bigint[]):flatbuffers.Offset { + builder.prep(8, 16); + + for (let i = 1; i >= 0; --i) { + builder.writeInt64(BigInt(g?.[i] ?? 0)); + } + + return builder.offset(); +} + + +unpack(): EvenMoreStructT { + return new EvenMoreStructT( + this.bb!.createScalarList(this.g.bind(this), 2) + ); +} + + +unpackTo(_o: EvenMoreStructT): void { + _o.g = this.bb!.createScalarList(this.g.bind(this), 2); +} +} + +export class EvenMoreStructT implements flatbuffers.IGeneratedObject { +constructor( + public g: (bigint)[] = [] +){} + + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return EvenMoreStruct.createEvenMoreStruct(builder, + this.g + ); +} +} diff --git a/tests/ts/even_more_defaults.ts b/tests/ts/even_more_defaults.ts new file mode 100644 index 000000000..84f4c2925 --- /dev/null +++ b/tests/ts/even_more_defaults.ts @@ -0,0 +1,7 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +export { ABC } from './abc.js'; +export { EvenMoreDefaults, EvenMoreDefaultsT } from './even-more-defaults.js'; +export { EvenMoreStruct, EvenMoreStructT } from './even-more-struct.js'; diff --git a/tests/ts/foobar.d.ts b/tests/ts/foobar.d.ts index 36ea4d7cf..c920a8c3c 100644 --- a/tests/ts/foobar.d.ts +++ b/tests/ts/foobar.d.ts @@ -1 +1 @@ -export {Abc} from './foobar/abc.js'; +export { Abc } from './foobar/abc.js'; diff --git a/tests/ts/foobar.js b/tests/ts/foobar.js index 28853ee8d..fa5fd6dbf 100644 --- a/tests/ts/foobar.js +++ b/tests/ts/foobar.js @@ -1,4 +1,3 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {Abc} from './foobar/abc.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Abc } from './foobar/abc.js'; diff --git a/tests/ts/foobar.ts b/tests/ts/foobar.ts index 57d1f73a9..e513600c6 100644 --- a/tests/ts/foobar.ts +++ b/tests/ts/foobar.ts @@ -2,4 +2,4 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {Abc} from './foobar/abc.js'; +export { Abc } from './foobar/abc.js'; diff --git a/tests/ts/foobar/abc.d.ts b/tests/ts/foobar/abc.d.ts index d1d3b9e19..874a35db0 100644 --- a/tests/ts/foobar/abc.d.ts +++ b/tests/ts/foobar/abc.d.ts @@ -1,3 +1,3 @@ export declare enum Abc { - a = 0, + a = 0 } diff --git a/tests/ts/foobar/abc.js b/tests/ts/foobar/abc.js index eedccbdea..8c3aeb952 100644 --- a/tests/ts/foobar/abc.js +++ b/tests/ts/foobar/abc.js @@ -1,7 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var Abc; -(function(Abc) { -Abc[Abc['a'] = 0] = 'a'; +(function (Abc) { + Abc[Abc["a"] = 0] = "a"; })(Abc || (Abc = {})); diff --git a/tests/ts/foobar/abc.ts b/tests/ts/foobar/abc.ts index c2eb2e1d0..308713cc6 100644 --- a/tests/ts/foobar/abc.ts +++ b/tests/ts/foobar/abc.ts @@ -3,5 +3,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export enum Abc { - a = 0, + a = 0 } diff --git a/tests/ts/foobar/class.d.ts b/tests/ts/foobar/class.d.ts index 5aa7ad012..2815be18c 100644 --- a/tests/ts/foobar/class.d.ts +++ b/tests/ts/foobar/class.d.ts @@ -1,3 +1,3 @@ export declare enum class_ { - arguments_ = 0, + arguments_ = 0 } diff --git a/tests/ts/foobar/class.js b/tests/ts/foobar/class.js index 2633c6e23..179ab6f04 100644 --- a/tests/ts/foobar/class.js +++ b/tests/ts/foobar/class.js @@ -1,7 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var class_; -(function(class_) { -class_[class_['arguments_'] = 0] = 'arguments_'; +(function (class_) { + class_[class_["arguments_"] = 0] = "arguments_"; })(class_ || (class_ = {})); diff --git a/tests/ts/foobar/class.ts b/tests/ts/foobar/class.ts index 0a48a6519..db45d22ca 100644 --- a/tests/ts/foobar/class.ts +++ b/tests/ts/foobar/class.ts @@ -3,5 +3,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export enum class_ { - arguments_ = 0, + arguments_ = 0 } diff --git a/tests/ts/foobar/tab.ts b/tests/ts/foobar/tab.ts index f94c3551a..018cd9d8d 100644 --- a/tests/ts/foobar/tab.ts +++ b/tests/ts/foobar/tab.ts @@ -4,135 +4,131 @@ import * as flatbuffers from 'flatbuffers'; -import {Abc} from '../foobar/abc.js'; -import {class_} from '../foobar/class.js'; +import { Abc } from './abc.js'; +import { class_ } from './class.js'; + export class Tab implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Tab { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Tab { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsTab(bb:flatbuffers.ByteBuffer, obj?:Tab):Tab { + return (obj || new Tab()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsTab(bb:flatbuffers.ByteBuffer, obj?:Tab):Tab { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Tab()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +abc():Abc { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a; +} + +mutate_abc(value:Abc):boolean { + const offset = this.bb!.__offset(this.bb_pos, 4); + + if (offset === 0) { + return false; } - static getRootAsTab(bb: flatbuffers.ByteBuffer, obj?: Tab): Tab { - return (obj || new Tab()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +arg():class_ { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.arguments_; +} + +mutate_arg(value:class_):boolean { + const offset = this.bb!.__offset(this.bb_pos, 6); + + if (offset === 0) { + return false; } - static getSizePrefixedRootAsTab(bb: flatbuffers.ByteBuffer, obj?: Tab): Tab { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Tab()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} - abc(): Abc { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a; - } +name():string|null +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +name(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} - mutate_abc(value: Abc): boolean { - const offset = this.bb!.__offset(this.bb_pos, 4); +static getFullyQualifiedName(): "foobar.Tab" { + return 'foobar.Tab'; +} - if (offset === 0) { - return false; - } +static startTab(builder:flatbuffers.Builder):void { + builder.startObject(3); +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } +static addAbc(builder:flatbuffers.Builder, abc:Abc):void { + builder.addFieldInt32(0, abc, Abc.a); +} - arg(): class_ { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? this.bb!.readInt32(this.bb_pos + offset) - : class_.arguments_; - } +static addArg(builder:flatbuffers.Builder, arg:class_):void { + builder.addFieldInt32(1, arg, class_.arguments_); +} - mutate_arg(value: class_): boolean { - const offset = this.bb!.__offset(this.bb_pos, 6); +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(2, nameOffset, 0); +} - if (offset === 0) { - return false; - } +static endTab(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } +static createTab(builder:flatbuffers.Builder, abc:Abc, arg:class_, nameOffset:flatbuffers.Offset):flatbuffers.Offset { + Tab.startTab(builder); + Tab.addAbc(builder, abc); + Tab.addArg(builder, arg); + Tab.addName(builder, nameOffset); + return Tab.endTab(builder); +} - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +unpack(): TabT { + return new TabT( + this.abc(), + this.arg(), + this.name() + ); +} - static getFullyQualifiedName(): string { - return 'foobar.Tab'; - } - static startTab(builder: flatbuffers.Builder) { - builder.startObject(3); - } - - static addAbc(builder: flatbuffers.Builder, abc: Abc) { - builder.addFieldInt32(0, abc, Abc.a); - } - - static addArg(builder: flatbuffers.Builder, arg: class_) { - builder.addFieldInt32(1, arg, class_.arguments_); - } - - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(2, nameOffset, 0); - } - - static endTab(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static createTab( - builder: flatbuffers.Builder, - abc: Abc, - arg: class_, - nameOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - Tab.startTab(builder); - Tab.addAbc(builder, abc); - Tab.addArg(builder, arg); - Tab.addName(builder, nameOffset); - return Tab.endTab(builder); - } - - unpack(): TabT { - return new TabT(this.abc(), this.arg(), this.name()); - } - - unpackTo(_o: TabT): void { - _o.abc = this.abc(); - _o.arg = this.arg(); - _o.name = this.name(); - } +unpackTo(_o: TabT): void { + _o.abc = this.abc(); + _o.arg = this.arg(); + _o.name = this.name(); +} } export class TabT implements flatbuffers.IGeneratedObject { - constructor( - public abc: Abc = Abc.a, - public arg: class_ = class_.arguments_, - public name: string | Uint8Array | null = null, - ) {} +constructor( + public abc: Abc = Abc.a, + public arg: class_ = class_.arguments_, + public name: string|Uint8Array|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const name = this.name !== null ? builder.createString(this.name!) : 0; - return Tab.createTab(builder, this.abc, this.arg, name); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const name = (this.name !== null ? builder.createString(this.name!) : 0); + + return Tab.createTab(builder, + this.abc, + this.arg, + name + ); +} } diff --git a/tests/ts/longer-namespace/a/b/c.d.ts b/tests/ts/longer-namespace/a/b/c.d.ts index cd50050a9..e57007967 100644 --- a/tests/ts/longer-namespace/a/b/c.d.ts +++ b/tests/ts/longer-namespace/a/b/c.d.ts @@ -1 +1 @@ -export {Person} from './c/person.js'; +export { Person } from './c/person.js'; diff --git a/tests/ts/longer-namespace/a/b/c.js b/tests/ts/longer-namespace/a/b/c.js index a2a45dfbb..b448f9100 100644 --- a/tests/ts/longer-namespace/a/b/c.js +++ b/tests/ts/longer-namespace/a/b/c.js @@ -1,4 +1,3 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {Person} from './c/person.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Person } from './c/person.js'; diff --git a/tests/ts/longer-namespace/a/b/c.ts b/tests/ts/longer-namespace/a/b/c.ts index 05f84e137..a30937e06 100644 --- a/tests/ts/longer-namespace/a/b/c.ts +++ b/tests/ts/longer-namespace/a/b/c.ts @@ -2,4 +2,4 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {Person} from './c/person.js'; +export { Person } from './c/person.js'; diff --git a/tests/ts/longer-namespace/a/b/c/person.d.ts b/tests/ts/longer-namespace/a/b/c/person.d.ts index aeb6045d5..cbd8fcb41 100644 --- a/tests/ts/longer-namespace/a/b/c/person.d.ts +++ b/tests/ts/longer-namespace/a/b/c/person.d.ts @@ -1,34 +1,18 @@ import * as flatbuffers from 'flatbuffers'; export declare class Person { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Person; - static getRootAsPerson(bb: flatbuffers.ByteBuffer, obj?: Person): Person; - static getSizePrefixedRootAsPerson( - bb: flatbuffers.ByteBuffer, - obj?: Person, - ): Person; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - age(): number; - static startPerson(builder: flatbuffers.Builder): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addAge(builder: flatbuffers.Builder, age: number): void; - static endPerson(builder: flatbuffers.Builder): flatbuffers.Offset; - static finishPersonBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static finishSizePrefixedPersonBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static createPerson( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - age: number, - ): flatbuffers.Offset; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Person; + static getRootAsPerson(bb: flatbuffers.ByteBuffer, obj?: Person): Person; + static getSizePrefixedRootAsPerson(bb: flatbuffers.ByteBuffer, obj?: Person): Person; + name(): string | null; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + age(): number; + static startPerson(builder: flatbuffers.Builder): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addAge(builder: flatbuffers.Builder, age: number): void; + static endPerson(builder: flatbuffers.Builder): flatbuffers.Offset; + static finishPersonBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static finishSizePrefixedPersonBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static createPerson(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset, age: number): flatbuffers.Offset; } diff --git a/tests/ts/longer-namespace/a/b/c/person.js b/tests/ts/longer-namespace/a/b/c/person.js index 355968d0d..2195fc45b 100644 --- a/tests/ts/longer-namespace/a/b/c/person.js +++ b/tests/ts/longer-namespace/a/b/c/person.js @@ -1,58 +1,54 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class Person { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsPerson(bb, obj) { - return (obj || new Person()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsPerson(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Person()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - age() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt16(this.bb_pos + offset) : 0; - } - static startPerson(builder) { - builder.startObject(2); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(0, nameOffset, 0); - } - static addAge(builder, age) { - builder.addFieldInt16(1, age, 0); - } - static endPerson(builder) { - const offset = builder.endObject(); - return offset; - } - static finishPersonBuffer(builder, offset) { - builder.finish(offset); - } - static finishSizePrefixedPersonBuffer(builder, offset) { - builder.finish(offset, undefined, true); - } - static createPerson(builder, nameOffset, age) { - Person.startPerson(builder); - Person.addName(builder, nameOffset); - Person.addAge(builder, age); - return Person.endPerson(builder); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsPerson(bb, obj) { + return (obj || new Person()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsPerson(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Person()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + age() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt16(this.bb_pos + offset) : 0; + } + static startPerson(builder) { + builder.startObject(2); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + static addAge(builder, age) { + builder.addFieldInt16(1, age, 0); + } + static endPerson(builder) { + const offset = builder.endObject(); + return offset; + } + static finishPersonBuffer(builder, offset) { + builder.finish(offset); + } + static finishSizePrefixedPersonBuffer(builder, offset) { + builder.finish(offset, undefined, true); + } + static createPerson(builder, nameOffset, age) { + Person.startPerson(builder); + Person.addName(builder, nameOffset); + Person.addAge(builder, age); + return Person.endPerson(builder); + } } diff --git a/tests/ts/longer-namespace/a/b/c/person.ts b/tests/ts/longer-namespace/a/b/c/person.ts index 9ac360c0e..f4d3472cd 100644 --- a/tests/ts/longer-namespace/a/b/c/person.ts +++ b/tests/ts/longer-namespace/a/b/c/person.ts @@ -4,86 +4,67 @@ import * as flatbuffers from 'flatbuffers'; + + export class Person { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Person { - this.bb_pos = i; - this.bb = bb; - return this; - } - - static getRootAsPerson(bb: flatbuffers.ByteBuffer, obj?: Person): Person { - return (obj || new Person()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } - - static getSizePrefixedRootAsPerson( - bb: flatbuffers.ByteBuffer, - obj?: Person, - ): Person { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Person()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } - - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } - - age(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0; - } - - static startPerson(builder: flatbuffers.Builder) { - builder.startObject(2); - } - - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } - - static addAge(builder: flatbuffers.Builder, age: number) { - builder.addFieldInt16(1, age, 0); - } - - static endPerson(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static finishPersonBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset); - } - - static finishSizePrefixedPersonBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, undefined, true); - } - - static createPerson( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - age: number, - ): flatbuffers.Offset { - Person.startPerson(builder); - Person.addName(builder, nameOffset); - Person.addAge(builder, age); - return Person.endPerson(builder); - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Person { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsPerson(bb:flatbuffers.ByteBuffer, obj?:Person):Person { + return (obj || new Person()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsPerson(bb:flatbuffers.ByteBuffer, obj?:Person):Person { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Person()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +name():string|null +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +name(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} + +age():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0; +} + +static startPerson(builder:flatbuffers.Builder):void { + builder.startObject(2); +} + +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} + +static addAge(builder:flatbuffers.Builder, age:number):void { + builder.addFieldInt16(1, age, 0); +} + +static endPerson(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static finishPersonBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset); +} + +static finishSizePrefixedPersonBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, undefined, true); +} + +static createPerson(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset, age:number):flatbuffers.Offset { + Person.startPerson(builder); + Person.addName(builder, nameOffset); + Person.addAge(builder, age); + return Person.endPerson(builder); +} } diff --git a/tests/ts/monster_test.d.ts b/tests/ts/monster_test.d.ts index 7d77f47f2..e89d898e4 100644 --- a/tests/ts/monster_test.d.ts +++ b/tests/ts/monster_test.d.ts @@ -1,2 +1,2 @@ +export { TableA, TableAT } from './table-a.js'; export * as MyGame from './my-game.js'; -export {TableA, TableAT} from './table-a.js'; diff --git a/tests/ts/monster_test.js b/tests/ts/monster_test.js index ba672f577..04d21753c 100644 --- a/tests/ts/monster_test.js +++ b/tests/ts/monster_test.js @@ -1,5 +1,4 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { TableA, TableAT } from './table-a.js'; export * as MyGame from './my-game.js'; -export {TableA, TableAT} from './table-a.js'; diff --git a/tests/ts/monster_test_generated.cjs b/tests/ts/monster_test_generated.cjs index d78fd5d05..b7b62e479 100644 --- a/tests/ts/monster_test_generated.cjs +++ b/tests/ts/monster_test_generated.cjs @@ -882,7 +882,7 @@ var Monster2 = class _Monster { } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } inventory(index) { const offset = this.bb.__offset(this.bb_pos, 14); @@ -1274,7 +1274,7 @@ var Monster2 = class _Monster { } vectorOfEnums(index) { const offset = this.bb.__offset(this.bb_pos, 98); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : null; } vectorOfEnumsLength() { const offset = this.bb.__offset(this.bb_pos, 98); diff --git a/tests/ts/my-game.d.ts b/tests/ts/my-game.d.ts index 08dad659c..e82f8a313 100644 --- a/tests/ts/my-game.d.ts +++ b/tests/ts/my-game.d.ts @@ -1,7 +1,4 @@ +export { InParentNamespace, InParentNamespaceT } from './my-game/in-parent-namespace.js'; export * as Example from './my-game/example.js'; export * as Example2 from './my-game/example2.js'; -export { - InParentNamespace, - InParentNamespaceT, -} from './my-game/in-parent-namespace.js'; export * as OtherNameSpace from './my-game/other-name-space.js'; diff --git a/tests/ts/my-game.js b/tests/ts/my-game.js index a70dacfa6..59aabe994 100644 --- a/tests/ts/my-game.js +++ b/tests/ts/my-game.js @@ -1,7 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { InParentNamespace, InParentNamespaceT } from './my-game/in-parent-namespace.js'; export * as Example from './my-game/example.js'; export * as Example2 from './my-game/example2.js'; -export {InParentNamespace, InParentNamespaceT} from './my-game/in-parent-namespace.js'; export * as OtherNameSpace from './my-game/other-name-space.js'; diff --git a/tests/ts/my-game/example.d.ts b/tests/ts/my-game/example.d.ts index 041191520..a09b7f849 100644 --- a/tests/ts/my-game/example.d.ts +++ b/tests/ts/my-game/example.d.ts @@ -1,25 +1,16 @@ -export {Ability, AbilityT} from './example/ability.js'; -export {AnyAmbiguousAliases} from './example/any-ambiguous-aliases.js'; -export {AnyUniqueAliases} from './example/any-unique-aliases.js'; -export {Any} from './example/any.js'; -export {Color} from './example/color.js'; -export {LongEnum} from './example/long-enum.js'; -export {Monster, MonsterT} from './example/monster.js'; -export {Race} from './example/race.js'; -export {Referrable, ReferrableT} from './example/referrable.js'; -export {Stat, StatT} from './example/stat.js'; -export { - StructOfStructsOfStructs, - StructOfStructsOfStructsT, -} from './example/struct-of-structs-of-structs.js'; -export { - StructOfStructs, - StructOfStructsT, -} from './example/struct-of-structs.js'; -export { - TestSimpleTableWithEnum, - TestSimpleTableWithEnumT, -} from './example/test-simple-table-with-enum.js'; -export {Test, TestT} from './example/test.js'; -export {TypeAliases, TypeAliasesT} from './example/type-aliases.js'; -export {Vec3, Vec3T} from './example/vec3.js'; +export { Ability, AbilityT } from './example/ability.js'; +export { Any } from './example/any.js'; +export { AnyAmbiguousAliases } from './example/any-ambiguous-aliases.js'; +export { AnyUniqueAliases } from './example/any-unique-aliases.js'; +export { Color } from './example/color.js'; +export { LongEnum } from './example/long-enum.js'; +export { Monster, MonsterT } from './example/monster.js'; +export { Race } from './example/race.js'; +export { Referrable, ReferrableT } from './example/referrable.js'; +export { Stat, StatT } from './example/stat.js'; +export { StructOfStructs, StructOfStructsT } from './example/struct-of-structs.js'; +export { StructOfStructsOfStructs, StructOfStructsOfStructsT } from './example/struct-of-structs-of-structs.js'; +export { Test, TestT } from './example/test.js'; +export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './example/test-simple-table-with-enum.js'; +export { TypeAliases, TypeAliasesT } from './example/type-aliases.js'; +export { Vec3, Vec3T } from './example/vec3.js'; diff --git a/tests/ts/my-game/example.js b/tests/ts/my-game/example.js index b553cd573..d63f78c77 100644 --- a/tests/ts/my-game/example.js +++ b/tests/ts/my-game/example.js @@ -1,19 +1,18 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {Ability, AbilityT} from './example/ability.js'; -export {AnyAmbiguousAliases} from './example/any-ambiguous-aliases.js'; -export {AnyUniqueAliases} from './example/any-unique-aliases.js'; -export {Any} from './example/any.js'; -export {Color} from './example/color.js'; -export {LongEnum} from './example/long-enum.js'; -export {Monster, MonsterT} from './example/monster.js'; -export {Race} from './example/race.js'; -export {Referrable, ReferrableT} from './example/referrable.js'; -export {Stat, StatT} from './example/stat.js'; -export {StructOfStructsOfStructs, StructOfStructsOfStructsT} from './example/struct-of-structs-of-structs.js'; -export {StructOfStructs, StructOfStructsT} from './example/struct-of-structs.js'; -export {TestSimpleTableWithEnum, TestSimpleTableWithEnumT} from './example/test-simple-table-with-enum.js'; -export {Test, TestT} from './example/test.js'; -export {TypeAliases, TypeAliasesT} from './example/type-aliases.js'; -export {Vec3, Vec3T} from './example/vec3.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Ability, AbilityT } from './example/ability.js'; +export { Any } from './example/any.js'; +export { AnyAmbiguousAliases } from './example/any-ambiguous-aliases.js'; +export { AnyUniqueAliases } from './example/any-unique-aliases.js'; +export { Color } from './example/color.js'; +export { LongEnum } from './example/long-enum.js'; +export { Monster, MonsterT } from './example/monster.js'; +export { Race } from './example/race.js'; +export { Referrable, ReferrableT } from './example/referrable.js'; +export { Stat, StatT } from './example/stat.js'; +export { StructOfStructs, StructOfStructsT } from './example/struct-of-structs.js'; +export { StructOfStructsOfStructs, StructOfStructsOfStructsT } from './example/struct-of-structs-of-structs.js'; +export { Test, TestT } from './example/test.js'; +export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './example/test-simple-table-with-enum.js'; +export { TypeAliases, TypeAliasesT } from './example/type-aliases.js'; +export { Vec3, Vec3T } from './example/vec3.js'; diff --git a/tests/ts/my-game/example/ability.d.ts b/tests/ts/my-game/example/ability.d.ts index b3391a1b0..c0d067d1d 100644 --- a/tests/ts/my-game/example/ability.d.ts +++ b/tests/ts/my-game/example/ability.d.ts @@ -1,27 +1,21 @@ import * as flatbuffers from 'flatbuffers'; -export declare class Ability - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Ability; - id(): number; - mutate_id(value: number): boolean; - distance(): number; - mutate_distance(value: number): boolean; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createAbility( - builder: flatbuffers.Builder, - id: number, - distance: number, - ): flatbuffers.Offset; - unpack(): AbilityT; - unpackTo(_o: AbilityT): void; +export declare class Ability implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Ability; + id(): number; + mutate_id(value: number): boolean; + distance(): number; + mutate_distance(value: number): boolean; + static getFullyQualifiedName(): "MyGame.Example.Ability"; + static sizeOf(): number; + static createAbility(builder: flatbuffers.Builder, id: number, distance: number): flatbuffers.Offset; + unpack(): AbilityT; + unpackTo(_o: AbilityT): void; } export declare class AbilityT implements flatbuffers.IGeneratedObject { - id: number; - distance: number; - constructor(id?: number, distance?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + id: number; + distance: number; + constructor(id?: number, distance?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/ability.js b/tests/ts/my-game/example/ability.js index 8ade5097b..9fea3d6b4 100644 --- a/tests/ts/my-game/example/ability.js +++ b/tests/ts/my-game/example/ability.js @@ -1,54 +1,54 @@ // automatically generated by the FlatBuffers compiler, do not modify export class Ability { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - id() { - return this.bb.readUint32(this.bb_pos); - } - mutate_id(value) { - this.bb.writeUint32(this.bb_pos + 0, value); - return true; - } - distance() { - return this.bb.readUint32(this.bb_pos + 4); - } - mutate_distance(value) { - this.bb.writeUint32(this.bb_pos + 4, value); - return true; - } - static getFullyQualifiedName() { - return 'MyGame.Example.Ability'; - } - static sizeOf() { - return 8; - } - static createAbility(builder, id, distance) { - builder.prep(4, 8); - builder.writeInt32(distance); - builder.writeInt32(id); - return builder.offset(); - } - unpack() { - return new AbilityT(this.id(), this.distance()); - } - unpackTo(_o) { - _o.id = this.id(); - _o.distance = this.distance(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + id() { + return this.bb.readUint32(this.bb_pos); + } + mutate_id(value) { + this.bb.writeUint32(this.bb_pos + 0, value); + return true; + } + distance() { + return this.bb.readUint32(this.bb_pos + 4); + } + mutate_distance(value) { + this.bb.writeUint32(this.bb_pos + 4, value); + return true; + } + static getFullyQualifiedName() { + return 'MyGame.Example.Ability'; + } + static sizeOf() { + return 8; + } + static createAbility(builder, id, distance) { + builder.prep(4, 8); + builder.writeInt32(distance); + builder.writeInt32(id); + return builder.offset(); + } + unpack() { + return new AbilityT(this.id(), this.distance()); + } + unpackTo(_o) { + _o.id = this.id(); + _o.distance = this.distance(); + } } export class AbilityT { - constructor(id = 0, distance = 0) { - this.id = id; - this.distance = distance; - } - pack(builder) { - return Ability.createAbility(builder, this.id, this.distance); - } + constructor(id = 0, distance = 0) { + this.id = id; + this.distance = distance; + } + pack(builder) { + return Ability.createAbility(builder, this.id, this.distance); + } } diff --git a/tests/ts/my-game/example/ability.ts b/tests/ts/my-game/example/ability.ts index 02951cbf2..65e5be739 100644 --- a/tests/ts/my-game/example/ability.ts +++ b/tests/ts/my-game/example/ability.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class Ability implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Ability { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/my-game/example/any-ambiguous-aliases.d.ts b/tests/ts/my-game/example/any-ambiguous-aliases.d.ts index 06b40920b..402a756ac 100644 --- a/tests/ts/my-game/example/any-ambiguous-aliases.d.ts +++ b/tests/ts/my-game/example/any-ambiguous-aliases.d.ts @@ -1,16 +1,9 @@ -import {Monster} from '../../my-game/example/monster.js'; +import { Monster } from './monster.js'; export declare enum AnyAmbiguousAliases { - NONE = 0, - M1 = 1, - M2 = 2, - M3 = 3, + NONE = 0, + M1 = 1, + M2 = 2, + M3 = 3 } -export declare function unionToAnyAmbiguousAliases( - type: AnyAmbiguousAliases, - accessor: (obj: Monster) => Monster | null, -): Monster | null; -export declare function unionListToAnyAmbiguousAliases( - type: AnyAmbiguousAliases, - accessor: (index: number, obj: Monster) => Monster | null, - index: number, -): Monster | null; +export declare function unionToAnyAmbiguousAliases(type: AnyAmbiguousAliases, accessor: (obj: Monster) => Monster | null): Monster | null; +export declare function unionListToAnyAmbiguousAliases(type: AnyAmbiguousAliases, accessor: (index: number, obj: Monster) => Monster | null, index: number): Monster | null; diff --git a/tests/ts/my-game/example/any-ambiguous-aliases.js b/tests/ts/my-game/example/any-ambiguous-aliases.js index 8156b88e2..2bea14d5b 100644 --- a/tests/ts/my-game/example/any-ambiguous-aliases.js +++ b/tests/ts/my-game/example/any-ambiguous-aliases.js @@ -1,39 +1,28 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -import {Monster} from '../../my-game/example/monster.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import { Monster } from './monster.js'; export var AnyAmbiguousAliases; -(function(AnyAmbiguousAliases) { -AnyAmbiguousAliases[AnyAmbiguousAliases['NONE'] = 0] = 'NONE'; -AnyAmbiguousAliases[AnyAmbiguousAliases['M1'] = 1] = 'M1'; -AnyAmbiguousAliases[AnyAmbiguousAliases['M2'] = 2] = 'M2'; -AnyAmbiguousAliases[AnyAmbiguousAliases['M3'] = 3] = 'M3'; +(function (AnyAmbiguousAliases) { + AnyAmbiguousAliases[AnyAmbiguousAliases["NONE"] = 0] = "NONE"; + AnyAmbiguousAliases[AnyAmbiguousAliases["M1"] = 1] = "M1"; + AnyAmbiguousAliases[AnyAmbiguousAliases["M2"] = 2] = "M2"; + AnyAmbiguousAliases[AnyAmbiguousAliases["M3"] = 3] = "M3"; })(AnyAmbiguousAliases || (AnyAmbiguousAliases = {})); export function unionToAnyAmbiguousAliases(type, accessor) { - switch (AnyAmbiguousAliases[type]) { - case 'NONE': - return null; - case 'M1': - return accessor(new Monster()); - case 'M2': - return accessor(new Monster()); - case 'M3': - return accessor(new Monster()); - default: - return null; - } + switch (AnyAmbiguousAliases[type]) { + case 'NONE': return null; + case 'M1': return accessor(new Monster()); + case 'M2': return accessor(new Monster()); + case 'M3': return accessor(new Monster()); + default: return null; + } } export function unionListToAnyAmbiguousAliases(type, accessor, index) { - switch (AnyAmbiguousAliases[type]) { - case 'NONE': - return null; - case 'M1': - return accessor(index, new Monster()); - case 'M2': - return accessor(index, new Monster()); - case 'M3': - return accessor(index, new Monster()); - default: - return null; - } + switch (AnyAmbiguousAliases[type]) { + case 'NONE': return null; + case 'M1': return accessor(index, new Monster()); + case 'M2': return accessor(index, new Monster()); + case 'M3': return accessor(index, new Monster()); + default: return null; + } } diff --git a/tests/ts/my-game/example/any-unique-aliases.d.ts b/tests/ts/my-game/example/any-unique-aliases.d.ts index 378efca7c..8d4cbbc96 100644 --- a/tests/ts/my-game/example/any-unique-aliases.d.ts +++ b/tests/ts/my-game/example/any-unique-aliases.d.ts @@ -1,23 +1,11 @@ -import {Monster} from '../../my-game/example/monster.js'; -import {TestSimpleTableWithEnum} from '../../my-game/example/test-simple-table-with-enum.js'; -import {Monster as MyGame_Example2_Monster} from '../../my-game/example2/monster.js'; +import { Monster as MyGame_Example2_Monster } from '../example2/monster.js'; +import { Monster } from './monster.js'; +import { TestSimpleTableWithEnum } from './test-simple-table-with-enum.js'; export declare enum AnyUniqueAliases { - NONE = 0, - M = 1, - TS = 2, - M2 = 3, + NONE = 0, + M = 1, + TS = 2, + M2 = 3 } -export declare function unionToAnyUniqueAliases( - type: AnyUniqueAliases, - accessor: ( - obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum, - ) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null, -): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; -export declare function unionListToAnyUniqueAliases( - type: AnyUniqueAliases, - accessor: ( - index: number, - obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum, - ) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null, - index: number, -): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; +export declare function unionToAnyUniqueAliases(type: AnyUniqueAliases, accessor: (obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; +export declare function unionListToAnyUniqueAliases(type: AnyUniqueAliases, accessor: (index: number, obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null, index: number): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; diff --git a/tests/ts/my-game/example/any-unique-aliases.js b/tests/ts/my-game/example/any-unique-aliases.js index c10c8f613..3fbcb4f1e 100644 --- a/tests/ts/my-game/example/any-unique-aliases.js +++ b/tests/ts/my-game/example/any-unique-aliases.js @@ -1,42 +1,30 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -import {Monster} from '../../my-game/example/monster.js'; -import {TestSimpleTableWithEnum} from '../../my-game/example/test-simple-table-with-enum.js'; -import {Monster as MyGame_Example2_Monster} from '../../my-game/example2/monster.js'; - +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import { Monster as MyGame_Example2_Monster } from '../example2/monster.js'; +import { Monster } from './monster.js'; +import { TestSimpleTableWithEnum } from './test-simple-table-with-enum.js'; export var AnyUniqueAliases; -(function(AnyUniqueAliases) { -AnyUniqueAliases[AnyUniqueAliases['NONE'] = 0] = 'NONE'; -AnyUniqueAliases[AnyUniqueAliases['M'] = 1] = 'M'; -AnyUniqueAliases[AnyUniqueAliases['TS'] = 2] = 'TS'; -AnyUniqueAliases[AnyUniqueAliases['M2'] = 3] = 'M2'; +(function (AnyUniqueAliases) { + AnyUniqueAliases[AnyUniqueAliases["NONE"] = 0] = "NONE"; + AnyUniqueAliases[AnyUniqueAliases["M"] = 1] = "M"; + AnyUniqueAliases[AnyUniqueAliases["TS"] = 2] = "TS"; + AnyUniqueAliases[AnyUniqueAliases["M2"] = 3] = "M2"; })(AnyUniqueAliases || (AnyUniqueAliases = {})); export function unionToAnyUniqueAliases(type, accessor) { - switch (AnyUniqueAliases[type]) { - case 'NONE': - return null; - case 'M': - return accessor(new Monster()); - case 'TS': - return accessor(new TestSimpleTableWithEnum()); - case 'M2': - return accessor(new MyGame_Example2_Monster()); - default: - return null; - } + switch (AnyUniqueAliases[type]) { + case 'NONE': return null; + case 'M': return accessor(new Monster()); + case 'TS': return accessor(new TestSimpleTableWithEnum()); + case 'M2': return accessor(new MyGame_Example2_Monster()); + default: return null; + } } export function unionListToAnyUniqueAliases(type, accessor, index) { - switch (AnyUniqueAliases[type]) { - case 'NONE': - return null; - case 'M': - return accessor(index, new Monster()); - case 'TS': - return accessor(index, new TestSimpleTableWithEnum()); - case 'M2': - return accessor(index, new MyGame_Example2_Monster()); - default: - return null; - } + switch (AnyUniqueAliases[type]) { + case 'NONE': return null; + case 'M': return accessor(index, new Monster()); + case 'TS': return accessor(index, new TestSimpleTableWithEnum()); + case 'M2': return accessor(index, new MyGame_Example2_Monster()); + default: return null; + } } diff --git a/tests/ts/my-game/example/any.d.ts b/tests/ts/my-game/example/any.d.ts index a5d1b1cfc..6d00e211e 100644 --- a/tests/ts/my-game/example/any.d.ts +++ b/tests/ts/my-game/example/any.d.ts @@ -1,23 +1,11 @@ -import {Monster} from '../../my-game/example/monster.js'; -import {TestSimpleTableWithEnum} from '../../my-game/example/test-simple-table-with-enum.js'; -import {Monster as MyGame_Example2_Monster} from '../../my-game/example2/monster.js'; +import { Monster as MyGame_Example2_Monster } from '../example2/monster.js'; +import { Monster } from './monster.js'; +import { TestSimpleTableWithEnum } from './test-simple-table-with-enum.js'; export declare enum Any { - NONE = 0, - Monster = 1, - TestSimpleTableWithEnum = 2, - MyGame_Example2_Monster = 3, + NONE = 0, + Monster = 1, + TestSimpleTableWithEnum = 2, + MyGame_Example2_Monster = 3 } -export declare function unionToAny( - type: Any, - accessor: ( - obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum, - ) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null, -): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; -export declare function unionListToAny( - type: Any, - accessor: ( - index: number, - obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum, - ) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null, - index: number, -): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; +export declare function unionToAny(type: Any, accessor: (obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; +export declare function unionListToAny(type: Any, accessor: (index: number, obj: Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum) => Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null, index: number): Monster | MyGame_Example2_Monster | TestSimpleTableWithEnum | null; diff --git a/tests/ts/my-game/example/any.js b/tests/ts/my-game/example/any.js index 495f2e824..61a19e9f6 100644 --- a/tests/ts/my-game/example/any.js +++ b/tests/ts/my-game/example/any.js @@ -1,42 +1,30 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -import {Monster} from '../../my-game/example/monster.js'; -import {TestSimpleTableWithEnum} from '../../my-game/example/test-simple-table-with-enum.js'; -import {Monster as MyGame_Example2_Monster} from '../../my-game/example2/monster.js'; - +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import { Monster as MyGame_Example2_Monster } from '../example2/monster.js'; +import { Monster } from './monster.js'; +import { TestSimpleTableWithEnum } from './test-simple-table-with-enum.js'; export var Any; -(function(Any) { -Any[Any['NONE'] = 0] = 'NONE'; -Any[Any['Monster'] = 1] = 'Monster'; -Any[Any['TestSimpleTableWithEnum'] = 2] = 'TestSimpleTableWithEnum'; -Any[Any['MyGame_Example2_Monster'] = 3] = 'MyGame_Example2_Monster'; +(function (Any) { + Any[Any["NONE"] = 0] = "NONE"; + Any[Any["Monster"] = 1] = "Monster"; + Any[Any["TestSimpleTableWithEnum"] = 2] = "TestSimpleTableWithEnum"; + Any[Any["MyGame_Example2_Monster"] = 3] = "MyGame_Example2_Monster"; })(Any || (Any = {})); export function unionToAny(type, accessor) { - switch (Any[type]) { - case 'NONE': - return null; - case 'Monster': - return accessor(new Monster()); - case 'TestSimpleTableWithEnum': - return accessor(new TestSimpleTableWithEnum()); - case 'MyGame_Example2_Monster': - return accessor(new MyGame_Example2_Monster()); - default: - return null; - } + switch (Any[type]) { + case 'NONE': return null; + case 'Monster': return accessor(new Monster()); + case 'TestSimpleTableWithEnum': return accessor(new TestSimpleTableWithEnum()); + case 'MyGame_Example2_Monster': return accessor(new MyGame_Example2_Monster()); + default: return null; + } } export function unionListToAny(type, accessor, index) { - switch (Any[type]) { - case 'NONE': - return null; - case 'Monster': - return accessor(index, new Monster()); - case 'TestSimpleTableWithEnum': - return accessor(index, new TestSimpleTableWithEnum()); - case 'MyGame_Example2_Monster': - return accessor(index, new MyGame_Example2_Monster()); - default: - return null; - } + switch (Any[type]) { + case 'NONE': return null; + case 'Monster': return accessor(index, new Monster()); + case 'TestSimpleTableWithEnum': return accessor(index, new TestSimpleTableWithEnum()); + case 'MyGame_Example2_Monster': return accessor(index, new MyGame_Example2_Monster()); + default: return null; + } } diff --git a/tests/ts/my-game/example/color.d.ts b/tests/ts/my-game/example/color.d.ts index 34e9a4de8..79906f4b1 100644 --- a/tests/ts/my-game/example/color.d.ts +++ b/tests/ts/my-game/example/color.d.ts @@ -2,14 +2,14 @@ * Composite components of Monster color. */ export declare enum Color { - Red = 1, - /** - * \brief color Green - * Green is bit_flag with value (1u << 1) - */ - Green = 2, - /** - * \brief color Blue (1u << 3) - */ - Blue = 8, + Red = 1, + /** + * \brief color Green + * Green is bit_flag with value (1u << 1) + */ + Green = 2, + /** + * \brief color Blue (1u << 3) + */ + Blue = 8 } diff --git a/tests/ts/my-game/example/color.js b/tests/ts/my-game/example/color.js index 0a89fd3e6..5f2f1fd53 100644 --- a/tests/ts/my-game/example/color.js +++ b/tests/ts/my-game/example/color.js @@ -1,19 +1,18 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ /** * Composite components of Monster color. */ export var Color; -(function(Color) { -Color[Color['Red'] = 1] = 'Red'; -/** - * \brief color Green - * Green is bit_flag with value (1u << 1) - */ -Color[Color['Green'] = 2] = 'Green'; -/** - * \brief color Blue (1u << 3) - */ -Color[Color['Blue'] = 8] = 'Blue'; +(function (Color) { + Color[Color["Red"] = 1] = "Red"; + /** + * \brief color Green + * Green is bit_flag with value (1u << 1) + */ + Color[Color["Green"] = 2] = "Green"; + /** + * \brief color Blue (1u << 3) + */ + Color[Color["Blue"] = 8] = "Blue"; })(Color || (Color = {})); diff --git a/tests/ts/my-game/example/long-enum.d.ts b/tests/ts/my-game/example/long-enum.d.ts index 608ddb7c7..72e656f14 100644 --- a/tests/ts/my-game/example/long-enum.d.ts +++ b/tests/ts/my-game/example/long-enum.d.ts @@ -1,5 +1,5 @@ export declare enum LongEnum { - LongOne = '2', - LongTwo = '4', - LongBig = '1099511627776', + LongOne = "2", + LongTwo = "4", + LongBig = "1099511627776" } diff --git a/tests/ts/my-game/example/long-enum.js b/tests/ts/my-game/example/long-enum.js index dfbaca608..100307204 100644 --- a/tests/ts/my-game/example/long-enum.js +++ b/tests/ts/my-game/example/long-enum.js @@ -1,9 +1,8 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var LongEnum; -(function(LongEnum) { -LongEnum['LongOne'] = '2'; -LongEnum['LongTwo'] = '4'; -LongEnum['LongBig'] = '1099511627776'; +(function (LongEnum) { + LongEnum["LongOne"] = "2"; + LongEnum["LongTwo"] = "4"; + LongEnum["LongBig"] = "1099511627776"; })(LongEnum || (LongEnum = {})); diff --git a/tests/ts/my-game/example/monster.d.ts b/tests/ts/my-game/example/monster.d.ts index b2d3a774b..03380f39c 100644 --- a/tests/ts/my-game/example/monster.d.ts +++ b/tests/ts/my-game/example/monster.d.ts @@ -1,674 +1,325 @@ import * as flatbuffers from 'flatbuffers'; -import {Ability, AbilityT} from '../../my-game/example/ability.js'; -import {AnyAmbiguousAliases} from '../../my-game/example/any-ambiguous-aliases.js'; -import {AnyUniqueAliases} from '../../my-game/example/any-unique-aliases.js'; -import {Any} from '../../my-game/example/any.js'; -import {Color} from '../../my-game/example/color.js'; -import {Race} from '../../my-game/example/race.js'; -import {Referrable, ReferrableT} from '../../my-game/example/referrable.js'; -import {Stat, StatT} from '../../my-game/example/stat.js'; -import {TestSimpleTableWithEnumT} from '../../my-game/example/test-simple-table-with-enum.js'; -import {Test, TestT} from '../../my-game/example/test.js'; -import {Vec3, Vec3T} from '../../my-game/example/vec3.js'; -import {MonsterT as MyGame_Example2_MonsterT} from '../../my-game/example2/monster.js'; -import { - InParentNamespace, - InParentNamespaceT, -} from '../../my-game/in-parent-namespace.js'; +import { MonsterT as MyGame_Example2_MonsterT } from '../example2/monster.js'; +import { Ability, AbilityT } from './ability.js'; +import { Any } from './any.js'; +import { AnyAmbiguousAliases } from './any-ambiguous-aliases.js'; +import { AnyUniqueAliases } from './any-unique-aliases.js'; +import { Color } from './color.js'; +import { Race } from './race.js'; +import { Referrable, ReferrableT } from './referrable.js'; +import { Stat, StatT } from './stat.js'; +import { Test, TestT } from './test.js'; +import { TestSimpleTableWithEnumT } from './test-simple-table-with-enum.js'; +import { Vec3, Vec3T } from './vec3.js'; +import { InParentNamespace, InParentNamespaceT } from '../in-parent-namespace.js'; /** * an example documentation comment: "monster object" */ -export declare class Monster - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Monster; - static getRootAsMonster(bb: flatbuffers.ByteBuffer, obj?: Monster): Monster; - static getSizePrefixedRootAsMonster( - bb: flatbuffers.ByteBuffer, - obj?: Monster, - ): Monster; - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; - pos(obj?: Vec3): Vec3 | null; - mana(): number; - mutate_mana(value: number): boolean; - hp(): number; - mutate_hp(value: number): boolean; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - inventory(index: number): number | null; - inventoryLength(): number; - inventoryArray(): Uint8Array | null; - color(): Color; - mutate_color(value: Color): boolean; - testType(): Any; - test(obj: any): any | null; - test4(index: number, obj?: Test): Test | null; - test4Length(): number; - testarrayofstring(index: number): string; - testarrayofstring( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - testarrayofstringLength(): number; - /** - * an example documentation comment: this will end up in the generated code - * multiline too - */ - testarrayoftables(index: number, obj?: Monster): Monster | null; - testarrayoftablesLength(): number; - enemy(obj?: Monster): Monster | null; - testnestedflatbuffer(index: number): number | null; - testnestedflatbufferLength(): number; - testnestedflatbufferArray(): Uint8Array | null; - testempty(obj?: Stat): Stat | null; - testbool(): boolean; - mutate_testbool(value: boolean): boolean; - testhashs32Fnv1(): number; - mutate_testhashs32_fnv1(value: number): boolean; - testhashu32Fnv1(): number; - mutate_testhashu32_fnv1(value: number): boolean; - testhashs64Fnv1(): bigint; - mutate_testhashs64_fnv1(value: bigint): boolean; - testhashu64Fnv1(): bigint; - mutate_testhashu64_fnv1(value: bigint): boolean; - testhashs32Fnv1a(): number; - mutate_testhashs32_fnv1a(value: number): boolean; - testhashu32Fnv1a(): number; - mutate_testhashu32_fnv1a(value: number): boolean; - testhashs64Fnv1a(): bigint; - mutate_testhashs64_fnv1a(value: bigint): boolean; - testhashu64Fnv1a(): bigint; - mutate_testhashu64_fnv1a(value: bigint): boolean; - testarrayofbools(index: number): boolean | null; - testarrayofboolsLength(): number; - testarrayofboolsArray(): Int8Array | null; - testf(): number; - mutate_testf(value: number): boolean; - testf2(): number; - mutate_testf2(value: number): boolean; - testf3(): number; - mutate_testf3(value: number): boolean; - testarrayofstring2(index: number): string; - testarrayofstring2( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - testarrayofstring2Length(): number; - testarrayofsortedstruct(index: number, obj?: Ability): Ability | null; - testarrayofsortedstructLength(): number; - flex(index: number): number | null; - flexLength(): number; - flexArray(): Uint8Array | null; - test5(index: number, obj?: Test): Test | null; - test5Length(): number; - vectorOfLongs(index: number): bigint | null; - vectorOfLongsLength(): number; - vectorOfDoubles(index: number): number | null; - vectorOfDoublesLength(): number; - vectorOfDoublesArray(): Float64Array | null; - parentNamespaceTest(obj?: InParentNamespace): InParentNamespace | null; - vectorOfReferrables(index: number, obj?: Referrable): Referrable | null; - vectorOfReferrablesLength(): number; - singleWeakReference(): bigint; - mutate_single_weak_reference(value: bigint): boolean; - vectorOfWeakReferences(index: number): bigint | null; - vectorOfWeakReferencesLength(): number; - vectorOfStrongReferrables(index: number, obj?: Referrable): Referrable | null; - vectorOfStrongReferrablesLength(): number; - coOwningReference(): bigint; - mutate_co_owning_reference(value: bigint): boolean; - vectorOfCoOwningReferences(index: number): bigint | null; - vectorOfCoOwningReferencesLength(): number; - nonOwningReference(): bigint; - mutate_non_owning_reference(value: bigint): boolean; - vectorOfNonOwningReferences(index: number): bigint | null; - vectorOfNonOwningReferencesLength(): number; - anyUniqueType(): AnyUniqueAliases; - anyUnique(obj: any): any | null; - anyAmbiguousType(): AnyAmbiguousAliases; - anyAmbiguous(obj: any): any | null; - vectorOfEnums(index: number): Color | null; - vectorOfEnumsLength(): number; - vectorOfEnumsArray(): Uint8Array | null; - signedEnum(): Race; - mutate_signed_enum(value: Race): boolean; - testrequirednestedflatbuffer(index: number): number | null; - testrequirednestedflatbufferLength(): number; - testrequirednestedflatbufferArray(): Uint8Array | null; - scalarKeySortedTables(index: number, obj?: Stat): Stat | null; - scalarKeySortedTablesLength(): number; - nativeInline(obj?: Test): Test | null; - longEnumNonEnumDefault(): bigint; - mutate_long_enum_non_enum_default(value: bigint): boolean; - longEnumNormalDefault(): bigint; - mutate_long_enum_normal_default(value: bigint): boolean; - nanDefault(): number; - mutate_nan_default(value: number): boolean; - infDefault(): number; - mutate_inf_default(value: number): boolean; - positiveInfDefault(): number; - mutate_positive_inf_default(value: number): boolean; - infinityDefault(): number; - mutate_infinity_default(value: number): boolean; - positiveInfinityDefault(): number; - mutate_positive_infinity_default(value: number): boolean; - negativeInfDefault(): number; - mutate_negative_inf_default(value: number): boolean; - negativeInfinityDefault(): number; - mutate_negative_infinity_default(value: number): boolean; - doubleInfDefault(): number; - mutate_double_inf_default(value: number): boolean; - static getFullyQualifiedName(): string; - static startMonster(builder: flatbuffers.Builder): void; - static addPos( - builder: flatbuffers.Builder, - posOffset: flatbuffers.Offset, - ): void; - static addMana(builder: flatbuffers.Builder, mana: number): void; - static addHp(builder: flatbuffers.Builder, hp: number): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addInventory( - builder: flatbuffers.Builder, - inventoryOffset: flatbuffers.Offset, - ): void; - static createInventoryVector( - builder: flatbuffers.Builder, - data: number[] | Uint8Array, - ): flatbuffers.Offset; - static startInventoryVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addColor(builder: flatbuffers.Builder, color: Color): void; - static addTestType(builder: flatbuffers.Builder, testType: Any): void; - static addTest( - builder: flatbuffers.Builder, - testOffset: flatbuffers.Offset, - ): void; - static addTest4( - builder: flatbuffers.Builder, - test4Offset: flatbuffers.Offset, - ): void; - static startTest4Vector(builder: flatbuffers.Builder, numElems: number): void; - static addTestarrayofstring( - builder: flatbuffers.Builder, - testarrayofstringOffset: flatbuffers.Offset, - ): void; - static createTestarrayofstringVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startTestarrayofstringVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addTestarrayoftables( - builder: flatbuffers.Builder, - testarrayoftablesOffset: flatbuffers.Offset, - ): void; - static createTestarrayoftablesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startTestarrayoftablesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addEnemy( - builder: flatbuffers.Builder, - enemyOffset: flatbuffers.Offset, - ): void; - static addTestnestedflatbuffer( - builder: flatbuffers.Builder, - testnestedflatbufferOffset: flatbuffers.Offset, - ): void; - static createTestnestedflatbufferVector( - builder: flatbuffers.Builder, - data: number[] | Uint8Array, - ): flatbuffers.Offset; - static startTestnestedflatbufferVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addTestempty( - builder: flatbuffers.Builder, - testemptyOffset: flatbuffers.Offset, - ): void; - static addTestbool(builder: flatbuffers.Builder, testbool: boolean): void; - static addTesthashs32Fnv1( - builder: flatbuffers.Builder, - testhashs32Fnv1: number, - ): void; - static addTesthashu32Fnv1( - builder: flatbuffers.Builder, - testhashu32Fnv1: number, - ): void; - static addTesthashs64Fnv1( - builder: flatbuffers.Builder, - testhashs64Fnv1: bigint, - ): void; - static addTesthashu64Fnv1( - builder: flatbuffers.Builder, - testhashu64Fnv1: bigint, - ): void; - static addTesthashs32Fnv1a( - builder: flatbuffers.Builder, - testhashs32Fnv1a: number, - ): void; - static addTesthashu32Fnv1a( - builder: flatbuffers.Builder, - testhashu32Fnv1a: number, - ): void; - static addTesthashs64Fnv1a( - builder: flatbuffers.Builder, - testhashs64Fnv1a: bigint, - ): void; - static addTesthashu64Fnv1a( - builder: flatbuffers.Builder, - testhashu64Fnv1a: bigint, - ): void; - static addTestarrayofbools( - builder: flatbuffers.Builder, - testarrayofboolsOffset: flatbuffers.Offset, - ): void; - static createTestarrayofboolsVector( - builder: flatbuffers.Builder, - data: boolean[], - ): flatbuffers.Offset; - static startTestarrayofboolsVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addTestf(builder: flatbuffers.Builder, testf: number): void; - static addTestf2(builder: flatbuffers.Builder, testf2: number): void; - static addTestf3(builder: flatbuffers.Builder, testf3: number): void; - static addTestarrayofstring2( - builder: flatbuffers.Builder, - testarrayofstring2Offset: flatbuffers.Offset, - ): void; - static createTestarrayofstring2Vector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startTestarrayofstring2Vector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addTestarrayofsortedstruct( - builder: flatbuffers.Builder, - testarrayofsortedstructOffset: flatbuffers.Offset, - ): void; - static startTestarrayofsortedstructVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addFlex( - builder: flatbuffers.Builder, - flexOffset: flatbuffers.Offset, - ): void; - static createFlexVector( - builder: flatbuffers.Builder, - data: number[] | Uint8Array, - ): flatbuffers.Offset; - static startFlexVector(builder: flatbuffers.Builder, numElems: number): void; - static addTest5( - builder: flatbuffers.Builder, - test5Offset: flatbuffers.Offset, - ): void; - static startTest5Vector(builder: flatbuffers.Builder, numElems: number): void; - static addVectorOfLongs( - builder: flatbuffers.Builder, - vectorOfLongsOffset: flatbuffers.Offset, - ): void; - static createVectorOfLongsVector( - builder: flatbuffers.Builder, - data: bigint[], - ): flatbuffers.Offset; - static startVectorOfLongsVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addVectorOfDoubles( - builder: flatbuffers.Builder, - vectorOfDoublesOffset: flatbuffers.Offset, - ): void; - static createVectorOfDoublesVector( - builder: flatbuffers.Builder, - data: number[] | Float64Array, - ): flatbuffers.Offset; - /** - * @deprecated This Uint8Array overload will be removed in the future. - */ - static createVectorOfDoublesVector( - builder: flatbuffers.Builder, - data: number[] | Uint8Array, - ): flatbuffers.Offset; - static startVectorOfDoublesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addParentNamespaceTest( - builder: flatbuffers.Builder, - parentNamespaceTestOffset: flatbuffers.Offset, - ): void; - static addVectorOfReferrables( - builder: flatbuffers.Builder, - vectorOfReferrablesOffset: flatbuffers.Offset, - ): void; - static createVectorOfReferrablesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startVectorOfReferrablesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addSingleWeakReference( - builder: flatbuffers.Builder, - singleWeakReference: bigint, - ): void; - static addVectorOfWeakReferences( - builder: flatbuffers.Builder, - vectorOfWeakReferencesOffset: flatbuffers.Offset, - ): void; - static createVectorOfWeakReferencesVector( - builder: flatbuffers.Builder, - data: bigint[], - ): flatbuffers.Offset; - static startVectorOfWeakReferencesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addVectorOfStrongReferrables( - builder: flatbuffers.Builder, - vectorOfStrongReferrablesOffset: flatbuffers.Offset, - ): void; - static createVectorOfStrongReferrablesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startVectorOfStrongReferrablesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addCoOwningReference( - builder: flatbuffers.Builder, - coOwningReference: bigint, - ): void; - static addVectorOfCoOwningReferences( - builder: flatbuffers.Builder, - vectorOfCoOwningReferencesOffset: flatbuffers.Offset, - ): void; - static createVectorOfCoOwningReferencesVector( - builder: flatbuffers.Builder, - data: bigint[], - ): flatbuffers.Offset; - static startVectorOfCoOwningReferencesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addNonOwningReference( - builder: flatbuffers.Builder, - nonOwningReference: bigint, - ): void; - static addVectorOfNonOwningReferences( - builder: flatbuffers.Builder, - vectorOfNonOwningReferencesOffset: flatbuffers.Offset, - ): void; - static createVectorOfNonOwningReferencesVector( - builder: flatbuffers.Builder, - data: bigint[], - ): flatbuffers.Offset; - static startVectorOfNonOwningReferencesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addAnyUniqueType( - builder: flatbuffers.Builder, - anyUniqueType: AnyUniqueAliases, - ): void; - static addAnyUnique( - builder: flatbuffers.Builder, - anyUniqueOffset: flatbuffers.Offset, - ): void; - static addAnyAmbiguousType( - builder: flatbuffers.Builder, - anyAmbiguousType: AnyAmbiguousAliases, - ): void; - static addAnyAmbiguous( - builder: flatbuffers.Builder, - anyAmbiguousOffset: flatbuffers.Offset, - ): void; - static addVectorOfEnums( - builder: flatbuffers.Builder, - vectorOfEnumsOffset: flatbuffers.Offset, - ): void; - static createVectorOfEnumsVector( - builder: flatbuffers.Builder, - data: Color[], - ): flatbuffers.Offset; - static startVectorOfEnumsVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addSignedEnum(builder: flatbuffers.Builder, signedEnum: Race): void; - static addTestrequirednestedflatbuffer( - builder: flatbuffers.Builder, - testrequirednestedflatbufferOffset: flatbuffers.Offset, - ): void; - static createTestrequirednestedflatbufferVector( - builder: flatbuffers.Builder, - data: number[] | Uint8Array, - ): flatbuffers.Offset; - static startTestrequirednestedflatbufferVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addScalarKeySortedTables( - builder: flatbuffers.Builder, - scalarKeySortedTablesOffset: flatbuffers.Offset, - ): void; - static createScalarKeySortedTablesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startScalarKeySortedTablesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addNativeInline( - builder: flatbuffers.Builder, - nativeInlineOffset: flatbuffers.Offset, - ): void; - static addLongEnumNonEnumDefault( - builder: flatbuffers.Builder, - longEnumNonEnumDefault: bigint, - ): void; - static addLongEnumNormalDefault( - builder: flatbuffers.Builder, - longEnumNormalDefault: bigint, - ): void; - static addNanDefault(builder: flatbuffers.Builder, nanDefault: number): void; - static addInfDefault(builder: flatbuffers.Builder, infDefault: number): void; - static addPositiveInfDefault( - builder: flatbuffers.Builder, - positiveInfDefault: number, - ): void; - static addInfinityDefault( - builder: flatbuffers.Builder, - infinityDefault: number, - ): void; - static addPositiveInfinityDefault( - builder: flatbuffers.Builder, - positiveInfinityDefault: number, - ): void; - static addNegativeInfDefault( - builder: flatbuffers.Builder, - negativeInfDefault: number, - ): void; - static addNegativeInfinityDefault( - builder: flatbuffers.Builder, - negativeInfinityDefault: number, - ): void; - static addDoubleInfDefault( - builder: flatbuffers.Builder, - doubleInfDefault: number, - ): void; - static endMonster(builder: flatbuffers.Builder): flatbuffers.Offset; - static finishMonsterBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static finishSizePrefixedMonsterBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): Monster; - unpack(): MonsterT; - unpackTo(_o: MonsterT): void; +export declare class Monster implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Monster; + static getRootAsMonster(bb: flatbuffers.ByteBuffer, obj?: Monster): Monster; + static getSizePrefixedRootAsMonster(bb: flatbuffers.ByteBuffer, obj?: Monster): Monster; + static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; + pos(obj?: Vec3): Vec3 | null; + mana(): number; + mutate_mana(value: number): boolean; + hp(): number; + mutate_hp(value: number): boolean; + name(): string; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + inventory(index: number): number | null; + inventoryLength(): number; + inventoryArray(): Uint8Array | null; + color(): Color; + mutate_color(value: Color): boolean; + testType(): Any; + test(obj: any): any | null; + test4(index: number, obj?: Test): Test | null; + test4Length(): number; + testarrayofstring(index: number): string; + testarrayofstring(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + testarrayofstringLength(): number; + /** + * an example documentation comment: this will end up in the generated code + * multiline too + */ + testarrayoftables(index: number, obj?: Monster): Monster | null; + testarrayoftablesLength(): number; + enemy(obj?: Monster): Monster | null; + testnestedflatbuffer(index: number): number | null; + testnestedflatbufferLength(): number; + testnestedflatbufferArray(): Uint8Array | null; + testempty(obj?: Stat): Stat | null; + testbool(): boolean; + mutate_testbool(value: boolean): boolean; + testhashs32Fnv1(): number; + mutate_testhashs32_fnv1(value: number): boolean; + testhashu32Fnv1(): number; + mutate_testhashu32_fnv1(value: number): boolean; + testhashs64Fnv1(): bigint; + mutate_testhashs64_fnv1(value: bigint): boolean; + testhashu64Fnv1(): bigint; + mutate_testhashu64_fnv1(value: bigint): boolean; + testhashs32Fnv1a(): number; + mutate_testhashs32_fnv1a(value: number): boolean; + testhashu32Fnv1a(): number; + mutate_testhashu32_fnv1a(value: number): boolean; + testhashs64Fnv1a(): bigint; + mutate_testhashs64_fnv1a(value: bigint): boolean; + testhashu64Fnv1a(): bigint; + mutate_testhashu64_fnv1a(value: bigint): boolean; + testarrayofbools(index: number): boolean | null; + testarrayofboolsLength(): number; + testarrayofboolsArray(): Int8Array | null; + testf(): number; + mutate_testf(value: number): boolean; + testf2(): number; + mutate_testf2(value: number): boolean; + testf3(): number; + mutate_testf3(value: number): boolean; + testarrayofstring2(index: number): string; + testarrayofstring2(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + testarrayofstring2Length(): number; + testarrayofsortedstruct(index: number, obj?: Ability): Ability | null; + testarrayofsortedstructLength(): number; + flex(index: number): number | null; + flexLength(): number; + flexArray(): Uint8Array | null; + test5(index: number, obj?: Test): Test | null; + test5Length(): number; + vectorOfLongs(index: number): bigint | null; + vectorOfLongsLength(): number; + vectorOfDoubles(index: number): number | null; + vectorOfDoublesLength(): number; + vectorOfDoublesArray(): Float64Array | null; + parentNamespaceTest(obj?: InParentNamespace): InParentNamespace | null; + vectorOfReferrables(index: number, obj?: Referrable): Referrable | null; + vectorOfReferrablesLength(): number; + singleWeakReference(): bigint; + mutate_single_weak_reference(value: bigint): boolean; + vectorOfWeakReferences(index: number): bigint | null; + vectorOfWeakReferencesLength(): number; + vectorOfStrongReferrables(index: number, obj?: Referrable): Referrable | null; + vectorOfStrongReferrablesLength(): number; + coOwningReference(): bigint; + mutate_co_owning_reference(value: bigint): boolean; + vectorOfCoOwningReferences(index: number): bigint | null; + vectorOfCoOwningReferencesLength(): number; + nonOwningReference(): bigint; + mutate_non_owning_reference(value: bigint): boolean; + vectorOfNonOwningReferences(index: number): bigint | null; + vectorOfNonOwningReferencesLength(): number; + anyUniqueType(): AnyUniqueAliases; + anyUnique(obj: any): any | null; + anyAmbiguousType(): AnyAmbiguousAliases; + anyAmbiguous(obj: any): any | null; + vectorOfEnums(index: number): Color | null; + vectorOfEnumsLength(): number; + vectorOfEnumsArray(): Uint8Array | null; + signedEnum(): Race; + mutate_signed_enum(value: Race): boolean; + testrequirednestedflatbuffer(index: number): number | null; + testrequirednestedflatbufferLength(): number; + testrequirednestedflatbufferArray(): Uint8Array | null; + scalarKeySortedTables(index: number, obj?: Stat): Stat | null; + scalarKeySortedTablesLength(): number; + nativeInline(obj?: Test): Test | null; + longEnumNonEnumDefault(): bigint; + mutate_long_enum_non_enum_default(value: bigint): boolean; + longEnumNormalDefault(): bigint; + mutate_long_enum_normal_default(value: bigint): boolean; + nanDefault(): number; + mutate_nan_default(value: number): boolean; + infDefault(): number; + mutate_inf_default(value: number): boolean; + positiveInfDefault(): number; + mutate_positive_inf_default(value: number): boolean; + infinityDefault(): number; + mutate_infinity_default(value: number): boolean; + positiveInfinityDefault(): number; + mutate_positive_infinity_default(value: number): boolean; + negativeInfDefault(): number; + mutate_negative_inf_default(value: number): boolean; + negativeInfinityDefault(): number; + mutate_negative_infinity_default(value: number): boolean; + doubleInfDefault(): number; + mutate_double_inf_default(value: number): boolean; + static getFullyQualifiedName(): "MyGame.Example.Monster"; + static startMonster(builder: flatbuffers.Builder): void; + static addPos(builder: flatbuffers.Builder, posOffset: flatbuffers.Offset): void; + static addMana(builder: flatbuffers.Builder, mana: number): void; + static addHp(builder: flatbuffers.Builder, hp: number): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addInventory(builder: flatbuffers.Builder, inventoryOffset: flatbuffers.Offset): void; + static createInventoryVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset; + static startInventoryVector(builder: flatbuffers.Builder, numElems: number): void; + static addColor(builder: flatbuffers.Builder, color: Color): void; + static addTestType(builder: flatbuffers.Builder, testType: Any): void; + static addTest(builder: flatbuffers.Builder, testOffset: flatbuffers.Offset): void; + static addTest4(builder: flatbuffers.Builder, test4Offset: flatbuffers.Offset): void; + static startTest4Vector(builder: flatbuffers.Builder, numElems: number): void; + static addTestarrayofstring(builder: flatbuffers.Builder, testarrayofstringOffset: flatbuffers.Offset): void; + static createTestarrayofstringVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startTestarrayofstringVector(builder: flatbuffers.Builder, numElems: number): void; + static addTestarrayoftables(builder: flatbuffers.Builder, testarrayoftablesOffset: flatbuffers.Offset): void; + static createTestarrayoftablesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startTestarrayoftablesVector(builder: flatbuffers.Builder, numElems: number): void; + static addEnemy(builder: flatbuffers.Builder, enemyOffset: flatbuffers.Offset): void; + static addTestnestedflatbuffer(builder: flatbuffers.Builder, testnestedflatbufferOffset: flatbuffers.Offset): void; + static createTestnestedflatbufferVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset; + static startTestnestedflatbufferVector(builder: flatbuffers.Builder, numElems: number): void; + static addTestempty(builder: flatbuffers.Builder, testemptyOffset: flatbuffers.Offset): void; + static addTestbool(builder: flatbuffers.Builder, testbool: boolean): void; + static addTesthashs32Fnv1(builder: flatbuffers.Builder, testhashs32Fnv1: number): void; + static addTesthashu32Fnv1(builder: flatbuffers.Builder, testhashu32Fnv1: number): void; + static addTesthashs64Fnv1(builder: flatbuffers.Builder, testhashs64Fnv1: bigint): void; + static addTesthashu64Fnv1(builder: flatbuffers.Builder, testhashu64Fnv1: bigint): void; + static addTesthashs32Fnv1a(builder: flatbuffers.Builder, testhashs32Fnv1a: number): void; + static addTesthashu32Fnv1a(builder: flatbuffers.Builder, testhashu32Fnv1a: number): void; + static addTesthashs64Fnv1a(builder: flatbuffers.Builder, testhashs64Fnv1a: bigint): void; + static addTesthashu64Fnv1a(builder: flatbuffers.Builder, testhashu64Fnv1a: bigint): void; + static addTestarrayofbools(builder: flatbuffers.Builder, testarrayofboolsOffset: flatbuffers.Offset): void; + static createTestarrayofboolsVector(builder: flatbuffers.Builder, data: boolean[]): flatbuffers.Offset; + static startTestarrayofboolsVector(builder: flatbuffers.Builder, numElems: number): void; + static addTestf(builder: flatbuffers.Builder, testf: number): void; + static addTestf2(builder: flatbuffers.Builder, testf2: number): void; + static addTestf3(builder: flatbuffers.Builder, testf3: number): void; + static addTestarrayofstring2(builder: flatbuffers.Builder, testarrayofstring2Offset: flatbuffers.Offset): void; + static createTestarrayofstring2Vector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startTestarrayofstring2Vector(builder: flatbuffers.Builder, numElems: number): void; + static addTestarrayofsortedstruct(builder: flatbuffers.Builder, testarrayofsortedstructOffset: flatbuffers.Offset): void; + static startTestarrayofsortedstructVector(builder: flatbuffers.Builder, numElems: number): void; + static addFlex(builder: flatbuffers.Builder, flexOffset: flatbuffers.Offset): void; + static createFlexVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset; + static startFlexVector(builder: flatbuffers.Builder, numElems: number): void; + static addTest5(builder: flatbuffers.Builder, test5Offset: flatbuffers.Offset): void; + static startTest5Vector(builder: flatbuffers.Builder, numElems: number): void; + static addVectorOfLongs(builder: flatbuffers.Builder, vectorOfLongsOffset: flatbuffers.Offset): void; + static createVectorOfLongsVector(builder: flatbuffers.Builder, data: bigint[]): flatbuffers.Offset; + static startVectorOfLongsVector(builder: flatbuffers.Builder, numElems: number): void; + static addVectorOfDoubles(builder: flatbuffers.Builder, vectorOfDoublesOffset: flatbuffers.Offset): void; + static createVectorOfDoublesVector(builder: flatbuffers.Builder, data: number[] | Float64Array): flatbuffers.Offset; + /** + * @deprecated This Uint8Array overload will be removed in the future. + */ + static createVectorOfDoublesVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset; + static startVectorOfDoublesVector(builder: flatbuffers.Builder, numElems: number): void; + static addParentNamespaceTest(builder: flatbuffers.Builder, parentNamespaceTestOffset: flatbuffers.Offset): void; + static addVectorOfReferrables(builder: flatbuffers.Builder, vectorOfReferrablesOffset: flatbuffers.Offset): void; + static createVectorOfReferrablesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startVectorOfReferrablesVector(builder: flatbuffers.Builder, numElems: number): void; + static addSingleWeakReference(builder: flatbuffers.Builder, singleWeakReference: bigint): void; + static addVectorOfWeakReferences(builder: flatbuffers.Builder, vectorOfWeakReferencesOffset: flatbuffers.Offset): void; + static createVectorOfWeakReferencesVector(builder: flatbuffers.Builder, data: bigint[]): flatbuffers.Offset; + static startVectorOfWeakReferencesVector(builder: flatbuffers.Builder, numElems: number): void; + static addVectorOfStrongReferrables(builder: flatbuffers.Builder, vectorOfStrongReferrablesOffset: flatbuffers.Offset): void; + static createVectorOfStrongReferrablesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startVectorOfStrongReferrablesVector(builder: flatbuffers.Builder, numElems: number): void; + static addCoOwningReference(builder: flatbuffers.Builder, coOwningReference: bigint): void; + static addVectorOfCoOwningReferences(builder: flatbuffers.Builder, vectorOfCoOwningReferencesOffset: flatbuffers.Offset): void; + static createVectorOfCoOwningReferencesVector(builder: flatbuffers.Builder, data: bigint[]): flatbuffers.Offset; + static startVectorOfCoOwningReferencesVector(builder: flatbuffers.Builder, numElems: number): void; + static addNonOwningReference(builder: flatbuffers.Builder, nonOwningReference: bigint): void; + static addVectorOfNonOwningReferences(builder: flatbuffers.Builder, vectorOfNonOwningReferencesOffset: flatbuffers.Offset): void; + static createVectorOfNonOwningReferencesVector(builder: flatbuffers.Builder, data: bigint[]): flatbuffers.Offset; + static startVectorOfNonOwningReferencesVector(builder: flatbuffers.Builder, numElems: number): void; + static addAnyUniqueType(builder: flatbuffers.Builder, anyUniqueType: AnyUniqueAliases): void; + static addAnyUnique(builder: flatbuffers.Builder, anyUniqueOffset: flatbuffers.Offset): void; + static addAnyAmbiguousType(builder: flatbuffers.Builder, anyAmbiguousType: AnyAmbiguousAliases): void; + static addAnyAmbiguous(builder: flatbuffers.Builder, anyAmbiguousOffset: flatbuffers.Offset): void; + static addVectorOfEnums(builder: flatbuffers.Builder, vectorOfEnumsOffset: flatbuffers.Offset): void; + static createVectorOfEnumsVector(builder: flatbuffers.Builder, data: Color[]): flatbuffers.Offset; + static startVectorOfEnumsVector(builder: flatbuffers.Builder, numElems: number): void; + static addSignedEnum(builder: flatbuffers.Builder, signedEnum: Race): void; + static addTestrequirednestedflatbuffer(builder: flatbuffers.Builder, testrequirednestedflatbufferOffset: flatbuffers.Offset): void; + static createTestrequirednestedflatbufferVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset; + static startTestrequirednestedflatbufferVector(builder: flatbuffers.Builder, numElems: number): void; + static addScalarKeySortedTables(builder: flatbuffers.Builder, scalarKeySortedTablesOffset: flatbuffers.Offset): void; + static createScalarKeySortedTablesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startScalarKeySortedTablesVector(builder: flatbuffers.Builder, numElems: number): void; + static addNativeInline(builder: flatbuffers.Builder, nativeInlineOffset: flatbuffers.Offset): void; + static addLongEnumNonEnumDefault(builder: flatbuffers.Builder, longEnumNonEnumDefault: bigint): void; + static addLongEnumNormalDefault(builder: flatbuffers.Builder, longEnumNormalDefault: bigint): void; + static addNanDefault(builder: flatbuffers.Builder, nanDefault: number): void; + static addInfDefault(builder: flatbuffers.Builder, infDefault: number): void; + static addPositiveInfDefault(builder: flatbuffers.Builder, positiveInfDefault: number): void; + static addInfinityDefault(builder: flatbuffers.Builder, infinityDefault: number): void; + static addPositiveInfinityDefault(builder: flatbuffers.Builder, positiveInfinityDefault: number): void; + static addNegativeInfDefault(builder: flatbuffers.Builder, negativeInfDefault: number): void; + static addNegativeInfinityDefault(builder: flatbuffers.Builder, negativeInfinityDefault: number): void; + static addDoubleInfDefault(builder: flatbuffers.Builder, doubleInfDefault: number): void; + static endMonster(builder: flatbuffers.Builder): flatbuffers.Offset; + static finishMonsterBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static finishSizePrefixedMonsterBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): Monster; + unpack(): MonsterT; + unpackTo(_o: MonsterT): void; } export declare class MonsterT implements flatbuffers.IGeneratedObject { - pos: Vec3T | null; - mana: number; - hp: number; - name: string | Uint8Array | null; - inventory: number[]; - color: Color; - testType: Any; - test: MonsterT | MyGame_Example2_MonsterT | TestSimpleTableWithEnumT | null; - test4: TestT[]; - testarrayofstring: string[]; - testarrayoftables: MonsterT[]; - enemy: MonsterT | null; - testnestedflatbuffer: number[]; - testempty: StatT | null; - testbool: boolean; - testhashs32Fnv1: number; - testhashu32Fnv1: number; - testhashs64Fnv1: bigint; - testhashu64Fnv1: bigint; - testhashs32Fnv1a: number; - testhashu32Fnv1a: number; - testhashs64Fnv1a: bigint; - testhashu64Fnv1a: bigint; - testarrayofbools: boolean[]; - testf: number; - testf2: number; - testf3: number; - testarrayofstring2: string[]; - testarrayofsortedstruct: AbilityT[]; - flex: number[]; - test5: TestT[]; - vectorOfLongs: bigint[]; - vectorOfDoubles: number[]; - parentNamespaceTest: InParentNamespaceT | null; - vectorOfReferrables: ReferrableT[]; - singleWeakReference: bigint; - vectorOfWeakReferences: bigint[]; - vectorOfStrongReferrables: ReferrableT[]; - coOwningReference: bigint; - vectorOfCoOwningReferences: bigint[]; - nonOwningReference: bigint; - vectorOfNonOwningReferences: bigint[]; - anyUniqueType: AnyUniqueAliases; - anyUnique: - | MonsterT - | MyGame_Example2_MonsterT - | TestSimpleTableWithEnumT - | null; - anyAmbiguousType: AnyAmbiguousAliases; - anyAmbiguous: MonsterT | null; - vectorOfEnums: Color[]; - signedEnum: Race; - testrequirednestedflatbuffer: number[]; - scalarKeySortedTables: StatT[]; - nativeInline: TestT | null; - longEnumNonEnumDefault: bigint; - longEnumNormalDefault: bigint; - nanDefault: number; - infDefault: number; - positiveInfDefault: number; - infinityDefault: number; - positiveInfinityDefault: number; - negativeInfDefault: number; - negativeInfinityDefault: number; - doubleInfDefault: number; - constructor( - pos?: Vec3T | null, - mana?: number, - hp?: number, - name?: string | Uint8Array | null, - inventory?: number[], - color?: Color, - testType?: Any, - test?: - | MonsterT - | MyGame_Example2_MonsterT - | TestSimpleTableWithEnumT - | null, - test4?: TestT[], - testarrayofstring?: string[], - testarrayoftables?: MonsterT[], - enemy?: MonsterT | null, - testnestedflatbuffer?: number[], - testempty?: StatT | null, - testbool?: boolean, - testhashs32Fnv1?: number, - testhashu32Fnv1?: number, - testhashs64Fnv1?: bigint, - testhashu64Fnv1?: bigint, - testhashs32Fnv1a?: number, - testhashu32Fnv1a?: number, - testhashs64Fnv1a?: bigint, - testhashu64Fnv1a?: bigint, - testarrayofbools?: boolean[], - testf?: number, - testf2?: number, - testf3?: number, - testarrayofstring2?: string[], - testarrayofsortedstruct?: AbilityT[], - flex?: number[], - test5?: TestT[], - vectorOfLongs?: bigint[], - vectorOfDoubles?: number[], - parentNamespaceTest?: InParentNamespaceT | null, - vectorOfReferrables?: ReferrableT[], - singleWeakReference?: bigint, - vectorOfWeakReferences?: bigint[], - vectorOfStrongReferrables?: ReferrableT[], - coOwningReference?: bigint, - vectorOfCoOwningReferences?: bigint[], - nonOwningReference?: bigint, - vectorOfNonOwningReferences?: bigint[], - anyUniqueType?: AnyUniqueAliases, - anyUnique?: - | MonsterT - | MyGame_Example2_MonsterT - | TestSimpleTableWithEnumT - | null, - anyAmbiguousType?: AnyAmbiguousAliases, - anyAmbiguous?: MonsterT | null, - vectorOfEnums?: Color[], - signedEnum?: Race, - testrequirednestedflatbuffer?: number[], - scalarKeySortedTables?: StatT[], - nativeInline?: TestT | null, - longEnumNonEnumDefault?: bigint, - longEnumNormalDefault?: bigint, - nanDefault?: number, - infDefault?: number, - positiveInfDefault?: number, - infinityDefault?: number, - positiveInfinityDefault?: number, - negativeInfDefault?: number, - negativeInfinityDefault?: number, - doubleInfDefault?: number, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + pos: Vec3T | null; + mana: number; + hp: number; + name: string | Uint8Array | null; + inventory: (number)[]; + color: Color; + testType: Any; + test: MonsterT | MyGame_Example2_MonsterT | TestSimpleTableWithEnumT | null; + test4: (TestT)[]; + testarrayofstring: (string)[]; + testarrayoftables: (MonsterT)[]; + enemy: MonsterT | null; + testnestedflatbuffer: (number)[]; + testempty: StatT | null; + testbool: boolean; + testhashs32Fnv1: number; + testhashu32Fnv1: number; + testhashs64Fnv1: bigint; + testhashu64Fnv1: bigint; + testhashs32Fnv1a: number; + testhashu32Fnv1a: number; + testhashs64Fnv1a: bigint; + testhashu64Fnv1a: bigint; + testarrayofbools: (boolean)[]; + testf: number; + testf2: number; + testf3: number; + testarrayofstring2: (string)[]; + testarrayofsortedstruct: (AbilityT)[]; + flex: (number)[]; + test5: (TestT)[]; + vectorOfLongs: (bigint)[]; + vectorOfDoubles: (number)[]; + parentNamespaceTest: InParentNamespaceT | null; + vectorOfReferrables: (ReferrableT)[]; + singleWeakReference: bigint; + vectorOfWeakReferences: (bigint)[]; + vectorOfStrongReferrables: (ReferrableT)[]; + coOwningReference: bigint; + vectorOfCoOwningReferences: (bigint)[]; + nonOwningReference: bigint; + vectorOfNonOwningReferences: (bigint)[]; + anyUniqueType: AnyUniqueAliases; + anyUnique: MonsterT | MyGame_Example2_MonsterT | TestSimpleTableWithEnumT | null; + anyAmbiguousType: AnyAmbiguousAliases; + anyAmbiguous: MonsterT | null; + vectorOfEnums: (Color)[]; + signedEnum: Race; + testrequirednestedflatbuffer: (number)[]; + scalarKeySortedTables: (StatT)[]; + nativeInline: TestT | null; + longEnumNonEnumDefault: bigint; + longEnumNormalDefault: bigint; + nanDefault: number; + infDefault: number; + positiveInfDefault: number; + infinityDefault: number; + positiveInfinityDefault: number; + negativeInfDefault: number; + negativeInfinityDefault: number; + doubleInfDefault: number; + constructor(pos?: Vec3T | null, mana?: number, hp?: number, name?: string | Uint8Array | null, inventory?: (number)[], color?: Color, testType?: Any, test?: MonsterT | MyGame_Example2_MonsterT | TestSimpleTableWithEnumT | null, test4?: (TestT)[], testarrayofstring?: (string)[], testarrayoftables?: (MonsterT)[], enemy?: MonsterT | null, testnestedflatbuffer?: (number)[], testempty?: StatT | null, testbool?: boolean, testhashs32Fnv1?: number, testhashu32Fnv1?: number, testhashs64Fnv1?: bigint, testhashu64Fnv1?: bigint, testhashs32Fnv1a?: number, testhashu32Fnv1a?: number, testhashs64Fnv1a?: bigint, testhashu64Fnv1a?: bigint, testarrayofbools?: (boolean)[], testf?: number, testf2?: number, testf3?: number, testarrayofstring2?: (string)[], testarrayofsortedstruct?: (AbilityT)[], flex?: (number)[], test5?: (TestT)[], vectorOfLongs?: (bigint)[], vectorOfDoubles?: (number)[], parentNamespaceTest?: InParentNamespaceT | null, vectorOfReferrables?: (ReferrableT)[], singleWeakReference?: bigint, vectorOfWeakReferences?: (bigint)[], vectorOfStrongReferrables?: (ReferrableT)[], coOwningReference?: bigint, vectorOfCoOwningReferences?: (bigint)[], nonOwningReference?: bigint, vectorOfNonOwningReferences?: (bigint)[], anyUniqueType?: AnyUniqueAliases, anyUnique?: MonsterT | MyGame_Example2_MonsterT | TestSimpleTableWithEnumT | null, anyAmbiguousType?: AnyAmbiguousAliases, anyAmbiguous?: MonsterT | null, vectorOfEnums?: (Color)[], signedEnum?: Race, testrequirednestedflatbuffer?: (number)[], scalarKeySortedTables?: (StatT)[], nativeInline?: TestT | null, longEnumNonEnumDefault?: bigint, longEnumNormalDefault?: bigint, nanDefault?: number, infDefault?: number, positiveInfDefault?: number, infinityDefault?: number, positiveInfinityDefault?: number, negativeInfDefault?: number, negativeInfinityDefault?: number, doubleInfDefault?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/monster.js b/tests/ts/my-game/example/monster.js index 070efbfab..33591b117 100644 --- a/tests/ts/my-game/example/monster.js +++ b/tests/ts/my-game/example/monster.js @@ -1,1554 +1,1270 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {Ability} from '../../my-game/example/ability.js'; -import {AnyAmbiguousAliases, unionToAnyAmbiguousAliases} from '../../my-game/example/any-ambiguous-aliases.js'; -import {AnyUniqueAliases, unionToAnyUniqueAliases} from '../../my-game/example/any-unique-aliases.js'; -import {Any, unionToAny} from '../../my-game/example/any.js'; -import {Color} from '../../my-game/example/color.js'; -import {Race} from '../../my-game/example/race.js'; -import {Referrable} from '../../my-game/example/referrable.js'; -import {Stat} from '../../my-game/example/stat.js'; -import {Test} from '../../my-game/example/test.js'; -import {Vec3} from '../../my-game/example/vec3.js'; -import {InParentNamespace} from '../../my-game/in-parent-namespace.js'; - +import { Ability } from './ability.js'; +import { Any, unionToAny } from './any.js'; +import { AnyAmbiguousAliases, unionToAnyAmbiguousAliases } from './any-ambiguous-aliases.js'; +import { AnyUniqueAliases, unionToAnyUniqueAliases } from './any-unique-aliases.js'; +import { Color } from './color.js'; +import { Race } from './race.js'; +import { Referrable } from './referrable.js'; +import { Stat } from './stat.js'; +import { Test } from './test.js'; +import { Vec3 } from './vec3.js'; +import { InParentNamespace } from '../in-parent-namespace.js'; /** * an example documentation comment: "monster object" */ export class Monster { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsMonster(bb, obj) { - return (obj || new Monster()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsMonster(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Monster()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static bufferHasIdentifier(bb) { - return bb.__has_identifier('MONS'); - } - pos(obj) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? (obj || new Vec3()).__init(this.bb_pos + offset, this.bb) : - null; - } - mana() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt16(this.bb_pos + offset) : 150; - } - mutate_mana(value) { - const offset = this.bb.__offset(this.bb_pos, 6); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt16(this.bb_pos + offset, value); - return true; - } - hp() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readInt16(this.bb_pos + offset) : 100; - } - mutate_hp(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - this.bb.writeInt16(this.bb_pos + offset, value); - return true; - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - inventory(index) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? - this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : - 0; - } - inventoryLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - inventoryArray() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? - new Uint8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - color() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint8(this.bb_pos + offset) : Color.Blue; - } - mutate_color(value) { - const offset = this.bb.__offset(this.bb_pos, 16); - if (offset === 0) { - return false; + static getRootAsMonster(bb, obj) { + return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeUint8(this.bb_pos + offset, value); - return true; - } - testType() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : Any.NONE; - } - test(obj) { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; - } - test4(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 22); - return offset ? - (obj || new Test()) - .__init( - this.bb.__vector(this.bb_pos + offset) + index * 4, this.bb) : - null; - } - test4Length() { - const offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - testarrayofstring(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - testarrayofstringLength() { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - /** - * an example documentation comment: this will end up in the generated code - * multiline too - */ - testarrayoftables(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? - (obj || new Monster()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - testarrayoftablesLength() { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - enemy(obj) { - const offset = this.bb.__offset(this.bb_pos, 28); - return offset ? - (obj || new Monster()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - testnestedflatbuffer(index) { - const offset = this.bb.__offset(this.bb_pos, 30); - return offset ? - this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : - 0; - } - testnestedflatbufferLength() { - const offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - testnestedflatbufferArray() { - const offset = this.bb.__offset(this.bb_pos, 30); - return offset ? - new Uint8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - testempty(obj) { - const offset = this.bb.__offset(this.bb_pos, 32); - return offset ? - (obj || new Stat()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - testbool() { - const offset = this.bb.__offset(this.bb_pos, 34); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_testbool(value) { - const offset = this.bb.__offset(this.bb_pos, 34); - if (offset === 0) { - return false; + static getSizePrefixedRootAsMonster(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - testhashs32Fnv1() { - const offset = this.bb.__offset(this.bb_pos, 36); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_testhashs32_fnv1(value) { - const offset = this.bb.__offset(this.bb_pos, 36); - if (offset === 0) { - return false; + static bufferHasIdentifier(bb) { + return bb.__has_identifier('MONS'); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - testhashu32Fnv1() { - const offset = this.bb.__offset(this.bb_pos, 38); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - mutate_testhashu32_fnv1(value) { - const offset = this.bb.__offset(this.bb_pos, 38); - if (offset === 0) { - return false; + pos(obj) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new Vec3()).__init(this.bb_pos + offset, this.bb) : null; } - this.bb.writeUint32(this.bb_pos + offset, value); - return true; - } - testhashs64Fnv1() { - const offset = this.bb.__offset(this.bb_pos, 40); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); - } - mutate_testhashs64_fnv1(value) { - const offset = this.bb.__offset(this.bb_pos, 40); - if (offset === 0) { - return false; + mana() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt16(this.bb_pos + offset) : 150; } - this.bb.writeInt64(this.bb_pos + offset, value); - return true; - } - testhashu64Fnv1() { - const offset = this.bb.__offset(this.bb_pos, 42); - return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); - } - mutate_testhashu64_fnv1(value) { - const offset = this.bb.__offset(this.bb_pos, 42); - if (offset === 0) { - return false; + mutate_mana(value) { + const offset = this.bb.__offset(this.bb_pos, 6); + if (offset === 0) { + return false; + } + this.bb.writeInt16(this.bb_pos + offset, value); + return true; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - testhashs32Fnv1a() { - const offset = this.bb.__offset(this.bb_pos, 44); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_testhashs32_fnv1a(value) { - const offset = this.bb.__offset(this.bb_pos, 44); - if (offset === 0) { - return false; + hp() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt16(this.bb_pos + offset) : 100; } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - testhashu32Fnv1a() { - const offset = this.bb.__offset(this.bb_pos, 46); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - mutate_testhashu32_fnv1a(value) { - const offset = this.bb.__offset(this.bb_pos, 46); - if (offset === 0) { - return false; + mutate_hp(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeInt16(this.bb_pos + offset, value); + return true; } - this.bb.writeUint32(this.bb_pos + offset, value); - return true; - } - testhashs64Fnv1a() { - const offset = this.bb.__offset(this.bb_pos, 48); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); - } - mutate_testhashs64_fnv1a(value) { - const offset = this.bb.__offset(this.bb_pos, 48); - if (offset === 0) { - return false; + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 10); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } - this.bb.writeInt64(this.bb_pos + offset, value); - return true; - } - testhashu64Fnv1a() { - const offset = this.bb.__offset(this.bb_pos, 50); - return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); - } - mutate_testhashu64_fnv1a(value) { - const offset = this.bb.__offset(this.bb_pos, 50); - if (offset === 0) { - return false; + inventory(index) { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - testarrayofbools(index) { - const offset = this.bb.__offset(this.bb_pos, 52); - return offset ? - !!this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : - false; - } - testarrayofboolsLength() { - const offset = this.bb.__offset(this.bb_pos, 52); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - testarrayofboolsArray() { - const offset = this.bb.__offset(this.bb_pos, 52); - return offset ? - new Int8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - testf() { - const offset = this.bb.__offset(this.bb_pos, 54); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.14159; - } - mutate_testf(value) { - const offset = this.bb.__offset(this.bb_pos, 54); - if (offset === 0) { - return false; + inventoryLength() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - testf2() { - const offset = this.bb.__offset(this.bb_pos, 56); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.0; - } - mutate_testf2(value) { - const offset = this.bb.__offset(this.bb_pos, 56); - if (offset === 0) { - return false; + inventoryArray() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - testf3() { - const offset = this.bb.__offset(this.bb_pos, 58); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; - } - mutate_testf3(value) { - const offset = this.bb.__offset(this.bb_pos, 58); - if (offset === 0) { - return false; + color() { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.readUint8(this.bb_pos + offset) : Color.Blue; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - testarrayofstring2(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 60); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - testarrayofstring2Length() { - const offset = this.bb.__offset(this.bb_pos, 60); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - testarrayofsortedstruct(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 62); - return offset ? - (obj || new Ability()) - .__init( - this.bb.__vector(this.bb_pos + offset) + index * 8, this.bb) : - null; - } - testarrayofsortedstructLength() { - const offset = this.bb.__offset(this.bb_pos, 62); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - flex(index) { - const offset = this.bb.__offset(this.bb_pos, 64); - return offset ? - this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : - 0; - } - flexLength() { - const offset = this.bb.__offset(this.bb_pos, 64); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - flexArray() { - const offset = this.bb.__offset(this.bb_pos, 64); - return offset ? - new Uint8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - test5(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 66); - return offset ? - (obj || new Test()) - .__init( - this.bb.__vector(this.bb_pos + offset) + index * 4, this.bb) : - null; - } - test5Length() { - const offset = this.bb.__offset(this.bb_pos, 66); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - 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) : - BigInt(0); - } - vectorOfLongsLength() { - const offset = this.bb.__offset(this.bb_pos, 68); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - vectorOfDoubles(index) { - const offset = this.bb.__offset(this.bb_pos, 70); - return offset ? this.bb.readFloat64( - this.bb.__vector(this.bb_pos + offset) + index * 8) : - 0; - } - vectorOfDoublesLength() { - const offset = this.bb.__offset(this.bb_pos, 70); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - vectorOfDoublesArray() { - const offset = this.bb.__offset(this.bb_pos, 70); - return offset ? - new Float64Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - parentNamespaceTest(obj) { - const offset = this.bb.__offset(this.bb_pos, 72); - return offset ? - (obj || new InParentNamespace()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - vectorOfReferrables(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 74); - return offset ? - (obj || new Referrable()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - vectorOfReferrablesLength() { - const offset = this.bb.__offset(this.bb_pos, 74); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - singleWeakReference() { - const offset = this.bb.__offset(this.bb_pos, 76); - 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); - if (offset === 0) { - return false; + mutate_color(value) { + const offset = this.bb.__offset(this.bb_pos, 16); + if (offset === 0) { + return false; + } + this.bb.writeUint8(this.bb_pos + offset, value); + return true; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - 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) : - BigInt(0); - } - vectorOfWeakReferencesLength() { - const offset = this.bb.__offset(this.bb_pos, 78); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - vectorOfStrongReferrables(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 80); - return offset ? - (obj || new Referrable()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - vectorOfStrongReferrablesLength() { - const offset = this.bb.__offset(this.bb_pos, 80); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - coOwningReference() { - const offset = this.bb.__offset(this.bb_pos, 82); - 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); - if (offset === 0) { - return false; + testType() { + const offset = this.bb.__offset(this.bb_pos, 18); + return offset ? this.bb.readUint8(this.bb_pos + offset) : Any.NONE; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - 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) : - BigInt(0); - } - vectorOfCoOwningReferencesLength() { - const offset = this.bb.__offset(this.bb_pos, 84); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - nonOwningReference() { - const offset = this.bb.__offset(this.bb_pos, 86); - 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); - if (offset === 0) { - return false; + test(obj) { + const offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - 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) : - BigInt(0); - } - vectorOfNonOwningReferencesLength() { - const offset = this.bb.__offset(this.bb_pos, 88); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - anyUniqueType() { - const offset = this.bb.__offset(this.bb_pos, 90); - return offset ? this.bb.readUint8(this.bb_pos + offset) : - AnyUniqueAliases.NONE; - } - anyUnique(obj) { - const offset = this.bb.__offset(this.bb_pos, 92); - return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; - } - anyAmbiguousType() { - const offset = this.bb.__offset(this.bb_pos, 94); - return offset ? this.bb.readUint8(this.bb_pos + offset) : - AnyAmbiguousAliases.NONE; - } - anyAmbiguous(obj) { - const offset = this.bb.__offset(this.bb_pos, 96); - return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; - } - vectorOfEnums(index) { - const offset = this.bb.__offset(this.bb_pos, 98); - return offset ? - this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : - null; - } - vectorOfEnumsLength() { - const offset = this.bb.__offset(this.bb_pos, 98); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - vectorOfEnumsArray() { - const offset = this.bb.__offset(this.bb_pos, 98); - return offset ? - new Uint8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - signedEnum() { - const offset = this.bb.__offset(this.bb_pos, 100); - return offset ? this.bb.readInt8(this.bb_pos + offset) : Race.None; - } - mutate_signed_enum(value) { - const offset = this.bb.__offset(this.bb_pos, 100); - if (offset === 0) { - return false; + test4(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 22); + return offset ? (obj || new Test()).__init(this.bb.__vector(this.bb_pos + offset) + index * 4, this.bb) : null; } - this.bb.writeInt8(this.bb_pos + offset, value); - return true; - } - testrequirednestedflatbuffer(index) { - const offset = this.bb.__offset(this.bb_pos, 102); - return offset ? - this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : - 0; - } - testrequirednestedflatbufferLength() { - const offset = this.bb.__offset(this.bb_pos, 102); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - testrequirednestedflatbufferArray() { - const offset = this.bb.__offset(this.bb_pos, 102); - return offset ? - new Uint8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - scalarKeySortedTables(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 104); - return offset ? - (obj || new Stat()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - scalarKeySortedTablesLength() { - const offset = this.bb.__offset(this.bb_pos, 104); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - nativeInline(obj) { - const offset = this.bb.__offset(this.bb_pos, 106); - return offset ? (obj || new Test()).__init(this.bb_pos + offset, this.bb) : - null; - } - longEnumNonEnumDefault() { - 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) { - const offset = this.bb.__offset(this.bb_pos, 108); - if (offset === 0) { - return false; + test4Length() { + const offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - longEnumNormalDefault() { - 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) { - const offset = this.bb.__offset(this.bb_pos, 110); - if (offset === 0) { - return false; + testarrayofstring(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - nanDefault() { - const offset = this.bb.__offset(this.bb_pos, 112); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : NaN; - } - mutate_nan_default(value) { - const offset = this.bb.__offset(this.bb_pos, 112); - if (offset === 0) { - return false; + testarrayofstringLength() { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - infDefault() { - const offset = this.bb.__offset(this.bb_pos, 114); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; - } - mutate_inf_default(value) { - const offset = this.bb.__offset(this.bb_pos, 114); - if (offset === 0) { - return false; + /** + * an example documentation comment: this will end up in the generated code + * multiline too + */ + testarrayoftables(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 26); + return offset ? (obj || new Monster()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - positiveInfDefault() { - const offset = this.bb.__offset(this.bb_pos, 116); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; - } - mutate_positive_inf_default(value) { - const offset = this.bb.__offset(this.bb_pos, 116); - if (offset === 0) { - return false; + testarrayoftablesLength() { + const offset = this.bb.__offset(this.bb_pos, 26); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - infinityDefault() { - const offset = this.bb.__offset(this.bb_pos, 118); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; - } - mutate_infinity_default(value) { - const offset = this.bb.__offset(this.bb_pos, 118); - if (offset === 0) { - return false; + enemy(obj) { + const offset = this.bb.__offset(this.bb_pos, 28); + return offset ? (obj || new Monster()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - positiveInfinityDefault() { - const offset = this.bb.__offset(this.bb_pos, 120); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; - } - mutate_positive_infinity_default(value) { - const offset = this.bb.__offset(this.bb_pos, 120); - if (offset === 0) { - return false; + testnestedflatbuffer(index) { + const offset = this.bb.__offset(this.bb_pos, 30); + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - negativeInfDefault() { - const offset = this.bb.__offset(this.bb_pos, 122); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : -Infinity; - } - mutate_negative_inf_default(value) { - const offset = this.bb.__offset(this.bb_pos, 122); - if (offset === 0) { - return false; + testnestedflatbufferLength() { + const offset = this.bb.__offset(this.bb_pos, 30); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - negativeInfinityDefault() { - const offset = this.bb.__offset(this.bb_pos, 124); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : -Infinity; - } - mutate_negative_infinity_default(value) { - const offset = this.bb.__offset(this.bb_pos, 124); - if (offset === 0) { - return false; + testnestedflatbufferArray() { + const offset = this.bb.__offset(this.bb_pos, 30); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - doubleInfDefault() { - const offset = this.bb.__offset(this.bb_pos, 126); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : Infinity; - } - mutate_double_inf_default(value) { - const offset = this.bb.__offset(this.bb_pos, 126); - if (offset === 0) { - return false; + testempty(obj) { + const offset = this.bb.__offset(this.bb_pos, 32); + return offset ? (obj || new Stat()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; } - this.bb.writeFloat64(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'MyGame.Example.Monster'; - } - static startMonster(builder) { - builder.startObject(62); - } - static addPos(builder, posOffset) { - builder.addFieldStruct(0, posOffset, 0); - } - static addMana(builder, mana) { - builder.addFieldInt16(1, mana, 150); - } - static addHp(builder, hp) { - builder.addFieldInt16(2, hp, 100); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(3, nameOffset, 0); - } - static addInventory(builder, inventoryOffset) { - builder.addFieldOffset(5, inventoryOffset, 0); - } - static createInventoryVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); + testbool() { + const offset = this.bb.__offset(this.bb_pos, 34); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; } - return builder.endVector(); - } - static startInventoryVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addColor(builder, color) { - builder.addFieldInt8(6, color, Color.Blue); - } - static addTestType(builder, testType) { - builder.addFieldInt8(7, testType, Any.NONE); - } - static addTest(builder, testOffset) { - builder.addFieldOffset(8, testOffset, 0); - } - static addTest4(builder, test4Offset) { - builder.addFieldOffset(9, test4Offset, 0); - } - static startTest4Vector(builder, numElems) { - builder.startVector(4, numElems, 2); - } - static addTestarrayofstring(builder, testarrayofstringOffset) { - builder.addFieldOffset(10, testarrayofstringOffset, 0); - } - static createTestarrayofstringVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + mutate_testbool(value) { + const offset = this.bb.__offset(this.bb_pos, 34); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; } - return builder.endVector(); - } - static startTestarrayofstringVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addTestarrayoftables(builder, testarrayoftablesOffset) { - builder.addFieldOffset(11, testarrayoftablesOffset, 0); - } - static createTestarrayoftablesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + testhashs32Fnv1() { + const offset = this.bb.__offset(this.bb_pos, 36); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; } - return builder.endVector(); - } - static startTestarrayoftablesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addEnemy(builder, enemyOffset) { - builder.addFieldOffset(12, enemyOffset, 0); - } - static addTestnestedflatbuffer(builder, testnestedflatbufferOffset) { - builder.addFieldOffset(13, testnestedflatbufferOffset, 0); - } - static createTestnestedflatbufferVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); + mutate_testhashs32_fnv1(value) { + const offset = this.bb.__offset(this.bb_pos, 36); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; } - return builder.endVector(); - } - static startTestnestedflatbufferVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addTestempty(builder, testemptyOffset) { - builder.addFieldOffset(14, testemptyOffset, 0); - } - static addTestbool(builder, testbool) { - builder.addFieldInt8(15, +testbool, +false); - } - static addTesthashs32Fnv1(builder, testhashs32Fnv1) { - builder.addFieldInt32(16, testhashs32Fnv1, 0); - } - static addTesthashu32Fnv1(builder, testhashu32Fnv1) { - builder.addFieldInt32(17, testhashu32Fnv1, 0); - } - static addTesthashs64Fnv1(builder, testhashs64Fnv1) { - builder.addFieldInt64(18, testhashs64Fnv1, BigInt('0')); - } - static addTesthashu64Fnv1(builder, testhashu64Fnv1) { - builder.addFieldInt64(19, testhashu64Fnv1, BigInt('0')); - } - static addTesthashs32Fnv1a(builder, testhashs32Fnv1a) { - builder.addFieldInt32(20, testhashs32Fnv1a, 0); - } - static addTesthashu32Fnv1a(builder, testhashu32Fnv1a) { - builder.addFieldInt32(21, testhashu32Fnv1a, 0); - } - static addTesthashs64Fnv1a(builder, testhashs64Fnv1a) { - builder.addFieldInt64(22, testhashs64Fnv1a, BigInt('0')); - } - static addTesthashu64Fnv1a(builder, testhashu64Fnv1a) { - builder.addFieldInt64(23, testhashu64Fnv1a, BigInt('0')); - } - static addTestarrayofbools(builder, testarrayofboolsOffset) { - builder.addFieldOffset(24, testarrayofboolsOffset, 0); - } - static createTestarrayofboolsVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(+data[i]); + testhashu32Fnv1() { + const offset = this.bb.__offset(this.bb_pos, 38); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; } - return builder.endVector(); - } - static startTestarrayofboolsVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addTestf(builder, testf) { - builder.addFieldFloat32(25, testf, 3.14159); - } - static addTestf2(builder, testf2) { - builder.addFieldFloat32(26, testf2, 3.0); - } - static addTestf3(builder, testf3) { - builder.addFieldFloat32(27, testf3, 0.0); - } - static addTestarrayofstring2(builder, testarrayofstring2Offset) { - builder.addFieldOffset(28, testarrayofstring2Offset, 0); - } - static createTestarrayofstring2Vector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + mutate_testhashu32_fnv1(value) { + const offset = this.bb.__offset(this.bb_pos, 38); + if (offset === 0) { + return false; + } + this.bb.writeUint32(this.bb_pos + offset, value); + return true; } - return builder.endVector(); - } - static startTestarrayofstring2Vector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addTestarrayofsortedstruct(builder, testarrayofsortedstructOffset) { - builder.addFieldOffset(29, testarrayofsortedstructOffset, 0); - } - static startTestarrayofsortedstructVector(builder, numElems) { - builder.startVector(8, numElems, 4); - } - static addFlex(builder, flexOffset) { - builder.addFieldOffset(30, flexOffset, 0); - } - static createFlexVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); + testhashs64Fnv1() { + const offset = this.bb.__offset(this.bb_pos, 40); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); } - return builder.endVector(); - } - static startFlexVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addTest5(builder, test5Offset) { - builder.addFieldOffset(31, test5Offset, 0); - } - static startTest5Vector(builder, numElems) { - builder.startVector(4, numElems, 2); - } - static addVectorOfLongs(builder, vectorOfLongsOffset) { - builder.addFieldOffset(32, vectorOfLongsOffset, 0); - } - static createVectorOfLongsVector(builder, data) { - builder.startVector(8, data.length, 8); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt64(data[i]); + mutate_testhashs64_fnv1(value) { + const offset = this.bb.__offset(this.bb_pos, 40); + if (offset === 0) { + return false; + } + this.bb.writeInt64(this.bb_pos + offset, value); + return true; } - return builder.endVector(); - } - static startVectorOfLongsVector(builder, numElems) { - builder.startVector(8, numElems, 8); - } - static addVectorOfDoubles(builder, vectorOfDoublesOffset) { - builder.addFieldOffset(33, vectorOfDoublesOffset, 0); - } - static createVectorOfDoublesVector(builder, data) { - builder.startVector(8, data.length, 8); - for (let i = data.length - 1; i >= 0; i--) { - builder.addFloat64(data[i]); + testhashu64Fnv1() { + const offset = this.bb.__offset(this.bb_pos, 42); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); } - return builder.endVector(); - } - static startVectorOfDoublesVector(builder, numElems) { - builder.startVector(8, numElems, 8); - } - static addParentNamespaceTest(builder, parentNamespaceTestOffset) { - builder.addFieldOffset(34, parentNamespaceTestOffset, 0); - } - static addVectorOfReferrables(builder, vectorOfReferrablesOffset) { - builder.addFieldOffset(35, vectorOfReferrablesOffset, 0); - } - static createVectorOfReferrablesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + mutate_testhashu64_fnv1(value) { + const offset = this.bb.__offset(this.bb_pos, 42); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; } - return builder.endVector(); - } - static startVectorOfReferrablesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addSingleWeakReference(builder, singleWeakReference) { - builder.addFieldInt64(36, singleWeakReference, BigInt('0')); - } - static addVectorOfWeakReferences(builder, vectorOfWeakReferencesOffset) { - builder.addFieldOffset(37, vectorOfWeakReferencesOffset, 0); - } - static createVectorOfWeakReferencesVector(builder, data) { - builder.startVector(8, data.length, 8); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt64(data[i]); + testhashs32Fnv1a() { + const offset = this.bb.__offset(this.bb_pos, 44); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; } - return builder.endVector(); - } - static startVectorOfWeakReferencesVector(builder, numElems) { - builder.startVector(8, numElems, 8); - } - static addVectorOfStrongReferrables( - builder, vectorOfStrongReferrablesOffset) { - builder.addFieldOffset(38, vectorOfStrongReferrablesOffset, 0); - } - static createVectorOfStrongReferrablesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + mutate_testhashs32_fnv1a(value) { + const offset = this.bb.__offset(this.bb_pos, 44); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; } - return builder.endVector(); - } - static startVectorOfStrongReferrablesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addCoOwningReference(builder, coOwningReference) { - builder.addFieldInt64(39, coOwningReference, BigInt('0')); - } - static addVectorOfCoOwningReferences( - builder, vectorOfCoOwningReferencesOffset) { - builder.addFieldOffset(40, vectorOfCoOwningReferencesOffset, 0); - } - static createVectorOfCoOwningReferencesVector(builder, data) { - builder.startVector(8, data.length, 8); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt64(data[i]); + testhashu32Fnv1a() { + const offset = this.bb.__offset(this.bb_pos, 46); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; } - return builder.endVector(); - } - static startVectorOfCoOwningReferencesVector(builder, numElems) { - builder.startVector(8, numElems, 8); - } - static addNonOwningReference(builder, nonOwningReference) { - builder.addFieldInt64(41, nonOwningReference, BigInt('0')); - } - static addVectorOfNonOwningReferences( - builder, vectorOfNonOwningReferencesOffset) { - builder.addFieldOffset(42, vectorOfNonOwningReferencesOffset, 0); - } - static createVectorOfNonOwningReferencesVector(builder, data) { - builder.startVector(8, data.length, 8); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt64(data[i]); + mutate_testhashu32_fnv1a(value) { + const offset = this.bb.__offset(this.bb_pos, 46); + if (offset === 0) { + return false; + } + this.bb.writeUint32(this.bb_pos + offset, value); + return true; } - return builder.endVector(); - } - static startVectorOfNonOwningReferencesVector(builder, numElems) { - builder.startVector(8, numElems, 8); - } - static addAnyUniqueType(builder, anyUniqueType) { - builder.addFieldInt8(43, anyUniqueType, AnyUniqueAliases.NONE); - } - static addAnyUnique(builder, anyUniqueOffset) { - builder.addFieldOffset(44, anyUniqueOffset, 0); - } - static addAnyAmbiguousType(builder, anyAmbiguousType) { - builder.addFieldInt8(45, anyAmbiguousType, AnyAmbiguousAliases.NONE); - } - static addAnyAmbiguous(builder, anyAmbiguousOffset) { - builder.addFieldOffset(46, anyAmbiguousOffset, 0); - } - static addVectorOfEnums(builder, vectorOfEnumsOffset) { - builder.addFieldOffset(47, vectorOfEnumsOffset, 0); - } - static createVectorOfEnumsVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); + testhashs64Fnv1a() { + const offset = this.bb.__offset(this.bb_pos, 48); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); } - return builder.endVector(); - } - static startVectorOfEnumsVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addSignedEnum(builder, signedEnum) { - builder.addFieldInt8(48, signedEnum, Race.None); - } - static addTestrequirednestedflatbuffer( - builder, testrequirednestedflatbufferOffset) { - builder.addFieldOffset(49, testrequirednestedflatbufferOffset, 0); - } - static createTestrequirednestedflatbufferVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); + mutate_testhashs64_fnv1a(value) { + const offset = this.bb.__offset(this.bb_pos, 48); + if (offset === 0) { + return false; + } + this.bb.writeInt64(this.bb_pos + offset, value); + return true; } - return builder.endVector(); - } - static startTestrequirednestedflatbufferVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addScalarKeySortedTables(builder, scalarKeySortedTablesOffset) { - builder.addFieldOffset(50, scalarKeySortedTablesOffset, 0); - } - static createScalarKeySortedTablesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + testhashu64Fnv1a() { + const offset = this.bb.__offset(this.bb_pos, 50); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); + } + mutate_testhashu64_fnv1a(value) { + const offset = this.bb.__offset(this.bb_pos, 50); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + testarrayofbools(index) { + const offset = this.bb.__offset(this.bb_pos, 52); + return offset ? !!this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : false; + } + testarrayofboolsLength() { + const offset = this.bb.__offset(this.bb_pos, 52); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + testarrayofboolsArray() { + const offset = this.bb.__offset(this.bb_pos, 52); + return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + testf() { + const offset = this.bb.__offset(this.bb_pos, 54); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.14159; + } + mutate_testf(value) { + const offset = this.bb.__offset(this.bb_pos, 54); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + testf2() { + const offset = this.bb.__offset(this.bb_pos, 56); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.0; + } + mutate_testf2(value) { + const offset = this.bb.__offset(this.bb_pos, 56); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + testf3() { + const offset = this.bb.__offset(this.bb_pos, 58); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; + } + mutate_testf3(value) { + const offset = this.bb.__offset(this.bb_pos, 58); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + testarrayofstring2(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 60); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + testarrayofstring2Length() { + const offset = this.bb.__offset(this.bb_pos, 60); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + testarrayofsortedstruct(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 62); + return offset ? (obj || new Ability()).__init(this.bb.__vector(this.bb_pos + offset) + index * 8, this.bb) : null; + } + testarrayofsortedstructLength() { + const offset = this.bb.__offset(this.bb_pos, 62); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + flex(index) { + const offset = this.bb.__offset(this.bb_pos, 64); + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; + } + flexLength() { + const offset = this.bb.__offset(this.bb_pos, 64); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + flexArray() { + const offset = this.bb.__offset(this.bb_pos, 64); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + test5(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 66); + return offset ? (obj || new Test()).__init(this.bb.__vector(this.bb_pos + offset) + index * 4, this.bb) : null; + } + test5Length() { + const offset = this.bb.__offset(this.bb_pos, 66); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + 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) : BigInt(0); + } + vectorOfLongsLength() { + const offset = this.bb.__offset(this.bb_pos, 68); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + vectorOfDoubles(index) { + const offset = this.bb.__offset(this.bb_pos, 70); + return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0; + } + vectorOfDoublesLength() { + const offset = this.bb.__offset(this.bb_pos, 70); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + vectorOfDoublesArray() { + const offset = this.bb.__offset(this.bb_pos, 70); + return offset ? new Float64Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + parentNamespaceTest(obj) { + const offset = this.bb.__offset(this.bb_pos, 72); + return offset ? (obj || new InParentNamespace()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + vectorOfReferrables(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 74); + return offset ? (obj || new Referrable()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + vectorOfReferrablesLength() { + const offset = this.bb.__offset(this.bb_pos, 74); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + singleWeakReference() { + const offset = this.bb.__offset(this.bb_pos, 76); + 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); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + 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) : BigInt(0); + } + vectorOfWeakReferencesLength() { + const offset = this.bb.__offset(this.bb_pos, 78); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + vectorOfStrongReferrables(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 80); + return offset ? (obj || new Referrable()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + vectorOfStrongReferrablesLength() { + const offset = this.bb.__offset(this.bb_pos, 80); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + coOwningReference() { + const offset = this.bb.__offset(this.bb_pos, 82); + 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); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + 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) : BigInt(0); + } + vectorOfCoOwningReferencesLength() { + const offset = this.bb.__offset(this.bb_pos, 84); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + nonOwningReference() { + const offset = this.bb.__offset(this.bb_pos, 86); + 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); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + 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) : BigInt(0); + } + vectorOfNonOwningReferencesLength() { + const offset = this.bb.__offset(this.bb_pos, 88); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + anyUniqueType() { + const offset = this.bb.__offset(this.bb_pos, 90); + return offset ? this.bb.readUint8(this.bb_pos + offset) : AnyUniqueAliases.NONE; + } + anyUnique(obj) { + const offset = this.bb.__offset(this.bb_pos, 92); + return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; + } + anyAmbiguousType() { + const offset = this.bb.__offset(this.bb_pos, 94); + return offset ? this.bb.readUint8(this.bb_pos + offset) : AnyAmbiguousAliases.NONE; + } + anyAmbiguous(obj) { + const offset = this.bb.__offset(this.bb_pos, 96); + return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; + } + vectorOfEnums(index) { + const offset = this.bb.__offset(this.bb_pos, 98); + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : null; + } + vectorOfEnumsLength() { + const offset = this.bb.__offset(this.bb_pos, 98); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + vectorOfEnumsArray() { + const offset = this.bb.__offset(this.bb_pos, 98); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + signedEnum() { + const offset = this.bb.__offset(this.bb_pos, 100); + return offset ? this.bb.readInt8(this.bb_pos + offset) : Race.None; + } + mutate_signed_enum(value) { + const offset = this.bb.__offset(this.bb_pos, 100); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, value); + return true; + } + testrequirednestedflatbuffer(index) { + const offset = this.bb.__offset(this.bb_pos, 102); + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; + } + testrequirednestedflatbufferLength() { + const offset = this.bb.__offset(this.bb_pos, 102); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + testrequirednestedflatbufferArray() { + const offset = this.bb.__offset(this.bb_pos, 102); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + scalarKeySortedTables(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 104); + return offset ? (obj || new Stat()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + scalarKeySortedTablesLength() { + const offset = this.bb.__offset(this.bb_pos, 104); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + nativeInline(obj) { + const offset = this.bb.__offset(this.bb_pos, 106); + return offset ? (obj || new Test()).__init(this.bb_pos + offset, this.bb) : null; + } + longEnumNonEnumDefault() { + 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) { + 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() { + 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) { + const offset = this.bb.__offset(this.bb_pos, 110); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + nanDefault() { + const offset = this.bb.__offset(this.bb_pos, 112); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : NaN; + } + mutate_nan_default(value) { + const offset = this.bb.__offset(this.bb_pos, 112); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + infDefault() { + const offset = this.bb.__offset(this.bb_pos, 114); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; + } + mutate_inf_default(value) { + const offset = this.bb.__offset(this.bb_pos, 114); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + positiveInfDefault() { + const offset = this.bb.__offset(this.bb_pos, 116); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; + } + mutate_positive_inf_default(value) { + const offset = this.bb.__offset(this.bb_pos, 116); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + infinityDefault() { + const offset = this.bb.__offset(this.bb_pos, 118); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; + } + mutate_infinity_default(value) { + const offset = this.bb.__offset(this.bb_pos, 118); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + positiveInfinityDefault() { + const offset = this.bb.__offset(this.bb_pos, 120); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : Infinity; + } + mutate_positive_infinity_default(value) { + const offset = this.bb.__offset(this.bb_pos, 120); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + negativeInfDefault() { + const offset = this.bb.__offset(this.bb_pos, 122); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : -Infinity; + } + mutate_negative_inf_default(value) { + const offset = this.bb.__offset(this.bb_pos, 122); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + negativeInfinityDefault() { + const offset = this.bb.__offset(this.bb_pos, 124); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : -Infinity; + } + mutate_negative_infinity_default(value) { + const offset = this.bb.__offset(this.bb_pos, 124); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + doubleInfDefault() { + const offset = this.bb.__offset(this.bb_pos, 126); + return offset ? this.bb.readFloat64(this.bb_pos + offset) : Infinity; + } + mutate_double_inf_default(value) { + const offset = this.bb.__offset(this.bb_pos, 126); + if (offset === 0) { + return false; + } + this.bb.writeFloat64(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'MyGame.Example.Monster'; + } + static startMonster(builder) { + builder.startObject(62); + } + static addPos(builder, posOffset) { + builder.addFieldStruct(0, posOffset, 0); + } + static addMana(builder, mana) { + builder.addFieldInt16(1, mana, 150); + } + static addHp(builder, hp) { + builder.addFieldInt16(2, hp, 100); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(3, nameOffset, 0); + } + static addInventory(builder, inventoryOffset) { + builder.addFieldOffset(5, inventoryOffset, 0); + } + static createInventoryVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + static startInventoryVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addColor(builder, color) { + builder.addFieldInt8(6, color, Color.Blue); + } + static addTestType(builder, testType) { + builder.addFieldInt8(7, testType, Any.NONE); + } + static addTest(builder, testOffset) { + builder.addFieldOffset(8, testOffset, 0); + } + static addTest4(builder, test4Offset) { + builder.addFieldOffset(9, test4Offset, 0); + } + static startTest4Vector(builder, numElems) { + builder.startVector(4, numElems, 2); + } + static addTestarrayofstring(builder, testarrayofstringOffset) { + builder.addFieldOffset(10, testarrayofstringOffset, 0); + } + static createTestarrayofstringVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startTestarrayofstringVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addTestarrayoftables(builder, testarrayoftablesOffset) { + builder.addFieldOffset(11, testarrayoftablesOffset, 0); + } + static createTestarrayoftablesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startTestarrayoftablesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addEnemy(builder, enemyOffset) { + builder.addFieldOffset(12, enemyOffset, 0); + } + static addTestnestedflatbuffer(builder, testnestedflatbufferOffset) { + builder.addFieldOffset(13, testnestedflatbufferOffset, 0); + } + static createTestnestedflatbufferVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + static startTestnestedflatbufferVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addTestempty(builder, testemptyOffset) { + builder.addFieldOffset(14, testemptyOffset, 0); + } + static addTestbool(builder, testbool) { + builder.addFieldInt8(15, +testbool, +false); + } + static addTesthashs32Fnv1(builder, testhashs32Fnv1) { + builder.addFieldInt32(16, testhashs32Fnv1, 0); + } + static addTesthashu32Fnv1(builder, testhashu32Fnv1) { + builder.addFieldInt32(17, testhashu32Fnv1, 0); + } + static addTesthashs64Fnv1(builder, testhashs64Fnv1) { + builder.addFieldInt64(18, testhashs64Fnv1, BigInt('0')); + } + static addTesthashu64Fnv1(builder, testhashu64Fnv1) { + builder.addFieldInt64(19, testhashu64Fnv1, BigInt('0')); + } + static addTesthashs32Fnv1a(builder, testhashs32Fnv1a) { + builder.addFieldInt32(20, testhashs32Fnv1a, 0); + } + static addTesthashu32Fnv1a(builder, testhashu32Fnv1a) { + builder.addFieldInt32(21, testhashu32Fnv1a, 0); + } + static addTesthashs64Fnv1a(builder, testhashs64Fnv1a) { + builder.addFieldInt64(22, testhashs64Fnv1a, BigInt('0')); + } + static addTesthashu64Fnv1a(builder, testhashu64Fnv1a) { + builder.addFieldInt64(23, testhashu64Fnv1a, BigInt('0')); + } + static addTestarrayofbools(builder, testarrayofboolsOffset) { + builder.addFieldOffset(24, testarrayofboolsOffset, 0); + } + static createTestarrayofboolsVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(+data[i]); + } + return builder.endVector(); + } + static startTestarrayofboolsVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addTestf(builder, testf) { + builder.addFieldFloat32(25, testf, 3.14159); + } + static addTestf2(builder, testf2) { + builder.addFieldFloat32(26, testf2, 3.0); + } + static addTestf3(builder, testf3) { + builder.addFieldFloat32(27, testf3, 0.0); + } + static addTestarrayofstring2(builder, testarrayofstring2Offset) { + builder.addFieldOffset(28, testarrayofstring2Offset, 0); + } + static createTestarrayofstring2Vector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startTestarrayofstring2Vector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addTestarrayofsortedstruct(builder, testarrayofsortedstructOffset) { + builder.addFieldOffset(29, testarrayofsortedstructOffset, 0); + } + static startTestarrayofsortedstructVector(builder, numElems) { + builder.startVector(8, numElems, 4); + } + static addFlex(builder, flexOffset) { + builder.addFieldOffset(30, flexOffset, 0); + } + static createFlexVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + static startFlexVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addTest5(builder, test5Offset) { + builder.addFieldOffset(31, test5Offset, 0); + } + static startTest5Vector(builder, numElems) { + builder.startVector(4, numElems, 2); + } + static addVectorOfLongs(builder, vectorOfLongsOffset) { + builder.addFieldOffset(32, vectorOfLongsOffset, 0); + } + static createVectorOfLongsVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + static startVectorOfLongsVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + static addVectorOfDoubles(builder, vectorOfDoublesOffset) { + builder.addFieldOffset(33, vectorOfDoublesOffset, 0); + } + static createVectorOfDoublesVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addFloat64(data[i]); + } + return builder.endVector(); + } + static startVectorOfDoublesVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + static addParentNamespaceTest(builder, parentNamespaceTestOffset) { + builder.addFieldOffset(34, parentNamespaceTestOffset, 0); + } + static addVectorOfReferrables(builder, vectorOfReferrablesOffset) { + builder.addFieldOffset(35, vectorOfReferrablesOffset, 0); + } + static createVectorOfReferrablesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startVectorOfReferrablesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addSingleWeakReference(builder, singleWeakReference) { + builder.addFieldInt64(36, singleWeakReference, BigInt('0')); + } + static addVectorOfWeakReferences(builder, vectorOfWeakReferencesOffset) { + builder.addFieldOffset(37, vectorOfWeakReferencesOffset, 0); + } + static createVectorOfWeakReferencesVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + static startVectorOfWeakReferencesVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + static addVectorOfStrongReferrables(builder, vectorOfStrongReferrablesOffset) { + builder.addFieldOffset(38, vectorOfStrongReferrablesOffset, 0); + } + static createVectorOfStrongReferrablesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startVectorOfStrongReferrablesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addCoOwningReference(builder, coOwningReference) { + builder.addFieldInt64(39, coOwningReference, BigInt('0')); + } + static addVectorOfCoOwningReferences(builder, vectorOfCoOwningReferencesOffset) { + builder.addFieldOffset(40, vectorOfCoOwningReferencesOffset, 0); + } + static createVectorOfCoOwningReferencesVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + static startVectorOfCoOwningReferencesVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + static addNonOwningReference(builder, nonOwningReference) { + builder.addFieldInt64(41, nonOwningReference, BigInt('0')); + } + static addVectorOfNonOwningReferences(builder, vectorOfNonOwningReferencesOffset) { + builder.addFieldOffset(42, vectorOfNonOwningReferencesOffset, 0); + } + static createVectorOfNonOwningReferencesVector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt64(data[i]); + } + return builder.endVector(); + } + static startVectorOfNonOwningReferencesVector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + static addAnyUniqueType(builder, anyUniqueType) { + builder.addFieldInt8(43, anyUniqueType, AnyUniqueAliases.NONE); + } + static addAnyUnique(builder, anyUniqueOffset) { + builder.addFieldOffset(44, anyUniqueOffset, 0); + } + static addAnyAmbiguousType(builder, anyAmbiguousType) { + builder.addFieldInt8(45, anyAmbiguousType, AnyAmbiguousAliases.NONE); + } + static addAnyAmbiguous(builder, anyAmbiguousOffset) { + builder.addFieldOffset(46, anyAmbiguousOffset, 0); + } + static addVectorOfEnums(builder, vectorOfEnumsOffset) { + builder.addFieldOffset(47, vectorOfEnumsOffset, 0); + } + static createVectorOfEnumsVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + static startVectorOfEnumsVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addSignedEnum(builder, signedEnum) { + builder.addFieldInt8(48, signedEnum, Race.None); + } + static addTestrequirednestedflatbuffer(builder, testrequirednestedflatbufferOffset) { + builder.addFieldOffset(49, testrequirednestedflatbufferOffset, 0); + } + static createTestrequirednestedflatbufferVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + static startTestrequirednestedflatbufferVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addScalarKeySortedTables(builder, scalarKeySortedTablesOffset) { + builder.addFieldOffset(50, scalarKeySortedTablesOffset, 0); + } + static createScalarKeySortedTablesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startScalarKeySortedTablesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addNativeInline(builder, nativeInlineOffset) { + builder.addFieldStruct(51, nativeInlineOffset, 0); + } + static addLongEnumNonEnumDefault(builder, longEnumNonEnumDefault) { + builder.addFieldInt64(52, longEnumNonEnumDefault, BigInt('0')); + } + static addLongEnumNormalDefault(builder, longEnumNormalDefault) { + builder.addFieldInt64(53, longEnumNormalDefault, BigInt('2')); + } + static addNanDefault(builder, nanDefault) { + builder.addFieldFloat32(54, nanDefault, NaN); + } + static addInfDefault(builder, infDefault) { + builder.addFieldFloat32(55, infDefault, Infinity); + } + static addPositiveInfDefault(builder, positiveInfDefault) { + builder.addFieldFloat32(56, positiveInfDefault, Infinity); + } + static addInfinityDefault(builder, infinityDefault) { + builder.addFieldFloat32(57, infinityDefault, Infinity); + } + static addPositiveInfinityDefault(builder, positiveInfinityDefault) { + builder.addFieldFloat32(58, positiveInfinityDefault, Infinity); + } + static addNegativeInfDefault(builder, negativeInfDefault) { + builder.addFieldFloat32(59, negativeInfDefault, -Infinity); + } + static addNegativeInfinityDefault(builder, negativeInfinityDefault) { + builder.addFieldFloat32(60, negativeInfinityDefault, -Infinity); + } + static addDoubleInfDefault(builder, doubleInfDefault) { + builder.addFieldFloat64(61, doubleInfDefault, Infinity); + } + static endMonster(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 10); // name + return offset; + } + static finishMonsterBuffer(builder, offset) { + builder.finish(offset, 'MONS'); + } + static finishSizePrefixedMonsterBuffer(builder, offset) { + builder.finish(offset, 'MONS', true); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new MonsterT((this.pos() !== null ? this.pos().unpack() : null), this.mana(), this.hp(), this.name(), this.bb.createScalarList(this.inventory.bind(this), this.inventoryLength()), this.color(), this.testType(), (() => { + const temp = unionToAny(this.testType(), this.test.bind(this)); + if (temp === null) { + return null; + } + return temp.unpack(); + })(), this.bb.createObjList(this.test4.bind(this), this.test4Length()), this.bb.createScalarList(this.testarrayofstring.bind(this), this.testarrayofstringLength()), this.bb.createObjList(this.testarrayoftables.bind(this), this.testarrayoftablesLength()), (this.enemy() !== null ? this.enemy().unpack() : null), this.bb.createScalarList(this.testnestedflatbuffer.bind(this), this.testnestedflatbufferLength()), (this.testempty() !== null ? this.testempty().unpack() : null), this.testbool(), this.testhashs32Fnv1(), this.testhashu32Fnv1(), this.testhashs64Fnv1(), this.testhashu64Fnv1(), this.testhashs32Fnv1a(), this.testhashu32Fnv1a(), this.testhashs64Fnv1a(), this.testhashu64Fnv1a(), this.bb.createScalarList(this.testarrayofbools.bind(this), this.testarrayofboolsLength()), this.testf(), this.testf2(), this.testf3(), this.bb.createScalarList(this.testarrayofstring2.bind(this), this.testarrayofstring2Length()), this.bb.createObjList(this.testarrayofsortedstruct.bind(this), this.testarrayofsortedstructLength()), this.bb.createScalarList(this.flex.bind(this), this.flexLength()), this.bb.createObjList(this.test5.bind(this), this.test5Length()), this.bb.createScalarList(this.vectorOfLongs.bind(this), this.vectorOfLongsLength()), this.bb.createScalarList(this.vectorOfDoubles.bind(this), this.vectorOfDoublesLength()), (this.parentNamespaceTest() !== null ? this.parentNamespaceTest().unpack() : null), this.bb.createObjList(this.vectorOfReferrables.bind(this), this.vectorOfReferrablesLength()), this.singleWeakReference(), this.bb.createScalarList(this.vectorOfWeakReferences.bind(this), this.vectorOfWeakReferencesLength()), this.bb.createObjList(this.vectorOfStrongReferrables.bind(this), this.vectorOfStrongReferrablesLength()), this.coOwningReference(), this.bb.createScalarList(this.vectorOfCoOwningReferences.bind(this), this.vectorOfCoOwningReferencesLength()), this.nonOwningReference(), this.bb.createScalarList(this.vectorOfNonOwningReferences.bind(this), this.vectorOfNonOwningReferencesLength()), this.anyUniqueType(), (() => { + const temp = unionToAnyUniqueAliases(this.anyUniqueType(), this.anyUnique.bind(this)); + if (temp === null) { + return null; + } + return temp.unpack(); + })(), this.anyAmbiguousType(), (() => { + const temp = unionToAnyAmbiguousAliases(this.anyAmbiguousType(), this.anyAmbiguous.bind(this)); + if (temp === null) { + return null; + } + return temp.unpack(); + })(), this.bb.createScalarList(this.vectorOfEnums.bind(this), this.vectorOfEnumsLength()), 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.longEnumNonEnumDefault(), this.longEnumNormalDefault(), this.nanDefault(), this.infDefault(), this.positiveInfDefault(), this.infinityDefault(), this.positiveInfinityDefault(), this.negativeInfDefault(), this.negativeInfinityDefault(), this.doubleInfDefault()); + } + unpackTo(_o) { + _o.pos = (this.pos() !== null ? this.pos().unpack() : null); + _o.mana = this.mana(); + _o.hp = this.hp(); + _o.name = this.name(); + _o.inventory = this.bb.createScalarList(this.inventory.bind(this), this.inventoryLength()); + _o.color = this.color(); + _o.testType = this.testType(); + _o.test = (() => { + const temp = unionToAny(this.testType(), this.test.bind(this)); + if (temp === null) { + return null; + } + return temp.unpack(); + })(); + _o.test4 = this.bb.createObjList(this.test4.bind(this), this.test4Length()); + _o.testarrayofstring = this.bb.createScalarList(this.testarrayofstring.bind(this), this.testarrayofstringLength()); + _o.testarrayoftables = this.bb.createObjList(this.testarrayoftables.bind(this), this.testarrayoftablesLength()); + _o.enemy = (this.enemy() !== null ? this.enemy().unpack() : null); + _o.testnestedflatbuffer = this.bb.createScalarList(this.testnestedflatbuffer.bind(this), this.testnestedflatbufferLength()); + _o.testempty = (this.testempty() !== null ? this.testempty().unpack() : null); + _o.testbool = this.testbool(); + _o.testhashs32Fnv1 = this.testhashs32Fnv1(); + _o.testhashu32Fnv1 = this.testhashu32Fnv1(); + _o.testhashs64Fnv1 = this.testhashs64Fnv1(); + _o.testhashu64Fnv1 = this.testhashu64Fnv1(); + _o.testhashs32Fnv1a = this.testhashs32Fnv1a(); + _o.testhashu32Fnv1a = this.testhashu32Fnv1a(); + _o.testhashs64Fnv1a = this.testhashs64Fnv1a(); + _o.testhashu64Fnv1a = this.testhashu64Fnv1a(); + _o.testarrayofbools = this.bb.createScalarList(this.testarrayofbools.bind(this), this.testarrayofboolsLength()); + _o.testf = this.testf(); + _o.testf2 = this.testf2(); + _o.testf3 = this.testf3(); + _o.testarrayofstring2 = this.bb.createScalarList(this.testarrayofstring2.bind(this), this.testarrayofstring2Length()); + _o.testarrayofsortedstruct = this.bb.createObjList(this.testarrayofsortedstruct.bind(this), this.testarrayofsortedstructLength()); + _o.flex = this.bb.createScalarList(this.flex.bind(this), this.flexLength()); + _o.test5 = this.bb.createObjList(this.test5.bind(this), this.test5Length()); + _o.vectorOfLongs = this.bb.createScalarList(this.vectorOfLongs.bind(this), this.vectorOfLongsLength()); + _o.vectorOfDoubles = this.bb.createScalarList(this.vectorOfDoubles.bind(this), this.vectorOfDoublesLength()); + _o.parentNamespaceTest = (this.parentNamespaceTest() !== null ? this.parentNamespaceTest().unpack() : null); + _o.vectorOfReferrables = this.bb.createObjList(this.vectorOfReferrables.bind(this), this.vectorOfReferrablesLength()); + _o.singleWeakReference = this.singleWeakReference(); + _o.vectorOfWeakReferences = this.bb.createScalarList(this.vectorOfWeakReferences.bind(this), this.vectorOfWeakReferencesLength()); + _o.vectorOfStrongReferrables = this.bb.createObjList(this.vectorOfStrongReferrables.bind(this), this.vectorOfStrongReferrablesLength()); + _o.coOwningReference = this.coOwningReference(); + _o.vectorOfCoOwningReferences = this.bb.createScalarList(this.vectorOfCoOwningReferences.bind(this), this.vectorOfCoOwningReferencesLength()); + _o.nonOwningReference = this.nonOwningReference(); + _o.vectorOfNonOwningReferences = this.bb.createScalarList(this.vectorOfNonOwningReferences.bind(this), this.vectorOfNonOwningReferencesLength()); + _o.anyUniqueType = this.anyUniqueType(); + _o.anyUnique = (() => { + const temp = unionToAnyUniqueAliases(this.anyUniqueType(), this.anyUnique.bind(this)); + if (temp === null) { + return null; + } + return temp.unpack(); + })(); + _o.anyAmbiguousType = this.anyAmbiguousType(); + _o.anyAmbiguous = (() => { + const temp = unionToAnyAmbiguousAliases(this.anyAmbiguousType(), this.anyAmbiguous.bind(this)); + if (temp === null) { + return null; + } + return temp.unpack(); + })(); + _o.vectorOfEnums = this.bb.createScalarList(this.vectorOfEnums.bind(this), this.vectorOfEnumsLength()); + _o.signedEnum = this.signedEnum(); + _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(); + _o.nanDefault = this.nanDefault(); + _o.infDefault = this.infDefault(); + _o.positiveInfDefault = this.positiveInfDefault(); + _o.infinityDefault = this.infinityDefault(); + _o.positiveInfinityDefault = this.positiveInfinityDefault(); + _o.negativeInfDefault = this.negativeInfDefault(); + _o.negativeInfinityDefault = this.negativeInfinityDefault(); + _o.doubleInfDefault = this.doubleInfDefault(); } - return builder.endVector(); - } - static startScalarKeySortedTablesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addNativeInline(builder, nativeInlineOffset) { - builder.addFieldStruct(51, nativeInlineOffset, 0); - } - static addLongEnumNonEnumDefault(builder, longEnumNonEnumDefault) { - builder.addFieldInt64(52, longEnumNonEnumDefault, BigInt('0')); - } - static addLongEnumNormalDefault(builder, longEnumNormalDefault) { - builder.addFieldInt64(53, longEnumNormalDefault, BigInt('2')); - } - static addNanDefault(builder, nanDefault) { - builder.addFieldFloat32(54, nanDefault, NaN); - } - static addInfDefault(builder, infDefault) { - builder.addFieldFloat32(55, infDefault, Infinity); - } - static addPositiveInfDefault(builder, positiveInfDefault) { - builder.addFieldFloat32(56, positiveInfDefault, Infinity); - } - static addInfinityDefault(builder, infinityDefault) { - builder.addFieldFloat32(57, infinityDefault, Infinity); - } - static addPositiveInfinityDefault(builder, positiveInfinityDefault) { - builder.addFieldFloat32(58, positiveInfinityDefault, Infinity); - } - static addNegativeInfDefault(builder, negativeInfDefault) { - builder.addFieldFloat32(59, negativeInfDefault, -Infinity); - } - static addNegativeInfinityDefault(builder, negativeInfinityDefault) { - builder.addFieldFloat32(60, negativeInfinityDefault, -Infinity); - } - static addDoubleInfDefault(builder, doubleInfDefault) { - builder.addFieldFloat64(61, doubleInfDefault, Infinity); - } - static endMonster(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 10); // name - return offset; - } - static finishMonsterBuffer(builder, offset) { - builder.finish(offset, 'MONS'); - } - static finishSizePrefixedMonsterBuffer(builder, offset) { - builder.finish(offset, 'MONS', true); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new MonsterT( - (this.pos() !== null ? this.pos().unpack() : null), this.mana(), - this.hp(), this.name(), - this.bb.createScalarList( - this.inventory.bind(this), this.inventoryLength()), - this.color(), this.testType(), (() => { - const temp = unionToAny(this.testType(), this.test.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(), - this.bb.createObjList(this.test4.bind(this), this.test4Length()), - this.bb.createScalarList( - this.testarrayofstring.bind(this), this.testarrayofstringLength()), - this.bb.createObjList( - this.testarrayoftables.bind(this), this.testarrayoftablesLength()), - (this.enemy() !== null ? this.enemy().unpack() : null), - this.bb.createScalarList( - this.testnestedflatbuffer.bind(this), - this.testnestedflatbufferLength()), - (this.testempty() !== null ? this.testempty().unpack() : null), - this.testbool(), this.testhashs32Fnv1(), this.testhashu32Fnv1(), - this.testhashs64Fnv1(), this.testhashu64Fnv1(), this.testhashs32Fnv1a(), - this.testhashu32Fnv1a(), this.testhashs64Fnv1a(), - this.testhashu64Fnv1a(), - this.bb.createScalarList( - this.testarrayofbools.bind(this), this.testarrayofboolsLength()), - this.testf(), this.testf2(), this.testf3(), - this.bb.createScalarList( - this.testarrayofstring2.bind(this), - this.testarrayofstring2Length()), - this.bb.createObjList( - this.testarrayofsortedstruct.bind(this), - this.testarrayofsortedstructLength()), - this.bb.createScalarList(this.flex.bind(this), this.flexLength()), - this.bb.createObjList(this.test5.bind(this), this.test5Length()), - this.bb.createScalarList( - this.vectorOfLongs.bind(this), this.vectorOfLongsLength()), - this.bb.createScalarList( - this.vectorOfDoubles.bind(this), this.vectorOfDoublesLength()), - (this.parentNamespaceTest() !== null ? - this.parentNamespaceTest().unpack() : - null), - this.bb.createObjList( - this.vectorOfReferrables.bind(this), - this.vectorOfReferrablesLength()), - this.singleWeakReference(), - this.bb.createScalarList( - this.vectorOfWeakReferences.bind(this), - this.vectorOfWeakReferencesLength()), - this.bb.createObjList( - this.vectorOfStrongReferrables.bind(this), - this.vectorOfStrongReferrablesLength()), - this.coOwningReference(), - this.bb.createScalarList( - this.vectorOfCoOwningReferences.bind(this), - this.vectorOfCoOwningReferencesLength()), - this.nonOwningReference(), - this.bb.createScalarList( - this.vectorOfNonOwningReferences.bind(this), - this.vectorOfNonOwningReferencesLength()), - this.anyUniqueType(), (() => { - const temp = unionToAnyUniqueAliases( - this.anyUniqueType(), this.anyUnique.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(), - this.anyAmbiguousType(), (() => { - const temp = unionToAnyAmbiguousAliases( - this.anyAmbiguousType(), this.anyAmbiguous.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(), - this.bb.createScalarList( - this.vectorOfEnums.bind(this), this.vectorOfEnumsLength()), - 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.longEnumNonEnumDefault(), this.longEnumNormalDefault(), - this.nanDefault(), this.infDefault(), this.positiveInfDefault(), - this.infinityDefault(), this.positiveInfinityDefault(), - this.negativeInfDefault(), this.negativeInfinityDefault(), - this.doubleInfDefault()); - } - unpackTo(_o) { - _o.pos = (this.pos() !== null ? this.pos().unpack() : null); - _o.mana = this.mana(); - _o.hp = this.hp(); - _o.name = this.name(); - _o.inventory = this.bb.createScalarList( - this.inventory.bind(this), this.inventoryLength()); - _o.color = this.color(); - _o.testType = this.testType(); - _o.test = (() => { - const temp = unionToAny(this.testType(), this.test.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(); - _o.test4 = this.bb.createObjList(this.test4.bind(this), this.test4Length()); - _o.testarrayofstring = this.bb.createScalarList( - this.testarrayofstring.bind(this), this.testarrayofstringLength()); - _o.testarrayoftables = this.bb.createObjList( - this.testarrayoftables.bind(this), this.testarrayoftablesLength()); - _o.enemy = (this.enemy() !== null ? this.enemy().unpack() : null); - _o.testnestedflatbuffer = this.bb.createScalarList( - this.testnestedflatbuffer.bind(this), - this.testnestedflatbufferLength()); - _o.testempty = - (this.testempty() !== null ? this.testempty().unpack() : null); - _o.testbool = this.testbool(); - _o.testhashs32Fnv1 = this.testhashs32Fnv1(); - _o.testhashu32Fnv1 = this.testhashu32Fnv1(); - _o.testhashs64Fnv1 = this.testhashs64Fnv1(); - _o.testhashu64Fnv1 = this.testhashu64Fnv1(); - _o.testhashs32Fnv1a = this.testhashs32Fnv1a(); - _o.testhashu32Fnv1a = this.testhashu32Fnv1a(); - _o.testhashs64Fnv1a = this.testhashs64Fnv1a(); - _o.testhashu64Fnv1a = this.testhashu64Fnv1a(); - _o.testarrayofbools = this.bb.createScalarList( - this.testarrayofbools.bind(this), this.testarrayofboolsLength()); - _o.testf = this.testf(); - _o.testf2 = this.testf2(); - _o.testf3 = this.testf3(); - _o.testarrayofstring2 = this.bb.createScalarList( - this.testarrayofstring2.bind(this), this.testarrayofstring2Length()); - _o.testarrayofsortedstruct = this.bb.createObjList( - this.testarrayofsortedstruct.bind(this), - this.testarrayofsortedstructLength()); - _o.flex = this.bb.createScalarList(this.flex.bind(this), this.flexLength()); - _o.test5 = this.bb.createObjList(this.test5.bind(this), this.test5Length()); - _o.vectorOfLongs = this.bb.createScalarList( - this.vectorOfLongs.bind(this), this.vectorOfLongsLength()); - _o.vectorOfDoubles = this.bb.createScalarList( - this.vectorOfDoubles.bind(this), this.vectorOfDoublesLength()); - _o.parentNamespaceTest = - (this.parentNamespaceTest() !== null ? - this.parentNamespaceTest().unpack() : - null); - _o.vectorOfReferrables = this.bb.createObjList( - this.vectorOfReferrables.bind(this), this.vectorOfReferrablesLength()); - _o.singleWeakReference = this.singleWeakReference(); - _o.vectorOfWeakReferences = this.bb.createScalarList( - this.vectorOfWeakReferences.bind(this), - this.vectorOfWeakReferencesLength()); - _o.vectorOfStrongReferrables = this.bb.createObjList( - this.vectorOfStrongReferrables.bind(this), - this.vectorOfStrongReferrablesLength()); - _o.coOwningReference = this.coOwningReference(); - _o.vectorOfCoOwningReferences = this.bb.createScalarList( - this.vectorOfCoOwningReferences.bind(this), - this.vectorOfCoOwningReferencesLength()); - _o.nonOwningReference = this.nonOwningReference(); - _o.vectorOfNonOwningReferences = this.bb.createScalarList( - this.vectorOfNonOwningReferences.bind(this), - this.vectorOfNonOwningReferencesLength()); - _o.anyUniqueType = this.anyUniqueType(); - _o.anyUnique = (() => { - const temp = unionToAnyUniqueAliases( - this.anyUniqueType(), this.anyUnique.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(); - _o.anyAmbiguousType = this.anyAmbiguousType(); - _o.anyAmbiguous = (() => { - const temp = unionToAnyAmbiguousAliases( - this.anyAmbiguousType(), this.anyAmbiguous.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(); - _o.vectorOfEnums = this.bb.createScalarList( - this.vectorOfEnums.bind(this), this.vectorOfEnumsLength()); - _o.signedEnum = this.signedEnum(); - _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(); - _o.nanDefault = this.nanDefault(); - _o.infDefault = this.infDefault(); - _o.positiveInfDefault = this.positiveInfDefault(); - _o.infinityDefault = this.infinityDefault(); - _o.positiveInfinityDefault = this.positiveInfinityDefault(); - _o.negativeInfDefault = this.negativeInfDefault(); - _o.negativeInfinityDefault = this.negativeInfinityDefault(); - _o.doubleInfDefault = this.doubleInfDefault(); - } } 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 = 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 = [], - nativeInline = null, longEnumNonEnumDefault = BigInt('0'), - longEnumNormalDefault = BigInt('2'), nanDefault = NaN, - infDefault = Infinity, positiveInfDefault = Infinity, - infinityDefault = Infinity, positiveInfinityDefault = Infinity, - negativeInfDefault = -Infinity, negativeInfinityDefault = -Infinity, - doubleInfDefault = Infinity) { - this.pos = pos; - this.mana = mana; - this.hp = hp; - this.name = name; - this.inventory = inventory; - this.color = color; - this.testType = testType; - this.test = test; - this.test4 = test4; - this.testarrayofstring = testarrayofstring; - this.testarrayoftables = testarrayoftables; - this.enemy = enemy; - this.testnestedflatbuffer = testnestedflatbuffer; - this.testempty = testempty; - this.testbool = testbool; - this.testhashs32Fnv1 = testhashs32Fnv1; - this.testhashu32Fnv1 = testhashu32Fnv1; - this.testhashs64Fnv1 = testhashs64Fnv1; - this.testhashu64Fnv1 = testhashu64Fnv1; - this.testhashs32Fnv1a = testhashs32Fnv1a; - this.testhashu32Fnv1a = testhashu32Fnv1a; - this.testhashs64Fnv1a = testhashs64Fnv1a; - this.testhashu64Fnv1a = testhashu64Fnv1a; - this.testarrayofbools = testarrayofbools; - this.testf = testf; - this.testf2 = testf2; - this.testf3 = testf3; - this.testarrayofstring2 = testarrayofstring2; - this.testarrayofsortedstruct = testarrayofsortedstruct; - this.flex = flex; - this.test5 = test5; - this.vectorOfLongs = vectorOfLongs; - this.vectorOfDoubles = vectorOfDoubles; - this.parentNamespaceTest = parentNamespaceTest; - this.vectorOfReferrables = vectorOfReferrables; - this.singleWeakReference = singleWeakReference; - this.vectorOfWeakReferences = vectorOfWeakReferences; - this.vectorOfStrongReferrables = vectorOfStrongReferrables; - this.coOwningReference = coOwningReference; - this.vectorOfCoOwningReferences = vectorOfCoOwningReferences; - this.nonOwningReference = nonOwningReference; - this.vectorOfNonOwningReferences = vectorOfNonOwningReferences; - this.anyUniqueType = anyUniqueType; - this.anyUnique = anyUnique; - this.anyAmbiguousType = anyAmbiguousType; - this.anyAmbiguous = anyAmbiguous; - this.vectorOfEnums = vectorOfEnums; - this.signedEnum = signedEnum; - this.testrequirednestedflatbuffer = testrequirednestedflatbuffer; - this.scalarKeySortedTables = scalarKeySortedTables; - this.nativeInline = nativeInline; - this.longEnumNonEnumDefault = longEnumNonEnumDefault; - this.longEnumNormalDefault = longEnumNormalDefault; - this.nanDefault = nanDefault; - this.infDefault = infDefault; - this.positiveInfDefault = positiveInfDefault; - this.infinityDefault = infinityDefault; - this.positiveInfinityDefault = positiveInfinityDefault; - this.negativeInfDefault = negativeInfDefault; - this.negativeInfinityDefault = negativeInfinityDefault; - this.doubleInfDefault = doubleInfDefault; - } - pack(builder) { - const name = (this.name !== null ? builder.createString(this.name) : 0); - const inventory = Monster.createInventoryVector(builder, this.inventory); - const test = builder.createObjectOffset(this.test); - const test4 = - builder.createStructOffsetList(this.test4, Monster.startTest4Vector); - const testarrayofstring = Monster.createTestarrayofstringVector( - builder, builder.createObjectOffsetList(this.testarrayofstring)); - const testarrayoftables = Monster.createTestarrayoftablesVector( - builder, builder.createObjectOffsetList(this.testarrayoftables)); - const enemy = (this.enemy !== null ? this.enemy.pack(builder) : 0); - const testnestedflatbuffer = Monster.createTestnestedflatbufferVector( - builder, this.testnestedflatbuffer); - const testempty = - (this.testempty !== null ? this.testempty.pack(builder) : 0); - const testarrayofbools = - Monster.createTestarrayofboolsVector(builder, this.testarrayofbools); - const testarrayofstring2 = Monster.createTestarrayofstring2Vector( - builder, builder.createObjectOffsetList(this.testarrayofstring2)); - const testarrayofsortedstruct = builder.createStructOffsetList( - this.testarrayofsortedstruct, - Monster.startTestarrayofsortedstructVector); - const flex = Monster.createFlexVector(builder, this.flex); - const test5 = - builder.createStructOffsetList(this.test5, Monster.startTest5Vector); - const vectorOfLongs = - Monster.createVectorOfLongsVector(builder, this.vectorOfLongs); - const vectorOfDoubles = - Monster.createVectorOfDoublesVector(builder, this.vectorOfDoubles); - const parentNamespaceTest = - (this.parentNamespaceTest !== null ? - this.parentNamespaceTest.pack(builder) : - 0); - const vectorOfReferrables = Monster.createVectorOfReferrablesVector( - builder, builder.createObjectOffsetList(this.vectorOfReferrables)); - const vectorOfWeakReferences = Monster.createVectorOfWeakReferencesVector( - builder, this.vectorOfWeakReferences); - const vectorOfStrongReferrables = - Monster.createVectorOfStrongReferrablesVector( - builder, - builder.createObjectOffsetList(this.vectorOfStrongReferrables)); - const vectorOfCoOwningReferences = - Monster.createVectorOfCoOwningReferencesVector( - builder, this.vectorOfCoOwningReferences); - const vectorOfNonOwningReferences = - Monster.createVectorOfNonOwningReferencesVector( - builder, this.vectorOfNonOwningReferences); - const anyUnique = builder.createObjectOffset(this.anyUnique); - const anyAmbiguous = builder.createObjectOffset(this.anyAmbiguous); - const vectorOfEnums = - Monster.createVectorOfEnumsVector(builder, this.vectorOfEnums); - const testrequirednestedflatbuffer = - Monster.createTestrequirednestedflatbufferVector( - builder, this.testrequirednestedflatbuffer); - const scalarKeySortedTables = Monster.createScalarKeySortedTablesVector( - builder, builder.createObjectOffsetList(this.scalarKeySortedTables)); - Monster.startMonster(builder); - Monster.addPos(builder, (this.pos !== null ? this.pos.pack(builder) : 0)); - Monster.addMana(builder, this.mana); - Monster.addHp(builder, this.hp); - Monster.addName(builder, name); - Monster.addInventory(builder, inventory); - Monster.addColor(builder, this.color); - Monster.addTestType(builder, this.testType); - Monster.addTest(builder, test); - Monster.addTest4(builder, test4); - Monster.addTestarrayofstring(builder, testarrayofstring); - Monster.addTestarrayoftables(builder, testarrayoftables); - Monster.addEnemy(builder, enemy); - Monster.addTestnestedflatbuffer(builder, testnestedflatbuffer); - Monster.addTestempty(builder, testempty); - Monster.addTestbool(builder, this.testbool); - Monster.addTesthashs32Fnv1(builder, this.testhashs32Fnv1); - Monster.addTesthashu32Fnv1(builder, this.testhashu32Fnv1); - Monster.addTesthashs64Fnv1(builder, this.testhashs64Fnv1); - Monster.addTesthashu64Fnv1(builder, this.testhashu64Fnv1); - Monster.addTesthashs32Fnv1a(builder, this.testhashs32Fnv1a); - Monster.addTesthashu32Fnv1a(builder, this.testhashu32Fnv1a); - Monster.addTesthashs64Fnv1a(builder, this.testhashs64Fnv1a); - Monster.addTesthashu64Fnv1a(builder, this.testhashu64Fnv1a); - Monster.addTestarrayofbools(builder, testarrayofbools); - Monster.addTestf(builder, this.testf); - Monster.addTestf2(builder, this.testf2); - Monster.addTestf3(builder, this.testf3); - Monster.addTestarrayofstring2(builder, testarrayofstring2); - Monster.addTestarrayofsortedstruct(builder, testarrayofsortedstruct); - Monster.addFlex(builder, flex); - Monster.addTest5(builder, test5); - Monster.addVectorOfLongs(builder, vectorOfLongs); - Monster.addVectorOfDoubles(builder, vectorOfDoubles); - Monster.addParentNamespaceTest(builder, parentNamespaceTest); - Monster.addVectorOfReferrables(builder, vectorOfReferrables); - Monster.addSingleWeakReference(builder, this.singleWeakReference); - Monster.addVectorOfWeakReferences(builder, vectorOfWeakReferences); - Monster.addVectorOfStrongReferrables(builder, vectorOfStrongReferrables); - Monster.addCoOwningReference(builder, this.coOwningReference); - Monster.addVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences); - Monster.addNonOwningReference(builder, this.nonOwningReference); - Monster.addVectorOfNonOwningReferences( - builder, vectorOfNonOwningReferences); - Monster.addAnyUniqueType(builder, this.anyUniqueType); - Monster.addAnyUnique(builder, anyUnique); - Monster.addAnyAmbiguousType(builder, this.anyAmbiguousType); - Monster.addAnyAmbiguous(builder, anyAmbiguous); - Monster.addVectorOfEnums(builder, vectorOfEnums); - Monster.addSignedEnum(builder, this.signedEnum); - 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); - Monster.addNanDefault(builder, this.nanDefault); - Monster.addInfDefault(builder, this.infDefault); - Monster.addPositiveInfDefault(builder, this.positiveInfDefault); - Monster.addInfinityDefault(builder, this.infinityDefault); - Monster.addPositiveInfinityDefault(builder, this.positiveInfinityDefault); - Monster.addNegativeInfDefault(builder, this.negativeInfDefault); - Monster.addNegativeInfinityDefault(builder, this.negativeInfinityDefault); - Monster.addDoubleInfDefault(builder, this.doubleInfDefault); - return Monster.endMonster(builder); - } + 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 = [], nativeInline = null, longEnumNonEnumDefault = BigInt('0'), longEnumNormalDefault = BigInt('2'), nanDefault = NaN, infDefault = Infinity, positiveInfDefault = Infinity, infinityDefault = Infinity, positiveInfinityDefault = Infinity, negativeInfDefault = -Infinity, negativeInfinityDefault = -Infinity, doubleInfDefault = Infinity) { + this.pos = pos; + this.mana = mana; + this.hp = hp; + this.name = name; + this.inventory = inventory; + this.color = color; + this.testType = testType; + this.test = test; + this.test4 = test4; + this.testarrayofstring = testarrayofstring; + this.testarrayoftables = testarrayoftables; + this.enemy = enemy; + this.testnestedflatbuffer = testnestedflatbuffer; + this.testempty = testempty; + this.testbool = testbool; + this.testhashs32Fnv1 = testhashs32Fnv1; + this.testhashu32Fnv1 = testhashu32Fnv1; + this.testhashs64Fnv1 = testhashs64Fnv1; + this.testhashu64Fnv1 = testhashu64Fnv1; + this.testhashs32Fnv1a = testhashs32Fnv1a; + this.testhashu32Fnv1a = testhashu32Fnv1a; + this.testhashs64Fnv1a = testhashs64Fnv1a; + this.testhashu64Fnv1a = testhashu64Fnv1a; + this.testarrayofbools = testarrayofbools; + this.testf = testf; + this.testf2 = testf2; + this.testf3 = testf3; + this.testarrayofstring2 = testarrayofstring2; + this.testarrayofsortedstruct = testarrayofsortedstruct; + this.flex = flex; + this.test5 = test5; + this.vectorOfLongs = vectorOfLongs; + this.vectorOfDoubles = vectorOfDoubles; + this.parentNamespaceTest = parentNamespaceTest; + this.vectorOfReferrables = vectorOfReferrables; + this.singleWeakReference = singleWeakReference; + this.vectorOfWeakReferences = vectorOfWeakReferences; + this.vectorOfStrongReferrables = vectorOfStrongReferrables; + this.coOwningReference = coOwningReference; + this.vectorOfCoOwningReferences = vectorOfCoOwningReferences; + this.nonOwningReference = nonOwningReference; + this.vectorOfNonOwningReferences = vectorOfNonOwningReferences; + this.anyUniqueType = anyUniqueType; + this.anyUnique = anyUnique; + this.anyAmbiguousType = anyAmbiguousType; + this.anyAmbiguous = anyAmbiguous; + this.vectorOfEnums = vectorOfEnums; + this.signedEnum = signedEnum; + this.testrequirednestedflatbuffer = testrequirednestedflatbuffer; + this.scalarKeySortedTables = scalarKeySortedTables; + this.nativeInline = nativeInline; + this.longEnumNonEnumDefault = longEnumNonEnumDefault; + this.longEnumNormalDefault = longEnumNormalDefault; + this.nanDefault = nanDefault; + this.infDefault = infDefault; + this.positiveInfDefault = positiveInfDefault; + this.infinityDefault = infinityDefault; + this.positiveInfinityDefault = positiveInfinityDefault; + this.negativeInfDefault = negativeInfDefault; + this.negativeInfinityDefault = negativeInfinityDefault; + this.doubleInfDefault = doubleInfDefault; + } + pack(builder) { + const name = (this.name !== null ? builder.createString(this.name) : 0); + const inventory = Monster.createInventoryVector(builder, this.inventory); + const test = builder.createObjectOffset(this.test); + const test4 = builder.createStructOffsetList(this.test4, Monster.startTest4Vector); + const testarrayofstring = Monster.createTestarrayofstringVector(builder, builder.createObjectOffsetList(this.testarrayofstring)); + const testarrayoftables = Monster.createTestarrayoftablesVector(builder, builder.createObjectOffsetList(this.testarrayoftables)); + const enemy = (this.enemy !== null ? this.enemy.pack(builder) : 0); + const testnestedflatbuffer = Monster.createTestnestedflatbufferVector(builder, this.testnestedflatbuffer); + const testempty = (this.testempty !== null ? this.testempty.pack(builder) : 0); + const testarrayofbools = Monster.createTestarrayofboolsVector(builder, this.testarrayofbools); + const testarrayofstring2 = Monster.createTestarrayofstring2Vector(builder, builder.createObjectOffsetList(this.testarrayofstring2)); + const testarrayofsortedstruct = builder.createStructOffsetList(this.testarrayofsortedstruct, Monster.startTestarrayofsortedstructVector); + const flex = Monster.createFlexVector(builder, this.flex); + const test5 = builder.createStructOffsetList(this.test5, Monster.startTest5Vector); + const vectorOfLongs = Monster.createVectorOfLongsVector(builder, this.vectorOfLongs); + const vectorOfDoubles = Monster.createVectorOfDoublesVector(builder, this.vectorOfDoubles); + const parentNamespaceTest = (this.parentNamespaceTest !== null ? this.parentNamespaceTest.pack(builder) : 0); + const vectorOfReferrables = Monster.createVectorOfReferrablesVector(builder, builder.createObjectOffsetList(this.vectorOfReferrables)); + const vectorOfWeakReferences = Monster.createVectorOfWeakReferencesVector(builder, this.vectorOfWeakReferences); + const vectorOfStrongReferrables = Monster.createVectorOfStrongReferrablesVector(builder, builder.createObjectOffsetList(this.vectorOfStrongReferrables)); + const vectorOfCoOwningReferences = Monster.createVectorOfCoOwningReferencesVector(builder, this.vectorOfCoOwningReferences); + const vectorOfNonOwningReferences = Monster.createVectorOfNonOwningReferencesVector(builder, this.vectorOfNonOwningReferences); + const anyUnique = builder.createObjectOffset(this.anyUnique); + const anyAmbiguous = builder.createObjectOffset(this.anyAmbiguous); + const vectorOfEnums = Monster.createVectorOfEnumsVector(builder, this.vectorOfEnums); + const testrequirednestedflatbuffer = Monster.createTestrequirednestedflatbufferVector(builder, this.testrequirednestedflatbuffer); + const scalarKeySortedTables = Monster.createScalarKeySortedTablesVector(builder, builder.createObjectOffsetList(this.scalarKeySortedTables)); + Monster.startMonster(builder); + Monster.addPos(builder, (this.pos !== null ? this.pos.pack(builder) : 0)); + Monster.addMana(builder, this.mana); + Monster.addHp(builder, this.hp); + Monster.addName(builder, name); + Monster.addInventory(builder, inventory); + Monster.addColor(builder, this.color); + Monster.addTestType(builder, this.testType); + Monster.addTest(builder, test); + Monster.addTest4(builder, test4); + Monster.addTestarrayofstring(builder, testarrayofstring); + Monster.addTestarrayoftables(builder, testarrayoftables); + Monster.addEnemy(builder, enemy); + Monster.addTestnestedflatbuffer(builder, testnestedflatbuffer); + Monster.addTestempty(builder, testempty); + Monster.addTestbool(builder, this.testbool); + Monster.addTesthashs32Fnv1(builder, this.testhashs32Fnv1); + Monster.addTesthashu32Fnv1(builder, this.testhashu32Fnv1); + Monster.addTesthashs64Fnv1(builder, this.testhashs64Fnv1); + Monster.addTesthashu64Fnv1(builder, this.testhashu64Fnv1); + Monster.addTesthashs32Fnv1a(builder, this.testhashs32Fnv1a); + Monster.addTesthashu32Fnv1a(builder, this.testhashu32Fnv1a); + Monster.addTesthashs64Fnv1a(builder, this.testhashs64Fnv1a); + Monster.addTesthashu64Fnv1a(builder, this.testhashu64Fnv1a); + Monster.addTestarrayofbools(builder, testarrayofbools); + Monster.addTestf(builder, this.testf); + Monster.addTestf2(builder, this.testf2); + Monster.addTestf3(builder, this.testf3); + Monster.addTestarrayofstring2(builder, testarrayofstring2); + Monster.addTestarrayofsortedstruct(builder, testarrayofsortedstruct); + Monster.addFlex(builder, flex); + Monster.addTest5(builder, test5); + Monster.addVectorOfLongs(builder, vectorOfLongs); + Monster.addVectorOfDoubles(builder, vectorOfDoubles); + Monster.addParentNamespaceTest(builder, parentNamespaceTest); + Monster.addVectorOfReferrables(builder, vectorOfReferrables); + Monster.addSingleWeakReference(builder, this.singleWeakReference); + Monster.addVectorOfWeakReferences(builder, vectorOfWeakReferences); + Monster.addVectorOfStrongReferrables(builder, vectorOfStrongReferrables); + Monster.addCoOwningReference(builder, this.coOwningReference); + Monster.addVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences); + Monster.addNonOwningReference(builder, this.nonOwningReference); + Monster.addVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences); + Monster.addAnyUniqueType(builder, this.anyUniqueType); + Monster.addAnyUnique(builder, anyUnique); + Monster.addAnyAmbiguousType(builder, this.anyAmbiguousType); + Monster.addAnyAmbiguous(builder, anyAmbiguous); + Monster.addVectorOfEnums(builder, vectorOfEnums); + Monster.addSignedEnum(builder, this.signedEnum); + 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); + Monster.addNanDefault(builder, this.nanDefault); + Monster.addInfDefault(builder, this.infDefault); + Monster.addPositiveInfDefault(builder, this.positiveInfDefault); + Monster.addInfinityDefault(builder, this.infinityDefault); + Monster.addPositiveInfinityDefault(builder, this.positiveInfinityDefault); + Monster.addNegativeInfDefault(builder, this.negativeInfDefault); + Monster.addNegativeInfinityDefault(builder, this.negativeInfinityDefault); + Monster.addDoubleInfDefault(builder, this.doubleInfDefault); + return Monster.endMonster(builder); + } } diff --git a/tests/ts/my-game/example/monster.ts b/tests/ts/my-game/example/monster.ts index dd7333ccb..c28dbea18 100644 --- a/tests/ts/my-game/example/monster.ts +++ b/tests/ts/my-game/example/monster.ts @@ -24,7 +24,7 @@ import { InParentNamespace, InParentNamespaceT } from '../in-parent-namespace.js */ export class Monster implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Monster { this.bb_pos = i; this.bb = bb; @@ -817,27 +817,27 @@ static getFullyQualifiedName(): "MyGame.Example.Monster" { return 'MyGame.Example.Monster'; } -static startMonster(builder:flatbuffers.Builder) { +static startMonster(builder:flatbuffers.Builder):void { builder.startObject(62); } -static addPos(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset) { +static addPos(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset):void { builder.addFieldStruct(0, posOffset, 0); } -static addMana(builder:flatbuffers.Builder, mana:number) { +static addMana(builder:flatbuffers.Builder, mana:number):void { builder.addFieldInt16(1, mana, 150); } -static addHp(builder:flatbuffers.Builder, hp:number) { +static addHp(builder:flatbuffers.Builder, hp:number):void { builder.addFieldInt16(2, hp, 100); } -static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) { +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { builder.addFieldOffset(3, nameOffset, 0); } -static addInventory(builder:flatbuffers.Builder, inventoryOffset:flatbuffers.Offset) { +static addInventory(builder:flatbuffers.Builder, inventoryOffset:flatbuffers.Offset):void { builder.addFieldOffset(5, inventoryOffset, 0); } @@ -849,31 +849,31 @@ static createInventoryVector(builder:flatbuffers.Builder, data:number[]|Uint8Arr return builder.endVector(); } -static startInventoryVector(builder:flatbuffers.Builder, numElems:number) { +static startInventoryVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addColor(builder:flatbuffers.Builder, color:Color) { +static addColor(builder:flatbuffers.Builder, color:Color):void { builder.addFieldInt8(6, color, Color.Blue); } -static addTestType(builder:flatbuffers.Builder, testType:Any) { +static addTestType(builder:flatbuffers.Builder, testType:Any):void { builder.addFieldInt8(7, testType, Any.NONE); } -static addTest(builder:flatbuffers.Builder, testOffset:flatbuffers.Offset) { +static addTest(builder:flatbuffers.Builder, testOffset:flatbuffers.Offset):void { builder.addFieldOffset(8, testOffset, 0); } -static addTest4(builder:flatbuffers.Builder, test4Offset:flatbuffers.Offset) { +static addTest4(builder:flatbuffers.Builder, test4Offset:flatbuffers.Offset):void { builder.addFieldOffset(9, test4Offset, 0); } -static startTest4Vector(builder:flatbuffers.Builder, numElems:number) { +static startTest4Vector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 2); } -static addTestarrayofstring(builder:flatbuffers.Builder, testarrayofstringOffset:flatbuffers.Offset) { +static addTestarrayofstring(builder:flatbuffers.Builder, testarrayofstringOffset:flatbuffers.Offset):void { builder.addFieldOffset(10, testarrayofstringOffset, 0); } @@ -885,11 +885,11 @@ static createTestarrayofstringVector(builder:flatbuffers.Builder, data:flatbuffe return builder.endVector(); } -static startTestarrayofstringVector(builder:flatbuffers.Builder, numElems:number) { +static startTestarrayofstringVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 4); } -static addTestarrayoftables(builder:flatbuffers.Builder, testarrayoftablesOffset:flatbuffers.Offset) { +static addTestarrayoftables(builder:flatbuffers.Builder, testarrayoftablesOffset:flatbuffers.Offset):void { builder.addFieldOffset(11, testarrayoftablesOffset, 0); } @@ -901,15 +901,15 @@ static createTestarrayoftablesVector(builder:flatbuffers.Builder, data:flatbuffe return builder.endVector(); } -static startTestarrayoftablesVector(builder:flatbuffers.Builder, numElems:number) { +static startTestarrayoftablesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 4); } -static addEnemy(builder:flatbuffers.Builder, enemyOffset:flatbuffers.Offset) { +static addEnemy(builder:flatbuffers.Builder, enemyOffset:flatbuffers.Offset):void { builder.addFieldOffset(12, enemyOffset, 0); } -static addTestnestedflatbuffer(builder:flatbuffers.Builder, testnestedflatbufferOffset:flatbuffers.Offset) { +static addTestnestedflatbuffer(builder:flatbuffers.Builder, testnestedflatbufferOffset:flatbuffers.Offset):void { builder.addFieldOffset(13, testnestedflatbufferOffset, 0); } @@ -921,51 +921,51 @@ static createTestnestedflatbufferVector(builder:flatbuffers.Builder, data:number return builder.endVector(); } -static startTestnestedflatbufferVector(builder:flatbuffers.Builder, numElems:number) { +static startTestnestedflatbufferVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addTestempty(builder:flatbuffers.Builder, testemptyOffset:flatbuffers.Offset) { +static addTestempty(builder:flatbuffers.Builder, testemptyOffset:flatbuffers.Offset):void { builder.addFieldOffset(14, testemptyOffset, 0); } -static addTestbool(builder:flatbuffers.Builder, testbool:boolean) { +static addTestbool(builder:flatbuffers.Builder, testbool:boolean):void { builder.addFieldInt8(15, +testbool, +false); } -static addTesthashs32Fnv1(builder:flatbuffers.Builder, testhashs32Fnv1:number) { +static addTesthashs32Fnv1(builder:flatbuffers.Builder, testhashs32Fnv1:number):void { builder.addFieldInt32(16, testhashs32Fnv1, 0); } -static addTesthashu32Fnv1(builder:flatbuffers.Builder, testhashu32Fnv1:number) { +static addTesthashu32Fnv1(builder:flatbuffers.Builder, testhashu32Fnv1:number):void { builder.addFieldInt32(17, testhashu32Fnv1, 0); } -static addTesthashs64Fnv1(builder:flatbuffers.Builder, testhashs64Fnv1:bigint) { +static addTesthashs64Fnv1(builder:flatbuffers.Builder, testhashs64Fnv1:bigint):void { builder.addFieldInt64(18, testhashs64Fnv1, BigInt('0')); } -static addTesthashu64Fnv1(builder:flatbuffers.Builder, testhashu64Fnv1:bigint) { +static addTesthashu64Fnv1(builder:flatbuffers.Builder, testhashu64Fnv1:bigint):void { builder.addFieldInt64(19, testhashu64Fnv1, BigInt('0')); } -static addTesthashs32Fnv1a(builder:flatbuffers.Builder, testhashs32Fnv1a:number) { +static addTesthashs32Fnv1a(builder:flatbuffers.Builder, testhashs32Fnv1a:number):void { builder.addFieldInt32(20, testhashs32Fnv1a, 0); } -static addTesthashu32Fnv1a(builder:flatbuffers.Builder, testhashu32Fnv1a:number) { +static addTesthashu32Fnv1a(builder:flatbuffers.Builder, testhashu32Fnv1a:number):void { builder.addFieldInt32(21, testhashu32Fnv1a, 0); } -static addTesthashs64Fnv1a(builder:flatbuffers.Builder, testhashs64Fnv1a:bigint) { +static addTesthashs64Fnv1a(builder:flatbuffers.Builder, testhashs64Fnv1a:bigint):void { builder.addFieldInt64(22, testhashs64Fnv1a, BigInt('0')); } -static addTesthashu64Fnv1a(builder:flatbuffers.Builder, testhashu64Fnv1a:bigint) { +static addTesthashu64Fnv1a(builder:flatbuffers.Builder, testhashu64Fnv1a:bigint):void { builder.addFieldInt64(23, testhashu64Fnv1a, BigInt('0')); } -static addTestarrayofbools(builder:flatbuffers.Builder, testarrayofboolsOffset:flatbuffers.Offset) { +static addTestarrayofbools(builder:flatbuffers.Builder, testarrayofboolsOffset:flatbuffers.Offset):void { builder.addFieldOffset(24, testarrayofboolsOffset, 0); } @@ -977,23 +977,23 @@ static createTestarrayofboolsVector(builder:flatbuffers.Builder, data:boolean[]) return builder.endVector(); } -static startTestarrayofboolsVector(builder:flatbuffers.Builder, numElems:number) { +static startTestarrayofboolsVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addTestf(builder:flatbuffers.Builder, testf:number) { +static addTestf(builder:flatbuffers.Builder, testf:number):void { builder.addFieldFloat32(25, testf, 3.14159); } -static addTestf2(builder:flatbuffers.Builder, testf2:number) { +static addTestf2(builder:flatbuffers.Builder, testf2:number):void { builder.addFieldFloat32(26, testf2, 3.0); } -static addTestf3(builder:flatbuffers.Builder, testf3:number) { +static addTestf3(builder:flatbuffers.Builder, testf3:number):void { builder.addFieldFloat32(27, testf3, 0.0); } -static addTestarrayofstring2(builder:flatbuffers.Builder, testarrayofstring2Offset:flatbuffers.Offset) { +static addTestarrayofstring2(builder:flatbuffers.Builder, testarrayofstring2Offset:flatbuffers.Offset):void { builder.addFieldOffset(28, testarrayofstring2Offset, 0); } @@ -1005,19 +1005,19 @@ static createTestarrayofstring2Vector(builder:flatbuffers.Builder, data:flatbuff return builder.endVector(); } -static startTestarrayofstring2Vector(builder:flatbuffers.Builder, numElems:number) { +static startTestarrayofstring2Vector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 4); } -static addTestarrayofsortedstruct(builder:flatbuffers.Builder, testarrayofsortedstructOffset:flatbuffers.Offset) { +static addTestarrayofsortedstruct(builder:flatbuffers.Builder, testarrayofsortedstructOffset:flatbuffers.Offset):void { builder.addFieldOffset(29, testarrayofsortedstructOffset, 0); } -static startTestarrayofsortedstructVector(builder:flatbuffers.Builder, numElems:number) { +static startTestarrayofsortedstructVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(8, numElems, 4); } -static addFlex(builder:flatbuffers.Builder, flexOffset:flatbuffers.Offset) { +static addFlex(builder:flatbuffers.Builder, flexOffset:flatbuffers.Offset):void { builder.addFieldOffset(30, flexOffset, 0); } @@ -1029,19 +1029,19 @@ static createFlexVector(builder:flatbuffers.Builder, data:number[]|Uint8Array):f return builder.endVector(); } -static startFlexVector(builder:flatbuffers.Builder, numElems:number) { +static startFlexVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addTest5(builder:flatbuffers.Builder, test5Offset:flatbuffers.Offset) { +static addTest5(builder:flatbuffers.Builder, test5Offset:flatbuffers.Offset):void { builder.addFieldOffset(31, test5Offset, 0); } -static startTest5Vector(builder:flatbuffers.Builder, numElems:number) { +static startTest5Vector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 2); } -static addVectorOfLongs(builder:flatbuffers.Builder, vectorOfLongsOffset:flatbuffers.Offset) { +static addVectorOfLongs(builder:flatbuffers.Builder, vectorOfLongsOffset:flatbuffers.Offset):void { builder.addFieldOffset(32, vectorOfLongsOffset, 0); } @@ -1053,11 +1053,11 @@ static createVectorOfLongsVector(builder:flatbuffers.Builder, data:bigint[]):fla return builder.endVector(); } -static startVectorOfLongsVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfLongsVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(8, numElems, 8); } -static addVectorOfDoubles(builder:flatbuffers.Builder, vectorOfDoublesOffset:flatbuffers.Offset) { +static addVectorOfDoubles(builder:flatbuffers.Builder, vectorOfDoublesOffset:flatbuffers.Offset):void { builder.addFieldOffset(33, vectorOfDoublesOffset, 0); } @@ -1074,15 +1074,15 @@ static createVectorOfDoublesVector(builder:flatbuffers.Builder, data:number[]|Fl return builder.endVector(); } -static startVectorOfDoublesVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfDoublesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(8, numElems, 8); } -static addParentNamespaceTest(builder:flatbuffers.Builder, parentNamespaceTestOffset:flatbuffers.Offset) { +static addParentNamespaceTest(builder:flatbuffers.Builder, parentNamespaceTestOffset:flatbuffers.Offset):void { builder.addFieldOffset(34, parentNamespaceTestOffset, 0); } -static addVectorOfReferrables(builder:flatbuffers.Builder, vectorOfReferrablesOffset:flatbuffers.Offset) { +static addVectorOfReferrables(builder:flatbuffers.Builder, vectorOfReferrablesOffset:flatbuffers.Offset):void { builder.addFieldOffset(35, vectorOfReferrablesOffset, 0); } @@ -1094,15 +1094,15 @@ static createVectorOfReferrablesVector(builder:flatbuffers.Builder, data:flatbuf return builder.endVector(); } -static startVectorOfReferrablesVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfReferrablesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 4); } -static addSingleWeakReference(builder:flatbuffers.Builder, singleWeakReference:bigint) { +static addSingleWeakReference(builder:flatbuffers.Builder, singleWeakReference:bigint):void { builder.addFieldInt64(36, singleWeakReference, BigInt('0')); } -static addVectorOfWeakReferences(builder:flatbuffers.Builder, vectorOfWeakReferencesOffset:flatbuffers.Offset) { +static addVectorOfWeakReferences(builder:flatbuffers.Builder, vectorOfWeakReferencesOffset:flatbuffers.Offset):void { builder.addFieldOffset(37, vectorOfWeakReferencesOffset, 0); } @@ -1114,11 +1114,11 @@ static createVectorOfWeakReferencesVector(builder:flatbuffers.Builder, data:bigi return builder.endVector(); } -static startVectorOfWeakReferencesVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfWeakReferencesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(8, numElems, 8); } -static addVectorOfStrongReferrables(builder:flatbuffers.Builder, vectorOfStrongReferrablesOffset:flatbuffers.Offset) { +static addVectorOfStrongReferrables(builder:flatbuffers.Builder, vectorOfStrongReferrablesOffset:flatbuffers.Offset):void { builder.addFieldOffset(38, vectorOfStrongReferrablesOffset, 0); } @@ -1130,15 +1130,15 @@ static createVectorOfStrongReferrablesVector(builder:flatbuffers.Builder, data:f return builder.endVector(); } -static startVectorOfStrongReferrablesVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfStrongReferrablesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 4); } -static addCoOwningReference(builder:flatbuffers.Builder, coOwningReference:bigint) { +static addCoOwningReference(builder:flatbuffers.Builder, coOwningReference:bigint):void { builder.addFieldInt64(39, coOwningReference, BigInt('0')); } -static addVectorOfCoOwningReferences(builder:flatbuffers.Builder, vectorOfCoOwningReferencesOffset:flatbuffers.Offset) { +static addVectorOfCoOwningReferences(builder:flatbuffers.Builder, vectorOfCoOwningReferencesOffset:flatbuffers.Offset):void { builder.addFieldOffset(40, vectorOfCoOwningReferencesOffset, 0); } @@ -1150,15 +1150,15 @@ static createVectorOfCoOwningReferencesVector(builder:flatbuffers.Builder, data: return builder.endVector(); } -static startVectorOfCoOwningReferencesVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfCoOwningReferencesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(8, numElems, 8); } -static addNonOwningReference(builder:flatbuffers.Builder, nonOwningReference:bigint) { +static addNonOwningReference(builder:flatbuffers.Builder, nonOwningReference:bigint):void { builder.addFieldInt64(41, nonOwningReference, BigInt('0')); } -static addVectorOfNonOwningReferences(builder:flatbuffers.Builder, vectorOfNonOwningReferencesOffset:flatbuffers.Offset) { +static addVectorOfNonOwningReferences(builder:flatbuffers.Builder, vectorOfNonOwningReferencesOffset:flatbuffers.Offset):void { builder.addFieldOffset(42, vectorOfNonOwningReferencesOffset, 0); } @@ -1170,27 +1170,27 @@ static createVectorOfNonOwningReferencesVector(builder:flatbuffers.Builder, data return builder.endVector(); } -static startVectorOfNonOwningReferencesVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfNonOwningReferencesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(8, numElems, 8); } -static addAnyUniqueType(builder:flatbuffers.Builder, anyUniqueType:AnyUniqueAliases) { +static addAnyUniqueType(builder:flatbuffers.Builder, anyUniqueType:AnyUniqueAliases):void { builder.addFieldInt8(43, anyUniqueType, AnyUniqueAliases.NONE); } -static addAnyUnique(builder:flatbuffers.Builder, anyUniqueOffset:flatbuffers.Offset) { +static addAnyUnique(builder:flatbuffers.Builder, anyUniqueOffset:flatbuffers.Offset):void { builder.addFieldOffset(44, anyUniqueOffset, 0); } -static addAnyAmbiguousType(builder:flatbuffers.Builder, anyAmbiguousType:AnyAmbiguousAliases) { +static addAnyAmbiguousType(builder:flatbuffers.Builder, anyAmbiguousType:AnyAmbiguousAliases):void { builder.addFieldInt8(45, anyAmbiguousType, AnyAmbiguousAliases.NONE); } -static addAnyAmbiguous(builder:flatbuffers.Builder, anyAmbiguousOffset:flatbuffers.Offset) { +static addAnyAmbiguous(builder:flatbuffers.Builder, anyAmbiguousOffset:flatbuffers.Offset):void { builder.addFieldOffset(46, anyAmbiguousOffset, 0); } -static addVectorOfEnums(builder:flatbuffers.Builder, vectorOfEnumsOffset:flatbuffers.Offset) { +static addVectorOfEnums(builder:flatbuffers.Builder, vectorOfEnumsOffset:flatbuffers.Offset):void { builder.addFieldOffset(47, vectorOfEnumsOffset, 0); } @@ -1202,15 +1202,15 @@ static createVectorOfEnumsVector(builder:flatbuffers.Builder, data:Color[]):flat return builder.endVector(); } -static startVectorOfEnumsVector(builder:flatbuffers.Builder, numElems:number) { +static startVectorOfEnumsVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addSignedEnum(builder:flatbuffers.Builder, signedEnum:Race) { +static addSignedEnum(builder:flatbuffers.Builder, signedEnum:Race):void { builder.addFieldInt8(48, signedEnum, Race.None); } -static addTestrequirednestedflatbuffer(builder:flatbuffers.Builder, testrequirednestedflatbufferOffset:flatbuffers.Offset) { +static addTestrequirednestedflatbuffer(builder:flatbuffers.Builder, testrequirednestedflatbufferOffset:flatbuffers.Offset):void { builder.addFieldOffset(49, testrequirednestedflatbufferOffset, 0); } @@ -1222,11 +1222,11 @@ static createTestrequirednestedflatbufferVector(builder:flatbuffers.Builder, dat return builder.endVector(); } -static startTestrequirednestedflatbufferVector(builder:flatbuffers.Builder, numElems:number) { +static startTestrequirednestedflatbufferVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addScalarKeySortedTables(builder:flatbuffers.Builder, scalarKeySortedTablesOffset:flatbuffers.Offset) { +static addScalarKeySortedTables(builder:flatbuffers.Builder, scalarKeySortedTablesOffset:flatbuffers.Offset):void { builder.addFieldOffset(50, scalarKeySortedTablesOffset, 0); } @@ -1238,51 +1238,51 @@ static createScalarKeySortedTablesVector(builder:flatbuffers.Builder, data:flatb return builder.endVector(); } -static startScalarKeySortedTablesVector(builder:flatbuffers.Builder, numElems:number) { +static startScalarKeySortedTablesVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 4); } -static addNativeInline(builder:flatbuffers.Builder, nativeInlineOffset:flatbuffers.Offset) { +static addNativeInline(builder:flatbuffers.Builder, nativeInlineOffset:flatbuffers.Offset):void { builder.addFieldStruct(51, nativeInlineOffset, 0); } -static addLongEnumNonEnumDefault(builder:flatbuffers.Builder, longEnumNonEnumDefault:bigint) { +static addLongEnumNonEnumDefault(builder:flatbuffers.Builder, longEnumNonEnumDefault:bigint):void { builder.addFieldInt64(52, longEnumNonEnumDefault, BigInt('0')); } -static addLongEnumNormalDefault(builder:flatbuffers.Builder, longEnumNormalDefault:bigint) { +static addLongEnumNormalDefault(builder:flatbuffers.Builder, longEnumNormalDefault:bigint):void { builder.addFieldInt64(53, longEnumNormalDefault, BigInt('2')); } -static addNanDefault(builder:flatbuffers.Builder, nanDefault:number) { +static addNanDefault(builder:flatbuffers.Builder, nanDefault:number):void { builder.addFieldFloat32(54, nanDefault, NaN); } -static addInfDefault(builder:flatbuffers.Builder, infDefault:number) { +static addInfDefault(builder:flatbuffers.Builder, infDefault:number):void { builder.addFieldFloat32(55, infDefault, Infinity); } -static addPositiveInfDefault(builder:flatbuffers.Builder, positiveInfDefault:number) { +static addPositiveInfDefault(builder:flatbuffers.Builder, positiveInfDefault:number):void { builder.addFieldFloat32(56, positiveInfDefault, Infinity); } -static addInfinityDefault(builder:flatbuffers.Builder, infinityDefault:number) { +static addInfinityDefault(builder:flatbuffers.Builder, infinityDefault:number):void { builder.addFieldFloat32(57, infinityDefault, Infinity); } -static addPositiveInfinityDefault(builder:flatbuffers.Builder, positiveInfinityDefault:number) { +static addPositiveInfinityDefault(builder:flatbuffers.Builder, positiveInfinityDefault:number):void { builder.addFieldFloat32(58, positiveInfinityDefault, Infinity); } -static addNegativeInfDefault(builder:flatbuffers.Builder, negativeInfDefault:number) { +static addNegativeInfDefault(builder:flatbuffers.Builder, negativeInfDefault:number):void { builder.addFieldFloat32(59, negativeInfDefault, -Infinity); } -static addNegativeInfinityDefault(builder:flatbuffers.Builder, negativeInfinityDefault:number) { +static addNegativeInfinityDefault(builder:flatbuffers.Builder, negativeInfinityDefault:number):void { builder.addFieldFloat32(60, negativeInfinityDefault, -Infinity); } -static addDoubleInfDefault(builder:flatbuffers.Builder, doubleInfDefault:number) { +static addDoubleInfDefault(builder:flatbuffers.Builder, doubleInfDefault:number):void { builder.addFieldFloat64(61, doubleInfDefault, Infinity); } @@ -1292,11 +1292,11 @@ static endMonster(builder:flatbuffers.Builder):flatbuffers.Offset { return offset; } -static finishMonsterBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishMonsterBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'MONS'); } -static finishSizePrefixedMonsterBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishSizePrefixedMonsterBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'MONS', true); } diff --git a/tests/ts/my-game/example/race.d.ts b/tests/ts/my-game/example/race.d.ts index 1276d536c..393807db4 100644 --- a/tests/ts/my-game/example/race.d.ts +++ b/tests/ts/my-game/example/race.d.ts @@ -1,6 +1,6 @@ export declare enum Race { - None = -1, - Human = 0, - Dwarf = 1, - Elf = 2, + None = -1, + Human = 0, + Dwarf = 1, + Elf = 2 } diff --git a/tests/ts/my-game/example/race.js b/tests/ts/my-game/example/race.js index 5e7e12d85..26f54c515 100644 --- a/tests/ts/my-game/example/race.js +++ b/tests/ts/my-game/example/race.js @@ -1,10 +1,9 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var Race; -(function(Race) { -Race[Race['None'] = -1] = 'None'; -Race[Race['Human'] = 0] = 'Human'; -Race[Race['Dwarf'] = 1] = 'Dwarf'; -Race[Race['Elf'] = 2] = 'Elf'; +(function (Race) { + Race[Race["None"] = -1] = "None"; + Race[Race["Human"] = 0] = "Human"; + Race[Race["Dwarf"] = 1] = "Dwarf"; + Race[Race["Elf"] = 2] = "Elf"; })(Race || (Race = {})); diff --git a/tests/ts/my-game/example/referrable.d.ts b/tests/ts/my-game/example/referrable.d.ts index f49038ee5..8b4316428 100644 --- a/tests/ts/my-game/example/referrable.d.ts +++ b/tests/ts/my-game/example/referrable.d.ts @@ -1,35 +1,24 @@ import * as flatbuffers from 'flatbuffers'; -export declare class Referrable - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Referrable; - static getRootAsReferrable( - bb: flatbuffers.ByteBuffer, - obj?: Referrable, - ): Referrable; - static getSizePrefixedRootAsReferrable( - bb: flatbuffers.ByteBuffer, - obj?: Referrable, - ): Referrable; - id(): bigint; - mutate_id(value: bigint): boolean; - static getFullyQualifiedName(): string; - static startReferrable(builder: flatbuffers.Builder): void; - static addId(builder: flatbuffers.Builder, id: bigint): void; - static endReferrable(builder: flatbuffers.Builder): flatbuffers.Offset; - static createReferrable( - builder: flatbuffers.Builder, - id: bigint, - ): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): Referrable; - unpack(): ReferrableT; - unpackTo(_o: ReferrableT): void; +export declare class Referrable implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Referrable; + static getRootAsReferrable(bb: flatbuffers.ByteBuffer, obj?: Referrable): Referrable; + static getSizePrefixedRootAsReferrable(bb: flatbuffers.ByteBuffer, obj?: Referrable): Referrable; + id(): bigint; + mutate_id(value: bigint): boolean; + static getFullyQualifiedName(): "MyGame.Example.Referrable"; + static startReferrable(builder: flatbuffers.Builder): void; + static addId(builder: flatbuffers.Builder, id: bigint): void; + static endReferrable(builder: flatbuffers.Builder): flatbuffers.Offset; + static createReferrable(builder: flatbuffers.Builder, id: bigint): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): Referrable; + unpack(): ReferrableT; + unpackTo(_o: ReferrableT): void; } export declare class ReferrableT implements flatbuffers.IGeneratedObject { - id: bigint; - constructor(id?: bigint); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + id: bigint; + constructor(id?: bigint); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/referrable.js b/tests/ts/my-game/example/referrable.js index e04e07124..e37d9b7c3 100644 --- a/tests/ts/my-game/example/referrable.js +++ b/tests/ts/my-game/example/referrable.js @@ -1,74 +1,71 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class Referrable { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsReferrable(bb, obj) { - return (obj || new Referrable()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsReferrable(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Referrable()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - id() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); - } - mutate_id(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsReferrable(bb, obj) { + return (obj || new Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsReferrable(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + id() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); + } + mutate_id(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'MyGame.Example.Referrable'; + } + static startReferrable(builder) { + builder.startObject(1); + } + static addId(builder, id) { + builder.addFieldInt64(0, id, BigInt('0')); + } + static endReferrable(builder) { + const offset = builder.endObject(); + return offset; + } + static createReferrable(builder, id) { + Referrable.startReferrable(builder); + Referrable.addId(builder, id); + return Referrable.endReferrable(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return Referrable.getRootAsReferrable(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new ReferrableT(this.id()); + } + unpackTo(_o) { + _o.id = this.id(); } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'MyGame.Example.Referrable'; - } - static startReferrable(builder) { - builder.startObject(1); - } - static addId(builder, id) { - builder.addFieldInt64(0, id, BigInt('0')); - } - static endReferrable(builder) { - const offset = builder.endObject(); - return offset; - } - static createReferrable(builder, id) { - Referrable.startReferrable(builder); - Referrable.addId(builder, id); - return Referrable.endReferrable(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return Referrable.getRootAsReferrable(new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new ReferrableT(this.id()); - } - unpackTo(_o) { - _o.id = this.id(); - } } export class ReferrableT { - constructor(id = BigInt('0')) { - this.id = id; - } - pack(builder) { - return Referrable.createReferrable(builder, this.id); - } + constructor(id = BigInt('0')) { + this.id = id; + } + pack(builder) { + return Referrable.createReferrable(builder, this.id); + } } diff --git a/tests/ts/my-game/example/referrable.ts b/tests/ts/my-game/example/referrable.ts index 9affeedba..d69122cbd 100644 --- a/tests/ts/my-game/example/referrable.ts +++ b/tests/ts/my-game/example/referrable.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class Referrable implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Referrable { this.bb_pos = i; this.bb = bb; @@ -44,11 +44,11 @@ static getFullyQualifiedName(): "MyGame.Example.Referrable" { return 'MyGame.Example.Referrable'; } -static startReferrable(builder:flatbuffers.Builder) { +static startReferrable(builder:flatbuffers.Builder):void { builder.startObject(1); } -static addId(builder:flatbuffers.Builder, id:bigint) { +static addId(builder:flatbuffers.Builder, id:bigint):void { builder.addFieldInt64(0, id, BigInt('0')); } diff --git a/tests/ts/my-game/example/stat.d.ts b/tests/ts/my-game/example/stat.d.ts index 2464dc163..0ae29dae3 100644 --- a/tests/ts/my-game/example/stat.d.ts +++ b/tests/ts/my-game/example/stat.d.ts @@ -1,43 +1,32 @@ import * as flatbuffers from 'flatbuffers'; export declare class Stat implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Stat; - static getRootAsStat(bb: flatbuffers.ByteBuffer, obj?: Stat): Stat; - static getSizePrefixedRootAsStat( - bb: flatbuffers.ByteBuffer, - obj?: Stat, - ): Stat; - id(): string | null; - id(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - val(): bigint; - mutate_val(value: bigint): boolean; - count(): number; - mutate_count(value: number): boolean; - static getFullyQualifiedName(): string; - static startStat(builder: flatbuffers.Builder): void; - static addId( - builder: flatbuffers.Builder, - idOffset: flatbuffers.Offset, - ): void; - static addVal(builder: flatbuffers.Builder, val: bigint): void; - static addCount(builder: flatbuffers.Builder, count: number): void; - static endStat(builder: flatbuffers.Builder): flatbuffers.Offset; - static createStat( - builder: flatbuffers.Builder, - idOffset: flatbuffers.Offset, - val: bigint, - count: number, - ): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): Stat; - unpack(): StatT; - unpackTo(_o: StatT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Stat; + static getRootAsStat(bb: flatbuffers.ByteBuffer, obj?: Stat): Stat; + static getSizePrefixedRootAsStat(bb: flatbuffers.ByteBuffer, obj?: Stat): Stat; + id(): string | null; + id(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + val(): bigint; + mutate_val(value: bigint): boolean; + count(): number; + mutate_count(value: number): boolean; + static getFullyQualifiedName(): "MyGame.Example.Stat"; + static startStat(builder: flatbuffers.Builder): void; + static addId(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset): void; + static addVal(builder: flatbuffers.Builder, val: bigint): void; + static addCount(builder: flatbuffers.Builder, count: number): void; + static endStat(builder: flatbuffers.Builder): flatbuffers.Offset; + static createStat(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset, val: bigint, count: number): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): Stat; + unpack(): StatT; + unpackTo(_o: StatT): void; } export declare class StatT implements flatbuffers.IGeneratedObject { - id: string | Uint8Array | null; - val: bigint; - count: number; - constructor(id?: string | Uint8Array | null, val?: bigint, count?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + id: string | Uint8Array | null; + val: bigint; + count: number; + constructor(id?: string | Uint8Array | null, val?: bigint, count?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/stat.js b/tests/ts/my-game/example/stat.js index 21d911f0f..8c1686903 100644 --- a/tests/ts/my-game/example/stat.js +++ b/tests/ts/my-game/example/stat.js @@ -1,104 +1,100 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class Stat { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsStat(bb, obj) { - return (obj || new Stat()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsStat(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Stat()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - id(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - val() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); - } - mutate_val(value) { - const offset = this.bb.__offset(this.bb_pos, 6); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt64(this.bb_pos + offset, value); - return true; - } - count() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - mutate_count(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsStat(bb, obj) { + return (obj || new Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsStat(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + id(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + val() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); + } + mutate_val(value) { + const offset = this.bb.__offset(this.bb_pos, 6); + if (offset === 0) { + return false; + } + this.bb.writeInt64(this.bb_pos + offset, value); + return true; + } + count() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; + } + mutate_count(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeUint16(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'MyGame.Example.Stat'; + } + static startStat(builder) { + builder.startObject(3); + } + static addId(builder, idOffset) { + builder.addFieldOffset(0, idOffset, 0); + } + static addVal(builder, val) { + builder.addFieldInt64(1, val, BigInt('0')); + } + static addCount(builder, count) { + builder.addFieldInt16(2, count, 0); + } + static endStat(builder) { + const offset = builder.endObject(); + return offset; + } + static createStat(builder, idOffset, val, count) { + Stat.startStat(builder); + Stat.addId(builder, idOffset); + Stat.addVal(builder, val); + Stat.addCount(builder, count); + return Stat.endStat(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return Stat.getRootAsStat(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new StatT(this.id(), this.val(), this.count()); + } + unpackTo(_o) { + _o.id = this.id(); + _o.val = this.val(); + _o.count = this.count(); } - this.bb.writeUint16(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'MyGame.Example.Stat'; - } - static startStat(builder) { - builder.startObject(3); - } - static addId(builder, idOffset) { - builder.addFieldOffset(0, idOffset, 0); - } - static addVal(builder, val) { - builder.addFieldInt64(1, val, BigInt('0')); - } - static addCount(builder, count) { - builder.addFieldInt16(2, count, 0); - } - static endStat(builder) { - const offset = builder.endObject(); - return offset; - } - static createStat(builder, idOffset, val, count) { - Stat.startStat(builder); - Stat.addId(builder, idOffset); - Stat.addVal(builder, val); - Stat.addCount(builder, count); - return Stat.endStat(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return Stat.getRootAsStat(new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new StatT(this.id(), this.val(), this.count()); - } - unpackTo(_o) { - _o.id = this.id(); - _o.val = this.val(); - _o.count = this.count(); - } } export class StatT { - constructor(id = null, val = BigInt('0'), count = 0) { - this.id = id; - this.val = val; - this.count = count; - } - pack(builder) { - const id = (this.id !== null ? builder.createString(this.id) : 0); - return Stat.createStat(builder, id, this.val, this.count); - } + constructor(id = null, val = BigInt('0'), count = 0) { + this.id = id; + this.val = val; + this.count = count; + } + pack(builder) { + const id = (this.id !== null ? builder.createString(this.id) : 0); + return Stat.createStat(builder, id, this.val, this.count); + } } diff --git a/tests/ts/my-game/example/stat.ts b/tests/ts/my-game/example/stat.ts index 72cd032ac..ce98eb519 100644 --- a/tests/ts/my-game/example/stat.ts +++ b/tests/ts/my-game/example/stat.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class Stat implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Stat { this.bb_pos = i; this.bb = bb; @@ -67,19 +67,19 @@ static getFullyQualifiedName(): "MyGame.Example.Stat" { return 'MyGame.Example.Stat'; } -static startStat(builder:flatbuffers.Builder) { +static startStat(builder:flatbuffers.Builder):void { builder.startObject(3); } -static addId(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset) { +static addId(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset):void { builder.addFieldOffset(0, idOffset, 0); } -static addVal(builder:flatbuffers.Builder, val:bigint) { +static addVal(builder:flatbuffers.Builder, val:bigint):void { builder.addFieldInt64(1, val, BigInt('0')); } -static addCount(builder:flatbuffers.Builder, count:number) { +static addCount(builder:flatbuffers.Builder, count:number):void { builder.addFieldInt16(2, count, 0); } diff --git a/tests/ts/my-game/example/struct-of-structs-of-structs.d.ts b/tests/ts/my-game/example/struct-of-structs-of-structs.d.ts index b0d760ad3..36f143c27 100644 --- a/tests/ts/my-game/example/struct-of-structs-of-structs.d.ts +++ b/tests/ts/my-game/example/struct-of-structs-of-structs.d.ts @@ -1,33 +1,18 @@ import * as flatbuffers from 'flatbuffers'; -import { - StructOfStructs, - StructOfStructsT, -} from '../../my-game/example/struct-of-structs.js'; -export declare class StructOfStructsOfStructs - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): StructOfStructsOfStructs; - a(obj?: StructOfStructs): StructOfStructs | null; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createStructOfStructsOfStructs( - builder: flatbuffers.Builder, - a_a_id: number, - a_a_distance: number, - a_b_a: number, - a_b_b: number, - a_c_id: number, - a_c_distance: number, - ): flatbuffers.Offset; - unpack(): StructOfStructsOfStructsT; - unpackTo(_o: StructOfStructsOfStructsT): void; +import { StructOfStructs, StructOfStructsT } from './struct-of-structs.js'; +export declare class StructOfStructsOfStructs implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): StructOfStructsOfStructs; + a(obj?: StructOfStructs): StructOfStructs | null; + static getFullyQualifiedName(): "MyGame.Example.StructOfStructsOfStructs"; + static sizeOf(): number; + static createStructOfStructsOfStructs(builder: flatbuffers.Builder, a_a_id: number, a_a_distance: number, a_b_a: number, a_b_b: number, a_c_id: number, a_c_distance: number): flatbuffers.Offset; + unpack(): StructOfStructsOfStructsT; + unpackTo(_o: StructOfStructsOfStructsT): void; } -export declare class StructOfStructsOfStructsT - implements flatbuffers.IGeneratedObject -{ - a: StructOfStructsT | null; - constructor(a?: StructOfStructsT | null); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; +export declare class StructOfStructsOfStructsT implements flatbuffers.IGeneratedObject { + a: StructOfStructsT | null; + constructor(a?: StructOfStructsT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/struct-of-structs-of-structs.js b/tests/ts/my-game/example/struct-of-structs-of-structs.js index e024d4d37..292fc8481 100644 --- a/tests/ts/my-game/example/struct-of-structs-of-structs.js +++ b/tests/ts/my-game/example/struct-of-structs-of-structs.js @@ -1,56 +1,51 @@ // automatically generated by the FlatBuffers compiler, do not modify -import {StructOfStructs} from '../../my-game/example/struct-of-structs.js'; +import { StructOfStructs } from './struct-of-structs.js'; export class StructOfStructsOfStructs { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - a(obj) { - return (obj || new StructOfStructs()).__init(this.bb_pos, this.bb); - } - static getFullyQualifiedName() { - return 'MyGame.Example.StructOfStructsOfStructs'; - } - static sizeOf() { - return 20; - } - static createStructOfStructsOfStructs( - builder, a_a_id, a_a_distance, a_b_a, a_b_b, a_c_id, a_c_distance) { - builder.prep(4, 20); - builder.prep(4, 20); - builder.prep(4, 8); - builder.writeInt32(a_c_distance); - builder.writeInt32(a_c_id); - builder.prep(2, 4); - builder.pad(1); - builder.writeInt8(a_b_b); - builder.writeInt16(a_b_a); - builder.prep(4, 8); - builder.writeInt32(a_a_distance); - builder.writeInt32(a_a_id); - return builder.offset(); - } - unpack() { - return new StructOfStructsOfStructsT( - (this.a() !== null ? this.a().unpack() : null)); - } - unpackTo(_o) { - _o.a = (this.a() !== null ? this.a().unpack() : null); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + a(obj) { + return (obj || new StructOfStructs()).__init(this.bb_pos, this.bb); + } + static getFullyQualifiedName() { + return 'MyGame.Example.StructOfStructsOfStructs'; + } + static sizeOf() { + return 20; + } + static createStructOfStructsOfStructs(builder, a_a_id, a_a_distance, a_b_a, a_b_b, a_c_id, a_c_distance) { + builder.prep(4, 20); + builder.prep(4, 20); + builder.prep(4, 8); + builder.writeInt32(a_c_distance); + builder.writeInt32(a_c_id); + builder.prep(2, 4); + builder.pad(1); + builder.writeInt8(a_b_b); + builder.writeInt16(a_b_a); + builder.prep(4, 8); + builder.writeInt32(a_a_distance); + builder.writeInt32(a_a_id); + return builder.offset(); + } + unpack() { + return new StructOfStructsOfStructsT((this.a() !== null ? this.a().unpack() : null)); + } + unpackTo(_o) { + _o.a = (this.a() !== null ? this.a().unpack() : null); + } } export class StructOfStructsOfStructsT { - constructor(a = null) { - this.a = a; - } - pack(builder) { - return StructOfStructsOfStructs.createStructOfStructsOfStructs( - builder, (this.a?.a?.id ?? 0), (this.a?.a?.distance ?? 0), - (this.a?.b?.a ?? 0), (this.a?.b?.b ?? 0), (this.a?.c?.id ?? 0), - (this.a?.c?.distance ?? 0)); - } + constructor(a = null) { + this.a = a; + } + pack(builder) { + return StructOfStructsOfStructs.createStructOfStructsOfStructs(builder, (this.a?.a?.id ?? 0), (this.a?.a?.distance ?? 0), (this.a?.b?.a ?? 0), (this.a?.b?.b ?? 0), (this.a?.c?.id ?? 0), (this.a?.c?.distance ?? 0)); + } } diff --git a/tests/ts/my-game/example/struct-of-structs-of-structs.ts b/tests/ts/my-game/example/struct-of-structs-of-structs.ts index f47d42d24..f27f411e6 100644 --- a/tests/ts/my-game/example/struct-of-structs-of-structs.ts +++ b/tests/ts/my-game/example/struct-of-structs-of-structs.ts @@ -9,7 +9,7 @@ import { StructOfStructs, StructOfStructsT } from './struct-of-structs.js'; export class StructOfStructsOfStructs implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructsOfStructs { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/my-game/example/struct-of-structs.d.ts b/tests/ts/my-game/example/struct-of-structs.d.ts index e4ae46d65..de2b623e3 100644 --- a/tests/ts/my-game/example/struct-of-structs.d.ts +++ b/tests/ts/my-game/example/struct-of-structs.d.ts @@ -1,33 +1,23 @@ import * as flatbuffers from 'flatbuffers'; -import {Ability, AbilityT} from '../../my-game/example/ability.js'; -import {Test, TestT} from '../../my-game/example/test.js'; -export declare class StructOfStructs - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): StructOfStructs; - a(obj?: Ability): Ability | null; - b(obj?: Test): Test | null; - c(obj?: Ability): Ability | null; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createStructOfStructs( - builder: flatbuffers.Builder, - a_id: number, - a_distance: number, - b_a: number, - b_b: number, - c_id: number, - c_distance: number, - ): flatbuffers.Offset; - unpack(): StructOfStructsT; - unpackTo(_o: StructOfStructsT): void; +import { Ability, AbilityT } from './ability.js'; +import { Test, TestT } from './test.js'; +export declare class StructOfStructs implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): StructOfStructs; + a(obj?: Ability): Ability | null; + b(obj?: Test): Test | null; + c(obj?: Ability): Ability | null; + static getFullyQualifiedName(): "MyGame.Example.StructOfStructs"; + static sizeOf(): number; + static createStructOfStructs(builder: flatbuffers.Builder, a_id: number, a_distance: number, b_a: number, b_b: number, c_id: number, c_distance: number): flatbuffers.Offset; + unpack(): StructOfStructsT; + unpackTo(_o: StructOfStructsT): void; } export declare class StructOfStructsT implements flatbuffers.IGeneratedObject { - a: AbilityT | null; - b: TestT | null; - c: AbilityT | null; - constructor(a?: AbilityT | null, b?: TestT | null, c?: AbilityT | null); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: AbilityT | null; + b: TestT | null; + c: AbilityT | null; + constructor(a?: AbilityT | null, b?: TestT | null, c?: AbilityT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/struct-of-structs.js b/tests/ts/my-game/example/struct-of-structs.js index b818cc50f..8b8236a7e 100644 --- a/tests/ts/my-game/example/struct-of-structs.js +++ b/tests/ts/my-game/example/struct-of-structs.js @@ -1,67 +1,61 @@ // automatically generated by the FlatBuffers compiler, do not modify -import {Ability} from '../../my-game/example/ability.js'; -import {Test} from '../../my-game/example/test.js'; +import { Ability } from './ability.js'; +import { Test } from './test.js'; export class StructOfStructs { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - a(obj) { - return (obj || new Ability()).__init(this.bb_pos, this.bb); - } - b(obj) { - return (obj || new Test()).__init(this.bb_pos + 8, this.bb); - } - c(obj) { - return (obj || new Ability()).__init(this.bb_pos + 12, this.bb); - } - static getFullyQualifiedName() { - return 'MyGame.Example.StructOfStructs'; - } - static sizeOf() { - return 20; - } - static createStructOfStructs( - builder, a_id, a_distance, b_a, b_b, c_id, c_distance) { - builder.prep(4, 20); - builder.prep(4, 8); - builder.writeInt32(c_distance); - builder.writeInt32(c_id); - builder.prep(2, 4); - builder.pad(1); - builder.writeInt8(b_b); - builder.writeInt16(b_a); - builder.prep(4, 8); - builder.writeInt32(a_distance); - builder.writeInt32(a_id); - return builder.offset(); - } - unpack() { - return new StructOfStructsT( - (this.a() !== null ? this.a().unpack() : null), - (this.b() !== null ? this.b().unpack() : null), - (this.c() !== null ? this.c().unpack() : null)); - } - unpackTo(_o) { - _o.a = (this.a() !== null ? this.a().unpack() : null); - _o.b = (this.b() !== null ? this.b().unpack() : null); - _o.c = (this.c() !== null ? this.c().unpack() : null); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + a(obj) { + return (obj || new Ability()).__init(this.bb_pos, this.bb); + } + b(obj) { + return (obj || new Test()).__init(this.bb_pos + 8, this.bb); + } + c(obj) { + return (obj || new Ability()).__init(this.bb_pos + 12, this.bb); + } + static getFullyQualifiedName() { + return 'MyGame.Example.StructOfStructs'; + } + static sizeOf() { + return 20; + } + static createStructOfStructs(builder, a_id, a_distance, b_a, b_b, c_id, c_distance) { + builder.prep(4, 20); + builder.prep(4, 8); + builder.writeInt32(c_distance); + builder.writeInt32(c_id); + builder.prep(2, 4); + builder.pad(1); + builder.writeInt8(b_b); + builder.writeInt16(b_a); + builder.prep(4, 8); + builder.writeInt32(a_distance); + builder.writeInt32(a_id); + return builder.offset(); + } + unpack() { + return new StructOfStructsT((this.a() !== null ? this.a().unpack() : null), (this.b() !== null ? this.b().unpack() : null), (this.c() !== null ? this.c().unpack() : null)); + } + unpackTo(_o) { + _o.a = (this.a() !== null ? this.a().unpack() : null); + _o.b = (this.b() !== null ? this.b().unpack() : null); + _o.c = (this.c() !== null ? this.c().unpack() : null); + } } export class StructOfStructsT { - constructor(a = null, b = null, c = null) { - this.a = a; - this.b = b; - this.c = c; - } - pack(builder) { - return StructOfStructs.createStructOfStructs( - builder, (this.a?.id ?? 0), (this.a?.distance ?? 0), (this.b?.a ?? 0), - (this.b?.b ?? 0), (this.c?.id ?? 0), (this.c?.distance ?? 0)); - } + constructor(a = null, b = null, c = null) { + this.a = a; + this.b = b; + this.c = c; + } + pack(builder) { + return StructOfStructs.createStructOfStructs(builder, (this.a?.id ?? 0), (this.a?.distance ?? 0), (this.b?.a ?? 0), (this.b?.b ?? 0), (this.c?.id ?? 0), (this.c?.distance ?? 0)); + } } diff --git a/tests/ts/my-game/example/struct-of-structs.ts b/tests/ts/my-game/example/struct-of-structs.ts index c3ff69da3..e295cbba4 100644 --- a/tests/ts/my-game/example/struct-of-structs.ts +++ b/tests/ts/my-game/example/struct-of-structs.ts @@ -10,7 +10,7 @@ import { Test, TestT } from './test.js'; export class StructOfStructs implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):StructOfStructs { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/my-game/example/test-simple-table-with-enum.d.ts b/tests/ts/my-game/example/test-simple-table-with-enum.d.ts index 6d40e23a4..1a3e85559 100644 --- a/tests/ts/my-game/example/test-simple-table-with-enum.d.ts +++ b/tests/ts/my-game/example/test-simple-table-with-enum.d.ts @@ -1,40 +1,25 @@ import * as flatbuffers from 'flatbuffers'; -import {Color} from '../../my-game/example/color.js'; -export declare class TestSimpleTableWithEnum - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): TestSimpleTableWithEnum; - static getRootAsTestSimpleTableWithEnum( - bb: flatbuffers.ByteBuffer, - obj?: TestSimpleTableWithEnum, - ): TestSimpleTableWithEnum; - static getSizePrefixedRootAsTestSimpleTableWithEnum( - bb: flatbuffers.ByteBuffer, - obj?: TestSimpleTableWithEnum, - ): TestSimpleTableWithEnum; - color(): Color; - mutate_color(value: Color): boolean; - static getFullyQualifiedName(): string; - static startTestSimpleTableWithEnum(builder: flatbuffers.Builder): void; - static addColor(builder: flatbuffers.Builder, color: Color): void; - static endTestSimpleTableWithEnum( - builder: flatbuffers.Builder, - ): flatbuffers.Offset; - static createTestSimpleTableWithEnum( - builder: flatbuffers.Builder, - color: Color, - ): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): TestSimpleTableWithEnum; - unpack(): TestSimpleTableWithEnumT; - unpackTo(_o: TestSimpleTableWithEnumT): void; +import { Color } from './color.js'; +export declare class TestSimpleTableWithEnum implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): TestSimpleTableWithEnum; + static getRootAsTestSimpleTableWithEnum(bb: flatbuffers.ByteBuffer, obj?: TestSimpleTableWithEnum): TestSimpleTableWithEnum; + static getSizePrefixedRootAsTestSimpleTableWithEnum(bb: flatbuffers.ByteBuffer, obj?: TestSimpleTableWithEnum): TestSimpleTableWithEnum; + color(): Color; + mutate_color(value: Color): boolean; + static getFullyQualifiedName(): "MyGame.Example.TestSimpleTableWithEnum"; + static startTestSimpleTableWithEnum(builder: flatbuffers.Builder): void; + static addColor(builder: flatbuffers.Builder, color: Color): void; + static endTestSimpleTableWithEnum(builder: flatbuffers.Builder): flatbuffers.Offset; + static createTestSimpleTableWithEnum(builder: flatbuffers.Builder, color: Color): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): TestSimpleTableWithEnum; + unpack(): TestSimpleTableWithEnumT; + unpackTo(_o: TestSimpleTableWithEnumT): void; } -export declare class TestSimpleTableWithEnumT - implements flatbuffers.IGeneratedObject -{ - color: Color; - constructor(color?: Color); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; +export declare class TestSimpleTableWithEnumT implements flatbuffers.IGeneratedObject { + color: Color; + constructor(color?: Color); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/test-simple-table-with-enum.js b/tests/ts/my-game/example/test-simple-table-with-enum.js index cd50ab081..3f3b1938c 100644 --- a/tests/ts/my-game/example/test-simple-table-with-enum.js +++ b/tests/ts/my-game/example/test-simple-table-with-enum.js @@ -1,79 +1,72 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {Color} from '../../my-game/example/color.js'; - +import { Color } from './color.js'; export class TestSimpleTableWithEnum { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsTestSimpleTableWithEnum(bb, obj) { - return (obj || new TestSimpleTableWithEnum()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsTestSimpleTableWithEnum(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new TestSimpleTableWithEnum()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - color() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : Color.Green; - } - mutate_color(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsTestSimpleTableWithEnum(bb, obj) { + return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsTestSimpleTableWithEnum(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + color() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readUint8(this.bb_pos + offset) : Color.Green; + } + mutate_color(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeUint8(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'MyGame.Example.TestSimpleTableWithEnum'; + } + static startTestSimpleTableWithEnum(builder) { + builder.startObject(1); + } + static addColor(builder, color) { + builder.addFieldInt8(0, color, Color.Green); + } + static endTestSimpleTableWithEnum(builder) { + const offset = builder.endObject(); + return offset; + } + static createTestSimpleTableWithEnum(builder, color) { + TestSimpleTableWithEnum.startTestSimpleTableWithEnum(builder); + TestSimpleTableWithEnum.addColor(builder, color); + return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return TestSimpleTableWithEnum.getRootAsTestSimpleTableWithEnum(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new TestSimpleTableWithEnumT(this.color()); + } + unpackTo(_o) { + _o.color = this.color(); } - this.bb.writeUint8(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'MyGame.Example.TestSimpleTableWithEnum'; - } - static startTestSimpleTableWithEnum(builder) { - builder.startObject(1); - } - static addColor(builder, color) { - builder.addFieldInt8(0, color, Color.Green); - } - static endTestSimpleTableWithEnum(builder) { - const offset = builder.endObject(); - return offset; - } - static createTestSimpleTableWithEnum(builder, color) { - TestSimpleTableWithEnum.startTestSimpleTableWithEnum(builder); - TestSimpleTableWithEnum.addColor(builder, color); - return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return TestSimpleTableWithEnum.getRootAsTestSimpleTableWithEnum( - new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new TestSimpleTableWithEnumT(this.color()); - } - unpackTo(_o) { - _o.color = this.color(); - } } export class TestSimpleTableWithEnumT { - constructor(color = Color.Green) { - this.color = color; - } - pack(builder) { - return TestSimpleTableWithEnum.createTestSimpleTableWithEnum( - builder, this.color); - } + constructor(color = Color.Green) { + this.color = color; + } + pack(builder) { + return TestSimpleTableWithEnum.createTestSimpleTableWithEnum(builder, this.color); + } } diff --git a/tests/ts/my-game/example/test-simple-table-with-enum.ts b/tests/ts/my-game/example/test-simple-table-with-enum.ts index ac9d7add2..841990868 100644 --- a/tests/ts/my-game/example/test-simple-table-with-enum.ts +++ b/tests/ts/my-game/example/test-simple-table-with-enum.ts @@ -9,7 +9,7 @@ import { Color } from './color.js'; export class TestSimpleTableWithEnum implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):TestSimpleTableWithEnum { this.bb_pos = i; this.bb = bb; @@ -45,11 +45,11 @@ static getFullyQualifiedName(): "MyGame.Example.TestSimpleTableWithEnum" { return 'MyGame.Example.TestSimpleTableWithEnum'; } -static startTestSimpleTableWithEnum(builder:flatbuffers.Builder) { +static startTestSimpleTableWithEnum(builder:flatbuffers.Builder):void { builder.startObject(1); } -static addColor(builder:flatbuffers.Builder, color:Color) { +static addColor(builder:flatbuffers.Builder, color:Color):void { builder.addFieldInt8(0, color, Color.Green); } diff --git a/tests/ts/my-game/example/test.d.ts b/tests/ts/my-game/example/test.d.ts index 03424a483..205a2085c 100644 --- a/tests/ts/my-game/example/test.d.ts +++ b/tests/ts/my-game/example/test.d.ts @@ -1,25 +1,21 @@ import * as flatbuffers from 'flatbuffers'; export declare class Test implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Test; - a(): number; - mutate_a(value: number): boolean; - b(): number; - mutate_b(value: number): boolean; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createTest( - builder: flatbuffers.Builder, - a: number, - b: number, - ): flatbuffers.Offset; - unpack(): TestT; - unpackTo(_o: TestT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Test; + a(): number; + mutate_a(value: number): boolean; + b(): number; + mutate_b(value: number): boolean; + static getFullyQualifiedName(): "MyGame.Example.Test"; + static sizeOf(): number; + static createTest(builder: flatbuffers.Builder, a: number, b: number): flatbuffers.Offset; + unpack(): TestT; + unpackTo(_o: TestT): void; } export declare class TestT implements flatbuffers.IGeneratedObject { - a: number; - b: number; - constructor(a?: number, b?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: number; + b: number; + constructor(a?: number, b?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/test.js b/tests/ts/my-game/example/test.js index b6d4800f4..ba6ebfb7a 100644 --- a/tests/ts/my-game/example/test.js +++ b/tests/ts/my-game/example/test.js @@ -1,55 +1,55 @@ // automatically generated by the FlatBuffers compiler, do not modify export class Test { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - a() { - return this.bb.readInt16(this.bb_pos); - } - mutate_a(value) { - this.bb.writeInt16(this.bb_pos + 0, value); - return true; - } - b() { - return this.bb.readInt8(this.bb_pos + 2); - } - mutate_b(value) { - this.bb.writeInt8(this.bb_pos + 2, value); - return true; - } - static getFullyQualifiedName() { - return 'MyGame.Example.Test'; - } - static sizeOf() { - return 4; - } - static createTest(builder, a, b) { - builder.prep(2, 4); - builder.pad(1); - builder.writeInt8(b); - builder.writeInt16(a); - return builder.offset(); - } - unpack() { - return new TestT(this.a(), this.b()); - } - unpackTo(_o) { - _o.a = this.a(); - _o.b = this.b(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + a() { + return this.bb.readInt16(this.bb_pos); + } + mutate_a(value) { + this.bb.writeInt16(this.bb_pos + 0, value); + return true; + } + b() { + return this.bb.readInt8(this.bb_pos + 2); + } + mutate_b(value) { + this.bb.writeInt8(this.bb_pos + 2, value); + return true; + } + static getFullyQualifiedName() { + return 'MyGame.Example.Test'; + } + static sizeOf() { + return 4; + } + static createTest(builder, a, b) { + builder.prep(2, 4); + builder.pad(1); + builder.writeInt8(b); + builder.writeInt16(a); + return builder.offset(); + } + unpack() { + return new TestT(this.a(), this.b()); + } + unpackTo(_o) { + _o.a = this.a(); + _o.b = this.b(); + } } export class TestT { - constructor(a = 0, b = 0) { - this.a = a; - this.b = b; - } - pack(builder) { - return Test.createTest(builder, this.a, this.b); - } + constructor(a = 0, b = 0) { + this.a = a; + this.b = b; + } + pack(builder) { + return Test.createTest(builder, this.a, this.b); + } } diff --git a/tests/ts/my-game/example/test.ts b/tests/ts/my-game/example/test.ts index 40fff16e6..9eaae34e7 100644 --- a/tests/ts/my-game/example/test.ts +++ b/tests/ts/my-game/example/test.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class Test implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Test { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/my-game/example/type-aliases.d.ts b/tests/ts/my-game/example/type-aliases.d.ts index d12c88a8a..7ead7d8db 100644 --- a/tests/ts/my-game/example/type-aliases.d.ts +++ b/tests/ts/my-game/example/type-aliases.d.ts @@ -1,135 +1,82 @@ import * as flatbuffers from 'flatbuffers'; -export declare class TypeAliases - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): TypeAliases; - static getRootAsTypeAliases( - bb: flatbuffers.ByteBuffer, - obj?: TypeAliases, - ): TypeAliases; - static getSizePrefixedRootAsTypeAliases( - bb: flatbuffers.ByteBuffer, - obj?: TypeAliases, - ): TypeAliases; - i8(): number; - mutate_i8(value: number): boolean; - u8(): number; - mutate_u8(value: number): boolean; - i16(): number; - mutate_i16(value: number): boolean; - u16(): number; - mutate_u16(value: number): boolean; - i32(): number; - mutate_i32(value: number): boolean; - u32(): number; - mutate_u32(value: number): boolean; - i64(): bigint; - mutate_i64(value: bigint): boolean; - u64(): bigint; - mutate_u64(value: bigint): boolean; - f32(): number; - mutate_f32(value: number): boolean; - f64(): number; - mutate_f64(value: number): boolean; - v8(index: number): number | null; - v8Length(): number; - v8Array(): Int8Array | null; - vf64(index: number): number | null; - vf64Length(): number; - vf64Array(): Float64Array | null; - static getFullyQualifiedName(): string; - static startTypeAliases(builder: flatbuffers.Builder): void; - static addI8(builder: flatbuffers.Builder, i8: number): void; - static addU8(builder: flatbuffers.Builder, u8: number): void; - static addI16(builder: flatbuffers.Builder, i16: number): void; - static addU16(builder: flatbuffers.Builder, u16: number): void; - static addI32(builder: flatbuffers.Builder, i32: number): void; - static addU32(builder: flatbuffers.Builder, u32: number): void; - static addI64(builder: flatbuffers.Builder, i64: bigint): void; - static addU64(builder: flatbuffers.Builder, u64: bigint): void; - static addF32(builder: flatbuffers.Builder, f32: number): void; - static addF64(builder: flatbuffers.Builder, f64: number): void; - static addV8( - builder: flatbuffers.Builder, - v8Offset: flatbuffers.Offset, - ): void; - static createV8Vector( - builder: flatbuffers.Builder, - data: number[] | Int8Array, - ): flatbuffers.Offset; - /** - * @deprecated This Uint8Array overload will be removed in the future. - */ - static createV8Vector( - builder: flatbuffers.Builder, - data: number[] | Uint8Array, - ): flatbuffers.Offset; - static startV8Vector(builder: flatbuffers.Builder, numElems: number): void; - static addVf64( - builder: flatbuffers.Builder, - vf64Offset: flatbuffers.Offset, - ): void; - static createVf64Vector( - builder: flatbuffers.Builder, - data: number[] | Float64Array, - ): flatbuffers.Offset; - /** - * @deprecated This Uint8Array overload will be removed in the future. - */ - static createVf64Vector( - builder: flatbuffers.Builder, - data: number[] | Uint8Array, - ): flatbuffers.Offset; - static startVf64Vector(builder: flatbuffers.Builder, numElems: number): void; - static endTypeAliases(builder: flatbuffers.Builder): flatbuffers.Offset; - static createTypeAliases( - builder: flatbuffers.Builder, - i8: number, - u8: number, - i16: number, - u16: number, - i32: number, - u32: number, - i64: bigint, - u64: bigint, - f32: number, - f64: number, - v8Offset: flatbuffers.Offset, - vf64Offset: flatbuffers.Offset, - ): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): TypeAliases; - unpack(): TypeAliasesT; - unpackTo(_o: TypeAliasesT): void; +export declare class TypeAliases implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): TypeAliases; + static getRootAsTypeAliases(bb: flatbuffers.ByteBuffer, obj?: TypeAliases): TypeAliases; + static getSizePrefixedRootAsTypeAliases(bb: flatbuffers.ByteBuffer, obj?: TypeAliases): TypeAliases; + i8(): number; + mutate_i8(value: number): boolean; + u8(): number; + mutate_u8(value: number): boolean; + i16(): number; + mutate_i16(value: number): boolean; + u16(): number; + mutate_u16(value: number): boolean; + i32(): number; + mutate_i32(value: number): boolean; + u32(): number; + mutate_u32(value: number): boolean; + i64(): bigint; + mutate_i64(value: bigint): boolean; + u64(): bigint; + mutate_u64(value: bigint): boolean; + f32(): number; + mutate_f32(value: number): boolean; + f64(): number; + mutate_f64(value: number): boolean; + v8(index: number): number | null; + v8Length(): number; + v8Array(): Int8Array | null; + vf64(index: number): number | null; + vf64Length(): number; + vf64Array(): Float64Array | null; + static getFullyQualifiedName(): "MyGame.Example.TypeAliases"; + static startTypeAliases(builder: flatbuffers.Builder): void; + static addI8(builder: flatbuffers.Builder, i8: number): void; + static addU8(builder: flatbuffers.Builder, u8: number): void; + static addI16(builder: flatbuffers.Builder, i16: number): void; + static addU16(builder: flatbuffers.Builder, u16: number): void; + static addI32(builder: flatbuffers.Builder, i32: number): void; + static addU32(builder: flatbuffers.Builder, u32: number): void; + static addI64(builder: flatbuffers.Builder, i64: bigint): void; + static addU64(builder: flatbuffers.Builder, u64: bigint): void; + static addF32(builder: flatbuffers.Builder, f32: number): void; + static addF64(builder: flatbuffers.Builder, f64: number): void; + static addV8(builder: flatbuffers.Builder, v8Offset: flatbuffers.Offset): void; + static createV8Vector(builder: flatbuffers.Builder, data: number[] | Int8Array): flatbuffers.Offset; + /** + * @deprecated This Uint8Array overload will be removed in the future. + */ + static createV8Vector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset; + static startV8Vector(builder: flatbuffers.Builder, numElems: number): void; + static addVf64(builder: flatbuffers.Builder, vf64Offset: flatbuffers.Offset): void; + static createVf64Vector(builder: flatbuffers.Builder, data: number[] | Float64Array): flatbuffers.Offset; + /** + * @deprecated This Uint8Array overload will be removed in the future. + */ + static createVf64Vector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset; + static startVf64Vector(builder: flatbuffers.Builder, numElems: number): void; + static endTypeAliases(builder: flatbuffers.Builder): flatbuffers.Offset; + static createTypeAliases(builder: flatbuffers.Builder, i8: number, u8: number, i16: number, u16: number, i32: number, u32: number, i64: bigint, u64: bigint, f32: number, f64: number, v8Offset: flatbuffers.Offset, vf64Offset: flatbuffers.Offset): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): TypeAliases; + unpack(): TypeAliasesT; + unpackTo(_o: TypeAliasesT): void; } export declare class TypeAliasesT implements flatbuffers.IGeneratedObject { - i8: number; - u8: number; - i16: number; - u16: number; - i32: number; - u32: number; - i64: bigint; - u64: bigint; - f32: number; - f64: number; - v8: number[]; - vf64: number[]; - constructor( - i8?: number, - u8?: number, - i16?: number, - u16?: number, - i32?: number, - u32?: number, - i64?: bigint, - u64?: bigint, - f32?: number, - f64?: number, - v8?: number[], - vf64?: number[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + i8: number; + u8: number; + i16: number; + u16: number; + i32: number; + u32: number; + i64: bigint; + u64: bigint; + f32: number; + f64: number; + v8: (number)[]; + vf64: (number)[]; + constructor(i8?: number, u8?: number, i16?: number, u16?: number, i32?: number, u32?: number, i64?: bigint, u64?: bigint, f32?: number, f64?: number, v8?: (number)[], vf64?: (number)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/type-aliases.js b/tests/ts/my-game/example/type-aliases.js index 59d80d146..81f32772b 100644 --- a/tests/ts/my-game/example/type-aliases.js +++ b/tests/ts/my-game/example/type-aliases.js @@ -1,318 +1,291 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class TypeAliases { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsTypeAliases(bb, obj) { - return (obj || new TypeAliases()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsTypeAliases(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new TypeAliases()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - i8() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt8(this.bb_pos + offset) : 0; - } - mutate_i8(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt8(this.bb_pos + offset, value); - return true; - } - u8() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; - } - mutate_u8(value) { - const offset = this.bb.__offset(this.bb_pos, 6); - if (offset === 0) { - return false; + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - this.bb.writeUint8(this.bb_pos + offset, value); - return true; - } - i16() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readInt16(this.bb_pos + offset) : 0; - } - mutate_i16(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + static getRootAsTypeAliases(bb, obj) { + return (obj || new TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeInt16(this.bb_pos + offset, value); - return true; - } - u16() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - mutate_u16(value) { - const offset = this.bb.__offset(this.bb_pos, 10); - if (offset === 0) { - return false; + static getSizePrefixedRootAsTypeAliases(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeUint16(this.bb_pos + offset, value); - return true; - } - i32() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_i32(value) { - const offset = this.bb.__offset(this.bb_pos, 12); - if (offset === 0) { - return false; + i8() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt8(this.bb_pos + offset) : 0; } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - u32() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - mutate_u32(value) { - const offset = this.bb.__offset(this.bb_pos, 14); - if (offset === 0) { - return false; + mutate_i8(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, value); + return true; } - this.bb.writeUint32(this.bb_pos + offset, value); - return true; - } - i64() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); - } - mutate_i64(value) { - const offset = this.bb.__offset(this.bb_pos, 16); - if (offset === 0) { - return false; + u8() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; } - this.bb.writeInt64(this.bb_pos + offset, value); - return true; - } - u64() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); - } - mutate_u64(value) { - const offset = this.bb.__offset(this.bb_pos, 18); - if (offset === 0) { - return false; + mutate_u8(value) { + const offset = this.bb.__offset(this.bb_pos, 6); + if (offset === 0) { + return false; + } + this.bb.writeUint8(this.bb_pos + offset, value); + return true; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - f32() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; - } - mutate_f32(value) { - const offset = this.bb.__offset(this.bb_pos, 20); - if (offset === 0) { - return false; + i16() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt16(this.bb_pos + offset) : 0; } - this.bb.writeFloat32(this.bb_pos + offset, value); - return true; - } - f64() { - const offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0; - } - mutate_f64(value) { - const offset = this.bb.__offset(this.bb_pos, 22); - if (offset === 0) { - return false; + mutate_i16(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeInt16(this.bb_pos + offset, value); + return true; } - this.bb.writeFloat64(this.bb_pos + offset, value); - return true; - } - v8(index) { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? - this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : - 0; - } - v8Length() { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - v8Array() { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? - new Int8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - vf64(index) { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readFloat64( - this.bb.__vector(this.bb_pos + offset) + index * 8) : - 0; - } - vf64Length() { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - vf64Array() { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? - new Float64Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - static getFullyQualifiedName() { - return 'MyGame.Example.TypeAliases'; - } - static startTypeAliases(builder) { - builder.startObject(12); - } - static addI8(builder, i8) { - builder.addFieldInt8(0, i8, 0); - } - static addU8(builder, u8) { - builder.addFieldInt8(1, u8, 0); - } - static addI16(builder, i16) { - builder.addFieldInt16(2, i16, 0); - } - static addU16(builder, u16) { - builder.addFieldInt16(3, u16, 0); - } - static addI32(builder, i32) { - builder.addFieldInt32(4, i32, 0); - } - static addU32(builder, u32) { - builder.addFieldInt32(5, u32, 0); - } - static addI64(builder, i64) { - builder.addFieldInt64(6, i64, BigInt('0')); - } - static addU64(builder, u64) { - builder.addFieldInt64(7, u64, BigInt('0')); - } - static addF32(builder, f32) { - builder.addFieldFloat32(8, f32, 0.0); - } - static addF64(builder, f64) { - builder.addFieldFloat64(9, f64, 0.0); - } - static addV8(builder, v8Offset) { - builder.addFieldOffset(10, v8Offset, 0); - } - static createV8Vector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); + u16() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; } - return builder.endVector(); - } - static startV8Vector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addVf64(builder, vf64Offset) { - builder.addFieldOffset(11, vf64Offset, 0); - } - static createVf64Vector(builder, data) { - builder.startVector(8, data.length, 8); - for (let i = data.length - 1; i >= 0; i--) { - builder.addFloat64(data[i]); + mutate_u16(value) { + const offset = this.bb.__offset(this.bb_pos, 10); + if (offset === 0) { + return false; + } + this.bb.writeUint16(this.bb_pos + offset, value); + return true; + } + i32() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_i32(value) { + const offset = this.bb.__offset(this.bb_pos, 12); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + u32() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; + } + mutate_u32(value) { + const offset = this.bb.__offset(this.bb_pos, 14); + if (offset === 0) { + return false; + } + this.bb.writeUint32(this.bb_pos + offset, value); + return true; + } + i64() { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); + } + mutate_i64(value) { + const offset = this.bb.__offset(this.bb_pos, 16); + if (offset === 0) { + return false; + } + this.bb.writeInt64(this.bb_pos + offset, value); + return true; + } + u64() { + const offset = this.bb.__offset(this.bb_pos, 18); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); + } + mutate_u64(value) { + const offset = this.bb.__offset(this.bb_pos, 18); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + f32() { + const offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; + } + mutate_f32(value) { + const offset = this.bb.__offset(this.bb_pos, 20); + if (offset === 0) { + return false; + } + this.bb.writeFloat32(this.bb_pos + offset, value); + return true; + } + f64() { + const offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0; + } + mutate_f64(value) { + const offset = this.bb.__offset(this.bb_pos, 22); + if (offset === 0) { + return false; + } + this.bb.writeFloat64(this.bb_pos + offset, value); + return true; + } + v8(index) { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : 0; + } + v8Length() { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + v8Array() { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + vf64(index) { + const offset = this.bb.__offset(this.bb_pos, 26); + return offset ? this.bb.readFloat64(this.bb.__vector(this.bb_pos + offset) + index * 8) : 0; + } + vf64Length() { + const offset = this.bb.__offset(this.bb_pos, 26); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + vf64Array() { + const offset = this.bb.__offset(this.bb_pos, 26); + return offset ? new Float64Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + static getFullyQualifiedName() { + return 'MyGame.Example.TypeAliases'; + } + static startTypeAliases(builder) { + builder.startObject(12); + } + static addI8(builder, i8) { + builder.addFieldInt8(0, i8, 0); + } + static addU8(builder, u8) { + builder.addFieldInt8(1, u8, 0); + } + static addI16(builder, i16) { + builder.addFieldInt16(2, i16, 0); + } + static addU16(builder, u16) { + builder.addFieldInt16(3, u16, 0); + } + static addI32(builder, i32) { + builder.addFieldInt32(4, i32, 0); + } + static addU32(builder, u32) { + builder.addFieldInt32(5, u32, 0); + } + static addI64(builder, i64) { + builder.addFieldInt64(6, i64, BigInt('0')); + } + static addU64(builder, u64) { + builder.addFieldInt64(7, u64, BigInt('0')); + } + static addF32(builder, f32) { + builder.addFieldFloat32(8, f32, 0.0); + } + static addF64(builder, f64) { + builder.addFieldFloat64(9, f64, 0.0); + } + static addV8(builder, v8Offset) { + builder.addFieldOffset(10, v8Offset, 0); + } + static createV8Vector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + static startV8Vector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addVf64(builder, vf64Offset) { + builder.addFieldOffset(11, vf64Offset, 0); + } + static createVf64Vector(builder, data) { + builder.startVector(8, data.length, 8); + for (let i = data.length - 1; i >= 0; i--) { + builder.addFloat64(data[i]); + } + return builder.endVector(); + } + static startVf64Vector(builder, numElems) { + builder.startVector(8, numElems, 8); + } + static endTypeAliases(builder) { + const offset = builder.endObject(); + return offset; + } + static createTypeAliases(builder, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, v8Offset, vf64Offset) { + TypeAliases.startTypeAliases(builder); + TypeAliases.addI8(builder, i8); + TypeAliases.addU8(builder, u8); + TypeAliases.addI16(builder, i16); + TypeAliases.addU16(builder, u16); + TypeAliases.addI32(builder, i32); + TypeAliases.addU32(builder, u32); + TypeAliases.addI64(builder, i64); + TypeAliases.addU64(builder, u64); + TypeAliases.addF32(builder, f32); + TypeAliases.addF64(builder, f64); + TypeAliases.addV8(builder, v8Offset); + TypeAliases.addVf64(builder, vf64Offset); + return TypeAliases.endTypeAliases(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return TypeAliases.getRootAsTypeAliases(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new TypeAliasesT(this.i8(), this.u8(), this.i16(), this.u16(), this.i32(), this.u32(), this.i64(), this.u64(), this.f32(), this.f64(), this.bb.createScalarList(this.v8.bind(this), this.v8Length()), this.bb.createScalarList(this.vf64.bind(this), this.vf64Length())); + } + unpackTo(_o) { + _o.i8 = this.i8(); + _o.u8 = this.u8(); + _o.i16 = this.i16(); + _o.u16 = this.u16(); + _o.i32 = this.i32(); + _o.u32 = this.u32(); + _o.i64 = this.i64(); + _o.u64 = this.u64(); + _o.f32 = this.f32(); + _o.f64 = this.f64(); + _o.v8 = this.bb.createScalarList(this.v8.bind(this), this.v8Length()); + _o.vf64 = this.bb.createScalarList(this.vf64.bind(this), this.vf64Length()); } - return builder.endVector(); - } - static startVf64Vector(builder, numElems) { - builder.startVector(8, numElems, 8); - } - static endTypeAliases(builder) { - const offset = builder.endObject(); - return offset; - } - static createTypeAliases( - builder, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, v8Offset, - vf64Offset) { - TypeAliases.startTypeAliases(builder); - TypeAliases.addI8(builder, i8); - TypeAliases.addU8(builder, u8); - TypeAliases.addI16(builder, i16); - TypeAliases.addU16(builder, u16); - TypeAliases.addI32(builder, i32); - TypeAliases.addU32(builder, u32); - TypeAliases.addI64(builder, i64); - TypeAliases.addU64(builder, u64); - TypeAliases.addF32(builder, f32); - TypeAliases.addF64(builder, f64); - TypeAliases.addV8(builder, v8Offset); - TypeAliases.addVf64(builder, vf64Offset); - return TypeAliases.endTypeAliases(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return TypeAliases.getRootAsTypeAliases(new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new TypeAliasesT( - this.i8(), this.u8(), this.i16(), this.u16(), this.i32(), this.u32(), - this.i64(), this.u64(), this.f32(), this.f64(), - this.bb.createScalarList(this.v8.bind(this), this.v8Length()), - this.bb.createScalarList(this.vf64.bind(this), this.vf64Length())); - } - unpackTo(_o) { - _o.i8 = this.i8(); - _o.u8 = this.u8(); - _o.i16 = this.i16(); - _o.u16 = this.u16(); - _o.i32 = this.i32(); - _o.u32 = this.u32(); - _o.i64 = this.i64(); - _o.u64 = this.u64(); - _o.f32 = this.f32(); - _o.f64 = this.f64(); - _o.v8 = this.bb.createScalarList(this.v8.bind(this), this.v8Length()); - _o.vf64 = this.bb.createScalarList(this.vf64.bind(this), this.vf64Length()); - } } export class TypeAliasesT { - constructor( - i8 = 0, u8 = 0, i16 = 0, u16 = 0, i32 = 0, u32 = 0, i64 = BigInt('0'), - u64 = BigInt('0'), f32 = 0.0, f64 = 0.0, v8 = [], vf64 = []) { - this.i8 = i8; - this.u8 = u8; - this.i16 = i16; - this.u16 = u16; - this.i32 = i32; - this.u32 = u32; - this.i64 = i64; - this.u64 = u64; - this.f32 = f32; - this.f64 = f64; - this.v8 = v8; - this.vf64 = vf64; - } - pack(builder) { - const v8 = TypeAliases.createV8Vector(builder, this.v8); - const vf64 = TypeAliases.createVf64Vector(builder, this.vf64); - return TypeAliases.createTypeAliases( - builder, this.i8, this.u8, this.i16, this.u16, this.i32, this.u32, - this.i64, this.u64, this.f32, this.f64, v8, vf64); - } + constructor(i8 = 0, u8 = 0, i16 = 0, u16 = 0, i32 = 0, u32 = 0, i64 = BigInt('0'), u64 = BigInt('0'), f32 = 0.0, f64 = 0.0, v8 = [], vf64 = []) { + this.i8 = i8; + this.u8 = u8; + this.i16 = i16; + this.u16 = u16; + this.i32 = i32; + this.u32 = u32; + this.i64 = i64; + this.u64 = u64; + this.f32 = f32; + this.f64 = f64; + this.v8 = v8; + this.vf64 = vf64; + } + pack(builder) { + const v8 = TypeAliases.createV8Vector(builder, this.v8); + const vf64 = TypeAliases.createVf64Vector(builder, this.vf64); + return TypeAliases.createTypeAliases(builder, this.i8, this.u8, this.i16, this.u16, this.i32, this.u32, this.i64, this.u64, this.f32, this.f64, v8, vf64); + } } diff --git a/tests/ts/my-game/example/type-aliases.ts b/tests/ts/my-game/example/type-aliases.ts index 2897e9738..483629606 100644 --- a/tests/ts/my-game/example/type-aliases.ts +++ b/tests/ts/my-game/example/type-aliases.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class TypeAliases implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):TypeAliases { this.bb_pos = i; this.bb = bb; @@ -218,51 +218,51 @@ static getFullyQualifiedName(): "MyGame.Example.TypeAliases" { return 'MyGame.Example.TypeAliases'; } -static startTypeAliases(builder:flatbuffers.Builder) { +static startTypeAliases(builder:flatbuffers.Builder):void { builder.startObject(12); } -static addI8(builder:flatbuffers.Builder, i8:number) { +static addI8(builder:flatbuffers.Builder, i8:number):void { builder.addFieldInt8(0, i8, 0); } -static addU8(builder:flatbuffers.Builder, u8:number) { +static addU8(builder:flatbuffers.Builder, u8:number):void { builder.addFieldInt8(1, u8, 0); } -static addI16(builder:flatbuffers.Builder, i16:number) { +static addI16(builder:flatbuffers.Builder, i16:number):void { builder.addFieldInt16(2, i16, 0); } -static addU16(builder:flatbuffers.Builder, u16:number) { +static addU16(builder:flatbuffers.Builder, u16:number):void { builder.addFieldInt16(3, u16, 0); } -static addI32(builder:flatbuffers.Builder, i32:number) { +static addI32(builder:flatbuffers.Builder, i32:number):void { builder.addFieldInt32(4, i32, 0); } -static addU32(builder:flatbuffers.Builder, u32:number) { +static addU32(builder:flatbuffers.Builder, u32:number):void { builder.addFieldInt32(5, u32, 0); } -static addI64(builder:flatbuffers.Builder, i64:bigint) { +static addI64(builder:flatbuffers.Builder, i64:bigint):void { builder.addFieldInt64(6, i64, BigInt('0')); } -static addU64(builder:flatbuffers.Builder, u64:bigint) { +static addU64(builder:flatbuffers.Builder, u64:bigint):void { builder.addFieldInt64(7, u64, BigInt('0')); } -static addF32(builder:flatbuffers.Builder, f32:number) { +static addF32(builder:flatbuffers.Builder, f32:number):void { builder.addFieldFloat32(8, f32, 0.0); } -static addF64(builder:flatbuffers.Builder, f64:number) { +static addF64(builder:flatbuffers.Builder, f64:number):void { builder.addFieldFloat64(9, f64, 0.0); } -static addV8(builder:flatbuffers.Builder, v8Offset:flatbuffers.Offset) { +static addV8(builder:flatbuffers.Builder, v8Offset:flatbuffers.Offset):void { builder.addFieldOffset(10, v8Offset, 0); } @@ -279,11 +279,11 @@ static createV8Vector(builder:flatbuffers.Builder, data:number[]|Int8Array|Uint8 return builder.endVector(); } -static startV8Vector(builder:flatbuffers.Builder, numElems:number) { +static startV8Vector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addVf64(builder:flatbuffers.Builder, vf64Offset:flatbuffers.Offset) { +static addVf64(builder:flatbuffers.Builder, vf64Offset:flatbuffers.Offset):void { builder.addFieldOffset(11, vf64Offset, 0); } @@ -300,7 +300,7 @@ static createVf64Vector(builder:flatbuffers.Builder, data:number[]|Float64Array| return builder.endVector(); } -static startVf64Vector(builder:flatbuffers.Builder, numElems:number) { +static startVf64Vector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(8, numElems, 8); } diff --git a/tests/ts/my-game/example/vec3.d.ts b/tests/ts/my-game/example/vec3.d.ts index c3d79f976..ee991cc4b 100644 --- a/tests/ts/my-game/example/vec3.d.ts +++ b/tests/ts/my-game/example/vec3.d.ts @@ -1,50 +1,34 @@ import * as flatbuffers from 'flatbuffers'; -import {Color} from '../../my-game/example/color.js'; -import {Test, TestT} from '../../my-game/example/test.js'; +import { Color } from './color.js'; +import { Test, TestT } from './test.js'; export declare class Vec3 implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Vec3; - x(): number; - mutate_x(value: number): boolean; - y(): number; - mutate_y(value: number): boolean; - z(): number; - mutate_z(value: number): boolean; - test1(): number; - mutate_test1(value: number): boolean; - test2(): Color; - mutate_test2(value: Color): boolean; - test3(obj?: Test): Test | null; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createVec3( - builder: flatbuffers.Builder, - x: number, - y: number, - z: number, - test1: number, - test2: Color, - test3_a: number, - test3_b: number, - ): flatbuffers.Offset; - unpack(): Vec3T; - unpackTo(_o: Vec3T): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Vec3; + x(): number; + mutate_x(value: number): boolean; + y(): number; + mutate_y(value: number): boolean; + z(): number; + mutate_z(value: number): boolean; + test1(): number; + mutate_test1(value: number): boolean; + test2(): Color; + mutate_test2(value: Color): boolean; + test3(obj?: Test): Test | null; + static getFullyQualifiedName(): "MyGame.Example.Vec3"; + static sizeOf(): number; + static createVec3(builder: flatbuffers.Builder, x: number, y: number, z: number, test1: number, test2: Color, test3_a: number, test3_b: number): flatbuffers.Offset; + unpack(): Vec3T; + unpackTo(_o: Vec3T): void; } export declare class Vec3T implements flatbuffers.IGeneratedObject { - x: number; - y: number; - z: number; - test1: number; - test2: Color; - test3: TestT | null; - constructor( - x?: number, - y?: number, - z?: number, - test1?: number, - test2?: Color, - test3?: TestT | null, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + x: number; + y: number; + z: number; + test1: number; + test2: Color; + test3: TestT | null; + constructor(x?: number, y?: number, z?: number, test1?: number, test2?: Color, test3?: TestT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example/vec3.js b/tests/ts/my-game/example/vec3.js index a8f3effe8..de030ef2e 100644 --- a/tests/ts/my-game/example/vec3.js +++ b/tests/ts/my-game/example/vec3.js @@ -1,103 +1,98 @@ // automatically generated by the FlatBuffers compiler, do not modify -import {Color} from '../../my-game/example/color.js'; -import {Test} from '../../my-game/example/test.js'; +import { Color } from './color.js'; +import { Test } from './test.js'; export class Vec3 { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - x() { - return this.bb.readFloat32(this.bb_pos); - } - mutate_x(value) { - this.bb.writeFloat32(this.bb_pos + 0, value); - return true; - } - y() { - return this.bb.readFloat32(this.bb_pos + 4); - } - mutate_y(value) { - this.bb.writeFloat32(this.bb_pos + 4, value); - return true; - } - z() { - return this.bb.readFloat32(this.bb_pos + 8); - } - mutate_z(value) { - this.bb.writeFloat32(this.bb_pos + 8, value); - return true; - } - test1() { - return this.bb.readFloat64(this.bb_pos + 16); - } - mutate_test1(value) { - this.bb.writeFloat64(this.bb_pos + 16, value); - return true; - } - test2() { - return this.bb.readUint8(this.bb_pos + 24); - } - mutate_test2(value) { - this.bb.writeUint8(this.bb_pos + 24, value); - return true; - } - test3(obj) { - return (obj || new Test()).__init(this.bb_pos + 26, this.bb); - } - static getFullyQualifiedName() { - return 'MyGame.Example.Vec3'; - } - static sizeOf() { - return 32; - } - static createVec3(builder, x, y, z, test1, test2, test3_a, test3_b) { - builder.prep(8, 32); - builder.pad(2); - builder.prep(2, 4); - builder.pad(1); - builder.writeInt8(test3_b); - builder.writeInt16(test3_a); - builder.pad(1); - builder.writeInt8(test2); - builder.writeFloat64(test1); - builder.pad(4); - builder.writeFloat32(z); - builder.writeFloat32(y); - builder.writeFloat32(x); - return builder.offset(); - } - unpack() { - return new Vec3T( - this.x(), this.y(), this.z(), this.test1(), this.test2(), - (this.test3() !== null ? this.test3().unpack() : null)); - } - unpackTo(_o) { - _o.x = this.x(); - _o.y = this.y(); - _o.z = this.z(); - _o.test1 = this.test1(); - _o.test2 = this.test2(); - _o.test3 = (this.test3() !== null ? this.test3().unpack() : null); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + x() { + return this.bb.readFloat32(this.bb_pos); + } + mutate_x(value) { + this.bb.writeFloat32(this.bb_pos + 0, value); + return true; + } + y() { + return this.bb.readFloat32(this.bb_pos + 4); + } + mutate_y(value) { + this.bb.writeFloat32(this.bb_pos + 4, value); + return true; + } + z() { + return this.bb.readFloat32(this.bb_pos + 8); + } + mutate_z(value) { + this.bb.writeFloat32(this.bb_pos + 8, value); + return true; + } + test1() { + return this.bb.readFloat64(this.bb_pos + 16); + } + mutate_test1(value) { + this.bb.writeFloat64(this.bb_pos + 16, value); + return true; + } + test2() { + return this.bb.readUint8(this.bb_pos + 24); + } + mutate_test2(value) { + this.bb.writeUint8(this.bb_pos + 24, value); + return true; + } + test3(obj) { + return (obj || new Test()).__init(this.bb_pos + 26, this.bb); + } + static getFullyQualifiedName() { + return 'MyGame.Example.Vec3'; + } + static sizeOf() { + return 32; + } + static createVec3(builder, x, y, z, test1, test2, test3_a, test3_b) { + builder.prep(8, 32); + builder.pad(2); + builder.prep(2, 4); + builder.pad(1); + builder.writeInt8(test3_b); + builder.writeInt16(test3_a); + builder.pad(1); + builder.writeInt8(test2); + builder.writeFloat64(test1); + builder.pad(4); + builder.writeFloat32(z); + builder.writeFloat32(y); + builder.writeFloat32(x); + return builder.offset(); + } + unpack() { + return new Vec3T(this.x(), this.y(), this.z(), this.test1(), this.test2(), (this.test3() !== null ? this.test3().unpack() : null)); + } + unpackTo(_o) { + _o.x = this.x(); + _o.y = this.y(); + _o.z = this.z(); + _o.test1 = this.test1(); + _o.test2 = this.test2(); + _o.test3 = (this.test3() !== null ? this.test3().unpack() : null); + } } export class Vec3T { - constructor( - x = 0.0, y = 0.0, z = 0.0, test1 = 0.0, test2 = Color.Red, test3 = null) { - this.x = x; - this.y = y; - this.z = z; - this.test1 = test1; - this.test2 = test2; - this.test3 = test3; - } - pack(builder) { - return Vec3.createVec3( - builder, this.x, this.y, this.z, this.test1, this.test2, - (this.test3?.a ?? 0), (this.test3?.b ?? 0)); - } + constructor(x = 0.0, y = 0.0, z = 0.0, test1 = 0.0, test2 = Color.Red, test3 = null) { + this.x = x; + this.y = y; + this.z = z; + this.test1 = test1; + this.test2 = test2; + this.test3 = test3; + } + pack(builder) { + return Vec3.createVec3(builder, this.x, this.y, this.z, this.test1, this.test2, (this.test3?.a ?? 0), (this.test3?.b ?? 0)); + } } diff --git a/tests/ts/my-game/example/vec3.ts b/tests/ts/my-game/example/vec3.ts index a5fd359fe..ba826fb71 100644 --- a/tests/ts/my-game/example/vec3.ts +++ b/tests/ts/my-game/example/vec3.ts @@ -10,7 +10,7 @@ import { Test, TestT } from './test.js'; export class Vec3 implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Vec3 { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/my-game/example2.d.ts b/tests/ts/my-game/example2.d.ts index 7037b7003..4aebab971 100644 --- a/tests/ts/my-game/example2.d.ts +++ b/tests/ts/my-game/example2.d.ts @@ -1 +1 @@ -export {Monster, MonsterT} from './example2/monster.js'; +export { Monster, MonsterT } from './example2/monster.js'; diff --git a/tests/ts/my-game/example2.js b/tests/ts/my-game/example2.js index b6e9a1563..2c599c5df 100644 --- a/tests/ts/my-game/example2.js +++ b/tests/ts/my-game/example2.js @@ -1,4 +1,3 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {Monster, MonsterT} from './example2/monster.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Monster, MonsterT } from './example2/monster.js'; diff --git a/tests/ts/my-game/example2/monster.d.ts b/tests/ts/my-game/example2/monster.d.ts index f15a2007c..3a093a3e8 100644 --- a/tests/ts/my-game/example2/monster.d.ts +++ b/tests/ts/my-game/example2/monster.d.ts @@ -1,25 +1,20 @@ import * as flatbuffers from 'flatbuffers'; -export declare class Monster - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Monster; - static getRootAsMonster(bb: flatbuffers.ByteBuffer, obj?: Monster): Monster; - static getSizePrefixedRootAsMonster( - bb: flatbuffers.ByteBuffer, - obj?: Monster, - ): Monster; - static getFullyQualifiedName(): string; - static startMonster(builder: flatbuffers.Builder): void; - static endMonster(builder: flatbuffers.Builder): flatbuffers.Offset; - static createMonster(builder: flatbuffers.Builder): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): Monster; - unpack(): MonsterT; - unpackTo(_o: MonsterT): void; +export declare class Monster implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Monster; + static getRootAsMonster(bb: flatbuffers.ByteBuffer, obj?: Monster): Monster; + static getSizePrefixedRootAsMonster(bb: flatbuffers.ByteBuffer, obj?: Monster): Monster; + static getFullyQualifiedName(): "MyGame.Example2.Monster"; + static startMonster(builder: flatbuffers.Builder): void; + static endMonster(builder: flatbuffers.Builder): flatbuffers.Offset; + static createMonster(builder: flatbuffers.Builder): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): Monster; + unpack(): MonsterT; + unpackTo(_o: MonsterT): void; } export declare class MonsterT implements flatbuffers.IGeneratedObject { - constructor(); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + constructor(); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/example2/monster.js b/tests/ts/my-game/example2/monster.js index 6fb80c983..56d215f94 100644 --- a/tests/ts/my-game/example2/monster.js +++ b/tests/ts/my-game/example2/monster.js @@ -1,54 +1,51 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class Monster { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsMonster(bb, obj) { - return (obj || new Monster()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsMonster(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Monster()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getFullyQualifiedName() { - return 'MyGame.Example2.Monster'; - } - static startMonster(builder) { - builder.startObject(0); - } - static endMonster(builder) { - const offset = builder.endObject(); - return offset; - } - static createMonster(builder) { - Monster.startMonster(builder); - return Monster.endMonster(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new MonsterT(); - } - unpackTo(_o) {} + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsMonster(bb, obj) { + return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsMonster(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getFullyQualifiedName() { + return 'MyGame.Example2.Monster'; + } + static startMonster(builder) { + builder.startObject(0); + } + static endMonster(builder) { + const offset = builder.endObject(); + return offset; + } + static createMonster(builder) { + Monster.startMonster(builder); + return Monster.endMonster(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new MonsterT(); + } + unpackTo(_o) { } } export class MonsterT { - constructor() {} - pack(builder) { - return Monster.createMonster(builder); - } + constructor() { } + pack(builder) { + return Monster.createMonster(builder); + } } diff --git a/tests/ts/my-game/example2/monster.ts b/tests/ts/my-game/example2/monster.ts index 2016c84e7..cadd4c1fb 100644 --- a/tests/ts/my-game/example2/monster.ts +++ b/tests/ts/my-game/example2/monster.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class Monster implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Monster { this.bb_pos = i; this.bb = bb; @@ -28,7 +28,7 @@ static getFullyQualifiedName(): "MyGame.Example2.Monster" { return 'MyGame.Example2.Monster'; } -static startMonster(builder:flatbuffers.Builder) { +static startMonster(builder:flatbuffers.Builder):void { builder.startObject(0); } diff --git a/tests/ts/my-game/in-parent-namespace.d.ts b/tests/ts/my-game/in-parent-namespace.d.ts index fcffe787e..0935e4e5b 100644 --- a/tests/ts/my-game/in-parent-namespace.d.ts +++ b/tests/ts/my-game/in-parent-namespace.d.ts @@ -1,32 +1,20 @@ import * as flatbuffers from 'flatbuffers'; -export declare class InParentNamespace - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): InParentNamespace; - static getRootAsInParentNamespace( - bb: flatbuffers.ByteBuffer, - obj?: InParentNamespace, - ): InParentNamespace; - static getSizePrefixedRootAsInParentNamespace( - bb: flatbuffers.ByteBuffer, - obj?: InParentNamespace, - ): InParentNamespace; - static getFullyQualifiedName(): string; - static startInParentNamespace(builder: flatbuffers.Builder): void; - static endInParentNamespace(builder: flatbuffers.Builder): flatbuffers.Offset; - static createInParentNamespace( - builder: flatbuffers.Builder, - ): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): InParentNamespace; - unpack(): InParentNamespaceT; - unpackTo(_o: InParentNamespaceT): void; +export declare class InParentNamespace implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): InParentNamespace; + static getRootAsInParentNamespace(bb: flatbuffers.ByteBuffer, obj?: InParentNamespace): InParentNamespace; + static getSizePrefixedRootAsInParentNamespace(bb: flatbuffers.ByteBuffer, obj?: InParentNamespace): InParentNamespace; + static getFullyQualifiedName(): "MyGame.InParentNamespace"; + static startInParentNamespace(builder: flatbuffers.Builder): void; + static endInParentNamespace(builder: flatbuffers.Builder): flatbuffers.Offset; + static createInParentNamespace(builder: flatbuffers.Builder): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): InParentNamespace; + unpack(): InParentNamespaceT; + unpackTo(_o: InParentNamespaceT): void; } -export declare class InParentNamespaceT - implements flatbuffers.IGeneratedObject -{ - constructor(); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; +export declare class InParentNamespaceT implements flatbuffers.IGeneratedObject { + constructor(); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/in-parent-namespace.js b/tests/ts/my-game/in-parent-namespace.js index f5141497f..197d271e8 100644 --- a/tests/ts/my-game/in-parent-namespace.js +++ b/tests/ts/my-game/in-parent-namespace.js @@ -1,55 +1,51 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class InParentNamespace { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsInParentNamespace(bb, obj) { - return (obj || new InParentNamespace()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsInParentNamespace(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new InParentNamespace()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getFullyQualifiedName() { - return 'MyGame.InParentNamespace'; - } - static startInParentNamespace(builder) { - builder.startObject(0); - } - static endInParentNamespace(builder) { - const offset = builder.endObject(); - return offset; - } - static createInParentNamespace(builder) { - InParentNamespace.startInParentNamespace(builder); - return InParentNamespace.endInParentNamespace(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return InParentNamespace.getRootAsInParentNamespace( - new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new InParentNamespaceT(); - } - unpackTo(_o) {} + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsInParentNamespace(bb, obj) { + return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsInParentNamespace(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getFullyQualifiedName() { + return 'MyGame.InParentNamespace'; + } + static startInParentNamespace(builder) { + builder.startObject(0); + } + static endInParentNamespace(builder) { + const offset = builder.endObject(); + return offset; + } + static createInParentNamespace(builder) { + InParentNamespace.startInParentNamespace(builder); + return InParentNamespace.endInParentNamespace(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return InParentNamespace.getRootAsInParentNamespace(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new InParentNamespaceT(); + } + unpackTo(_o) { } } export class InParentNamespaceT { - constructor() {} - pack(builder) { - return InParentNamespace.createInParentNamespace(builder); - } + constructor() { } + pack(builder) { + return InParentNamespace.createInParentNamespace(builder); + } } diff --git a/tests/ts/my-game/in-parent-namespace.ts b/tests/ts/my-game/in-parent-namespace.ts index 1b67a08db..619fa2c83 100644 --- a/tests/ts/my-game/in-parent-namespace.ts +++ b/tests/ts/my-game/in-parent-namespace.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class InParentNamespace implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):InParentNamespace { this.bb_pos = i; this.bb = bb; @@ -28,7 +28,7 @@ static getFullyQualifiedName(): "MyGame.InParentNamespace" { return 'MyGame.InParentNamespace'; } -static startInParentNamespace(builder:flatbuffers.Builder) { +static startInParentNamespace(builder:flatbuffers.Builder):void { builder.startObject(0); } diff --git a/tests/ts/my-game/other-name-space.d.ts b/tests/ts/my-game/other-name-space.d.ts index d195185f4..3152eff5d 100644 --- a/tests/ts/my-game/other-name-space.d.ts +++ b/tests/ts/my-game/other-name-space.d.ts @@ -1,3 +1,3 @@ -export {FromInclude} from './other-name-space/from-include.js'; -export {TableB, TableBT} from './other-name-space/table-b.js'; -export {Unused, UnusedT} from './other-name-space/unused.js'; +export { FromInclude } from './other-name-space/from-include.js'; +export { TableB, TableBT } from './other-name-space/table-b.js'; +export { Unused, UnusedT } from './other-name-space/unused.js'; diff --git a/tests/ts/my-game/other-name-space.js b/tests/ts/my-game/other-name-space.js index 2171b3021..6b80bdba6 100644 --- a/tests/ts/my-game/other-name-space.js +++ b/tests/ts/my-game/other-name-space.js @@ -1,6 +1,5 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {FromInclude} from './other-name-space/from-include.js'; -export {TableB, TableBT} from './other-name-space/table-b.js'; -export {Unused, UnusedT} from './other-name-space/unused.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { FromInclude } from './other-name-space/from-include.js'; +export { TableB, TableBT } from './other-name-space/table-b.js'; +export { Unused, UnusedT } from './other-name-space/unused.js'; diff --git a/tests/ts/my-game/other-name-space/from-include.d.ts b/tests/ts/my-game/other-name-space/from-include.d.ts index 2e220a651..dc12fa4b6 100644 --- a/tests/ts/my-game/other-name-space/from-include.d.ts +++ b/tests/ts/my-game/other-name-space/from-include.d.ts @@ -1,3 +1,3 @@ export declare enum FromInclude { - IncludeVal = '0', + IncludeVal = "0" } diff --git a/tests/ts/my-game/other-name-space/from-include.js b/tests/ts/my-game/other-name-space/from-include.js index 5ad1bd1e9..e9d4e43a6 100644 --- a/tests/ts/my-game/other-name-space/from-include.js +++ b/tests/ts/my-game/other-name-space/from-include.js @@ -1,7 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var FromInclude; -(function(FromInclude) { -FromInclude['IncludeVal'] = '0'; +(function (FromInclude) { + FromInclude["IncludeVal"] = "0"; })(FromInclude || (FromInclude = {})); diff --git a/tests/ts/my-game/other-name-space/from-include.ts b/tests/ts/my-game/other-name-space/from-include.ts index 6d087bfaa..86305f248 100644 --- a/tests/ts/my-game/other-name-space/from-include.ts +++ b/tests/ts/my-game/other-name-space/from-include.ts @@ -3,5 +3,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export enum FromInclude { - IncludeVal = '0', + IncludeVal = '0' } diff --git a/tests/ts/my-game/other-name-space/table-b.d.ts b/tests/ts/my-game/other-name-space/table-b.d.ts index 50c885c5b..ee5dd28cc 100644 --- a/tests/ts/my-game/other-name-space/table-b.d.ts +++ b/tests/ts/my-game/other-name-space/table-b.d.ts @@ -1,30 +1,24 @@ import * as flatbuffers from 'flatbuffers'; -import {TableA, TableAT} from '../../table-a.js'; +import { TableA, TableAT } from '../../table-a.js'; export declare class TableB implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): TableB; - static getRootAsTableB(bb: flatbuffers.ByteBuffer, obj?: TableB): TableB; - static getSizePrefixedRootAsTableB( - bb: flatbuffers.ByteBuffer, - obj?: TableB, - ): TableB; - a(obj?: TableA): TableA | null; - static getFullyQualifiedName(): string; - static startTableB(builder: flatbuffers.Builder): void; - static addA(builder: flatbuffers.Builder, aOffset: flatbuffers.Offset): void; - static endTableB(builder: flatbuffers.Builder): flatbuffers.Offset; - static createTableB( - builder: flatbuffers.Builder, - aOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): TableB; - unpack(): TableBT; - unpackTo(_o: TableBT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): TableB; + static getRootAsTableB(bb: flatbuffers.ByteBuffer, obj?: TableB): TableB; + static getSizePrefixedRootAsTableB(bb: flatbuffers.ByteBuffer, obj?: TableB): TableB; + a(obj?: TableA): TableA | null; + static getFullyQualifiedName(): "MyGame.OtherNameSpace.TableB"; + static startTableB(builder: flatbuffers.Builder): void; + static addA(builder: flatbuffers.Builder, aOffset: flatbuffers.Offset): void; + static endTableB(builder: flatbuffers.Builder): flatbuffers.Offset; + static createTableB(builder: flatbuffers.Builder, aOffset: flatbuffers.Offset): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): TableB; + unpack(): TableBT; + unpackTo(_o: TableBT): void; } export declare class TableBT implements flatbuffers.IGeneratedObject { - a: TableAT | null; - constructor(a?: TableAT | null); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: TableAT | null; + constructor(a?: TableAT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/other-name-space/table-b.js b/tests/ts/my-game/other-name-space/table-b.js index b439a8e88..74b170c88 100644 --- a/tests/ts/my-game/other-name-space/table-b.js +++ b/tests/ts/my-game/other-name-space/table-b.js @@ -1,73 +1,65 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {TableA} from '../../table-a.js'; - +import { TableA } from '../../table-a.js'; export class TableB { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsTableB(bb, obj) { - return (obj || new TableB()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsTableB(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new TableB()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - a(obj) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? - (obj || new TableA()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - static getFullyQualifiedName() { - return 'MyGame.OtherNameSpace.TableB'; - } - static startTableB(builder) { - builder.startObject(1); - } - static addA(builder, aOffset) { - builder.addFieldOffset(0, aOffset, 0); - } - static endTableB(builder) { - const offset = builder.endObject(); - return offset; - } - static createTableB(builder, aOffset) { - TableB.startTableB(builder); - TableB.addA(builder, aOffset); - return TableB.endTableB(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return TableB.getRootAsTableB(new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new TableBT((this.a() !== null ? this.a().unpack() : null)); - } - unpackTo(_o) { - _o.a = (this.a() !== null ? this.a().unpack() : null); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsTableB(bb, obj) { + return (obj || new TableB()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsTableB(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TableB()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + a(obj) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new TableA()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + static getFullyQualifiedName() { + return 'MyGame.OtherNameSpace.TableB'; + } + static startTableB(builder) { + builder.startObject(1); + } + static addA(builder, aOffset) { + builder.addFieldOffset(0, aOffset, 0); + } + static endTableB(builder) { + const offset = builder.endObject(); + return offset; + } + static createTableB(builder, aOffset) { + TableB.startTableB(builder); + TableB.addA(builder, aOffset); + return TableB.endTableB(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return TableB.getRootAsTableB(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new TableBT((this.a() !== null ? this.a().unpack() : null)); + } + unpackTo(_o) { + _o.a = (this.a() !== null ? this.a().unpack() : null); + } } export class TableBT { - constructor(a = null) { - this.a = a; - } - pack(builder) { - const a = (this.a !== null ? this.a.pack(builder) : 0); - return TableB.createTableB(builder, a); - } + constructor(a = null) { + this.a = a; + } + pack(builder) { + const a = (this.a !== null ? this.a.pack(builder) : 0); + return TableB.createTableB(builder, a); + } } diff --git a/tests/ts/my-game/other-name-space/table-b.ts b/tests/ts/my-game/other-name-space/table-b.ts index 2b7ae0ca5..624d933d0 100644 --- a/tests/ts/my-game/other-name-space/table-b.ts +++ b/tests/ts/my-game/other-name-space/table-b.ts @@ -4,94 +4,86 @@ import * as flatbuffers from 'flatbuffers'; -import {TableA, TableAT} from '../../table-a.js'; +import { TableA, TableAT } from '../../table-a.js'; + export class TableB implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): TableB { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):TableB { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsTableB(bb: flatbuffers.ByteBuffer, obj?: TableB): TableB { - return (obj || new TableB()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsTableB(bb:flatbuffers.ByteBuffer, obj?:TableB):TableB { + return (obj || new TableB()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsTableB( - bb: flatbuffers.ByteBuffer, - obj?: TableB, - ): TableB { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new TableB()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsTableB(bb:flatbuffers.ByteBuffer, obj?:TableB):TableB { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TableB()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - a(obj?: TableA): TableA | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? (obj || new TableA()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } +a(obj?:TableA):TableA|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new TableA()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} - static getFullyQualifiedName(): string { - return 'MyGame.OtherNameSpace.TableB'; - } +static getFullyQualifiedName(): "MyGame.OtherNameSpace.TableB" { + return 'MyGame.OtherNameSpace.TableB'; +} - static startTableB(builder: flatbuffers.Builder) { - builder.startObject(1); - } +static startTableB(builder:flatbuffers.Builder):void { + builder.startObject(1); +} - static addA(builder: flatbuffers.Builder, aOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, aOffset, 0); - } +static addA(builder:flatbuffers.Builder, aOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, aOffset, 0); +} - static endTableB(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } +static endTableB(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - static createTableB( - builder: flatbuffers.Builder, - aOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - TableB.startTableB(builder); - TableB.addA(builder, aOffset); - return TableB.endTableB(builder); - } +static createTableB(builder:flatbuffers.Builder, aOffset:flatbuffers.Offset):flatbuffers.Offset { + TableB.startTableB(builder); + TableB.addA(builder, aOffset); + return TableB.endTableB(builder); +} - serialize(): Uint8Array { - return this.bb!.bytes(); - } +serialize():Uint8Array { + return this.bb!.bytes(); +} - static deserialize(buffer: Uint8Array): TableB { - return TableB.getRootAsTableB(new flatbuffers.ByteBuffer(buffer)); - } +static deserialize(buffer: Uint8Array):TableB { + return TableB.getRootAsTableB(new flatbuffers.ByteBuffer(buffer)) +} - unpack(): TableBT { - return new TableBT(this.a() !== null ? this.a()!.unpack() : null); - } +unpack(): TableBT { + return new TableBT( + (this.a() !== null ? this.a()!.unpack() : null) + ); +} - unpackTo(_o: TableBT): void { - _o.a = this.a() !== null ? this.a()!.unpack() : null; - } + +unpackTo(_o: TableBT): void { + _o.a = (this.a() !== null ? this.a()!.unpack() : null); +} } export class TableBT implements flatbuffers.IGeneratedObject { - constructor(public a: TableAT | null = null) {} +constructor( + public a: TableAT|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const a = this.a !== null ? this.a!.pack(builder) : 0; - return TableB.createTableB(builder, a); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const a = (this.a !== null ? this.a!.pack(builder) : 0); + + return TableB.createTableB(builder, + a + ); +} } diff --git a/tests/ts/my-game/other-name-space/unused.d.ts b/tests/ts/my-game/other-name-space/unused.d.ts index ced7cac7d..a39310b2c 100644 --- a/tests/ts/my-game/other-name-space/unused.d.ts +++ b/tests/ts/my-game/other-name-space/unused.d.ts @@ -1,21 +1,18 @@ import * as flatbuffers from 'flatbuffers'; export declare class Unused implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Unused; - a(): number; - mutate_a(value: number): boolean; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createUnused( - builder: flatbuffers.Builder, - a: number, - ): flatbuffers.Offset; - unpack(): UnusedT; - unpackTo(_o: UnusedT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Unused; + a(): number; + mutate_a(value: number): boolean; + static getFullyQualifiedName(): "MyGame.OtherNameSpace.Unused"; + static sizeOf(): number; + static createUnused(builder: flatbuffers.Builder, a: number): flatbuffers.Offset; + unpack(): UnusedT; + unpackTo(_o: UnusedT): void; } export declare class UnusedT implements flatbuffers.IGeneratedObject { - a: number; - constructor(a?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: number; + constructor(a?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/my-game/other-name-space/unused.js b/tests/ts/my-game/other-name-space/unused.js index 2c2b46a51..0b42918d1 100644 --- a/tests/ts/my-game/other-name-space/unused.js +++ b/tests/ts/my-game/other-name-space/unused.js @@ -1,44 +1,44 @@ // automatically generated by the FlatBuffers compiler, do not modify export class Unused { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - a() { - return this.bb.readInt32(this.bb_pos); - } - mutate_a(value) { - this.bb.writeInt32(this.bb_pos + 0, value); - return true; - } - static getFullyQualifiedName() { - return 'MyGame.OtherNameSpace.Unused'; - } - static sizeOf() { - return 4; - } - static createUnused(builder, a) { - builder.prep(4, 4); - builder.writeInt32(a); - return builder.offset(); - } - unpack() { - return new UnusedT(this.a()); - } - unpackTo(_o) { - _o.a = this.a(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + a() { + return this.bb.readInt32(this.bb_pos); + } + mutate_a(value) { + this.bb.writeInt32(this.bb_pos + 0, value); + return true; + } + static getFullyQualifiedName() { + return 'MyGame.OtherNameSpace.Unused'; + } + static sizeOf() { + return 4; + } + static createUnused(builder, a) { + builder.prep(4, 4); + builder.writeInt32(a); + return builder.offset(); + } + unpack() { + return new UnusedT(this.a()); + } + unpackTo(_o) { + _o.a = this.a(); + } } export class UnusedT { - constructor(a = 0) { - this.a = a; - } - pack(builder) { - return Unused.createUnused(builder, this.a); - } + constructor(a = 0) { + this.a = a; + } + pack(builder) { + return Unused.createUnused(builder, this.a); + } } diff --git a/tests/ts/my-game/other-name-space/unused.ts b/tests/ts/my-game/other-name-space/unused.ts index dcd663fb0..ed63a6700 100644 --- a/tests/ts/my-game/other-name-space/unused.ts +++ b/tests/ts/my-game/other-name-space/unused.ts @@ -4,54 +4,62 @@ import * as flatbuffers from 'flatbuffers'; + + export class Unused implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Unused { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Unused { + this.bb_pos = i; + this.bb = bb; + return this; +} - a(): number { - return this.bb!.readInt32(this.bb_pos); - } +a():number { + return this.bb!.readInt32(this.bb_pos); +} - mutate_a(value: number): boolean { - this.bb!.writeInt32(this.bb_pos + 0, value); - return true; - } +mutate_a(value:number):boolean { + this.bb!.writeInt32(this.bb_pos + 0, value); + return true; +} - static getFullyQualifiedName(): string { - return 'MyGame.OtherNameSpace.Unused'; - } +static getFullyQualifiedName(): "MyGame.OtherNameSpace.Unused" { + return 'MyGame.OtherNameSpace.Unused'; +} - static sizeOf(): number { - return 4; - } +static sizeOf():number { + return 4; +} - static createUnused( - builder: flatbuffers.Builder, - a: number, - ): flatbuffers.Offset { - builder.prep(4, 4); - builder.writeInt32(a); - return builder.offset(); - } +static createUnused(builder:flatbuffers.Builder, a: number):flatbuffers.Offset { + builder.prep(4, 4); + builder.writeInt32(a); + return builder.offset(); +} - unpack(): UnusedT { - return new UnusedT(this.a()); - } - unpackTo(_o: UnusedT): void { - _o.a = this.a(); - } +unpack(): UnusedT { + return new UnusedT( + this.a() + ); +} + + +unpackTo(_o: UnusedT): void { + _o.a = this.a(); +} } export class UnusedT implements flatbuffers.IGeneratedObject { - constructor(public a: number = 0) {} +constructor( + public a: number = 0 +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return Unused.createUnused(builder, this.a); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return Unused.createUnused(builder, + this.a + ); +} } diff --git a/tests/ts/no_import_ext/optional-scalars.d.ts b/tests/ts/no_import_ext/optional-scalars.d.ts index 13cac5d29..40a0ac6fe 100644 --- a/tests/ts/no_import_ext/optional-scalars.d.ts +++ b/tests/ts/no_import_ext/optional-scalars.d.ts @@ -1,2 +1,2 @@ -export {OptionalByte} from './optional-scalars/optional-byte'; -export {ScalarStuff} from './optional-scalars/scalar-stuff'; +export { OptionalByte } from './optional-scalars/optional-byte'; +export { ScalarStuff } from './optional-scalars/scalar-stuff'; diff --git a/tests/ts/no_import_ext/optional-scalars.js b/tests/ts/no_import_ext/optional-scalars.js index 5301a8401..05aee5bf2 100644 --- a/tests/ts/no_import_ext/optional-scalars.js +++ b/tests/ts/no_import_ext/optional-scalars.js @@ -1,5 +1,4 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {OptionalByte} from './optional-scalars/optional-byte'; -export {ScalarStuff} from './optional-scalars/scalar-stuff'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { OptionalByte } from './optional-scalars/optional-byte'; +export { ScalarStuff } from './optional-scalars/scalar-stuff'; diff --git a/tests/ts/no_import_ext/optional-scalars.ts b/tests/ts/no_import_ext/optional-scalars.ts index e99c0508a..8fef7025a 100644 --- a/tests/ts/no_import_ext/optional-scalars.ts +++ b/tests/ts/no_import_ext/optional-scalars.ts @@ -2,5 +2,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {OptionalByte} from './optional-scalars/optional-byte'; -export {ScalarStuff} from './optional-scalars/scalar-stuff'; +export { OptionalByte } from './optional-scalars/optional-byte'; +export { ScalarStuff } from './optional-scalars/scalar-stuff'; diff --git a/tests/ts/no_import_ext/optional-scalars/optional-byte.d.ts b/tests/ts/no_import_ext/optional-scalars/optional-byte.d.ts index a6450bb24..fc5b5fecd 100644 --- a/tests/ts/no_import_ext/optional-scalars/optional-byte.d.ts +++ b/tests/ts/no_import_ext/optional-scalars/optional-byte.d.ts @@ -1,5 +1,5 @@ export declare enum OptionalByte { - None = 0, - One = 1, - Two = 2, + None = 0, + One = 1, + Two = 2 } diff --git a/tests/ts/no_import_ext/optional-scalars/optional-byte.js b/tests/ts/no_import_ext/optional-scalars/optional-byte.js index 7fcf62e1e..e669367e1 100644 --- a/tests/ts/no_import_ext/optional-scalars/optional-byte.js +++ b/tests/ts/no_import_ext/optional-scalars/optional-byte.js @@ -1,9 +1,8 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var OptionalByte; -(function(OptionalByte) { -OptionalByte[OptionalByte['None'] = 0] = 'None'; -OptionalByte[OptionalByte['One'] = 1] = 'One'; -OptionalByte[OptionalByte['Two'] = 2] = 'Two'; +(function (OptionalByte) { + OptionalByte[OptionalByte["None"] = 0] = "None"; + OptionalByte[OptionalByte["One"] = 1] = "One"; + OptionalByte[OptionalByte["Two"] = 2] = "Two"; })(OptionalByte || (OptionalByte = {})); diff --git a/tests/ts/no_import_ext/optional-scalars/optional-byte.ts b/tests/ts/no_import_ext/optional-scalars/optional-byte.ts index e77bf159e..9bb66a9bc 100644 --- a/tests/ts/no_import_ext/optional-scalars/optional-byte.ts +++ b/tests/ts/no_import_ext/optional-scalars/optional-byte.ts @@ -5,5 +5,5 @@ export enum OptionalByte { None = 0, One = 1, - Two = 2, + Two = 2 } diff --git a/tests/ts/no_import_ext/optional-scalars/scalar-stuff.d.ts b/tests/ts/no_import_ext/optional-scalars/scalar-stuff.d.ts index 03923ec56..33ba59523 100644 --- a/tests/ts/no_import_ext/optional-scalars/scalar-stuff.d.ts +++ b/tests/ts/no_import_ext/optional-scalars/scalar-stuff.d.ts @@ -1,150 +1,88 @@ import * as flatbuffers from 'flatbuffers'; -import {OptionalByte} from '../optional-scalars/optional-byte'; +import { OptionalByte } from './optional-byte'; export declare class ScalarStuff { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): ScalarStuff; - static getRootAsScalarStuff( - bb: flatbuffers.ByteBuffer, - obj?: ScalarStuff, - ): ScalarStuff; - static getSizePrefixedRootAsScalarStuff( - bb: flatbuffers.ByteBuffer, - obj?: ScalarStuff, - ): ScalarStuff; - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; - justI8(): number; - maybeI8(): number | null; - defaultI8(): number; - justU8(): number; - maybeU8(): number | null; - defaultU8(): number; - justI16(): number; - maybeI16(): number | null; - defaultI16(): number; - justU16(): number; - maybeU16(): number | null; - defaultU16(): number; - justI32(): number; - maybeI32(): number | null; - defaultI32(): number; - justU32(): number; - maybeU32(): number | null; - defaultU32(): number; - justI64(): bigint; - maybeI64(): bigint | null; - defaultI64(): bigint; - justU64(): bigint; - maybeU64(): bigint | null; - defaultU64(): bigint; - justF32(): number; - maybeF32(): number | null; - defaultF32(): number; - justF64(): number; - maybeF64(): number | null; - defaultF64(): number; - justBool(): boolean; - maybeBool(): boolean | null; - defaultBool(): boolean; - justEnum(): OptionalByte; - maybeEnum(): OptionalByte | null; - defaultEnum(): OptionalByte; - static getFullyQualifiedName(): string; - static startScalarStuff(builder: flatbuffers.Builder): void; - static addJustI8(builder: flatbuffers.Builder, justI8: number): void; - static addMaybeI8(builder: flatbuffers.Builder, maybeI8: number): void; - static addDefaultI8(builder: flatbuffers.Builder, defaultI8: number): void; - static addJustU8(builder: flatbuffers.Builder, justU8: number): void; - static addMaybeU8(builder: flatbuffers.Builder, maybeU8: number): void; - static addDefaultU8(builder: flatbuffers.Builder, defaultU8: number): void; - static addJustI16(builder: flatbuffers.Builder, justI16: number): void; - static addMaybeI16(builder: flatbuffers.Builder, maybeI16: number): void; - static addDefaultI16(builder: flatbuffers.Builder, defaultI16: number): void; - static addJustU16(builder: flatbuffers.Builder, justU16: number): void; - static addMaybeU16(builder: flatbuffers.Builder, maybeU16: number): void; - static addDefaultU16(builder: flatbuffers.Builder, defaultU16: number): void; - static addJustI32(builder: flatbuffers.Builder, justI32: number): void; - static addMaybeI32(builder: flatbuffers.Builder, maybeI32: number): void; - static addDefaultI32(builder: flatbuffers.Builder, defaultI32: number): void; - static addJustU32(builder: flatbuffers.Builder, justU32: number): void; - static addMaybeU32(builder: flatbuffers.Builder, maybeU32: number): void; - static addDefaultU32(builder: flatbuffers.Builder, defaultU32: number): void; - static addJustI64(builder: flatbuffers.Builder, justI64: bigint): void; - static addMaybeI64(builder: flatbuffers.Builder, maybeI64: bigint): void; - static addDefaultI64(builder: flatbuffers.Builder, defaultI64: bigint): void; - static addJustU64(builder: flatbuffers.Builder, justU64: bigint): void; - static addMaybeU64(builder: flatbuffers.Builder, maybeU64: bigint): void; - static addDefaultU64(builder: flatbuffers.Builder, defaultU64: bigint): void; - static addJustF32(builder: flatbuffers.Builder, justF32: number): void; - static addMaybeF32(builder: flatbuffers.Builder, maybeF32: number): void; - static addDefaultF32(builder: flatbuffers.Builder, defaultF32: number): void; - static addJustF64(builder: flatbuffers.Builder, justF64: number): void; - static addMaybeF64(builder: flatbuffers.Builder, maybeF64: number): void; - static addDefaultF64(builder: flatbuffers.Builder, defaultF64: number): void; - static addJustBool(builder: flatbuffers.Builder, justBool: boolean): void; - static addMaybeBool(builder: flatbuffers.Builder, maybeBool: boolean): void; - static addDefaultBool( - builder: flatbuffers.Builder, - defaultBool: boolean, - ): void; - static addJustEnum( - builder: flatbuffers.Builder, - justEnum: OptionalByte, - ): void; - static addMaybeEnum( - builder: flatbuffers.Builder, - maybeEnum: OptionalByte, - ): void; - static addDefaultEnum( - builder: flatbuffers.Builder, - defaultEnum: OptionalByte, - ): void; - static endScalarStuff(builder: flatbuffers.Builder): flatbuffers.Offset; - static finishScalarStuffBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static finishSizePrefixedScalarStuffBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static createScalarStuff( - builder: flatbuffers.Builder, - justI8: number, - maybeI8: number | null, - defaultI8: number, - justU8: number, - maybeU8: number | null, - defaultU8: number, - justI16: number, - maybeI16: number | null, - defaultI16: number, - justU16: number, - maybeU16: number | null, - defaultU16: number, - justI32: number, - maybeI32: number | null, - defaultI32: number, - justU32: number, - maybeU32: number | null, - defaultU32: number, - justI64: bigint, - maybeI64: bigint | null, - defaultI64: bigint, - justU64: bigint, - maybeU64: bigint | null, - defaultU64: bigint, - justF32: number, - maybeF32: number | null, - defaultF32: number, - justF64: number, - maybeF64: number | null, - defaultF64: number, - justBool: boolean, - maybeBool: boolean | null, - defaultBool: boolean, - justEnum: OptionalByte, - maybeEnum: OptionalByte | null, - defaultEnum: OptionalByte, - ): flatbuffers.Offset; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): ScalarStuff; + static getRootAsScalarStuff(bb: flatbuffers.ByteBuffer, obj?: ScalarStuff): ScalarStuff; + static getSizePrefixedRootAsScalarStuff(bb: flatbuffers.ByteBuffer, obj?: ScalarStuff): ScalarStuff; + static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; + justI8(): number; + maybeI8(): number | null; + defaultI8(): number; + justU8(): number; + maybeU8(): number | null; + defaultU8(): number; + justI16(): number; + maybeI16(): number | null; + defaultI16(): number; + justU16(): number; + maybeU16(): number | null; + defaultU16(): number; + justI32(): number; + maybeI32(): number | null; + defaultI32(): number; + justU32(): number; + maybeU32(): number | null; + defaultU32(): number; + justI64(): bigint; + maybeI64(): bigint | null; + defaultI64(): bigint; + justU64(): bigint; + maybeU64(): bigint | null; + defaultU64(): bigint; + justF32(): number; + maybeF32(): number | null; + defaultF32(): number; + justF64(): number; + maybeF64(): number | null; + defaultF64(): number; + justBool(): boolean; + maybeBool(): boolean | null; + defaultBool(): boolean; + justEnum(): OptionalByte; + maybeEnum(): OptionalByte | null; + defaultEnum(): OptionalByte; + static getFullyQualifiedName(): "optional_scalars.ScalarStuff"; + static startScalarStuff(builder: flatbuffers.Builder): void; + static addJustI8(builder: flatbuffers.Builder, justI8: number): void; + static addMaybeI8(builder: flatbuffers.Builder, maybeI8: number): void; + static addDefaultI8(builder: flatbuffers.Builder, defaultI8: number): void; + static addJustU8(builder: flatbuffers.Builder, justU8: number): void; + static addMaybeU8(builder: flatbuffers.Builder, maybeU8: number): void; + static addDefaultU8(builder: flatbuffers.Builder, defaultU8: number): void; + static addJustI16(builder: flatbuffers.Builder, justI16: number): void; + static addMaybeI16(builder: flatbuffers.Builder, maybeI16: number): void; + static addDefaultI16(builder: flatbuffers.Builder, defaultI16: number): void; + static addJustU16(builder: flatbuffers.Builder, justU16: number): void; + static addMaybeU16(builder: flatbuffers.Builder, maybeU16: number): void; + static addDefaultU16(builder: flatbuffers.Builder, defaultU16: number): void; + static addJustI32(builder: flatbuffers.Builder, justI32: number): void; + static addMaybeI32(builder: flatbuffers.Builder, maybeI32: number): void; + static addDefaultI32(builder: flatbuffers.Builder, defaultI32: number): void; + static addJustU32(builder: flatbuffers.Builder, justU32: number): void; + static addMaybeU32(builder: flatbuffers.Builder, maybeU32: number): void; + static addDefaultU32(builder: flatbuffers.Builder, defaultU32: number): void; + static addJustI64(builder: flatbuffers.Builder, justI64: bigint): void; + static addMaybeI64(builder: flatbuffers.Builder, maybeI64: bigint): void; + static addDefaultI64(builder: flatbuffers.Builder, defaultI64: bigint): void; + static addJustU64(builder: flatbuffers.Builder, justU64: bigint): void; + static addMaybeU64(builder: flatbuffers.Builder, maybeU64: bigint): void; + static addDefaultU64(builder: flatbuffers.Builder, defaultU64: bigint): void; + static addJustF32(builder: flatbuffers.Builder, justF32: number): void; + static addMaybeF32(builder: flatbuffers.Builder, maybeF32: number): void; + static addDefaultF32(builder: flatbuffers.Builder, defaultF32: number): void; + static addJustF64(builder: flatbuffers.Builder, justF64: number): void; + static addMaybeF64(builder: flatbuffers.Builder, maybeF64: number): void; + static addDefaultF64(builder: flatbuffers.Builder, defaultF64: number): void; + static addJustBool(builder: flatbuffers.Builder, justBool: boolean): void; + static addMaybeBool(builder: flatbuffers.Builder, maybeBool: boolean): void; + static addDefaultBool(builder: flatbuffers.Builder, defaultBool: boolean): void; + static addJustEnum(builder: flatbuffers.Builder, justEnum: OptionalByte): void; + static addMaybeEnum(builder: flatbuffers.Builder, maybeEnum: OptionalByte): void; + static addDefaultEnum(builder: flatbuffers.Builder, defaultEnum: OptionalByte): void; + static endScalarStuff(builder: flatbuffers.Builder): flatbuffers.Offset; + static finishScalarStuffBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static finishSizePrefixedScalarStuffBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static createScalarStuff(builder: flatbuffers.Builder, justI8: number, maybeI8: number | null, defaultI8: number, justU8: number, maybeU8: number | null, defaultU8: number, justI16: number, maybeI16: number | null, defaultI16: number, justU16: number, maybeU16: number | null, defaultU16: number, justI32: number, maybeI32: number | null, defaultI32: number, justU32: number, maybeU32: number | null, defaultU32: number, justI64: bigint, maybeI64: bigint | null, defaultI64: bigint, justU64: bigint, maybeU64: bigint | null, defaultU64: bigint, justF32: number, maybeF32: number | null, defaultF32: number, justF64: number, maybeF64: number | null, defaultF64: number, justBool: boolean, maybeBool: boolean | null, defaultBool: boolean, justEnum: OptionalByte, maybeEnum: OptionalByte | null, defaultEnum: OptionalByte): flatbuffers.Offset; } diff --git a/tests/ts/no_import_ext/optional-scalars/scalar-stuff.js b/tests/ts/no_import_ext/optional-scalars/scalar-stuff.js index ba16598e1..44ec7797e 100644 --- a/tests/ts/no_import_ext/optional-scalars/scalar-stuff.js +++ b/tests/ts/no_import_ext/optional-scalars/scalar-stuff.js @@ -1,344 +1,345 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {OptionalByte} from '../optional-scalars/optional-byte'; - +import { OptionalByte } from './optional-byte'; export class ScalarStuff { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsScalarStuff(bb, obj) { - return (obj || new ScalarStuff()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsScalarStuff(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new ScalarStuff()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static bufferHasIdentifier(bb) { - return bb.__has_identifier('NULL'); - } - justI8() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt8(this.bb_pos + offset) : 0; - } - maybeI8() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt8(this.bb_pos + offset) : null; - } - defaultI8() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readInt8(this.bb_pos + offset) : 42; - } - justU8() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; - } - maybeU8() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint8(this.bb_pos + offset) : null; - } - defaultU8() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 42; - } - justI16() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readInt16(this.bb_pos + offset) : 0; - } - maybeI16() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readInt16(this.bb_pos + offset) : null; - } - defaultI16() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readInt16(this.bb_pos + offset) : 42; - } - justU16() { - const offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - maybeU16() { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint16(this.bb_pos + offset) : null; - } - defaultU16() { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 42; - } - justI32() { - const offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - maybeI32() { - const offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readInt32(this.bb_pos + offset) : null; - } - defaultI32() { - const offset = this.bb.__offset(this.bb_pos, 32); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 42; - } - justU32() { - const offset = this.bb.__offset(this.bb_pos, 34); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - maybeU32() { - const offset = this.bb.__offset(this.bb_pos, 36); - return offset ? this.bb.readUint32(this.bb_pos + offset) : null; - } - defaultU32() { - const offset = this.bb.__offset(this.bb_pos, 38); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 42; - } - justI64() { - const offset = this.bb.__offset(this.bb_pos, 40); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); - } - maybeI64() { - const offset = this.bb.__offset(this.bb_pos, 42); - return offset ? this.bb.readInt64(this.bb_pos + offset) : null; - } - defaultI64() { - const offset = this.bb.__offset(this.bb_pos, 44); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('42'); - } - justU64() { - const offset = this.bb.__offset(this.bb_pos, 46); - return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); - } - maybeU64() { - const offset = this.bb.__offset(this.bb_pos, 48); - return offset ? this.bb.readUint64(this.bb_pos + offset) : null; - } - defaultU64() { - const offset = this.bb.__offset(this.bb_pos, 50); - return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('42'); - } - justF32() { - const offset = this.bb.__offset(this.bb_pos, 52); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; - } - maybeF32() { - const offset = this.bb.__offset(this.bb_pos, 54); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : null; - } - defaultF32() { - const offset = this.bb.__offset(this.bb_pos, 56); - return offset ? this.bb.readFloat32(this.bb_pos + offset) : 42.0; - } - justF64() { - const offset = this.bb.__offset(this.bb_pos, 58); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0; - } - maybeF64() { - const offset = this.bb.__offset(this.bb_pos, 60); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : null; - } - defaultF64() { - const offset = this.bb.__offset(this.bb_pos, 62); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : 42.0; - } - justBool() { - const offset = this.bb.__offset(this.bb_pos, 64); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - maybeBool() { - const offset = this.bb.__offset(this.bb_pos, 66); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : null; - } - defaultBool() { - const offset = this.bb.__offset(this.bb_pos, 68); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : true; - } - justEnum() { - const offset = this.bb.__offset(this.bb_pos, 70); - return offset ? this.bb.readInt8(this.bb_pos + offset) : OptionalByte.None; - } - maybeEnum() { - const offset = this.bb.__offset(this.bb_pos, 72); - return offset ? this.bb.readInt8(this.bb_pos + offset) : null; - } - defaultEnum() { - const offset = this.bb.__offset(this.bb_pos, 74); - return offset ? this.bb.readInt8(this.bb_pos + offset) : OptionalByte.One; - } - static getFullyQualifiedName() { - return 'optional_scalars.ScalarStuff'; - } - static startScalarStuff(builder) { - builder.startObject(36); - } - static addJustI8(builder, justI8) { - builder.addFieldInt8(0, justI8, 0); - } - static addMaybeI8(builder, maybeI8) { - builder.addFieldInt8(1, maybeI8, null); - } - static addDefaultI8(builder, defaultI8) { - builder.addFieldInt8(2, defaultI8, 42); - } - static addJustU8(builder, justU8) { - builder.addFieldInt8(3, justU8, 0); - } - static addMaybeU8(builder, maybeU8) { - builder.addFieldInt8(4, maybeU8, null); - } - static addDefaultU8(builder, defaultU8) { - builder.addFieldInt8(5, defaultU8, 42); - } - static addJustI16(builder, justI16) { - builder.addFieldInt16(6, justI16, 0); - } - static addMaybeI16(builder, maybeI16) { - builder.addFieldInt16(7, maybeI16, null); - } - static addDefaultI16(builder, defaultI16) { - builder.addFieldInt16(8, defaultI16, 42); - } - static addJustU16(builder, justU16) { - builder.addFieldInt16(9, justU16, 0); - } - static addMaybeU16(builder, maybeU16) { - builder.addFieldInt16(10, maybeU16, null); - } - static addDefaultU16(builder, defaultU16) { - builder.addFieldInt16(11, defaultU16, 42); - } - static addJustI32(builder, justI32) { - builder.addFieldInt32(12, justI32, 0); - } - static addMaybeI32(builder, maybeI32) { - builder.addFieldInt32(13, maybeI32, null); - } - static addDefaultI32(builder, defaultI32) { - builder.addFieldInt32(14, defaultI32, 42); - } - static addJustU32(builder, justU32) { - builder.addFieldInt32(15, justU32, 0); - } - static addMaybeU32(builder, maybeU32) { - builder.addFieldInt32(16, maybeU32, null); - } - static addDefaultU32(builder, defaultU32) { - builder.addFieldInt32(17, defaultU32, 42); - } - static addJustI64(builder, justI64) { - builder.addFieldInt64(18, justI64, BigInt('0')); - } - static addMaybeI64(builder, maybeI64) { - builder.addFieldInt64(19, maybeI64, null); - } - static addDefaultI64(builder, defaultI64) { - builder.addFieldInt64(20, defaultI64, BigInt('42')); - } - static addJustU64(builder, justU64) { - builder.addFieldInt64(21, justU64, BigInt('0')); - } - static addMaybeU64(builder, maybeU64) { - builder.addFieldInt64(22, maybeU64, null); - } - static addDefaultU64(builder, defaultU64) { - builder.addFieldInt64(23, defaultU64, BigInt('42')); - } - static addJustF32(builder, justF32) { - builder.addFieldFloat32(24, justF32, 0.0); - } - static addMaybeF32(builder, maybeF32) { - builder.addFieldFloat32(25, maybeF32, null); - } - static addDefaultF32(builder, defaultF32) { - builder.addFieldFloat32(26, defaultF32, 42.0); - } - static addJustF64(builder, justF64) { - builder.addFieldFloat64(27, justF64, 0.0); - } - static addMaybeF64(builder, maybeF64) { - builder.addFieldFloat64(28, maybeF64, null); - } - static addDefaultF64(builder, defaultF64) { - builder.addFieldFloat64(29, defaultF64, 42.0); - } - static addJustBool(builder, justBool) { - builder.addFieldInt8(30, +justBool, +false); - } - static addMaybeBool(builder, maybeBool) { - builder.addFieldInt8(31, +maybeBool, null); - } - static addDefaultBool(builder, defaultBool) { - builder.addFieldInt8(32, +defaultBool, +true); - } - static addJustEnum(builder, justEnum) { - builder.addFieldInt8(33, justEnum, OptionalByte.None); - } - static addMaybeEnum(builder, maybeEnum) { - builder.addFieldInt8(34, maybeEnum, null); - } - static addDefaultEnum(builder, defaultEnum) { - builder.addFieldInt8(35, defaultEnum, OptionalByte.One); - } - static endScalarStuff(builder) { - const offset = builder.endObject(); - return offset; - } - static finishScalarStuffBuffer(builder, offset) { - builder.finish(offset, 'NULL'); - } - static finishSizePrefixedScalarStuffBuffer(builder, offset) { - builder.finish(offset, 'NULL', true); - } - static createScalarStuff( - builder, justI8, maybeI8, defaultI8, justU8, maybeU8, defaultU8, justI16, - maybeI16, defaultI16, justU16, maybeU16, defaultU16, justI32, maybeI32, - defaultI32, justU32, maybeU32, defaultU32, justI64, maybeI64, defaultI64, - justU64, maybeU64, defaultU64, justF32, maybeF32, defaultF32, justF64, - maybeF64, defaultF64, justBool, maybeBool, defaultBool, justEnum, - maybeEnum, defaultEnum) { - ScalarStuff.startScalarStuff(builder); - ScalarStuff.addJustI8(builder, justI8); - if (maybeI8 !== null) ScalarStuff.addMaybeI8(builder, maybeI8); - ScalarStuff.addDefaultI8(builder, defaultI8); - ScalarStuff.addJustU8(builder, justU8); - if (maybeU8 !== null) ScalarStuff.addMaybeU8(builder, maybeU8); - ScalarStuff.addDefaultU8(builder, defaultU8); - ScalarStuff.addJustI16(builder, justI16); - if (maybeI16 !== null) ScalarStuff.addMaybeI16(builder, maybeI16); - ScalarStuff.addDefaultI16(builder, defaultI16); - ScalarStuff.addJustU16(builder, justU16); - if (maybeU16 !== null) ScalarStuff.addMaybeU16(builder, maybeU16); - ScalarStuff.addDefaultU16(builder, defaultU16); - ScalarStuff.addJustI32(builder, justI32); - if (maybeI32 !== null) ScalarStuff.addMaybeI32(builder, maybeI32); - ScalarStuff.addDefaultI32(builder, defaultI32); - ScalarStuff.addJustU32(builder, justU32); - if (maybeU32 !== null) ScalarStuff.addMaybeU32(builder, maybeU32); - ScalarStuff.addDefaultU32(builder, defaultU32); - ScalarStuff.addJustI64(builder, justI64); - if (maybeI64 !== null) ScalarStuff.addMaybeI64(builder, maybeI64); - ScalarStuff.addDefaultI64(builder, defaultI64); - ScalarStuff.addJustU64(builder, justU64); - if (maybeU64 !== null) ScalarStuff.addMaybeU64(builder, maybeU64); - ScalarStuff.addDefaultU64(builder, defaultU64); - ScalarStuff.addJustF32(builder, justF32); - if (maybeF32 !== null) ScalarStuff.addMaybeF32(builder, maybeF32); - ScalarStuff.addDefaultF32(builder, defaultF32); - ScalarStuff.addJustF64(builder, justF64); - if (maybeF64 !== null) ScalarStuff.addMaybeF64(builder, maybeF64); - ScalarStuff.addDefaultF64(builder, defaultF64); - ScalarStuff.addJustBool(builder, justBool); - if (maybeBool !== null) ScalarStuff.addMaybeBool(builder, maybeBool); - ScalarStuff.addDefaultBool(builder, defaultBool); - ScalarStuff.addJustEnum(builder, justEnum); - if (maybeEnum !== null) ScalarStuff.addMaybeEnum(builder, maybeEnum); - ScalarStuff.addDefaultEnum(builder, defaultEnum); - return ScalarStuff.endScalarStuff(builder); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsScalarStuff(bb, obj) { + return (obj || new ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsScalarStuff(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static bufferHasIdentifier(bb) { + return bb.__has_identifier('NULL'); + } + justI8() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt8(this.bb_pos + offset) : 0; + } + maybeI8() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt8(this.bb_pos + offset) : null; + } + defaultI8() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt8(this.bb_pos + offset) : 42; + } + justU8() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; + } + maybeU8() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readUint8(this.bb_pos + offset) : null; + } + defaultU8() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.readUint8(this.bb_pos + offset) : 42; + } + justI16() { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.readInt16(this.bb_pos + offset) : 0; + } + maybeI16() { + const offset = this.bb.__offset(this.bb_pos, 18); + return offset ? this.bb.readInt16(this.bb_pos + offset) : null; + } + defaultI16() { + const offset = this.bb.__offset(this.bb_pos, 20); + return offset ? this.bb.readInt16(this.bb_pos + offset) : 42; + } + justU16() { + const offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; + } + maybeU16() { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.readUint16(this.bb_pos + offset) : null; + } + defaultU16() { + const offset = this.bb.__offset(this.bb_pos, 26); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 42; + } + justI32() { + const offset = this.bb.__offset(this.bb_pos, 28); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + maybeI32() { + const offset = this.bb.__offset(this.bb_pos, 30); + return offset ? this.bb.readInt32(this.bb_pos + offset) : null; + } + defaultI32() { + const offset = this.bb.__offset(this.bb_pos, 32); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 42; + } + justU32() { + const offset = this.bb.__offset(this.bb_pos, 34); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; + } + maybeU32() { + const offset = this.bb.__offset(this.bb_pos, 36); + return offset ? this.bb.readUint32(this.bb_pos + offset) : null; + } + defaultU32() { + const offset = this.bb.__offset(this.bb_pos, 38); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 42; + } + justI64() { + const offset = this.bb.__offset(this.bb_pos, 40); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); + } + maybeI64() { + const offset = this.bb.__offset(this.bb_pos, 42); + return offset ? this.bb.readInt64(this.bb_pos + offset) : null; + } + defaultI64() { + const offset = this.bb.__offset(this.bb_pos, 44); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('42'); + } + justU64() { + const offset = this.bb.__offset(this.bb_pos, 46); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); + } + maybeU64() { + const offset = this.bb.__offset(this.bb_pos, 48); + return offset ? this.bb.readUint64(this.bb_pos + offset) : null; + } + defaultU64() { + const offset = this.bb.__offset(this.bb_pos, 50); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('42'); + } + justF32() { + const offset = this.bb.__offset(this.bb_pos, 52); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; + } + maybeF32() { + const offset = this.bb.__offset(this.bb_pos, 54); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : null; + } + defaultF32() { + const offset = this.bb.__offset(this.bb_pos, 56); + return offset ? this.bb.readFloat32(this.bb_pos + offset) : 42.0; + } + justF64() { + const offset = this.bb.__offset(this.bb_pos, 58); + return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0; + } + maybeF64() { + const offset = this.bb.__offset(this.bb_pos, 60); + return offset ? this.bb.readFloat64(this.bb_pos + offset) : null; + } + defaultF64() { + const offset = this.bb.__offset(this.bb_pos, 62); + return offset ? this.bb.readFloat64(this.bb_pos + offset) : 42.0; + } + justBool() { + const offset = this.bb.__offset(this.bb_pos, 64); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + maybeBool() { + const offset = this.bb.__offset(this.bb_pos, 66); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : null; + } + defaultBool() { + const offset = this.bb.__offset(this.bb_pos, 68); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : true; + } + justEnum() { + const offset = this.bb.__offset(this.bb_pos, 70); + return offset ? this.bb.readInt8(this.bb_pos + offset) : OptionalByte.None; + } + maybeEnum() { + const offset = this.bb.__offset(this.bb_pos, 72); + return offset ? this.bb.readInt8(this.bb_pos + offset) : null; + } + defaultEnum() { + const offset = this.bb.__offset(this.bb_pos, 74); + return offset ? this.bb.readInt8(this.bb_pos + offset) : OptionalByte.One; + } + static getFullyQualifiedName() { + return 'optional_scalars.ScalarStuff'; + } + static startScalarStuff(builder) { + builder.startObject(36); + } + static addJustI8(builder, justI8) { + builder.addFieldInt8(0, justI8, 0); + } + static addMaybeI8(builder, maybeI8) { + builder.addFieldInt8(1, maybeI8, null); + } + static addDefaultI8(builder, defaultI8) { + builder.addFieldInt8(2, defaultI8, 42); + } + static addJustU8(builder, justU8) { + builder.addFieldInt8(3, justU8, 0); + } + static addMaybeU8(builder, maybeU8) { + builder.addFieldInt8(4, maybeU8, null); + } + static addDefaultU8(builder, defaultU8) { + builder.addFieldInt8(5, defaultU8, 42); + } + static addJustI16(builder, justI16) { + builder.addFieldInt16(6, justI16, 0); + } + static addMaybeI16(builder, maybeI16) { + builder.addFieldInt16(7, maybeI16, null); + } + static addDefaultI16(builder, defaultI16) { + builder.addFieldInt16(8, defaultI16, 42); + } + static addJustU16(builder, justU16) { + builder.addFieldInt16(9, justU16, 0); + } + static addMaybeU16(builder, maybeU16) { + builder.addFieldInt16(10, maybeU16, null); + } + static addDefaultU16(builder, defaultU16) { + builder.addFieldInt16(11, defaultU16, 42); + } + static addJustI32(builder, justI32) { + builder.addFieldInt32(12, justI32, 0); + } + static addMaybeI32(builder, maybeI32) { + builder.addFieldInt32(13, maybeI32, null); + } + static addDefaultI32(builder, defaultI32) { + builder.addFieldInt32(14, defaultI32, 42); + } + static addJustU32(builder, justU32) { + builder.addFieldInt32(15, justU32, 0); + } + static addMaybeU32(builder, maybeU32) { + builder.addFieldInt32(16, maybeU32, null); + } + static addDefaultU32(builder, defaultU32) { + builder.addFieldInt32(17, defaultU32, 42); + } + static addJustI64(builder, justI64) { + builder.addFieldInt64(18, justI64, BigInt('0')); + } + static addMaybeI64(builder, maybeI64) { + builder.addFieldInt64(19, maybeI64, null); + } + static addDefaultI64(builder, defaultI64) { + builder.addFieldInt64(20, defaultI64, BigInt('42')); + } + static addJustU64(builder, justU64) { + builder.addFieldInt64(21, justU64, BigInt('0')); + } + static addMaybeU64(builder, maybeU64) { + builder.addFieldInt64(22, maybeU64, null); + } + static addDefaultU64(builder, defaultU64) { + builder.addFieldInt64(23, defaultU64, BigInt('42')); + } + static addJustF32(builder, justF32) { + builder.addFieldFloat32(24, justF32, 0.0); + } + static addMaybeF32(builder, maybeF32) { + builder.addFieldFloat32(25, maybeF32, null); + } + static addDefaultF32(builder, defaultF32) { + builder.addFieldFloat32(26, defaultF32, 42.0); + } + static addJustF64(builder, justF64) { + builder.addFieldFloat64(27, justF64, 0.0); + } + static addMaybeF64(builder, maybeF64) { + builder.addFieldFloat64(28, maybeF64, null); + } + static addDefaultF64(builder, defaultF64) { + builder.addFieldFloat64(29, defaultF64, 42.0); + } + static addJustBool(builder, justBool) { + builder.addFieldInt8(30, +justBool, +false); + } + static addMaybeBool(builder, maybeBool) { + builder.addFieldInt8(31, +maybeBool, null); + } + static addDefaultBool(builder, defaultBool) { + builder.addFieldInt8(32, +defaultBool, +true); + } + static addJustEnum(builder, justEnum) { + builder.addFieldInt8(33, justEnum, OptionalByte.None); + } + static addMaybeEnum(builder, maybeEnum) { + builder.addFieldInt8(34, maybeEnum, null); + } + static addDefaultEnum(builder, defaultEnum) { + builder.addFieldInt8(35, defaultEnum, OptionalByte.One); + } + static endScalarStuff(builder) { + const offset = builder.endObject(); + return offset; + } + static finishScalarStuffBuffer(builder, offset) { + builder.finish(offset, 'NULL'); + } + static finishSizePrefixedScalarStuffBuffer(builder, offset) { + builder.finish(offset, 'NULL', true); + } + static createScalarStuff(builder, justI8, maybeI8, defaultI8, justU8, maybeU8, defaultU8, justI16, maybeI16, defaultI16, justU16, maybeU16, defaultU16, justI32, maybeI32, defaultI32, justU32, maybeU32, defaultU32, justI64, maybeI64, defaultI64, justU64, maybeU64, defaultU64, justF32, maybeF32, defaultF32, justF64, maybeF64, defaultF64, justBool, maybeBool, defaultBool, justEnum, maybeEnum, defaultEnum) { + ScalarStuff.startScalarStuff(builder); + ScalarStuff.addJustI8(builder, justI8); + if (maybeI8 !== null) + ScalarStuff.addMaybeI8(builder, maybeI8); + ScalarStuff.addDefaultI8(builder, defaultI8); + ScalarStuff.addJustU8(builder, justU8); + if (maybeU8 !== null) + ScalarStuff.addMaybeU8(builder, maybeU8); + ScalarStuff.addDefaultU8(builder, defaultU8); + ScalarStuff.addJustI16(builder, justI16); + if (maybeI16 !== null) + ScalarStuff.addMaybeI16(builder, maybeI16); + ScalarStuff.addDefaultI16(builder, defaultI16); + ScalarStuff.addJustU16(builder, justU16); + if (maybeU16 !== null) + ScalarStuff.addMaybeU16(builder, maybeU16); + ScalarStuff.addDefaultU16(builder, defaultU16); + ScalarStuff.addJustI32(builder, justI32); + if (maybeI32 !== null) + ScalarStuff.addMaybeI32(builder, maybeI32); + ScalarStuff.addDefaultI32(builder, defaultI32); + ScalarStuff.addJustU32(builder, justU32); + if (maybeU32 !== null) + ScalarStuff.addMaybeU32(builder, maybeU32); + ScalarStuff.addDefaultU32(builder, defaultU32); + ScalarStuff.addJustI64(builder, justI64); + if (maybeI64 !== null) + ScalarStuff.addMaybeI64(builder, maybeI64); + ScalarStuff.addDefaultI64(builder, defaultI64); + ScalarStuff.addJustU64(builder, justU64); + if (maybeU64 !== null) + ScalarStuff.addMaybeU64(builder, maybeU64); + ScalarStuff.addDefaultU64(builder, defaultU64); + ScalarStuff.addJustF32(builder, justF32); + if (maybeF32 !== null) + ScalarStuff.addMaybeF32(builder, maybeF32); + ScalarStuff.addDefaultF32(builder, defaultF32); + ScalarStuff.addJustF64(builder, justF64); + if (maybeF64 !== null) + ScalarStuff.addMaybeF64(builder, maybeF64); + ScalarStuff.addDefaultF64(builder, defaultF64); + ScalarStuff.addJustBool(builder, justBool); + if (maybeBool !== null) + ScalarStuff.addMaybeBool(builder, maybeBool); + ScalarStuff.addDefaultBool(builder, defaultBool); + ScalarStuff.addJustEnum(builder, justEnum); + if (maybeEnum !== null) + ScalarStuff.addMaybeEnum(builder, maybeEnum); + ScalarStuff.addDefaultEnum(builder, defaultEnum); + return ScalarStuff.endScalarStuff(builder); + } } diff --git a/tests/ts/no_import_ext/optional-scalars/scalar-stuff.ts b/tests/ts/no_import_ext/optional-scalars/scalar-stuff.ts index f8433906b..aafbd04bc 100644 --- a/tests/ts/no_import_ext/optional-scalars/scalar-stuff.ts +++ b/tests/ts/no_import_ext/optional-scalars/scalar-stuff.ts @@ -4,472 +4,426 @@ import * as flatbuffers from 'flatbuffers'; -import {OptionalByte} from '../optional-scalars/optional-byte'; +import { OptionalByte } from './optional-byte'; + export class ScalarStuff { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): ScalarStuff { - this.bb_pos = i; - this.bb = bb; - return this; - } - - static getRootAsScalarStuff( - bb: flatbuffers.ByteBuffer, - obj?: ScalarStuff, - ): ScalarStuff { - return (obj || new ScalarStuff()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } - - static getSizePrefixedRootAsScalarStuff( - bb: flatbuffers.ByteBuffer, - obj?: ScalarStuff, - ): ScalarStuff { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new ScalarStuff()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } - - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean { - return bb.__has_identifier('NULL'); - } - - justI8(): number { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : 0; - } - - maybeI8(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : null; - } - - defaultI8(): number { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : 42; - } - - justU8(): number { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0; - } - - maybeU8(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? this.bb!.readUint8(this.bb_pos + offset) : null; - } - - defaultU8(): number { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.readUint8(this.bb_pos + offset) : 42; - } - - justI16(): number { - const offset = this.bb!.__offset(this.bb_pos, 16); - return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0; - } - - maybeI16(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 18); - return offset ? this.bb!.readInt16(this.bb_pos + offset) : null; - } - - defaultI16(): number { - const offset = this.bb!.__offset(this.bb_pos, 20); - return offset ? this.bb!.readInt16(this.bb_pos + offset) : 42; - } - - justU16(): number { - const offset = this.bb!.__offset(this.bb_pos, 22); - return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; - } - - maybeU16(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 24); - return offset ? this.bb!.readUint16(this.bb_pos + offset) : null; - } - - defaultU16(): number { - const offset = this.bb!.__offset(this.bb_pos, 26); - return offset ? this.bb!.readUint16(this.bb_pos + offset) : 42; - } - - justI32(): number { - const offset = this.bb!.__offset(this.bb_pos, 28); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; - } - - maybeI32(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 30); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : null; - } - - defaultI32(): number { - const offset = this.bb!.__offset(this.bb_pos, 32); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 42; - } - - justU32(): number { - const offset = this.bb!.__offset(this.bb_pos, 34); - return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; - } - - maybeU32(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 36); - return offset ? this.bb!.readUint32(this.bb_pos + offset) : null; - } - - defaultU32(): number { - const offset = this.bb!.__offset(this.bb_pos, 38); - return offset ? this.bb!.readUint32(this.bb_pos + offset) : 42; - } - - justI64(): bigint { - const offset = this.bb!.__offset(this.bb_pos, 40); - return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); - } - - maybeI64(): bigint | null { - const offset = this.bb!.__offset(this.bb_pos, 42); - return offset ? this.bb!.readInt64(this.bb_pos + offset) : null; - } - - defaultI64(): bigint { - const offset = this.bb!.__offset(this.bb_pos, 44); - return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('42'); - } - - justU64(): bigint { - const offset = this.bb!.__offset(this.bb_pos, 46); - return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); - } - - maybeU64(): bigint | null { - const offset = this.bb!.__offset(this.bb_pos, 48); - return offset ? this.bb!.readUint64(this.bb_pos + offset) : null; - } - - defaultU64(): bigint { - const offset = this.bb!.__offset(this.bb_pos, 50); - return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('42'); - } - - justF32(): number { - const offset = this.bb!.__offset(this.bb_pos, 52); - return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0; - } - - maybeF32(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 54); - return offset ? this.bb!.readFloat32(this.bb_pos + offset) : null; - } - - defaultF32(): number { - const offset = this.bb!.__offset(this.bb_pos, 56); - return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 42.0; - } - - justF64(): number { - const offset = this.bb!.__offset(this.bb_pos, 58); - return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0; - } - - maybeF64(): number | null { - const offset = this.bb!.__offset(this.bb_pos, 60); - return offset ? this.bb!.readFloat64(this.bb_pos + offset) : null; - } - - defaultF64(): number { - const offset = this.bb!.__offset(this.bb_pos, 62); - return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 42.0; - } - - justBool(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 64); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } - - maybeBool(): boolean | null { - const offset = this.bb!.__offset(this.bb_pos, 66); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : null; - } - - defaultBool(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 68); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : true; - } - - justEnum(): OptionalByte { - const offset = this.bb!.__offset(this.bb_pos, 70); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.None; - } - - maybeEnum(): OptionalByte | null { - const offset = this.bb!.__offset(this.bb_pos, 72); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : null; - } - - defaultEnum(): OptionalByte { - const offset = this.bb!.__offset(this.bb_pos, 74); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.One; - } - - static getFullyQualifiedName(): string { - return 'optional_scalars.ScalarStuff'; - } - - static startScalarStuff(builder: flatbuffers.Builder) { - builder.startObject(36); - } - - static addJustI8(builder: flatbuffers.Builder, justI8: number) { - builder.addFieldInt8(0, justI8, 0); - } - - static addMaybeI8(builder: flatbuffers.Builder, maybeI8: number) { - builder.addFieldInt8(1, maybeI8, null); - } - - static addDefaultI8(builder: flatbuffers.Builder, defaultI8: number) { - builder.addFieldInt8(2, defaultI8, 42); - } - - static addJustU8(builder: flatbuffers.Builder, justU8: number) { - builder.addFieldInt8(3, justU8, 0); - } - - static addMaybeU8(builder: flatbuffers.Builder, maybeU8: number) { - builder.addFieldInt8(4, maybeU8, null); - } - - static addDefaultU8(builder: flatbuffers.Builder, defaultU8: number) { - builder.addFieldInt8(5, defaultU8, 42); - } - - static addJustI16(builder: flatbuffers.Builder, justI16: number) { - builder.addFieldInt16(6, justI16, 0); - } - - static addMaybeI16(builder: flatbuffers.Builder, maybeI16: number) { - builder.addFieldInt16(7, maybeI16, null); - } - - static addDefaultI16(builder: flatbuffers.Builder, defaultI16: number) { - builder.addFieldInt16(8, defaultI16, 42); - } - - static addJustU16(builder: flatbuffers.Builder, justU16: number) { - builder.addFieldInt16(9, justU16, 0); - } - - static addMaybeU16(builder: flatbuffers.Builder, maybeU16: number) { - builder.addFieldInt16(10, maybeU16, null); - } - - static addDefaultU16(builder: flatbuffers.Builder, defaultU16: number) { - builder.addFieldInt16(11, defaultU16, 42); - } - - static addJustI32(builder: flatbuffers.Builder, justI32: number) { - builder.addFieldInt32(12, justI32, 0); - } - - static addMaybeI32(builder: flatbuffers.Builder, maybeI32: number) { - builder.addFieldInt32(13, maybeI32, null); - } - - static addDefaultI32(builder: flatbuffers.Builder, defaultI32: number) { - builder.addFieldInt32(14, defaultI32, 42); - } - - static addJustU32(builder: flatbuffers.Builder, justU32: number) { - builder.addFieldInt32(15, justU32, 0); - } - - static addMaybeU32(builder: flatbuffers.Builder, maybeU32: number) { - builder.addFieldInt32(16, maybeU32, null); - } - - static addDefaultU32(builder: flatbuffers.Builder, defaultU32: number) { - builder.addFieldInt32(17, defaultU32, 42); - } - - static addJustI64(builder: flatbuffers.Builder, justI64: bigint) { - builder.addFieldInt64(18, justI64, BigInt('0')); - } - - static addMaybeI64(builder: flatbuffers.Builder, maybeI64: bigint) { - builder.addFieldInt64(19, maybeI64, null); - } - - static addDefaultI64(builder: flatbuffers.Builder, defaultI64: bigint) { - builder.addFieldInt64(20, defaultI64, BigInt('42')); - } - - static addJustU64(builder: flatbuffers.Builder, justU64: bigint) { - builder.addFieldInt64(21, justU64, BigInt('0')); - } - - static addMaybeU64(builder: flatbuffers.Builder, maybeU64: bigint) { - builder.addFieldInt64(22, maybeU64, null); - } - - static addDefaultU64(builder: flatbuffers.Builder, defaultU64: bigint) { - builder.addFieldInt64(23, defaultU64, BigInt('42')); - } - - static addJustF32(builder: flatbuffers.Builder, justF32: number) { - builder.addFieldFloat32(24, justF32, 0.0); - } - - static addMaybeF32(builder: flatbuffers.Builder, maybeF32: number) { - builder.addFieldFloat32(25, maybeF32, null); - } - - static addDefaultF32(builder: flatbuffers.Builder, defaultF32: number) { - builder.addFieldFloat32(26, defaultF32, 42.0); - } - - static addJustF64(builder: flatbuffers.Builder, justF64: number) { - builder.addFieldFloat64(27, justF64, 0.0); - } - - static addMaybeF64(builder: flatbuffers.Builder, maybeF64: number) { - builder.addFieldFloat64(28, maybeF64, null); - } - - static addDefaultF64(builder: flatbuffers.Builder, defaultF64: number) { - builder.addFieldFloat64(29, defaultF64, 42.0); - } - - static addJustBool(builder: flatbuffers.Builder, justBool: boolean) { - builder.addFieldInt8(30, +justBool, +false); - } - - static addMaybeBool(builder: flatbuffers.Builder, maybeBool: boolean) { - builder.addFieldInt8(31, +maybeBool, null); - } - - static addDefaultBool(builder: flatbuffers.Builder, defaultBool: boolean) { - builder.addFieldInt8(32, +defaultBool, +true); - } - - static addJustEnum(builder: flatbuffers.Builder, justEnum: OptionalByte) { - builder.addFieldInt8(33, justEnum, OptionalByte.None); - } - - static addMaybeEnum(builder: flatbuffers.Builder, maybeEnum: OptionalByte) { - builder.addFieldInt8(34, maybeEnum, null); - } - - static addDefaultEnum( - builder: flatbuffers.Builder, - defaultEnum: OptionalByte, - ) { - builder.addFieldInt8(35, defaultEnum, OptionalByte.One); - } - - static endScalarStuff(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static finishScalarStuffBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, 'NULL'); - } - - static finishSizePrefixedScalarStuffBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, 'NULL', true); - } - - static createScalarStuff( - builder: flatbuffers.Builder, - justI8: number, - maybeI8: number | null, - defaultI8: number, - justU8: number, - maybeU8: number | null, - defaultU8: number, - justI16: number, - maybeI16: number | null, - defaultI16: number, - justU16: number, - maybeU16: number | null, - defaultU16: number, - justI32: number, - maybeI32: number | null, - defaultI32: number, - justU32: number, - maybeU32: number | null, - defaultU32: number, - justI64: bigint, - maybeI64: bigint | null, - defaultI64: bigint, - justU64: bigint, - maybeU64: bigint | null, - defaultU64: bigint, - justF32: number, - maybeF32: number | null, - defaultF32: number, - justF64: number, - maybeF64: number | null, - defaultF64: number, - justBool: boolean, - maybeBool: boolean | null, - defaultBool: boolean, - justEnum: OptionalByte, - maybeEnum: OptionalByte | null, - defaultEnum: OptionalByte, - ): flatbuffers.Offset { - ScalarStuff.startScalarStuff(builder); - ScalarStuff.addJustI8(builder, justI8); - if (maybeI8 !== null) ScalarStuff.addMaybeI8(builder, maybeI8); - ScalarStuff.addDefaultI8(builder, defaultI8); - ScalarStuff.addJustU8(builder, justU8); - if (maybeU8 !== null) ScalarStuff.addMaybeU8(builder, maybeU8); - ScalarStuff.addDefaultU8(builder, defaultU8); - ScalarStuff.addJustI16(builder, justI16); - if (maybeI16 !== null) ScalarStuff.addMaybeI16(builder, maybeI16); - ScalarStuff.addDefaultI16(builder, defaultI16); - ScalarStuff.addJustU16(builder, justU16); - if (maybeU16 !== null) ScalarStuff.addMaybeU16(builder, maybeU16); - ScalarStuff.addDefaultU16(builder, defaultU16); - ScalarStuff.addJustI32(builder, justI32); - if (maybeI32 !== null) ScalarStuff.addMaybeI32(builder, maybeI32); - ScalarStuff.addDefaultI32(builder, defaultI32); - ScalarStuff.addJustU32(builder, justU32); - if (maybeU32 !== null) ScalarStuff.addMaybeU32(builder, maybeU32); - ScalarStuff.addDefaultU32(builder, defaultU32); - ScalarStuff.addJustI64(builder, justI64); - if (maybeI64 !== null) ScalarStuff.addMaybeI64(builder, maybeI64); - ScalarStuff.addDefaultI64(builder, defaultI64); - ScalarStuff.addJustU64(builder, justU64); - if (maybeU64 !== null) ScalarStuff.addMaybeU64(builder, maybeU64); - ScalarStuff.addDefaultU64(builder, defaultU64); - ScalarStuff.addJustF32(builder, justF32); - if (maybeF32 !== null) ScalarStuff.addMaybeF32(builder, maybeF32); - ScalarStuff.addDefaultF32(builder, defaultF32); - ScalarStuff.addJustF64(builder, justF64); - if (maybeF64 !== null) ScalarStuff.addMaybeF64(builder, maybeF64); - ScalarStuff.addDefaultF64(builder, defaultF64); - ScalarStuff.addJustBool(builder, justBool); - if (maybeBool !== null) ScalarStuff.addMaybeBool(builder, maybeBool); - ScalarStuff.addDefaultBool(builder, defaultBool); - ScalarStuff.addJustEnum(builder, justEnum); - if (maybeEnum !== null) ScalarStuff.addMaybeEnum(builder, maybeEnum); - ScalarStuff.addDefaultEnum(builder, defaultEnum); - return ScalarStuff.endScalarStuff(builder); - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):ScalarStuff { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsScalarStuff(bb:flatbuffers.ByteBuffer, obj?:ScalarStuff):ScalarStuff { + return (obj || new ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsScalarStuff(bb:flatbuffers.ByteBuffer, obj?:ScalarStuff):ScalarStuff { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new ScalarStuff()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean { + return bb.__has_identifier('NULL'); +} + +justI8():number { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : 0; +} + +maybeI8():number|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : null; +} + +defaultI8():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : 42; +} + +justU8():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0; +} + +maybeU8():number|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : null; +} + +defaultU8():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : 42; +} + +justI16():number { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0; +} + +maybeI16():number|null { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : null; +} + +defaultI16():number { + const offset = this.bb!.__offset(this.bb_pos, 20); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : 42; +} + +justU16():number { + const offset = this.bb!.__offset(this.bb_pos, 22); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; +} + +maybeU16():number|null { + const offset = this.bb!.__offset(this.bb_pos, 24); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : null; +} + +defaultU16():number { + const offset = this.bb!.__offset(this.bb_pos, 26); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 42; +} + +justI32():number { + const offset = this.bb!.__offset(this.bb_pos, 28); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +maybeI32():number|null { + const offset = this.bb!.__offset(this.bb_pos, 30); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : null; +} + +defaultI32():number { + const offset = this.bb!.__offset(this.bb_pos, 32); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 42; +} + +justU32():number { + const offset = this.bb!.__offset(this.bb_pos, 34); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; +} + +maybeU32():number|null { + const offset = this.bb!.__offset(this.bb_pos, 36); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : null; +} + +defaultU32():number { + const offset = this.bb!.__offset(this.bb_pos, 38); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 42; +} + +justI64():bigint { + const offset = this.bb!.__offset(this.bb_pos, 40); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); +} + +maybeI64():bigint|null { + const offset = this.bb!.__offset(this.bb_pos, 42); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : null; +} + +defaultI64():bigint { + const offset = this.bb!.__offset(this.bb_pos, 44); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('42'); +} + +justU64():bigint { + const offset = this.bb!.__offset(this.bb_pos, 46); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +maybeU64():bigint|null { + const offset = this.bb!.__offset(this.bb_pos, 48); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : null; +} + +defaultU64():bigint { + const offset = this.bb!.__offset(this.bb_pos, 50); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('42'); +} + +justF32():number { + const offset = this.bb!.__offset(this.bb_pos, 52); + return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0; +} + +maybeF32():number|null { + const offset = this.bb!.__offset(this.bb_pos, 54); + return offset ? this.bb!.readFloat32(this.bb_pos + offset) : null; +} + +defaultF32():number { + const offset = this.bb!.__offset(this.bb_pos, 56); + return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 42.0; +} + +justF64():number { + const offset = this.bb!.__offset(this.bb_pos, 58); + return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0; +} + +maybeF64():number|null { + const offset = this.bb!.__offset(this.bb_pos, 60); + return offset ? this.bb!.readFloat64(this.bb_pos + offset) : null; +} + +defaultF64():number { + const offset = this.bb!.__offset(this.bb_pos, 62); + return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 42.0; +} + +justBool():boolean { + const offset = this.bb!.__offset(this.bb_pos, 64); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +maybeBool():boolean|null { + const offset = this.bb!.__offset(this.bb_pos, 66); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : null; +} + +defaultBool():boolean { + const offset = this.bb!.__offset(this.bb_pos, 68); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : true; +} + +justEnum():OptionalByte { + const offset = this.bb!.__offset(this.bb_pos, 70); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.None; +} + +maybeEnum():OptionalByte|null { + const offset = this.bb!.__offset(this.bb_pos, 72); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : null; +} + +defaultEnum():OptionalByte { + const offset = this.bb!.__offset(this.bb_pos, 74); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.One; +} + +static getFullyQualifiedName(): "optional_scalars.ScalarStuff" { + return 'optional_scalars.ScalarStuff'; +} + +static startScalarStuff(builder:flatbuffers.Builder):void { + builder.startObject(36); +} + +static addJustI8(builder:flatbuffers.Builder, justI8:number):void { + builder.addFieldInt8(0, justI8, 0); +} + +static addMaybeI8(builder:flatbuffers.Builder, maybeI8:number):void { + builder.addFieldInt8(1, maybeI8, null); +} + +static addDefaultI8(builder:flatbuffers.Builder, defaultI8:number):void { + builder.addFieldInt8(2, defaultI8, 42); +} + +static addJustU8(builder:flatbuffers.Builder, justU8:number):void { + builder.addFieldInt8(3, justU8, 0); +} + +static addMaybeU8(builder:flatbuffers.Builder, maybeU8:number):void { + builder.addFieldInt8(4, maybeU8, null); +} + +static addDefaultU8(builder:flatbuffers.Builder, defaultU8:number):void { + builder.addFieldInt8(5, defaultU8, 42); +} + +static addJustI16(builder:flatbuffers.Builder, justI16:number):void { + builder.addFieldInt16(6, justI16, 0); +} + +static addMaybeI16(builder:flatbuffers.Builder, maybeI16:number):void { + builder.addFieldInt16(7, maybeI16, null); +} + +static addDefaultI16(builder:flatbuffers.Builder, defaultI16:number):void { + builder.addFieldInt16(8, defaultI16, 42); +} + +static addJustU16(builder:flatbuffers.Builder, justU16:number):void { + builder.addFieldInt16(9, justU16, 0); +} + +static addMaybeU16(builder:flatbuffers.Builder, maybeU16:number):void { + builder.addFieldInt16(10, maybeU16, null); +} + +static addDefaultU16(builder:flatbuffers.Builder, defaultU16:number):void { + builder.addFieldInt16(11, defaultU16, 42); +} + +static addJustI32(builder:flatbuffers.Builder, justI32:number):void { + builder.addFieldInt32(12, justI32, 0); +} + +static addMaybeI32(builder:flatbuffers.Builder, maybeI32:number):void { + builder.addFieldInt32(13, maybeI32, null); +} + +static addDefaultI32(builder:flatbuffers.Builder, defaultI32:number):void { + builder.addFieldInt32(14, defaultI32, 42); +} + +static addJustU32(builder:flatbuffers.Builder, justU32:number):void { + builder.addFieldInt32(15, justU32, 0); +} + +static addMaybeU32(builder:flatbuffers.Builder, maybeU32:number):void { + builder.addFieldInt32(16, maybeU32, null); +} + +static addDefaultU32(builder:flatbuffers.Builder, defaultU32:number):void { + builder.addFieldInt32(17, defaultU32, 42); +} + +static addJustI64(builder:flatbuffers.Builder, justI64:bigint):void { + builder.addFieldInt64(18, justI64, BigInt('0')); +} + +static addMaybeI64(builder:flatbuffers.Builder, maybeI64:bigint):void { + builder.addFieldInt64(19, maybeI64, null); +} + +static addDefaultI64(builder:flatbuffers.Builder, defaultI64:bigint):void { + builder.addFieldInt64(20, defaultI64, BigInt('42')); +} + +static addJustU64(builder:flatbuffers.Builder, justU64:bigint):void { + builder.addFieldInt64(21, justU64, BigInt('0')); +} + +static addMaybeU64(builder:flatbuffers.Builder, maybeU64:bigint):void { + builder.addFieldInt64(22, maybeU64, null); +} + +static addDefaultU64(builder:flatbuffers.Builder, defaultU64:bigint):void { + builder.addFieldInt64(23, defaultU64, BigInt('42')); +} + +static addJustF32(builder:flatbuffers.Builder, justF32:number):void { + builder.addFieldFloat32(24, justF32, 0.0); +} + +static addMaybeF32(builder:flatbuffers.Builder, maybeF32:number):void { + builder.addFieldFloat32(25, maybeF32, null); +} + +static addDefaultF32(builder:flatbuffers.Builder, defaultF32:number):void { + builder.addFieldFloat32(26, defaultF32, 42.0); +} + +static addJustF64(builder:flatbuffers.Builder, justF64:number):void { + builder.addFieldFloat64(27, justF64, 0.0); +} + +static addMaybeF64(builder:flatbuffers.Builder, maybeF64:number):void { + builder.addFieldFloat64(28, maybeF64, null); +} + +static addDefaultF64(builder:flatbuffers.Builder, defaultF64:number):void { + builder.addFieldFloat64(29, defaultF64, 42.0); +} + +static addJustBool(builder:flatbuffers.Builder, justBool:boolean):void { + builder.addFieldInt8(30, +justBool, +false); +} + +static addMaybeBool(builder:flatbuffers.Builder, maybeBool:boolean):void { + builder.addFieldInt8(31, +maybeBool, null); +} + +static addDefaultBool(builder:flatbuffers.Builder, defaultBool:boolean):void { + builder.addFieldInt8(32, +defaultBool, +true); +} + +static addJustEnum(builder:flatbuffers.Builder, justEnum:OptionalByte):void { + builder.addFieldInt8(33, justEnum, OptionalByte.None); +} + +static addMaybeEnum(builder:flatbuffers.Builder, maybeEnum:OptionalByte):void { + builder.addFieldInt8(34, maybeEnum, null); +} + +static addDefaultEnum(builder:flatbuffers.Builder, defaultEnum:OptionalByte):void { + builder.addFieldInt8(35, defaultEnum, OptionalByte.One); +} + +static endScalarStuff(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static finishScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, 'NULL'); +} + +static finishSizePrefixedScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, 'NULL', true); +} + +static createScalarStuff(builder:flatbuffers.Builder, justI8:number, maybeI8:number|null, defaultI8:number, justU8:number, maybeU8:number|null, defaultU8:number, justI16:number, maybeI16:number|null, defaultI16:number, justU16:number, maybeU16:number|null, defaultU16:number, justI32:number, maybeI32:number|null, defaultI32:number, justU32:number, maybeU32:number|null, defaultU32:number, justI64:bigint, maybeI64:bigint|null, defaultI64:bigint, justU64:bigint, maybeU64:bigint|null, defaultU64:bigint, justF32:number, maybeF32:number|null, defaultF32:number, justF64:number, maybeF64:number|null, defaultF64:number, justBool:boolean, maybeBool:boolean|null, defaultBool:boolean, justEnum:OptionalByte, maybeEnum:OptionalByte|null, defaultEnum:OptionalByte):flatbuffers.Offset { + ScalarStuff.startScalarStuff(builder); + ScalarStuff.addJustI8(builder, justI8); + if (maybeI8 !== null) + ScalarStuff.addMaybeI8(builder, maybeI8); + ScalarStuff.addDefaultI8(builder, defaultI8); + ScalarStuff.addJustU8(builder, justU8); + if (maybeU8 !== null) + ScalarStuff.addMaybeU8(builder, maybeU8); + ScalarStuff.addDefaultU8(builder, defaultU8); + ScalarStuff.addJustI16(builder, justI16); + if (maybeI16 !== null) + ScalarStuff.addMaybeI16(builder, maybeI16); + ScalarStuff.addDefaultI16(builder, defaultI16); + ScalarStuff.addJustU16(builder, justU16); + if (maybeU16 !== null) + ScalarStuff.addMaybeU16(builder, maybeU16); + ScalarStuff.addDefaultU16(builder, defaultU16); + ScalarStuff.addJustI32(builder, justI32); + if (maybeI32 !== null) + ScalarStuff.addMaybeI32(builder, maybeI32); + ScalarStuff.addDefaultI32(builder, defaultI32); + ScalarStuff.addJustU32(builder, justU32); + if (maybeU32 !== null) + ScalarStuff.addMaybeU32(builder, maybeU32); + ScalarStuff.addDefaultU32(builder, defaultU32); + ScalarStuff.addJustI64(builder, justI64); + if (maybeI64 !== null) + ScalarStuff.addMaybeI64(builder, maybeI64); + ScalarStuff.addDefaultI64(builder, defaultI64); + ScalarStuff.addJustU64(builder, justU64); + if (maybeU64 !== null) + ScalarStuff.addMaybeU64(builder, maybeU64); + ScalarStuff.addDefaultU64(builder, defaultU64); + ScalarStuff.addJustF32(builder, justF32); + if (maybeF32 !== null) + ScalarStuff.addMaybeF32(builder, maybeF32); + ScalarStuff.addDefaultF32(builder, defaultF32); + ScalarStuff.addJustF64(builder, justF64); + if (maybeF64 !== null) + ScalarStuff.addMaybeF64(builder, maybeF64); + ScalarStuff.addDefaultF64(builder, defaultF64); + ScalarStuff.addJustBool(builder, justBool); + if (maybeBool !== null) + ScalarStuff.addMaybeBool(builder, maybeBool); + ScalarStuff.addDefaultBool(builder, defaultBool); + ScalarStuff.addJustEnum(builder, justEnum); + if (maybeEnum !== null) + ScalarStuff.addMaybeEnum(builder, maybeEnum); + ScalarStuff.addDefaultEnum(builder, defaultEnum); + return ScalarStuff.endScalarStuff(builder); +} } diff --git a/tests/ts/no_import_ext/optional_scalars.js b/tests/ts/no_import_ext/optional_scalars.js index b4fa8e57a..d519b38fa 100644 --- a/tests/ts/no_import_ext/optional_scalars.js +++ b/tests/ts/no_import_ext/optional_scalars.js @@ -1,4 +1,3 @@ // automatically generated by the FlatBuffers compiler, do not modify import * as optional_scalars_1 from './optional-scalars.js'; - -export {optional_scalars_1 as optional_scalars}; +export { optional_scalars_1 as optional_scalars }; diff --git a/tests/ts/non-zero-vector-table.ts b/tests/ts/non-zero-vector-table.ts new file mode 100644 index 000000000..b7c11761f --- /dev/null +++ b/tests/ts/non-zero-vector-table.ts @@ -0,0 +1,113 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +import * as flatbuffers from 'flatbuffers'; + +import { NonZero } from './non-zero.js'; + + +export class NonZeroVectorTable implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):NonZeroVectorTable { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsNonZeroVectorTable(bb:flatbuffers.ByteBuffer, obj?:NonZeroVectorTable):NonZeroVectorTable { + return (obj || new NonZeroVectorTable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsNonZeroVectorTable(bb:flatbuffers.ByteBuffer, obj?:NonZeroVectorTable):NonZeroVectorTable { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new NonZeroVectorTable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +values(index: number):NonZero|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : null; +} + +valuesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +valuesArray():Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null; +} + +value():NonZero { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : NonZero.VAL; +} + +static startNonZeroVectorTable(builder:flatbuffers.Builder):void { + builder.startObject(2); +} + +static addValues(builder:flatbuffers.Builder, valuesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, valuesOffset, 0); +} + +static createValuesVector(builder:flatbuffers.Builder, data:NonZero[]):flatbuffers.Offset { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]!); + } + return builder.endVector(); +} + +static startValuesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(1, numElems, 1); +} + +static addValue(builder:flatbuffers.Builder, value:NonZero):void { + builder.addFieldInt8(1, value, NonZero.VAL); +} + +static endNonZeroVectorTable(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createNonZeroVectorTable(builder:flatbuffers.Builder, valuesOffset:flatbuffers.Offset, value:NonZero):flatbuffers.Offset { + NonZeroVectorTable.startNonZeroVectorTable(builder); + NonZeroVectorTable.addValues(builder, valuesOffset); + NonZeroVectorTable.addValue(builder, value); + return NonZeroVectorTable.endNonZeroVectorTable(builder); +} + +unpack(): NonZeroVectorTableT { + return new NonZeroVectorTableT( + this.bb!.createScalarList(this.values.bind(this), this.valuesLength()), + this.value() + ); +} + + +unpackTo(_o: NonZeroVectorTableT): void { + _o.values = this.bb!.createScalarList(this.values.bind(this), this.valuesLength()); + _o.value = this.value(); +} +} + +export class NonZeroVectorTableT implements flatbuffers.IGeneratedObject { +constructor( + public values: (NonZero)[] = [], + public value: NonZero = NonZero.VAL +){} + + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const values = NonZeroVectorTable.createValuesVector(builder, this.values); + + return NonZeroVectorTable.createNonZeroVectorTable(builder, + values, + this.value + ); +} +} diff --git a/tests/ts/non-zero.ts b/tests/ts/non-zero.ts new file mode 100644 index 000000000..dc33fa2c5 --- /dev/null +++ b/tests/ts/non-zero.ts @@ -0,0 +1,7 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +export enum NonZero { + VAL = 1 +} diff --git a/tests/ts/non_zero_enum.ts b/tests/ts/non_zero_enum.ts new file mode 100644 index 000000000..e3897252f --- /dev/null +++ b/tests/ts/non_zero_enum.ts @@ -0,0 +1,6 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +export { NonZero } from './non-zero.js'; +export { NonZeroVectorTable, NonZeroVectorTableT } from './non-zero-vector-table.js'; diff --git a/tests/ts/optional-scalars/scalar-stuff.ts b/tests/ts/optional-scalars/scalar-stuff.ts index 69961af26..9afb62559 100644 --- a/tests/ts/optional-scalars/scalar-stuff.ts +++ b/tests/ts/optional-scalars/scalar-stuff.ts @@ -9,7 +9,7 @@ import { OptionalByte } from './optional-byte.js'; export class ScalarStuff { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):ScalarStuff { this.bb_pos = i; this.bb = bb; @@ -213,151 +213,151 @@ static getFullyQualifiedName(): "optional_scalars.ScalarStuff" { return 'optional_scalars.ScalarStuff'; } -static startScalarStuff(builder:flatbuffers.Builder) { +static startScalarStuff(builder:flatbuffers.Builder):void { builder.startObject(36); } -static addJustI8(builder:flatbuffers.Builder, justI8:number) { +static addJustI8(builder:flatbuffers.Builder, justI8:number):void { builder.addFieldInt8(0, justI8, 0); } -static addMaybeI8(builder:flatbuffers.Builder, maybeI8:number) { +static addMaybeI8(builder:flatbuffers.Builder, maybeI8:number):void { builder.addFieldInt8(1, maybeI8, null); } -static addDefaultI8(builder:flatbuffers.Builder, defaultI8:number) { +static addDefaultI8(builder:flatbuffers.Builder, defaultI8:number):void { builder.addFieldInt8(2, defaultI8, 42); } -static addJustU8(builder:flatbuffers.Builder, justU8:number) { +static addJustU8(builder:flatbuffers.Builder, justU8:number):void { builder.addFieldInt8(3, justU8, 0); } -static addMaybeU8(builder:flatbuffers.Builder, maybeU8:number) { +static addMaybeU8(builder:flatbuffers.Builder, maybeU8:number):void { builder.addFieldInt8(4, maybeU8, null); } -static addDefaultU8(builder:flatbuffers.Builder, defaultU8:number) { +static addDefaultU8(builder:flatbuffers.Builder, defaultU8:number):void { builder.addFieldInt8(5, defaultU8, 42); } -static addJustI16(builder:flatbuffers.Builder, justI16:number) { +static addJustI16(builder:flatbuffers.Builder, justI16:number):void { builder.addFieldInt16(6, justI16, 0); } -static addMaybeI16(builder:flatbuffers.Builder, maybeI16:number) { +static addMaybeI16(builder:flatbuffers.Builder, maybeI16:number):void { builder.addFieldInt16(7, maybeI16, null); } -static addDefaultI16(builder:flatbuffers.Builder, defaultI16:number) { +static addDefaultI16(builder:flatbuffers.Builder, defaultI16:number):void { builder.addFieldInt16(8, defaultI16, 42); } -static addJustU16(builder:flatbuffers.Builder, justU16:number) { +static addJustU16(builder:flatbuffers.Builder, justU16:number):void { builder.addFieldInt16(9, justU16, 0); } -static addMaybeU16(builder:flatbuffers.Builder, maybeU16:number) { +static addMaybeU16(builder:flatbuffers.Builder, maybeU16:number):void { builder.addFieldInt16(10, maybeU16, null); } -static addDefaultU16(builder:flatbuffers.Builder, defaultU16:number) { +static addDefaultU16(builder:flatbuffers.Builder, defaultU16:number):void { builder.addFieldInt16(11, defaultU16, 42); } -static addJustI32(builder:flatbuffers.Builder, justI32:number) { +static addJustI32(builder:flatbuffers.Builder, justI32:number):void { builder.addFieldInt32(12, justI32, 0); } -static addMaybeI32(builder:flatbuffers.Builder, maybeI32:number) { +static addMaybeI32(builder:flatbuffers.Builder, maybeI32:number):void { builder.addFieldInt32(13, maybeI32, null); } -static addDefaultI32(builder:flatbuffers.Builder, defaultI32:number) { +static addDefaultI32(builder:flatbuffers.Builder, defaultI32:number):void { builder.addFieldInt32(14, defaultI32, 42); } -static addJustU32(builder:flatbuffers.Builder, justU32:number) { +static addJustU32(builder:flatbuffers.Builder, justU32:number):void { builder.addFieldInt32(15, justU32, 0); } -static addMaybeU32(builder:flatbuffers.Builder, maybeU32:number) { +static addMaybeU32(builder:flatbuffers.Builder, maybeU32:number):void { builder.addFieldInt32(16, maybeU32, null); } -static addDefaultU32(builder:flatbuffers.Builder, defaultU32:number) { +static addDefaultU32(builder:flatbuffers.Builder, defaultU32:number):void { builder.addFieldInt32(17, defaultU32, 42); } -static addJustI64(builder:flatbuffers.Builder, justI64:bigint) { +static addJustI64(builder:flatbuffers.Builder, justI64:bigint):void { builder.addFieldInt64(18, justI64, BigInt('0')); } -static addMaybeI64(builder:flatbuffers.Builder, maybeI64:bigint) { +static addMaybeI64(builder:flatbuffers.Builder, maybeI64:bigint):void { builder.addFieldInt64(19, maybeI64, null); } -static addDefaultI64(builder:flatbuffers.Builder, defaultI64:bigint) { +static addDefaultI64(builder:flatbuffers.Builder, defaultI64:bigint):void { builder.addFieldInt64(20, defaultI64, BigInt('42')); } -static addJustU64(builder:flatbuffers.Builder, justU64:bigint) { +static addJustU64(builder:flatbuffers.Builder, justU64:bigint):void { builder.addFieldInt64(21, justU64, BigInt('0')); } -static addMaybeU64(builder:flatbuffers.Builder, maybeU64:bigint) { +static addMaybeU64(builder:flatbuffers.Builder, maybeU64:bigint):void { builder.addFieldInt64(22, maybeU64, null); } -static addDefaultU64(builder:flatbuffers.Builder, defaultU64:bigint) { +static addDefaultU64(builder:flatbuffers.Builder, defaultU64:bigint):void { builder.addFieldInt64(23, defaultU64, BigInt('42')); } -static addJustF32(builder:flatbuffers.Builder, justF32:number) { +static addJustF32(builder:flatbuffers.Builder, justF32:number):void { builder.addFieldFloat32(24, justF32, 0.0); } -static addMaybeF32(builder:flatbuffers.Builder, maybeF32:number) { +static addMaybeF32(builder:flatbuffers.Builder, maybeF32:number):void { builder.addFieldFloat32(25, maybeF32, null); } -static addDefaultF32(builder:flatbuffers.Builder, defaultF32:number) { +static addDefaultF32(builder:flatbuffers.Builder, defaultF32:number):void { builder.addFieldFloat32(26, defaultF32, 42.0); } -static addJustF64(builder:flatbuffers.Builder, justF64:number) { +static addJustF64(builder:flatbuffers.Builder, justF64:number):void { builder.addFieldFloat64(27, justF64, 0.0); } -static addMaybeF64(builder:flatbuffers.Builder, maybeF64:number) { +static addMaybeF64(builder:flatbuffers.Builder, maybeF64:number):void { builder.addFieldFloat64(28, maybeF64, null); } -static addDefaultF64(builder:flatbuffers.Builder, defaultF64:number) { +static addDefaultF64(builder:flatbuffers.Builder, defaultF64:number):void { builder.addFieldFloat64(29, defaultF64, 42.0); } -static addJustBool(builder:flatbuffers.Builder, justBool:boolean) { +static addJustBool(builder:flatbuffers.Builder, justBool:boolean):void { builder.addFieldInt8(30, +justBool, +false); } -static addMaybeBool(builder:flatbuffers.Builder, maybeBool:boolean) { +static addMaybeBool(builder:flatbuffers.Builder, maybeBool:boolean):void { builder.addFieldInt8(31, +maybeBool, null); } -static addDefaultBool(builder:flatbuffers.Builder, defaultBool:boolean) { +static addDefaultBool(builder:flatbuffers.Builder, defaultBool:boolean):void { builder.addFieldInt8(32, +defaultBool, +true); } -static addJustEnum(builder:flatbuffers.Builder, justEnum:OptionalByte) { +static addJustEnum(builder:flatbuffers.Builder, justEnum:OptionalByte):void { builder.addFieldInt8(33, justEnum, OptionalByte.None); } -static addMaybeEnum(builder:flatbuffers.Builder, maybeEnum:OptionalByte) { +static addMaybeEnum(builder:flatbuffers.Builder, maybeEnum:OptionalByte):void { builder.addFieldInt8(34, maybeEnum, null); } -static addDefaultEnum(builder:flatbuffers.Builder, defaultEnum:OptionalByte) { +static addDefaultEnum(builder:flatbuffers.Builder, defaultEnum:OptionalByte):void { builder.addFieldInt8(35, defaultEnum, OptionalByte.One); } @@ -366,11 +366,11 @@ static endScalarStuff(builder:flatbuffers.Builder):flatbuffers.Offset { return offset; } -static finishScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'NULL'); } -static finishSizePrefixedScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishSizePrefixedScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'NULL', true); } diff --git a/tests/ts/reflection.d.ts b/tests/ts/reflection.d.ts index 371077e5b..5e1f87694 100644 --- a/tests/ts/reflection.d.ts +++ b/tests/ts/reflection.d.ts @@ -1,12 +1,12 @@ -export {AdvancedFeatures} from './reflection/advanced-features.js'; -export {BaseType} from './reflection/base-type.js'; -export {EnumVal, EnumValT} from './reflection/enum-val.js'; -export {Enum, EnumT} from './reflection/enum.js'; -export {Field, FieldT} from './reflection/field.js'; -export {KeyValue, KeyValueT} from './reflection/key-value.js'; -export {Object_} from './reflection/object.js'; -export {RPCCall, RPCCallT} from './reflection/rpccall.js'; -export {SchemaFile, SchemaFileT} from './reflection/schema-file.js'; -export {Schema, SchemaT} from './reflection/schema.js'; -export {Service, ServiceT} from './reflection/service.js'; -export {Type, TypeT} from './reflection/type.js'; +export { AdvancedFeatures } from './reflection/advanced-features.js'; +export { BaseType } from './reflection/base-type.js'; +export { Enum, EnumT } from './reflection/enum.js'; +export { EnumVal, EnumValT } from './reflection/enum-val.js'; +export { Field, FieldT } from './reflection/field.js'; +export { KeyValue, KeyValueT } from './reflection/key-value.js'; +export { Object_ } from './reflection/object.js'; +export { RPCCall, RPCCallT } from './reflection/rpccall.js'; +export { Schema, SchemaT } from './reflection/schema.js'; +export { SchemaFile, SchemaFileT } from './reflection/schema-file.js'; +export { Service, ServiceT } from './reflection/service.js'; +export { Type, TypeT } from './reflection/type.js'; diff --git a/tests/ts/reflection.js b/tests/ts/reflection.js index 4fb7196c5..ac0705641 100644 --- a/tests/ts/reflection.js +++ b/tests/ts/reflection.js @@ -1,15 +1,14 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {AdvancedFeatures} from './reflection/advanced-features.js'; -export {BaseType} from './reflection/base-type.js'; -export {EnumVal, EnumValT} from './reflection/enum-val.js'; -export {Enum, EnumT} from './reflection/enum.js'; -export {Field, FieldT} from './reflection/field.js'; -export {KeyValue, KeyValueT} from './reflection/key-value.js'; -export {Object_} from './reflection/object.js'; -export {RPCCall, RPCCallT} from './reflection/rpccall.js'; -export {SchemaFile, SchemaFileT} from './reflection/schema-file.js'; -export {Schema, SchemaT} from './reflection/schema.js'; -export {Service, ServiceT} from './reflection/service.js'; -export {Type, TypeT} from './reflection/type.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { AdvancedFeatures } from './reflection/advanced-features.js'; +export { BaseType } from './reflection/base-type.js'; +export { Enum, EnumT } from './reflection/enum.js'; +export { EnumVal, EnumValT } from './reflection/enum-val.js'; +export { Field, FieldT } from './reflection/field.js'; +export { KeyValue, KeyValueT } from './reflection/key-value.js'; +export { Object_ } from './reflection/object.js'; +export { RPCCall, RPCCallT } from './reflection/rpccall.js'; +export { Schema, SchemaT } from './reflection/schema.js'; +export { SchemaFile, SchemaFileT } from './reflection/schema-file.js'; +export { Service, ServiceT } from './reflection/service.js'; +export { Type, TypeT } from './reflection/type.js'; diff --git a/tests/ts/reflection.ts b/tests/ts/reflection.ts index 20d7fd35f..a43d07d21 100644 --- a/tests/ts/reflection.ts +++ b/tests/ts/reflection.ts @@ -2,15 +2,15 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {AdvancedFeatures} from './reflection/advanced-features.js'; -export {BaseType} from './reflection/base-type.js'; -export {EnumVal, EnumValT} from './reflection/enum-val.js'; -export {Enum, EnumT} from './reflection/enum.js'; -export {Field, FieldT} from './reflection/field.js'; -export {KeyValue, KeyValueT} from './reflection/key-value.js'; -export {Object_} from './reflection/object.js'; -export {RPCCall, RPCCallT} from './reflection/rpccall.js'; -export {SchemaFile, SchemaFileT} from './reflection/schema-file.js'; -export {Schema, SchemaT} from './reflection/schema.js'; -export {Service, ServiceT} from './reflection/service.js'; -export {Type, TypeT} from './reflection/type.js'; +export { AdvancedFeatures } from './reflection/advanced-features.js'; +export { BaseType } from './reflection/base-type.js'; +export { Enum, EnumT } from './reflection/enum.js'; +export { EnumVal, EnumValT } from './reflection/enum-val.js'; +export { Field, FieldT } from './reflection/field.js'; +export { KeyValue, KeyValueT } from './reflection/key-value.js'; +export { Object_ } from './reflection/object.js'; +export { RPCCall, RPCCallT } from './reflection/rpccall.js'; +export { Schema, SchemaT } from './reflection/schema.js'; +export { SchemaFile, SchemaFileT } from './reflection/schema-file.js'; +export { Service, ServiceT } from './reflection/service.js'; +export { Type, TypeT } from './reflection/type.js'; diff --git a/tests/ts/reflection/advanced-features.d.ts b/tests/ts/reflection/advanced-features.d.ts index cb4705b21..a51745e45 100644 --- a/tests/ts/reflection/advanced-features.d.ts +++ b/tests/ts/reflection/advanced-features.d.ts @@ -2,8 +2,8 @@ * New schema language features that are not supported by old code generators. */ export declare enum AdvancedFeatures { - AdvancedArrayFeatures = '1', - AdvancedUnionFeatures = '2', - OptionalScalars = '4', - DefaultVectorsAndStrings = '8', + AdvancedArrayFeatures = "1", + AdvancedUnionFeatures = "2", + OptionalScalars = "4", + DefaultVectorsAndStrings = "8" } diff --git a/tests/ts/reflection/advanced-features.js b/tests/ts/reflection/advanced-features.js index c7f884428..aeef1a78d 100644 --- a/tests/ts/reflection/advanced-features.js +++ b/tests/ts/reflection/advanced-features.js @@ -1,13 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ /** * New schema language features that are not supported by old code generators. */ export var AdvancedFeatures; -(function(AdvancedFeatures) { -AdvancedFeatures['AdvancedArrayFeatures'] = '1'; -AdvancedFeatures['AdvancedUnionFeatures'] = '2'; -AdvancedFeatures['OptionalScalars'] = '4'; -AdvancedFeatures['DefaultVectorsAndStrings'] = '8'; +(function (AdvancedFeatures) { + AdvancedFeatures["AdvancedArrayFeatures"] = "1"; + AdvancedFeatures["AdvancedUnionFeatures"] = "2"; + AdvancedFeatures["OptionalScalars"] = "4"; + AdvancedFeatures["DefaultVectorsAndStrings"] = "8"; })(AdvancedFeatures || (AdvancedFeatures = {})); diff --git a/tests/ts/reflection/advanced-features.ts b/tests/ts/reflection/advanced-features.ts index 60990f6cf..f68b7e24d 100644 --- a/tests/ts/reflection/advanced-features.ts +++ b/tests/ts/reflection/advanced-features.ts @@ -9,5 +9,5 @@ export enum AdvancedFeatures { AdvancedArrayFeatures = '1', AdvancedUnionFeatures = '2', OptionalScalars = '4', - DefaultVectorsAndStrings = '8', + DefaultVectorsAndStrings = '8' } diff --git a/tests/ts/reflection/base-type.d.ts b/tests/ts/reflection/base-type.d.ts index 9cce32601..a4aea8bd1 100644 --- a/tests/ts/reflection/base-type.d.ts +++ b/tests/ts/reflection/base-type.d.ts @@ -1,22 +1,22 @@ export declare enum BaseType { - None = 0, - UType = 1, - Bool = 2, - Byte = 3, - UByte = 4, - Short = 5, - UShort = 6, - Int = 7, - UInt = 8, - Long = 9, - ULong = 10, - Float = 11, - Double = 12, - String = 13, - Vector = 14, - Obj = 15, - Union = 16, - Array = 17, - Vector64 = 18, - MaxBaseType = 19, + None = 0, + UType = 1, + Bool = 2, + Byte = 3, + UByte = 4, + Short = 5, + UShort = 6, + Int = 7, + UInt = 8, + Long = 9, + ULong = 10, + Float = 11, + Double = 12, + String = 13, + Vector = 14, + Obj = 15, + Union = 16, + Array = 17, + Vector64 = 18, + MaxBaseType = 19 } diff --git a/tests/ts/reflection/base-type.js b/tests/ts/reflection/base-type.js index c8a904bec..957d9fdc4 100644 --- a/tests/ts/reflection/base-type.js +++ b/tests/ts/reflection/base-type.js @@ -1,26 +1,25 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var BaseType; -(function(BaseType) { -BaseType[BaseType['None'] = 0] = 'None'; -BaseType[BaseType['UType'] = 1] = 'UType'; -BaseType[BaseType['Bool'] = 2] = 'Bool'; -BaseType[BaseType['Byte'] = 3] = 'Byte'; -BaseType[BaseType['UByte'] = 4] = 'UByte'; -BaseType[BaseType['Short'] = 5] = 'Short'; -BaseType[BaseType['UShort'] = 6] = 'UShort'; -BaseType[BaseType['Int'] = 7] = 'Int'; -BaseType[BaseType['UInt'] = 8] = 'UInt'; -BaseType[BaseType['Long'] = 9] = 'Long'; -BaseType[BaseType['ULong'] = 10] = 'ULong'; -BaseType[BaseType['Float'] = 11] = 'Float'; -BaseType[BaseType['Double'] = 12] = 'Double'; -BaseType[BaseType['String'] = 13] = 'String'; -BaseType[BaseType['Vector'] = 14] = 'Vector'; -BaseType[BaseType['Obj'] = 15] = 'Obj'; -BaseType[BaseType['Union'] = 16] = 'Union'; -BaseType[BaseType['Array'] = 17] = 'Array'; -BaseType[BaseType['Vector64'] = 18] = 'Vector64'; -BaseType[BaseType['MaxBaseType'] = 19] = 'MaxBaseType'; +(function (BaseType) { + BaseType[BaseType["None"] = 0] = "None"; + BaseType[BaseType["UType"] = 1] = "UType"; + BaseType[BaseType["Bool"] = 2] = "Bool"; + BaseType[BaseType["Byte"] = 3] = "Byte"; + BaseType[BaseType["UByte"] = 4] = "UByte"; + BaseType[BaseType["Short"] = 5] = "Short"; + BaseType[BaseType["UShort"] = 6] = "UShort"; + BaseType[BaseType["Int"] = 7] = "Int"; + BaseType[BaseType["UInt"] = 8] = "UInt"; + BaseType[BaseType["Long"] = 9] = "Long"; + BaseType[BaseType["ULong"] = 10] = "ULong"; + BaseType[BaseType["Float"] = 11] = "Float"; + BaseType[BaseType["Double"] = 12] = "Double"; + BaseType[BaseType["String"] = 13] = "String"; + BaseType[BaseType["Vector"] = 14] = "Vector"; + BaseType[BaseType["Obj"] = 15] = "Obj"; + BaseType[BaseType["Union"] = 16] = "Union"; + BaseType[BaseType["Array"] = 17] = "Array"; + BaseType[BaseType["Vector64"] = 18] = "Vector64"; + BaseType[BaseType["MaxBaseType"] = 19] = "MaxBaseType"; })(BaseType || (BaseType = {})); diff --git a/tests/ts/reflection/base-type.ts b/tests/ts/reflection/base-type.ts index a5bec6f2f..38ef9fa1c 100644 --- a/tests/ts/reflection/base-type.ts +++ b/tests/ts/reflection/base-type.ts @@ -22,5 +22,5 @@ export enum BaseType { Union = 16, Array = 17, Vector64 = 18, - MaxBaseType = 19, + MaxBaseType = 19 } diff --git a/tests/ts/reflection/enum-val.d.ts b/tests/ts/reflection/enum-val.d.ts index da471f343..0e6a2deaa 100644 --- a/tests/ts/reflection/enum-val.d.ts +++ b/tests/ts/reflection/enum-val.d.ts @@ -1,81 +1,43 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Type, TypeT} from '../reflection/type.js'; -export declare class EnumVal - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): EnumVal; - static getRootAsEnumVal(bb: flatbuffers.ByteBuffer, obj?: EnumVal): EnumVal; - static getSizePrefixedRootAsEnumVal( - bb: flatbuffers.ByteBuffer, - obj?: EnumVal, - ): EnumVal; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - value(): bigint; - mutate_value(value: bigint): boolean; - unionType(obj?: Type): Type | null; - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentationLength(): number; - attributes(index: number, obj?: KeyValue): KeyValue | null; - attributesLength(): number; - static getFullyQualifiedName(): string; - static startEnumVal(builder: flatbuffers.Builder): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addValue(builder: flatbuffers.Builder, value: bigint): void; - static addUnionType( - builder: flatbuffers.Builder, - unionTypeOffset: flatbuffers.Offset, - ): void; - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ): void; - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ): void; - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startAttributesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static endEnumVal(builder: flatbuffers.Builder): flatbuffers.Offset; - unpack(): EnumValT; - unpackTo(_o: EnumValT): void; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Type, TypeT } from './type.js'; +export declare class EnumVal implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): EnumVal; + static getRootAsEnumVal(bb: flatbuffers.ByteBuffer, obj?: EnumVal): EnumVal; + static getSizePrefixedRootAsEnumVal(bb: flatbuffers.ByteBuffer, obj?: EnumVal): EnumVal; + name(): string; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + value(): bigint; + mutate_value(value: bigint): boolean; + unionType(obj?: Type): Type | null; + documentation(index: number): string; + documentation(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + documentationLength(): number; + attributes(index: number, obj?: KeyValue): KeyValue | null; + attributesLength(): number; + static getFullyQualifiedName(): "reflection.EnumVal"; + static startEnumVal(builder: flatbuffers.Builder): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addValue(builder: flatbuffers.Builder, value: bigint): void; + static addUnionType(builder: flatbuffers.Builder, unionTypeOffset: flatbuffers.Offset): void; + static addDocumentation(builder: flatbuffers.Builder, documentationOffset: flatbuffers.Offset): void; + static createDocumentationVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startDocumentationVector(builder: flatbuffers.Builder, numElems: number): void; + static addAttributes(builder: flatbuffers.Builder, attributesOffset: flatbuffers.Offset): void; + static createAttributesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startAttributesVector(builder: flatbuffers.Builder, numElems: number): void; + static endEnumVal(builder: flatbuffers.Builder): flatbuffers.Offset; + unpack(): EnumValT; + unpackTo(_o: EnumValT): void; } export declare class EnumValT implements flatbuffers.IGeneratedObject { - name: string | Uint8Array | null; - value: bigint; - unionType: TypeT | null; - documentation: string[]; - attributes: KeyValueT[]; - constructor( - name?: string | Uint8Array | null, - value?: bigint, - unionType?: TypeT | null, - documentation?: string[], - attributes?: KeyValueT[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + name: string | Uint8Array | null; + value: bigint; + unionType: TypeT | null; + documentation: (string)[]; + attributes: (KeyValueT)[]; + constructor(name?: string | Uint8Array | null, value?: bigint, unionType?: TypeT | null, documentation?: (string)[], attributes?: (KeyValueT)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/enum-val.js b/tests/ts/reflection/enum-val.js index 6326367c1..0b7de92dc 100644 --- a/tests/ts/reflection/enum-val.js +++ b/tests/ts/reflection/enum-val.js @@ -1,169 +1,137 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {KeyValue} from '../reflection/key-value.js'; -import {Type} from '../reflection/type.js'; - +import { KeyValue } from './key-value.js'; +import { Type } from './type.js'; export class EnumVal { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsEnumVal(bb, obj) { - return (obj || new EnumVal()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsEnumVal(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new EnumVal()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - value() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); - } - mutate_value(value) { - const offset = this.bb.__offset(this.bb_pos, 6); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt64(this.bb_pos + offset, value); - return true; - } - unionType(obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? - (obj || new Type()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - documentation(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - documentationLength() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - attributes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? - (obj || new KeyValue()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - attributesLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static getFullyQualifiedName() { - return 'reflection.EnumVal'; - } - static startEnumVal(builder) { - builder.startObject(6); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(0, nameOffset, 0); - } - static addValue(builder, value) { - builder.addFieldInt64(1, value, BigInt('0')); - } - static addUnionType(builder, unionTypeOffset) { - builder.addFieldOffset(3, unionTypeOffset, 0); - } - static addDocumentation(builder, documentationOffset) { - builder.addFieldOffset(4, documentationOffset, 0); - } - static createDocumentationVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - return builder.endVector(); - } - static startDocumentationVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addAttributes(builder, attributesOffset) { - builder.addFieldOffset(5, attributesOffset, 0); - } - static createAttributesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static getRootAsEnumVal(bb, obj) { + return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsEnumVal(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); + } + value() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); + } + mutate_value(value) { + const offset = this.bb.__offset(this.bb_pos, 6); + if (offset === 0) { + return false; + } + this.bb.writeInt64(this.bb_pos + offset, value); + return true; + } + unionType(obj) { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? (obj || new Type()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + documentation(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + documentationLength() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + attributes(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + attributesLength() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + static getFullyQualifiedName() { + return 'reflection.EnumVal'; + } + static startEnumVal(builder) { + builder.startObject(6); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + static addValue(builder, value) { + builder.addFieldInt64(1, value, BigInt('0')); + } + static addUnionType(builder, unionTypeOffset) { + builder.addFieldOffset(3, unionTypeOffset, 0); + } + static addDocumentation(builder, documentationOffset) { + builder.addFieldOffset(4, documentationOffset, 0); + } + static createDocumentationVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startDocumentationVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addAttributes(builder, attributesOffset) { + builder.addFieldOffset(5, attributesOffset, 0); + } + static createAttributesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startAttributesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static endEnumVal(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // name + return offset; + } + unpack() { + return new EnumValT(this.name(), this.value(), (this.unionType() !== null ? this.unionType().unpack() : null), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.bb.createObjList(this.attributes.bind(this), this.attributesLength())); + } + unpackTo(_o) { + _o.name = this.name(); + _o.value = this.value(); + _o.unionType = (this.unionType() !== null ? this.unionType().unpack() : null); + _o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength()); } - return builder.endVector(); - } - static startAttributesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endEnumVal(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - return offset; - } - unpack() { - return new EnumValT( - this.name(), this.value(), - (this.unionType() !== null ? this.unionType().unpack() : null), - this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()), - this.bb.createObjList( - this.attributes.bind(this), this.attributesLength())); - } - unpackTo(_o) { - _o.name = this.name(); - _o.value = this.value(); - _o.unionType = - (this.unionType() !== null ? this.unionType().unpack() : null); - _o.documentation = this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()); - _o.attributes = this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()); - } } export class EnumValT { - constructor( - name = null, value = BigInt('0'), unionType = null, documentation = [], - attributes = []) { - this.name = name; - this.value = value; - this.unionType = unionType; - this.documentation = documentation; - this.attributes = attributes; - } - pack(builder) { - const name = (this.name !== null ? builder.createString(this.name) : 0); - const unionType = - (this.unionType !== null ? this.unionType.pack(builder) : 0); - const documentation = EnumVal.createDocumentationVector( - builder, builder.createObjectOffsetList(this.documentation)); - const attributes = EnumVal.createAttributesVector( - builder, builder.createObjectOffsetList(this.attributes)); - EnumVal.startEnumVal(builder); - EnumVal.addName(builder, name); - EnumVal.addValue(builder, this.value); - EnumVal.addUnionType(builder, unionType); - EnumVal.addDocumentation(builder, documentation); - EnumVal.addAttributes(builder, attributes); - return EnumVal.endEnumVal(builder); - } + constructor(name = null, value = BigInt('0'), unionType = null, documentation = [], attributes = []) { + this.name = name; + this.value = value; + this.unionType = unionType; + this.documentation = documentation; + this.attributes = attributes; + } + pack(builder) { + const name = (this.name !== null ? builder.createString(this.name) : 0); + const unionType = (this.unionType !== null ? this.unionType.pack(builder) : 0); + const documentation = EnumVal.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const attributes = EnumVal.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + EnumVal.startEnumVal(builder); + EnumVal.addName(builder, name); + EnumVal.addValue(builder, this.value); + EnumVal.addUnionType(builder, unionType); + EnumVal.addDocumentation(builder, documentation); + EnumVal.addAttributes(builder, attributes); + return EnumVal.endEnumVal(builder); + } } diff --git a/tests/ts/reflection/enum-val.ts b/tests/ts/reflection/enum-val.ts index 092394a38..1d8ab43d8 100644 --- a/tests/ts/reflection/enum-val.ts +++ b/tests/ts/reflection/enum-val.ts @@ -4,248 +4,180 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Type, TypeT} from '../reflection/type.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Type, TypeT } from './type.js'; + export class EnumVal implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): EnumVal { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):EnumVal { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsEnumVal(bb:flatbuffers.ByteBuffer, obj?:EnumVal):EnumVal { + return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsEnumVal(bb:flatbuffers.ByteBuffer, obj?:EnumVal):EnumVal { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new EnumVal()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +name():string +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +name(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} + +value():bigint { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); +} + +mutate_value(value:bigint):boolean { + const offset = this.bb!.__offset(this.bb_pos, 6); + + if (offset === 0) { + return false; } - static getRootAsEnumVal(bb: flatbuffers.ByteBuffer, obj?: EnumVal): EnumVal { - return (obj || new EnumVal()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt64(this.bb_pos + offset, value); + return true; +} + +unionType(obj?:Type):Type|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? (obj || new Type()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} + +documentation(index: number):string +documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +documentation(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} + +documentationLength():number { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +attributes(index: number, obj?:KeyValue):KeyValue|null { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +attributesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +static getFullyQualifiedName(): "reflection.EnumVal" { + return 'reflection.EnumVal'; +} + +static startEnumVal(builder:flatbuffers.Builder):void { + builder.startObject(6); +} + +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} + +static addValue(builder:flatbuffers.Builder, value:bigint):void { + builder.addFieldInt64(1, value, BigInt('0')); +} + +static addUnionType(builder:flatbuffers.Builder, unionTypeOffset:flatbuffers.Offset):void { + builder.addFieldOffset(3, unionTypeOffset, 0); +} + +static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset):void { + builder.addFieldOffset(4, documentationOffset, 0); +} + +static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static getSizePrefixedRootAsEnumVal( - bb: flatbuffers.ByteBuffer, - obj?: EnumVal, - ): EnumVal { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new EnumVal()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); +static startDocumentationVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(5, attributesOffset, 0); +} + +static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +static startAttributesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - value(): bigint { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); - } +static endEnumVal(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // name + return offset; +} - mutate_value(value: bigint): boolean { - const offset = this.bb!.__offset(this.bb_pos, 6); - if (offset === 0) { - return false; - } +unpack(): EnumValT { + return new EnumValT( + this.name(), + this.value(), + (this.unionType() !== null ? this.unionType()!.unpack() : null), + this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()), + this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()) + ); +} - this.bb!.writeInt64(this.bb_pos + offset, value); - return true; - } - unionType(obj?: Type): Type | null { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset - ? (obj || new Type()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } - - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentation( - index: number, - optionalEncoding?: any, - ): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset - ? this.bb!.__string( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding, - ) - : null; - } - - documentationLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - attributes(index: number, obj?: KeyValue): KeyValue | null { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset - ? (obj || new KeyValue()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } - - attributesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - static getFullyQualifiedName(): string { - return 'reflection.EnumVal'; - } - - static startEnumVal(builder: flatbuffers.Builder) { - builder.startObject(6); - } - - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } - - static addValue(builder: flatbuffers.Builder, value: bigint) { - builder.addFieldInt64(1, value, BigInt('0')); - } - - static addUnionType( - builder: flatbuffers.Builder, - unionTypeOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(3, unionTypeOffset, 0); - } - - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(4, documentationOffset, 0); - } - - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } - - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(5, attributesOffset, 0); - } - - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startAttributesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static endEnumVal(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - return offset; - } - - unpack(): EnumValT { - return new EnumValT( - this.name(), - this.value(), - this.unionType() !== null ? this.unionType()!.unpack() : null, - this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ), - this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ), - ); - } - - unpackTo(_o: EnumValT): void { - _o.name = this.name(); - _o.value = this.value(); - _o.unionType = - this.unionType() !== null ? this.unionType()!.unpack() : null; - _o.documentation = this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ); - _o.attributes = this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ); - } +unpackTo(_o: EnumValT): void { + _o.name = this.name(); + _o.value = this.value(); + _o.unionType = (this.unionType() !== null ? this.unionType()!.unpack() : null); + _o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()); +} } export class EnumValT implements flatbuffers.IGeneratedObject { - constructor( - public name: string | Uint8Array | null = null, - public value: bigint = BigInt('0'), - public unionType: TypeT | null = null, - public documentation: string[] = [], - public attributes: KeyValueT[] = [], - ) {} +constructor( + public name: string|Uint8Array|null = null, + public value: bigint = BigInt('0'), + public unionType: TypeT|null = null, + public documentation: (string)[] = [], + public attributes: (KeyValueT)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const name = this.name !== null ? builder.createString(this.name!) : 0; - const unionType = - this.unionType !== null ? this.unionType!.pack(builder) : 0; - const documentation = EnumVal.createDocumentationVector( - builder, - builder.createObjectOffsetList(this.documentation), - ); - const attributes = EnumVal.createAttributesVector( - builder, - builder.createObjectOffsetList(this.attributes), - ); - EnumVal.startEnumVal(builder); - EnumVal.addName(builder, name); - EnumVal.addValue(builder, this.value); - EnumVal.addUnionType(builder, unionType); - EnumVal.addDocumentation(builder, documentation); - EnumVal.addAttributes(builder, attributes); +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const name = (this.name !== null ? builder.createString(this.name!) : 0); + const unionType = (this.unionType !== null ? this.unionType!.pack(builder) : 0); + const documentation = EnumVal.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const attributes = EnumVal.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); - return EnumVal.endEnumVal(builder); - } + EnumVal.startEnumVal(builder); + EnumVal.addName(builder, name); + EnumVal.addValue(builder, this.value); + EnumVal.addUnionType(builder, unionType); + EnumVal.addDocumentation(builder, documentation); + EnumVal.addAttributes(builder, attributes); + + return EnumVal.endEnumVal(builder); +} } diff --git a/tests/ts/reflection/enum.d.ts b/tests/ts/reflection/enum.d.ts index 4d5aaa069..ced18da7e 100644 --- a/tests/ts/reflection/enum.d.ts +++ b/tests/ts/reflection/enum.d.ts @@ -1,109 +1,57 @@ import * as flatbuffers from 'flatbuffers'; -import {EnumVal, EnumValT} from '../reflection/enum-val.js'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Type, TypeT} from '../reflection/type.js'; +import { EnumVal, EnumValT } from './enum-val.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Type, TypeT } from './type.js'; export declare class Enum implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Enum; - static getRootAsEnum(bb: flatbuffers.ByteBuffer, obj?: Enum): Enum; - static getSizePrefixedRootAsEnum( - bb: flatbuffers.ByteBuffer, - obj?: Enum, - ): Enum; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - values(index: number, obj?: EnumVal): EnumVal | null; - valuesLength(): number; - isUnion(): boolean; - mutate_is_union(value: boolean): boolean; - underlyingType(obj?: Type): Type | null; - attributes(index: number, obj?: KeyValue): KeyValue | null; - attributesLength(): number; - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentationLength(): number; - /** - * File that this Enum is declared in. - */ - declarationFile(): string | null; - declarationFile( - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array | null; - static getFullyQualifiedName(): string; - static startEnum(builder: flatbuffers.Builder): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addValues( - builder: flatbuffers.Builder, - valuesOffset: flatbuffers.Offset, - ): void; - static createValuesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startValuesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addIsUnion(builder: flatbuffers.Builder, isUnion: boolean): void; - static addUnderlyingType( - builder: flatbuffers.Builder, - underlyingTypeOffset: flatbuffers.Offset, - ): void; - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ): void; - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startAttributesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ): void; - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDeclarationFile( - builder: flatbuffers.Builder, - declarationFileOffset: flatbuffers.Offset, - ): void; - static endEnum(builder: flatbuffers.Builder): flatbuffers.Offset; - unpack(): EnumT; - unpackTo(_o: EnumT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Enum; + static getRootAsEnum(bb: flatbuffers.ByteBuffer, obj?: Enum): Enum; + static getSizePrefixedRootAsEnum(bb: flatbuffers.ByteBuffer, obj?: Enum): Enum; + name(): string; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + values(index: number, obj?: EnumVal): EnumVal | null; + valuesLength(): number; + isUnion(): boolean; + mutate_is_union(value: boolean): boolean; + underlyingType(obj?: Type): Type | null; + attributes(index: number, obj?: KeyValue): KeyValue | null; + attributesLength(): number; + documentation(index: number): string; + documentation(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + documentationLength(): number; + /** + * File that this Enum is declared in. + */ + declarationFile(): string | null; + declarationFile(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + static getFullyQualifiedName(): "reflection.Enum"; + static startEnum(builder: flatbuffers.Builder): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addValues(builder: flatbuffers.Builder, valuesOffset: flatbuffers.Offset): void; + static createValuesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startValuesVector(builder: flatbuffers.Builder, numElems: number): void; + static addIsUnion(builder: flatbuffers.Builder, isUnion: boolean): void; + static addUnderlyingType(builder: flatbuffers.Builder, underlyingTypeOffset: flatbuffers.Offset): void; + static addAttributes(builder: flatbuffers.Builder, attributesOffset: flatbuffers.Offset): void; + static createAttributesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startAttributesVector(builder: flatbuffers.Builder, numElems: number): void; + static addDocumentation(builder: flatbuffers.Builder, documentationOffset: flatbuffers.Offset): void; + static createDocumentationVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startDocumentationVector(builder: flatbuffers.Builder, numElems: number): void; + static addDeclarationFile(builder: flatbuffers.Builder, declarationFileOffset: flatbuffers.Offset): void; + static endEnum(builder: flatbuffers.Builder): flatbuffers.Offset; + unpack(): EnumT; + unpackTo(_o: EnumT): void; } export declare class EnumT implements flatbuffers.IGeneratedObject { - name: string | Uint8Array | null; - values: EnumValT[]; - isUnion: boolean; - underlyingType: TypeT | null; - attributes: KeyValueT[]; - documentation: string[]; - declarationFile: string | Uint8Array | null; - constructor( - name?: string | Uint8Array | null, - values?: EnumValT[], - isUnion?: boolean, - underlyingType?: TypeT | null, - attributes?: KeyValueT[], - documentation?: string[], - declarationFile?: string | Uint8Array | null, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + name: string | Uint8Array | null; + values: (EnumValT)[]; + isUnion: boolean; + underlyingType: TypeT | null; + attributes: (KeyValueT)[]; + documentation: (string)[]; + declarationFile: string | Uint8Array | null; + constructor(name?: string | Uint8Array | null, values?: (EnumValT)[], isUnion?: boolean, underlyingType?: TypeT | null, attributes?: (KeyValueT)[], documentation?: (string)[], declarationFile?: string | Uint8Array | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/enum.js b/tests/ts/reflection/enum.js index 87b294276..579c12a6f 100644 --- a/tests/ts/reflection/enum.js +++ b/tests/ts/reflection/enum.js @@ -1,225 +1,176 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {EnumVal} from '../reflection/enum-val.js'; -import {KeyValue} from '../reflection/key-value.js'; -import {Type} from '../reflection/type.js'; - +import { EnumVal } from './enum-val.js'; +import { KeyValue } from './key-value.js'; +import { Type } from './type.js'; export class Enum { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsEnum(bb, obj) { - return (obj || new Enum()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsEnum(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Enum()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - values(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? - (obj || new EnumVal()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - valuesLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - isUnion() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_is_union(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - underlyingType(obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? - (obj || new Type()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - attributes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? - (obj || new KeyValue()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - attributesLength() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - documentation(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - documentationLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - declarationFile(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - static getFullyQualifiedName() { - return 'reflection.Enum'; - } - static startEnum(builder) { - builder.startObject(7); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(0, nameOffset, 0); - } - static addValues(builder, valuesOffset) { - builder.addFieldOffset(1, valuesOffset, 0); - } - static createValuesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - return builder.endVector(); - } - static startValuesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addIsUnion(builder, isUnion) { - builder.addFieldInt8(2, +isUnion, +false); - } - static addUnderlyingType(builder, underlyingTypeOffset) { - builder.addFieldOffset(3, underlyingTypeOffset, 0); - } - static addAttributes(builder, attributesOffset) { - builder.addFieldOffset(4, attributesOffset, 0); - } - static createAttributesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static getRootAsEnum(bb, obj) { + return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - return builder.endVector(); - } - static startAttributesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDocumentation(builder, documentationOffset) { - builder.addFieldOffset(5, documentationOffset, 0); - } - static createDocumentationVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static getSizePrefixedRootAsEnum(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); + } + values(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new EnumVal()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + valuesLength() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + isUnion() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_is_union(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + underlyingType(obj) { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? (obj || new Type()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + attributes(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + attributesLength() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + documentation(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + documentationLength() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + declarationFile(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + static getFullyQualifiedName() { + return 'reflection.Enum'; + } + static startEnum(builder) { + builder.startObject(7); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + static addValues(builder, valuesOffset) { + builder.addFieldOffset(1, valuesOffset, 0); + } + static createValuesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startValuesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addIsUnion(builder, isUnion) { + builder.addFieldInt8(2, +isUnion, +false); + } + static addUnderlyingType(builder, underlyingTypeOffset) { + builder.addFieldOffset(3, underlyingTypeOffset, 0); + } + static addAttributes(builder, attributesOffset) { + builder.addFieldOffset(4, attributesOffset, 0); + } + static createAttributesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startAttributesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDocumentation(builder, documentationOffset) { + builder.addFieldOffset(5, documentationOffset, 0); + } + static createDocumentationVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startDocumentationVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDeclarationFile(builder, declarationFileOffset) { + builder.addFieldOffset(6, declarationFileOffset, 0); + } + static endEnum(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // name + builder.requiredField(offset, 6); // values + builder.requiredField(offset, 10); // underlying_type + return offset; + } + unpack() { + return new EnumT(this.name(), this.bb.createObjList(this.values.bind(this), this.valuesLength()), this.isUnion(), (this.underlyingType() !== null ? this.underlyingType().unpack() : null), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.declarationFile()); + } + unpackTo(_o) { + _o.name = this.name(); + _o.values = this.bb.createObjList(this.values.bind(this), this.valuesLength()); + _o.isUnion = this.isUnion(); + _o.underlyingType = (this.underlyingType() !== null ? this.underlyingType().unpack() : null); + _o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.declarationFile = this.declarationFile(); } - return builder.endVector(); - } - static startDocumentationVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDeclarationFile(builder, declarationFileOffset) { - builder.addFieldOffset(6, declarationFileOffset, 0); - } - static endEnum(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // values - builder.requiredField(offset, 10); // underlying_type - return offset; - } - unpack() { - return new EnumT( - this.name(), - this.bb.createObjList(this.values.bind(this), this.valuesLength()), - this.isUnion(), - (this.underlyingType() !== null ? this.underlyingType().unpack() : - null), - this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()), - this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()), - this.declarationFile()); - } - unpackTo(_o) { - _o.name = this.name(); - _o.values = - this.bb.createObjList(this.values.bind(this), this.valuesLength()); - _o.isUnion = this.isUnion(); - _o.underlyingType = - (this.underlyingType() !== null ? this.underlyingType().unpack() : - null); - _o.attributes = this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()); - _o.documentation = this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()); - _o.declarationFile = this.declarationFile(); - } } export class EnumT { - constructor( - name = null, values = [], isUnion = false, underlyingType = null, - attributes = [], documentation = [], declarationFile = null) { - this.name = name; - this.values = values; - this.isUnion = isUnion; - this.underlyingType = underlyingType; - this.attributes = attributes; - this.documentation = documentation; - this.declarationFile = declarationFile; - } - pack(builder) { - const name = (this.name !== null ? builder.createString(this.name) : 0); - const values = Enum.createValuesVector( - builder, builder.createObjectOffsetList(this.values)); - const underlyingType = - (this.underlyingType !== null ? this.underlyingType.pack(builder) : 0); - const attributes = Enum.createAttributesVector( - builder, builder.createObjectOffsetList(this.attributes)); - const documentation = Enum.createDocumentationVector( - builder, builder.createObjectOffsetList(this.documentation)); - const declarationFile = - (this.declarationFile !== null ? - builder.createString(this.declarationFile) : - 0); - Enum.startEnum(builder); - Enum.addName(builder, name); - Enum.addValues(builder, values); - Enum.addIsUnion(builder, this.isUnion); - Enum.addUnderlyingType(builder, underlyingType); - Enum.addAttributes(builder, attributes); - Enum.addDocumentation(builder, documentation); - Enum.addDeclarationFile(builder, declarationFile); - return Enum.endEnum(builder); - } + constructor(name = null, values = [], isUnion = false, underlyingType = null, attributes = [], documentation = [], declarationFile = null) { + this.name = name; + this.values = values; + this.isUnion = isUnion; + this.underlyingType = underlyingType; + this.attributes = attributes; + this.documentation = documentation; + this.declarationFile = declarationFile; + } + pack(builder) { + const name = (this.name !== null ? builder.createString(this.name) : 0); + const values = Enum.createValuesVector(builder, builder.createObjectOffsetList(this.values)); + const underlyingType = (this.underlyingType !== null ? this.underlyingType.pack(builder) : 0); + const attributes = Enum.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Enum.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile) : 0); + Enum.startEnum(builder); + Enum.addName(builder, name); + Enum.addValues(builder, values); + Enum.addIsUnion(builder, this.isUnion); + Enum.addUnderlyingType(builder, underlyingType); + Enum.addAttributes(builder, attributes); + Enum.addDocumentation(builder, documentation); + Enum.addDeclarationFile(builder, declarationFile); + return Enum.endEnum(builder); + } } diff --git a/tests/ts/reflection/enum.ts b/tests/ts/reflection/enum.ts index f76f14630..2b3751536 100644 --- a/tests/ts/reflection/enum.ts +++ b/tests/ts/reflection/enum.ts @@ -4,333 +4,233 @@ import * as flatbuffers from 'flatbuffers'; -import {EnumVal, EnumValT} from '../reflection/enum-val.js'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Type, TypeT} from '../reflection/type.js'; +import { EnumVal, EnumValT } from './enum-val.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Type, TypeT } from './type.js'; + export class Enum implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Enum { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Enum { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsEnum(bb:flatbuffers.ByteBuffer, obj?:Enum):Enum { + return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsEnum(bb:flatbuffers.ByteBuffer, obj?:Enum):Enum { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Enum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +name():string +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +name(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} + +values(index: number, obj?:EnumVal):EnumVal|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new EnumVal()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +valuesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +isUnion():boolean { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +mutate_is_union(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 8); + + if (offset === 0) { + return false; } - static getRootAsEnum(bb: flatbuffers.ByteBuffer, obj?: Enum): Enum { - return (obj || new Enum()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} + +underlyingType(obj?:Type):Type|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? (obj || new Type()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} + +attributes(index: number, obj?:KeyValue):KeyValue|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +attributesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +documentation(index: number):string +documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +documentation(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} + +documentationLength():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +/** + * File that this Enum is declared in. + */ +declarationFile():string|null +declarationFile(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +declarationFile(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} + +static getFullyQualifiedName(): "reflection.Enum" { + return 'reflection.Enum'; +} + +static startEnum(builder:flatbuffers.Builder):void { + builder.startObject(7); +} + +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} + +static addValues(builder:flatbuffers.Builder, valuesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, valuesOffset, 0); +} + +static createValuesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static getSizePrefixedRootAsEnum( - bb: flatbuffers.ByteBuffer, - obj?: Enum, - ): Enum { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Enum()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); +static startValuesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addIsUnion(builder:flatbuffers.Builder, isUnion:boolean):void { + builder.addFieldInt8(2, +isUnion, +false); +} + +static addUnderlyingType(builder:flatbuffers.Builder, underlyingTypeOffset:flatbuffers.Offset):void { + builder.addFieldOffset(3, underlyingTypeOffset, 0); +} + +static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(4, attributesOffset, 0); +} + +static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; +static startAttributesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset):void { + builder.addFieldOffset(5, documentationOffset, 0); +} + +static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - values(index: number, obj?: EnumVal): EnumVal | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? (obj || new EnumVal()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } +static startDocumentationVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - valuesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +static addDeclarationFile(builder:flatbuffers.Builder, declarationFileOffset:flatbuffers.Offset):void { + builder.addFieldOffset(6, declarationFileOffset, 0); +} - isUnion(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } +static endEnum(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // name + builder.requiredField(offset, 6) // values + builder.requiredField(offset, 10) // underlying_type + return offset; +} - mutate_is_union(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; - } +unpack(): EnumT { + return new EnumT( + this.name(), + this.bb!.createObjList(this.values.bind(this), this.valuesLength()), + this.isUnion(), + (this.underlyingType() !== null ? this.underlyingType()!.unpack() : null), + this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()), + this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()), + this.declarationFile() + ); +} - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } - underlyingType(obj?: Type): Type | null { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset - ? (obj || new Type()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } - - attributes(index: number, obj?: KeyValue): KeyValue | null { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset - ? (obj || new KeyValue()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } - - attributesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentation( - index: number, - optionalEncoding?: any, - ): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset - ? this.bb!.__string( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding, - ) - : null; - } - - documentationLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - /** - * File that this Enum is declared in. - */ - declarationFile(): string | null; - declarationFile( - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array | null; - declarationFile(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 16); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } - - static getFullyQualifiedName(): string { - return 'reflection.Enum'; - } - - static startEnum(builder: flatbuffers.Builder) { - builder.startObject(7); - } - - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } - - static addValues( - builder: flatbuffers.Builder, - valuesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, valuesOffset, 0); - } - - static createValuesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startValuesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addIsUnion(builder: flatbuffers.Builder, isUnion: boolean) { - builder.addFieldInt8(2, +isUnion, +false); - } - - static addUnderlyingType( - builder: flatbuffers.Builder, - underlyingTypeOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(3, underlyingTypeOffset, 0); - } - - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(4, attributesOffset, 0); - } - - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startAttributesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(5, documentationOffset, 0); - } - - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } - - static addDeclarationFile( - builder: flatbuffers.Builder, - declarationFileOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(6, declarationFileOffset, 0); - } - - static endEnum(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // values - builder.requiredField(offset, 10); // underlying_type - return offset; - } - - unpack(): EnumT { - return new EnumT( - this.name(), - this.bb!.createObjList( - this.values.bind(this), - this.valuesLength(), - ), - this.isUnion(), - this.underlyingType() !== null ? this.underlyingType()!.unpack() : null, - this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ), - this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ), - this.declarationFile(), - ); - } - - unpackTo(_o: EnumT): void { - _o.name = this.name(); - _o.values = this.bb!.createObjList( - this.values.bind(this), - this.valuesLength(), - ); - _o.isUnion = this.isUnion(); - _o.underlyingType = - this.underlyingType() !== null ? this.underlyingType()!.unpack() : null; - _o.attributes = this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ); - _o.documentation = this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ); - _o.declarationFile = this.declarationFile(); - } +unpackTo(_o: EnumT): void { + _o.name = this.name(); + _o.values = this.bb!.createObjList(this.values.bind(this), this.valuesLength()); + _o.isUnion = this.isUnion(); + _o.underlyingType = (this.underlyingType() !== null ? this.underlyingType()!.unpack() : null); + _o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.declarationFile = this.declarationFile(); +} } export class EnumT implements flatbuffers.IGeneratedObject { - constructor( - public name: string | Uint8Array | null = null, - public values: EnumValT[] = [], - public isUnion: boolean = false, - public underlyingType: TypeT | null = null, - public attributes: KeyValueT[] = [], - public documentation: string[] = [], - public declarationFile: string | Uint8Array | null = null, - ) {} +constructor( + public name: string|Uint8Array|null = null, + public values: (EnumValT)[] = [], + public isUnion: boolean = false, + public underlyingType: TypeT|null = null, + public attributes: (KeyValueT)[] = [], + public documentation: (string)[] = [], + public declarationFile: string|Uint8Array|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const name = this.name !== null ? builder.createString(this.name!) : 0; - const values = Enum.createValuesVector( - builder, - builder.createObjectOffsetList(this.values), - ); - const underlyingType = - this.underlyingType !== null ? this.underlyingType!.pack(builder) : 0; - const attributes = Enum.createAttributesVector( - builder, - builder.createObjectOffsetList(this.attributes), - ); - const documentation = Enum.createDocumentationVector( - builder, - builder.createObjectOffsetList(this.documentation), - ); - const declarationFile = - this.declarationFile !== null - ? builder.createString(this.declarationFile!) - : 0; - Enum.startEnum(builder); - Enum.addName(builder, name); - Enum.addValues(builder, values); - Enum.addIsUnion(builder, this.isUnion); - Enum.addUnderlyingType(builder, underlyingType); - Enum.addAttributes(builder, attributes); - Enum.addDocumentation(builder, documentation); - Enum.addDeclarationFile(builder, declarationFile); +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const name = (this.name !== null ? builder.createString(this.name!) : 0); + const values = Enum.createValuesVector(builder, builder.createObjectOffsetList(this.values)); + const underlyingType = (this.underlyingType !== null ? this.underlyingType!.pack(builder) : 0); + const attributes = Enum.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Enum.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile!) : 0); - return Enum.endEnum(builder); - } + Enum.startEnum(builder); + Enum.addName(builder, name); + Enum.addValues(builder, values); + Enum.addIsUnion(builder, this.isUnion); + Enum.addUnderlyingType(builder, underlyingType); + Enum.addAttributes(builder, attributes); + Enum.addDocumentation(builder, documentation); + Enum.addDeclarationFile(builder, declarationFile); + + return Enum.endEnum(builder); +} } diff --git a/tests/ts/reflection/field.d.ts b/tests/ts/reflection/field.d.ts index a7d5077fe..3e4d6fc93 100644 --- a/tests/ts/reflection/field.d.ts +++ b/tests/ts/reflection/field.d.ts @@ -1,136 +1,85 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Type, TypeT} from '../reflection/type.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Type, TypeT } from './type.js'; export declare class Field implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Field; - static getRootAsField(bb: flatbuffers.ByteBuffer, obj?: Field): Field; - static getSizePrefixedRootAsField( - bb: flatbuffers.ByteBuffer, - obj?: Field, - ): Field; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - type(obj?: Type): Type | null; - id(): number; - mutate_id(value: number): boolean; - offset(): number; - mutate_offset(value: number): boolean; - defaultInteger(): bigint; - mutate_default_integer(value: bigint): boolean; - defaultReal(): number; - mutate_default_real(value: number): boolean; - deprecated(): boolean; - mutate_deprecated(value: boolean): boolean; - required(): boolean; - mutate_required(value: boolean): boolean; - key(): boolean; - mutate_key(value: boolean): boolean; - attributes(index: number, obj?: KeyValue): KeyValue | null; - attributesLength(): number; - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentationLength(): number; - optional(): boolean; - mutate_optional(value: boolean): boolean; - /** - * Number of padding octets to always add after this field. Structs only. - */ - padding(): number; - mutate_padding(value: number): boolean; - /** - * If the field uses 64-bit offsets. - */ - offset64(): boolean; - mutate_offset64(value: boolean): boolean; - static getFullyQualifiedName(): string; - static startField(builder: flatbuffers.Builder): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addType( - builder: flatbuffers.Builder, - typeOffset: flatbuffers.Offset, - ): void; - static addId(builder: flatbuffers.Builder, id: number): void; - static addOffset(builder: flatbuffers.Builder, offset: number): void; - static addDefaultInteger( - builder: flatbuffers.Builder, - defaultInteger: bigint, - ): void; - static addDefaultReal( - builder: flatbuffers.Builder, - defaultReal: number, - ): void; - static addDeprecated(builder: flatbuffers.Builder, deprecated: boolean): void; - static addRequired(builder: flatbuffers.Builder, required: boolean): void; - static addKey(builder: flatbuffers.Builder, key: boolean): void; - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ): void; - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startAttributesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ): void; - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addOptional(builder: flatbuffers.Builder, optional: boolean): void; - static addPadding(builder: flatbuffers.Builder, padding: number): void; - static addOffset64(builder: flatbuffers.Builder, offset64: boolean): void; - static endField(builder: flatbuffers.Builder): flatbuffers.Offset; - unpack(): FieldT; - unpackTo(_o: FieldT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Field; + static getRootAsField(bb: flatbuffers.ByteBuffer, obj?: Field): Field; + static getSizePrefixedRootAsField(bb: flatbuffers.ByteBuffer, obj?: Field): Field; + name(): string; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + type(obj?: Type): Type | null; + id(): number; + mutate_id(value: number): boolean; + offset(): number; + mutate_offset(value: number): boolean; + defaultInteger(): bigint; + mutate_default_integer(value: bigint): boolean; + defaultReal(): number; + mutate_default_real(value: number): boolean; + deprecated(): boolean; + mutate_deprecated(value: boolean): boolean; + required(): boolean; + mutate_required(value: boolean): boolean; + key(): boolean; + mutate_key(value: boolean): boolean; + attributes(index: number, obj?: KeyValue): KeyValue | null; + attributesLength(): number; + documentation(index: number): string; + documentation(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + documentationLength(): number; + optional(): boolean; + mutate_optional(value: boolean): boolean; + /** + * Number of padding octets to always add after this field. Structs only. + */ + padding(): number; + mutate_padding(value: number): boolean; + /** + * If the field uses 64-bit offsets. + */ + offset64(): boolean; + mutate_offset64(value: boolean): boolean; + static getFullyQualifiedName(): "reflection.Field"; + static startField(builder: flatbuffers.Builder): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addType(builder: flatbuffers.Builder, typeOffset: flatbuffers.Offset): void; + static addId(builder: flatbuffers.Builder, id: number): void; + static addOffset(builder: flatbuffers.Builder, offset: number): void; + static addDefaultInteger(builder: flatbuffers.Builder, defaultInteger: bigint): void; + static addDefaultReal(builder: flatbuffers.Builder, defaultReal: number): void; + static addDeprecated(builder: flatbuffers.Builder, deprecated: boolean): void; + static addRequired(builder: flatbuffers.Builder, required: boolean): void; + static addKey(builder: flatbuffers.Builder, key: boolean): void; + static addAttributes(builder: flatbuffers.Builder, attributesOffset: flatbuffers.Offset): void; + static createAttributesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startAttributesVector(builder: flatbuffers.Builder, numElems: number): void; + static addDocumentation(builder: flatbuffers.Builder, documentationOffset: flatbuffers.Offset): void; + static createDocumentationVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startDocumentationVector(builder: flatbuffers.Builder, numElems: number): void; + static addOptional(builder: flatbuffers.Builder, optional: boolean): void; + static addPadding(builder: flatbuffers.Builder, padding: number): void; + static addOffset64(builder: flatbuffers.Builder, offset64: boolean): void; + static endField(builder: flatbuffers.Builder): flatbuffers.Offset; + unpack(): FieldT; + unpackTo(_o: FieldT): void; } export declare class FieldT implements flatbuffers.IGeneratedObject { - name: string | Uint8Array | null; - type: TypeT | null; - id: number; - offset: number; - defaultInteger: bigint; - defaultReal: number; - deprecated: boolean; - required: boolean; - key: boolean; - attributes: KeyValueT[]; - documentation: string[]; - optional: boolean; - padding: number; - offset64: boolean; - constructor( - name?: string | Uint8Array | null, - type?: TypeT | null, - id?: number, - offset?: number, - defaultInteger?: bigint, - defaultReal?: number, - deprecated?: boolean, - required?: boolean, - key?: boolean, - attributes?: KeyValueT[], - documentation?: string[], - optional?: boolean, - padding?: number, - offset64?: boolean, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + name: string | Uint8Array | null; + type: TypeT | null; + id: number; + offset: number; + defaultInteger: bigint; + defaultReal: number; + deprecated: boolean; + required: boolean; + key: boolean; + attributes: (KeyValueT)[]; + documentation: (string)[]; + optional: boolean; + padding: number; + offset64: boolean; + constructor(name?: string | Uint8Array | null, type?: TypeT | null, id?: number, offset?: number, defaultInteger?: bigint, defaultReal?: number, deprecated?: boolean, required?: boolean, key?: boolean, attributes?: (KeyValueT)[], documentation?: (string)[], optional?: boolean, padding?: number, offset64?: boolean); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/field.js b/tests/ts/reflection/field.js index 0dceec4f0..054725d88 100644 --- a/tests/ts/reflection/field.js +++ b/tests/ts/reflection/field.js @@ -1,340 +1,306 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {KeyValue} from '../reflection/key-value.js'; -import {Type} from '../reflection/type.js'; - +import { KeyValue } from './key-value.js'; +import { Type } from './type.js'; export class Field { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsField(bb, obj) { - return (obj || new Field()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsField(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Field()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - type(obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? - (obj || new Type()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - id() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - mutate_id(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeUint16(this.bb_pos + offset, value); - return true; - } - offset() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - mutate_offset(value) { - const offset = this.bb.__offset(this.bb_pos, 10); - if (offset === 0) { - return false; + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - this.bb.writeUint16(this.bb_pos + offset, value); - return true; - } - defaultInteger() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); - } - mutate_default_integer(value) { - const offset = this.bb.__offset(this.bb_pos, 12); - if (offset === 0) { - return false; + static getRootAsField(bb, obj) { + return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeInt64(this.bb_pos + offset, value); - return true; - } - defaultReal() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0; - } - mutate_default_real(value) { - const offset = this.bb.__offset(this.bb_pos, 14); - if (offset === 0) { - return false; + static getSizePrefixedRootAsField(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeFloat64(this.bb_pos + offset, value); - return true; - } - deprecated() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_deprecated(value) { - const offset = this.bb.__offset(this.bb_pos, 16); - if (offset === 0) { - return false; + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - required() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_required(value) { - const offset = this.bb.__offset(this.bb_pos, 18); - if (offset === 0) { - return false; + type(obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new Type()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - key() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_key(value) { - const offset = this.bb.__offset(this.bb_pos, 20); - if (offset === 0) { - return false; + id() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - attributes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 22); - return offset ? - (obj || new KeyValue()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - attributesLength() { - const offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - documentation(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - documentationLength() { - const offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - optional() { - const offset = this.bb.__offset(this.bb_pos, 26); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_optional(value) { - const offset = this.bb.__offset(this.bb_pos, 26); - if (offset === 0) { - return false; + mutate_id(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeUint16(this.bb_pos + offset, value); + return true; } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - /** - * Number of padding octets to always add after this field. Structs only. - */ - padding() { - const offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - mutate_padding(value) { - const offset = this.bb.__offset(this.bb_pos, 28); - if (offset === 0) { - return false; + offset() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; } - this.bb.writeUint16(this.bb_pos + offset, value); - return true; - } - /** - * If the field uses 64-bit offsets. - */ - offset64() { - const offset = this.bb.__offset(this.bb_pos, 30); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_offset64(value) { - const offset = this.bb.__offset(this.bb_pos, 30); - if (offset === 0) { - return false; + mutate_offset(value) { + const offset = this.bb.__offset(this.bb_pos, 10); + if (offset === 0) { + return false; + } + this.bb.writeUint16(this.bb_pos + offset, value); + return true; } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - static getFullyQualifiedName() { - return 'reflection.Field'; - } - static startField(builder) { - builder.startObject(14); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(0, nameOffset, 0); - } - static addType(builder, typeOffset) { - builder.addFieldOffset(1, typeOffset, 0); - } - static addId(builder, id) { - builder.addFieldInt16(2, id, 0); - } - static addOffset(builder, offset) { - builder.addFieldInt16(3, offset, 0); - } - static addDefaultInteger(builder, defaultInteger) { - builder.addFieldInt64(4, defaultInteger, BigInt('0')); - } - static addDefaultReal(builder, defaultReal) { - builder.addFieldFloat64(5, defaultReal, 0.0); - } - static addDeprecated(builder, deprecated) { - builder.addFieldInt8(6, +deprecated, +false); - } - static addRequired(builder, required) { - builder.addFieldInt8(7, +required, +false); - } - static addKey(builder, key) { - builder.addFieldInt8(8, +key, +false); - } - static addAttributes(builder, attributesOffset) { - builder.addFieldOffset(9, attributesOffset, 0); - } - static createAttributesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + defaultInteger() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); } - return builder.endVector(); - } - static startAttributesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDocumentation(builder, documentationOffset) { - builder.addFieldOffset(10, documentationOffset, 0); - } - static createDocumentationVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + mutate_default_integer(value) { + const offset = this.bb.__offset(this.bb_pos, 12); + if (offset === 0) { + return false; + } + this.bb.writeInt64(this.bb_pos + offset, value); + return true; + } + defaultReal() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.readFloat64(this.bb_pos + offset) : 0.0; + } + mutate_default_real(value) { + const offset = this.bb.__offset(this.bb_pos, 14); + if (offset === 0) { + return false; + } + this.bb.writeFloat64(this.bb_pos + offset, value); + return true; + } + deprecated() { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_deprecated(value) { + const offset = this.bb.__offset(this.bb_pos, 16); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + required() { + const offset = this.bb.__offset(this.bb_pos, 18); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_required(value) { + const offset = this.bb.__offset(this.bb_pos, 18); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + key() { + const offset = this.bb.__offset(this.bb_pos, 20); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_key(value) { + const offset = this.bb.__offset(this.bb_pos, 20); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + attributes(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 22); + return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + attributesLength() { + const offset = this.bb.__offset(this.bb_pos, 22); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + documentation(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + documentationLength() { + const offset = this.bb.__offset(this.bb_pos, 24); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + optional() { + const offset = this.bb.__offset(this.bb_pos, 26); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_optional(value) { + const offset = this.bb.__offset(this.bb_pos, 26); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + /** + * Number of padding octets to always add after this field. Structs only. + */ + padding() { + const offset = this.bb.__offset(this.bb_pos, 28); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; + } + mutate_padding(value) { + const offset = this.bb.__offset(this.bb_pos, 28); + if (offset === 0) { + return false; + } + this.bb.writeUint16(this.bb_pos + offset, value); + return true; + } + /** + * If the field uses 64-bit offsets. + */ + offset64() { + const offset = this.bb.__offset(this.bb_pos, 30); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_offset64(value) { + const offset = this.bb.__offset(this.bb_pos, 30); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + static getFullyQualifiedName() { + return 'reflection.Field'; + } + static startField(builder) { + builder.startObject(14); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + static addType(builder, typeOffset) { + builder.addFieldOffset(1, typeOffset, 0); + } + static addId(builder, id) { + builder.addFieldInt16(2, id, 0); + } + static addOffset(builder, offset) { + builder.addFieldInt16(3, offset, 0); + } + static addDefaultInteger(builder, defaultInteger) { + builder.addFieldInt64(4, defaultInteger, BigInt('0')); + } + static addDefaultReal(builder, defaultReal) { + builder.addFieldFloat64(5, defaultReal, 0.0); + } + static addDeprecated(builder, deprecated) { + builder.addFieldInt8(6, +deprecated, +false); + } + static addRequired(builder, required) { + builder.addFieldInt8(7, +required, +false); + } + static addKey(builder, key) { + builder.addFieldInt8(8, +key, +false); + } + static addAttributes(builder, attributesOffset) { + builder.addFieldOffset(9, attributesOffset, 0); + } + static createAttributesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startAttributesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDocumentation(builder, documentationOffset) { + builder.addFieldOffset(10, documentationOffset, 0); + } + static createDocumentationVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startDocumentationVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addOptional(builder, optional) { + builder.addFieldInt8(11, +optional, +false); + } + static addPadding(builder, padding) { + builder.addFieldInt16(12, padding, 0); + } + static addOffset64(builder, offset64) { + builder.addFieldInt8(13, +offset64, +false); + } + static endField(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // name + builder.requiredField(offset, 6); // type + return offset; + } + unpack() { + return new FieldT(this.name(), (this.type() !== null ? this.type().unpack() : null), this.id(), this.offset(), this.defaultInteger(), this.defaultReal(), this.deprecated(), this.required(), this.key(), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.optional(), this.padding(), this.offset64()); + } + unpackTo(_o) { + _o.name = this.name(); + _o.type = (this.type() !== null ? this.type().unpack() : null); + _o.id = this.id(); + _o.offset = this.offset(); + _o.defaultInteger = this.defaultInteger(); + _o.defaultReal = this.defaultReal(); + _o.deprecated = this.deprecated(); + _o.required = this.required(); + _o.key = this.key(); + _o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.optional = this.optional(); + _o.padding = this.padding(); + _o.offset64 = this.offset64(); } - return builder.endVector(); - } - static startDocumentationVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addOptional(builder, optional) { - builder.addFieldInt8(11, +optional, +false); - } - static addPadding(builder, padding) { - builder.addFieldInt16(12, padding, 0); - } - static addOffset64(builder, offset64) { - builder.addFieldInt8(13, +offset64, +false); - } - static endField(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // type - return offset; - } - unpack() { - return new FieldT( - this.name(), (this.type() !== null ? this.type().unpack() : null), - this.id(), this.offset(), this.defaultInteger(), this.defaultReal(), - this.deprecated(), this.required(), this.key(), - this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()), - this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()), - this.optional(), this.padding(), this.offset64()); - } - unpackTo(_o) { - _o.name = this.name(); - _o.type = (this.type() !== null ? this.type().unpack() : null); - _o.id = this.id(); - _o.offset = this.offset(); - _o.defaultInteger = this.defaultInteger(); - _o.defaultReal = this.defaultReal(); - _o.deprecated = this.deprecated(); - _o.required = this.required(); - _o.key = this.key(); - _o.attributes = this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()); - _o.documentation = this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()); - _o.optional = this.optional(); - _o.padding = this.padding(); - _o.offset64 = this.offset64(); - } } export class FieldT { - constructor( - name = null, type = null, id = 0, offset = 0, - defaultInteger = BigInt('0'), defaultReal = 0.0, deprecated = false, - required = false, key = false, attributes = [], documentation = [], - optional = false, padding = 0, offset64 = false) { - this.name = name; - this.type = type; - this.id = id; - this.offset = offset; - this.defaultInteger = defaultInteger; - this.defaultReal = defaultReal; - this.deprecated = deprecated; - this.required = required; - this.key = key; - this.attributes = attributes; - this.documentation = documentation; - this.optional = optional; - this.padding = padding; - this.offset64 = offset64; - } - pack(builder) { - const name = (this.name !== null ? builder.createString(this.name) : 0); - const type = (this.type !== null ? this.type.pack(builder) : 0); - const attributes = Field.createAttributesVector( - builder, builder.createObjectOffsetList(this.attributes)); - const documentation = Field.createDocumentationVector( - builder, builder.createObjectOffsetList(this.documentation)); - Field.startField(builder); - Field.addName(builder, name); - Field.addType(builder, type); - Field.addId(builder, this.id); - Field.addOffset(builder, this.offset); - Field.addDefaultInteger(builder, this.defaultInteger); - Field.addDefaultReal(builder, this.defaultReal); - Field.addDeprecated(builder, this.deprecated); - Field.addRequired(builder, this.required); - Field.addKey(builder, this.key); - Field.addAttributes(builder, attributes); - Field.addDocumentation(builder, documentation); - Field.addOptional(builder, this.optional); - Field.addPadding(builder, this.padding); - Field.addOffset64(builder, this.offset64); - return Field.endField(builder); - } + constructor(name = null, type = null, id = 0, offset = 0, defaultInteger = BigInt('0'), defaultReal = 0.0, deprecated = false, required = false, key = false, attributes = [], documentation = [], optional = false, padding = 0, offset64 = false) { + this.name = name; + this.type = type; + this.id = id; + this.offset = offset; + this.defaultInteger = defaultInteger; + this.defaultReal = defaultReal; + this.deprecated = deprecated; + this.required = required; + this.key = key; + this.attributes = attributes; + this.documentation = documentation; + this.optional = optional; + this.padding = padding; + this.offset64 = offset64; + } + pack(builder) { + const name = (this.name !== null ? builder.createString(this.name) : 0); + const type = (this.type !== null ? this.type.pack(builder) : 0); + const attributes = Field.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Field.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + Field.startField(builder); + Field.addName(builder, name); + Field.addType(builder, type); + Field.addId(builder, this.id); + Field.addOffset(builder, this.offset); + Field.addDefaultInteger(builder, this.defaultInteger); + Field.addDefaultReal(builder, this.defaultReal); + Field.addDeprecated(builder, this.deprecated); + Field.addRequired(builder, this.required); + Field.addKey(builder, this.key); + Field.addAttributes(builder, attributes); + Field.addDocumentation(builder, documentation); + Field.addOptional(builder, this.optional); + Field.addPadding(builder, this.padding); + Field.addOffset64(builder, this.offset64); + return Field.endField(builder); + } } diff --git a/tests/ts/reflection/field.ts b/tests/ts/reflection/field.ts index 7f8eefd28..a116aef6c 100644 --- a/tests/ts/reflection/field.ts +++ b/tests/ts/reflection/field.ts @@ -4,469 +4,403 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Type, TypeT} from '../reflection/type.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Type, TypeT } from './type.js'; + export class Field implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Field { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Field { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsField(bb:flatbuffers.ByteBuffer, obj?:Field):Field { + return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsField(bb:flatbuffers.ByteBuffer, obj?:Field):Field { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Field()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +name():string +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +name(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} + +type(obj?:Type):Type|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new Type()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} + +id():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; +} + +mutate_id(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 8); + + if (offset === 0) { + return false; } - static getRootAsField(bb: flatbuffers.ByteBuffer, obj?: Field): Field { - return (obj || new Field()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeUint16(this.bb_pos + offset, value); + return true; +} + +offset():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; +} + +mutate_offset(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 10); + + if (offset === 0) { + return false; } - static getSizePrefixedRootAsField( - bb: flatbuffers.ByteBuffer, - obj?: Field, - ): Field { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Field()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeUint16(this.bb_pos + offset, value); + return true; +} + +defaultInteger():bigint { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); +} + +mutate_default_integer(value:bigint):boolean { + const offset = this.bb!.__offset(this.bb_pos, 12); + + if (offset === 0) { + return false; } - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; + this.bb!.writeInt64(this.bb_pos + offset, value); + return true; +} + +defaultReal():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0; +} + +mutate_default_real(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 14); + + if (offset === 0) { + return false; } - type(obj?: Type): Type | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? (obj || new Type()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; + this.bb!.writeFloat64(this.bb_pos + offset, value); + return true; +} + +deprecated():boolean { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +mutate_deprecated(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 16); + + if (offset === 0) { + return false; } - id(): number { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} + +required():boolean { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +mutate_required(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 18); + + if (offset === 0) { + return false; } - mutate_id(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 8); + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} - if (offset === 0) { - return false; - } +key():boolean { + const offset = this.bb!.__offset(this.bb_pos, 20); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} - this.bb!.writeUint16(this.bb_pos + offset, value); - return true; +mutate_key(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 20); + + if (offset === 0) { + return false; } - offset(): number { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} + +attributes(index: number, obj?:KeyValue):KeyValue|null { + const offset = this.bb!.__offset(this.bb_pos, 22); + return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +attributesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 22); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +documentation(index: number):string +documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +documentation(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 24); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} + +documentationLength():number { + const offset = this.bb!.__offset(this.bb_pos, 24); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +optional():boolean { + const offset = this.bb!.__offset(this.bb_pos, 26); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +mutate_optional(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 26); + + if (offset === 0) { + return false; } - mutate_offset(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 10); + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} - if (offset === 0) { - return false; - } +/** + * Number of padding octets to always add after this field. Structs only. + */ +padding():number { + const offset = this.bb!.__offset(this.bb_pos, 28); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; +} - this.bb!.writeUint16(this.bb_pos + offset, value); - return true; +mutate_padding(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 28); + + if (offset === 0) { + return false; } - defaultInteger(): bigint { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); + this.bb!.writeUint16(this.bb_pos + offset, value); + return true; +} + +/** + * If the field uses 64-bit offsets. + */ +offset64():boolean { + const offset = this.bb!.__offset(this.bb_pos, 30); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +mutate_offset64(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 30); + + if (offset === 0) { + return false; } - mutate_default_integer(value: bigint): boolean { - const offset = this.bb!.__offset(this.bb_pos, 12); + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} - if (offset === 0) { - return false; - } +static getFullyQualifiedName(): "reflection.Field" { + return 'reflection.Field'; +} - this.bb!.writeInt64(this.bb_pos + offset, value); - return true; +static startField(builder:flatbuffers.Builder):void { + builder.startObject(14); +} + +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} + +static addType(builder:flatbuffers.Builder, typeOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, typeOffset, 0); +} + +static addId(builder:flatbuffers.Builder, id:number):void { + builder.addFieldInt16(2, id, 0); +} + +static addOffset(builder:flatbuffers.Builder, offset:number):void { + builder.addFieldInt16(3, offset, 0); +} + +static addDefaultInteger(builder:flatbuffers.Builder, defaultInteger:bigint):void { + builder.addFieldInt64(4, defaultInteger, BigInt('0')); +} + +static addDefaultReal(builder:flatbuffers.Builder, defaultReal:number):void { + builder.addFieldFloat64(5, defaultReal, 0.0); +} + +static addDeprecated(builder:flatbuffers.Builder, deprecated:boolean):void { + builder.addFieldInt8(6, +deprecated, +false); +} + +static addRequired(builder:flatbuffers.Builder, required:boolean):void { + builder.addFieldInt8(7, +required, +false); +} + +static addKey(builder:flatbuffers.Builder, key:boolean):void { + builder.addFieldInt8(8, +key, +false); +} + +static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(9, attributesOffset, 0); +} + +static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - defaultReal(): number { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0; +static startAttributesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset):void { + builder.addFieldOffset(10, documentationOffset, 0); +} + +static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - mutate_default_real(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 14); +static startDocumentationVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - if (offset === 0) { - return false; - } +static addOptional(builder:flatbuffers.Builder, optional:boolean):void { + builder.addFieldInt8(11, +optional, +false); +} - this.bb!.writeFloat64(this.bb_pos + offset, value); - return true; - } +static addPadding(builder:flatbuffers.Builder, padding:number):void { + builder.addFieldInt16(12, padding, 0); +} - deprecated(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 16); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } +static addOffset64(builder:flatbuffers.Builder, offset64:boolean):void { + builder.addFieldInt8(13, +offset64, +false); +} - mutate_deprecated(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 16); +static endField(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // name + builder.requiredField(offset, 6) // type + return offset; +} - if (offset === 0) { - return false; - } - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } +unpack(): FieldT { + return new FieldT( + this.name(), + (this.type() !== null ? this.type()!.unpack() : null), + this.id(), + this.offset(), + this.defaultInteger(), + this.defaultReal(), + this.deprecated(), + this.required(), + this.key(), + this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()), + this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()), + this.optional(), + this.padding(), + this.offset64() + ); +} - required(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 18); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } - mutate_required(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 18); - - if (offset === 0) { - return false; - } - - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } - - key(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 20); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } - - mutate_key(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 20); - - if (offset === 0) { - return false; - } - - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } - - attributes(index: number, obj?: KeyValue): KeyValue | null { - const offset = this.bb!.__offset(this.bb_pos, 22); - return offset - ? (obj || new KeyValue()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } - - attributesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 22); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentation( - index: number, - optionalEncoding?: any, - ): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 24); - return offset - ? this.bb!.__string( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding, - ) - : null; - } - - documentationLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 24); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - optional(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 26); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } - - mutate_optional(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 26); - - if (offset === 0) { - return false; - } - - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } - - /** - * Number of padding octets to always add after this field. Structs only. - */ - padding(): number { - const offset = this.bb!.__offset(this.bb_pos, 28); - return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; - } - - mutate_padding(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 28); - - if (offset === 0) { - return false; - } - - this.bb!.writeUint16(this.bb_pos + offset, value); - return true; - } - - /** - * If the field uses 64-bit offsets. - */ - offset64(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 30); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } - - mutate_offset64(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 30); - - if (offset === 0) { - return false; - } - - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } - - static getFullyQualifiedName(): string { - return 'reflection.Field'; - } - - static startField(builder: flatbuffers.Builder) { - builder.startObject(14); - } - - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } - - static addType(builder: flatbuffers.Builder, typeOffset: flatbuffers.Offset) { - builder.addFieldOffset(1, typeOffset, 0); - } - - static addId(builder: flatbuffers.Builder, id: number) { - builder.addFieldInt16(2, id, 0); - } - - static addOffset(builder: flatbuffers.Builder, offset: number) { - builder.addFieldInt16(3, offset, 0); - } - - static addDefaultInteger( - builder: flatbuffers.Builder, - defaultInteger: bigint, - ) { - builder.addFieldInt64(4, defaultInteger, BigInt('0')); - } - - static addDefaultReal(builder: flatbuffers.Builder, defaultReal: number) { - builder.addFieldFloat64(5, defaultReal, 0.0); - } - - static addDeprecated(builder: flatbuffers.Builder, deprecated: boolean) { - builder.addFieldInt8(6, +deprecated, +false); - } - - static addRequired(builder: flatbuffers.Builder, required: boolean) { - builder.addFieldInt8(7, +required, +false); - } - - static addKey(builder: flatbuffers.Builder, key: boolean) { - builder.addFieldInt8(8, +key, +false); - } - - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(9, attributesOffset, 0); - } - - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startAttributesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(10, documentationOffset, 0); - } - - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } - - static addOptional(builder: flatbuffers.Builder, optional: boolean) { - builder.addFieldInt8(11, +optional, +false); - } - - static addPadding(builder: flatbuffers.Builder, padding: number) { - builder.addFieldInt16(12, padding, 0); - } - - static addOffset64(builder: flatbuffers.Builder, offset64: boolean) { - builder.addFieldInt8(13, +offset64, +false); - } - - static endField(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // type - return offset; - } - - unpack(): FieldT { - return new FieldT( - this.name(), - this.type() !== null ? this.type()!.unpack() : null, - this.id(), - this.offset(), - this.defaultInteger(), - this.defaultReal(), - this.deprecated(), - this.required(), - this.key(), - this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ), - this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ), - this.optional(), - this.padding(), - this.offset64(), - ); - } - - unpackTo(_o: FieldT): void { - _o.name = this.name(); - _o.type = this.type() !== null ? this.type()!.unpack() : null; - _o.id = this.id(); - _o.offset = this.offset(); - _o.defaultInteger = this.defaultInteger(); - _o.defaultReal = this.defaultReal(); - _o.deprecated = this.deprecated(); - _o.required = this.required(); - _o.key = this.key(); - _o.attributes = this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ); - _o.documentation = this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ); - _o.optional = this.optional(); - _o.padding = this.padding(); - _o.offset64 = this.offset64(); - } +unpackTo(_o: FieldT): void { + _o.name = this.name(); + _o.type = (this.type() !== null ? this.type()!.unpack() : null); + _o.id = this.id(); + _o.offset = this.offset(); + _o.defaultInteger = this.defaultInteger(); + _o.defaultReal = this.defaultReal(); + _o.deprecated = this.deprecated(); + _o.required = this.required(); + _o.key = this.key(); + _o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.optional = this.optional(); + _o.padding = this.padding(); + _o.offset64 = this.offset64(); +} } export class FieldT implements flatbuffers.IGeneratedObject { - constructor( - public name: string | Uint8Array | null = null, - public type: TypeT | null = null, - public id: number = 0, - public offset: number = 0, - public defaultInteger: bigint = BigInt('0'), - public defaultReal: number = 0.0, - public deprecated: boolean = false, - public required: boolean = false, - public key: boolean = false, - public attributes: KeyValueT[] = [], - public documentation: string[] = [], - public optional: boolean = false, - public padding: number = 0, - public offset64: boolean = false, - ) {} +constructor( + public name: string|Uint8Array|null = null, + public type: TypeT|null = null, + public id: number = 0, + public offset: number = 0, + public defaultInteger: bigint = BigInt('0'), + public defaultReal: number = 0.0, + public deprecated: boolean = false, + public required: boolean = false, + public key: boolean = false, + public attributes: (KeyValueT)[] = [], + public documentation: (string)[] = [], + public optional: boolean = false, + public padding: number = 0, + public offset64: boolean = false +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const name = this.name !== null ? builder.createString(this.name!) : 0; - const type = this.type !== null ? this.type!.pack(builder) : 0; - const attributes = Field.createAttributesVector( - builder, - builder.createObjectOffsetList(this.attributes), - ); - const documentation = Field.createDocumentationVector( - builder, - builder.createObjectOffsetList(this.documentation), - ); - Field.startField(builder); - Field.addName(builder, name); - Field.addType(builder, type); - Field.addId(builder, this.id); - Field.addOffset(builder, this.offset); - Field.addDefaultInteger(builder, this.defaultInteger); - Field.addDefaultReal(builder, this.defaultReal); - Field.addDeprecated(builder, this.deprecated); - Field.addRequired(builder, this.required); - Field.addKey(builder, this.key); - Field.addAttributes(builder, attributes); - Field.addDocumentation(builder, documentation); - Field.addOptional(builder, this.optional); - Field.addPadding(builder, this.padding); - Field.addOffset64(builder, this.offset64); +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const name = (this.name !== null ? builder.createString(this.name!) : 0); + const type = (this.type !== null ? this.type!.pack(builder) : 0); + const attributes = Field.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Field.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); - return Field.endField(builder); - } + Field.startField(builder); + Field.addName(builder, name); + Field.addType(builder, type); + Field.addId(builder, this.id); + Field.addOffset(builder, this.offset); + Field.addDefaultInteger(builder, this.defaultInteger); + Field.addDefaultReal(builder, this.defaultReal); + Field.addDeprecated(builder, this.deprecated); + Field.addRequired(builder, this.required); + Field.addKey(builder, this.key); + Field.addAttributes(builder, attributes); + Field.addDocumentation(builder, documentation); + Field.addOptional(builder, this.optional); + Field.addPadding(builder, this.padding); + Field.addOffset64(builder, this.offset64); + + return Field.endField(builder); +} } diff --git a/tests/ts/reflection/key-value.d.ts b/tests/ts/reflection/key-value.d.ts index 799863096..4d259ba5f 100644 --- a/tests/ts/reflection/key-value.d.ts +++ b/tests/ts/reflection/key-value.d.ts @@ -1,47 +1,26 @@ import * as flatbuffers from 'flatbuffers'; -export declare class KeyValue - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): KeyValue; - static getRootAsKeyValue( - bb: flatbuffers.ByteBuffer, - obj?: KeyValue, - ): KeyValue; - static getSizePrefixedRootAsKeyValue( - bb: flatbuffers.ByteBuffer, - obj?: KeyValue, - ): KeyValue; - key(): string | null; - key(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - value(): string | null; - value(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - static getFullyQualifiedName(): string; - static startKeyValue(builder: flatbuffers.Builder): void; - static addKey( - builder: flatbuffers.Builder, - keyOffset: flatbuffers.Offset, - ): void; - static addValue( - builder: flatbuffers.Builder, - valueOffset: flatbuffers.Offset, - ): void; - static endKeyValue(builder: flatbuffers.Builder): flatbuffers.Offset; - static createKeyValue( - builder: flatbuffers.Builder, - keyOffset: flatbuffers.Offset, - valueOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - unpack(): KeyValueT; - unpackTo(_o: KeyValueT): void; +export declare class KeyValue implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): KeyValue; + static getRootAsKeyValue(bb: flatbuffers.ByteBuffer, obj?: KeyValue): KeyValue; + static getSizePrefixedRootAsKeyValue(bb: flatbuffers.ByteBuffer, obj?: KeyValue): KeyValue; + key(): string; + key(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + value(): string | null; + value(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + static getFullyQualifiedName(): "reflection.KeyValue"; + static startKeyValue(builder: flatbuffers.Builder): void; + static addKey(builder: flatbuffers.Builder, keyOffset: flatbuffers.Offset): void; + static addValue(builder: flatbuffers.Builder, valueOffset: flatbuffers.Offset): void; + static endKeyValue(builder: flatbuffers.Builder): flatbuffers.Offset; + static createKeyValue(builder: flatbuffers.Builder, keyOffset: flatbuffers.Offset, valueOffset: flatbuffers.Offset): flatbuffers.Offset; + unpack(): KeyValueT; + unpackTo(_o: KeyValueT): void; } export declare class KeyValueT implements flatbuffers.IGeneratedObject { - key: string | Uint8Array | null; - value: string | Uint8Array | null; - constructor( - key?: string | Uint8Array | null, - value?: string | Uint8Array | null, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + key: string | Uint8Array | null; + value: string | Uint8Array | null; + constructor(key?: string | Uint8Array | null, value?: string | Uint8Array | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/key-value.js b/tests/ts/reflection/key-value.js index 32d2b3e34..ca16d2ad6 100644 --- a/tests/ts/reflection/key-value.js +++ b/tests/ts/reflection/key-value.js @@ -1,75 +1,70 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class KeyValue { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsKeyValue(bb, obj) { - return (obj || new KeyValue()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsKeyValue(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new KeyValue()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - key(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - value(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - static getFullyQualifiedName() { - return 'reflection.KeyValue'; - } - static startKeyValue(builder) { - builder.startObject(2); - } - static addKey(builder, keyOffset) { - builder.addFieldOffset(0, keyOffset, 0); - } - static addValue(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); - } - static endKeyValue(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // key - return offset; - } - static createKeyValue(builder, keyOffset, valueOffset) { - KeyValue.startKeyValue(builder); - KeyValue.addKey(builder, keyOffset); - KeyValue.addValue(builder, valueOffset); - return KeyValue.endKeyValue(builder); - } - unpack() { - return new KeyValueT(this.key(), this.value()); - } - unpackTo(_o) { - _o.key = this.key(); - _o.value = this.value(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsKeyValue(bb, obj) { + return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsKeyValue(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + key(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); + } + value(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + static getFullyQualifiedName() { + return 'reflection.KeyValue'; + } + static startKeyValue(builder) { + builder.startObject(2); + } + static addKey(builder, keyOffset) { + builder.addFieldOffset(0, keyOffset, 0); + } + static addValue(builder, valueOffset) { + builder.addFieldOffset(1, valueOffset, 0); + } + static endKeyValue(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // key + return offset; + } + static createKeyValue(builder, keyOffset, valueOffset) { + KeyValue.startKeyValue(builder); + KeyValue.addKey(builder, keyOffset); + KeyValue.addValue(builder, valueOffset); + return KeyValue.endKeyValue(builder); + } + unpack() { + return new KeyValueT(this.key(), this.value()); + } + unpackTo(_o) { + _o.key = this.key(); + _o.value = this.value(); + } } export class KeyValueT { - constructor(key = null, value = null) { - this.key = key; - this.value = value; - } - pack(builder) { - const key = (this.key !== null ? builder.createString(this.key) : 0); - const value = (this.value !== null ? builder.createString(this.value) : 0); - return KeyValue.createKeyValue(builder, key, value); - } + constructor(key = null, value = null) { + this.key = key; + this.value = value; + } + pack(builder) { + const key = (this.key !== null ? builder.createString(this.key) : 0); + const value = (this.value !== null ? builder.createString(this.value) : 0); + return KeyValue.createKeyValue(builder, key, value); + } } diff --git a/tests/ts/reflection/key-value.ts b/tests/ts/reflection/key-value.ts index ab9742c77..27ff90664 100644 --- a/tests/ts/reflection/key-value.ts +++ b/tests/ts/reflection/key-value.ts @@ -4,110 +4,97 @@ import * as flatbuffers from 'flatbuffers'; + + export class KeyValue implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): KeyValue { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):KeyValue { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsKeyValue( - bb: flatbuffers.ByteBuffer, - obj?: KeyValue, - ): KeyValue { - return (obj || new KeyValue()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsKeyValue(bb:flatbuffers.ByteBuffer, obj?:KeyValue):KeyValue { + return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsKeyValue( - bb: flatbuffers.ByteBuffer, - obj?: KeyValue, - ): KeyValue { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new KeyValue()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsKeyValue(bb:flatbuffers.ByteBuffer, obj?:KeyValue):KeyValue { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new KeyValue()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - key(): string | null; - key(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - key(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +key():string +key(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +key(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} - value(): string | null; - value(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - value(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +value():string|null +value(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +value(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} - static getFullyQualifiedName(): string { - return 'reflection.KeyValue'; - } +static getFullyQualifiedName(): "reflection.KeyValue" { + return 'reflection.KeyValue'; +} - static startKeyValue(builder: flatbuffers.Builder) { - builder.startObject(2); - } +static startKeyValue(builder:flatbuffers.Builder):void { + builder.startObject(2); +} - static addKey(builder: flatbuffers.Builder, keyOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, keyOffset, 0); - } +static addKey(builder:flatbuffers.Builder, keyOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, keyOffset, 0); +} - static addValue( - builder: flatbuffers.Builder, - valueOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, valueOffset, 0); - } +static addValue(builder:flatbuffers.Builder, valueOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, valueOffset, 0); +} - static endKeyValue(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // key - return offset; - } +static endKeyValue(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // key + return offset; +} - static createKeyValue( - builder: flatbuffers.Builder, - keyOffset: flatbuffers.Offset, - valueOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - KeyValue.startKeyValue(builder); - KeyValue.addKey(builder, keyOffset); - KeyValue.addValue(builder, valueOffset); - return KeyValue.endKeyValue(builder); - } +static createKeyValue(builder:flatbuffers.Builder, keyOffset:flatbuffers.Offset, valueOffset:flatbuffers.Offset):flatbuffers.Offset { + KeyValue.startKeyValue(builder); + KeyValue.addKey(builder, keyOffset); + KeyValue.addValue(builder, valueOffset); + return KeyValue.endKeyValue(builder); +} - unpack(): KeyValueT { - return new KeyValueT(this.key(), this.value()); - } +unpack(): KeyValueT { + return new KeyValueT( + this.key(), + this.value() + ); +} - unpackTo(_o: KeyValueT): void { - _o.key = this.key(); - _o.value = this.value(); - } + +unpackTo(_o: KeyValueT): void { + _o.key = this.key(); + _o.value = this.value(); +} } export class KeyValueT implements flatbuffers.IGeneratedObject { - constructor( - public key: string | Uint8Array | null = null, - public value: string | Uint8Array | null = null, - ) {} +constructor( + public key: string|Uint8Array|null = null, + public value: string|Uint8Array|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const key = this.key !== null ? builder.createString(this.key!) : 0; - const value = this.value !== null ? builder.createString(this.value!) : 0; - return KeyValue.createKeyValue(builder, key, value); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const key = (this.key !== null ? builder.createString(this.key!) : 0); + const value = (this.value !== null ? builder.createString(this.value!) : 0); + + return KeyValue.createKeyValue(builder, + key, + value + ); +} } diff --git a/tests/ts/reflection/object.d.ts b/tests/ts/reflection/object.d.ts index cd79bd8e8..01b49e625 100644 --- a/tests/ts/reflection/object.d.ts +++ b/tests/ts/reflection/object.d.ts @@ -1,124 +1,62 @@ import * as flatbuffers from 'flatbuffers'; -import {Field, FieldT} from '../reflection/field.js'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -export declare class Object_ - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Object_; - static getRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_; - static getSizePrefixedRootAsObject( - bb: flatbuffers.ByteBuffer, - obj?: Object_, - ): Object_; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - fields(index: number, obj?: Field): Field | null; - fieldsLength(): number; - isStruct(): boolean; - mutate_is_struct(value: boolean): boolean; - minalign(): number; - mutate_minalign(value: number): boolean; - bytesize(): number; - mutate_bytesize(value: number): boolean; - attributes(index: number, obj?: KeyValue): KeyValue | null; - attributesLength(): number; - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentationLength(): number; - /** - * File that this Object is declared in. - */ - declarationFile(): string | null; - declarationFile( - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array | null; - static getFullyQualifiedName(): string; - static startObject(builder: flatbuffers.Builder): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addFields( - builder: flatbuffers.Builder, - fieldsOffset: flatbuffers.Offset, - ): void; - static createFieldsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startFieldsVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addIsStruct(builder: flatbuffers.Builder, isStruct: boolean): void; - static addMinalign(builder: flatbuffers.Builder, minalign: number): void; - static addBytesize(builder: flatbuffers.Builder, bytesize: number): void; - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ): void; - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startAttributesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ): void; - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDeclarationFile( - builder: flatbuffers.Builder, - declarationFileOffset: flatbuffers.Offset, - ): void; - static endObject(builder: flatbuffers.Builder): flatbuffers.Offset; - static createObject( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - fieldsOffset: flatbuffers.Offset, - isStruct: boolean, - minalign: number, - bytesize: number, - attributesOffset: flatbuffers.Offset, - documentationOffset: flatbuffers.Offset, - declarationFileOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - unpack(): Object_T; - unpackTo(_o: Object_T): void; +import { Field, FieldT } from './field.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +export declare class Object_ implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Object_; + static getRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_; + static getSizePrefixedRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_; + name(): string; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + fields(index: number, obj?: Field): Field | null; + fieldsLength(): number; + isStruct(): boolean; + mutate_is_struct(value: boolean): boolean; + minalign(): number; + mutate_minalign(value: number): boolean; + bytesize(): number; + mutate_bytesize(value: number): boolean; + attributes(index: number, obj?: KeyValue): KeyValue | null; + attributesLength(): number; + documentation(index: number): string; + documentation(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + documentationLength(): number; + /** + * File that this Object is declared in. + */ + declarationFile(): string | null; + declarationFile(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + static getFullyQualifiedName(): "reflection.Object"; + static startObject(builder: flatbuffers.Builder): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addFields(builder: flatbuffers.Builder, fieldsOffset: flatbuffers.Offset): void; + static createFieldsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startFieldsVector(builder: flatbuffers.Builder, numElems: number): void; + static addIsStruct(builder: flatbuffers.Builder, isStruct: boolean): void; + static addMinalign(builder: flatbuffers.Builder, minalign: number): void; + static addBytesize(builder: flatbuffers.Builder, bytesize: number): void; + static addAttributes(builder: flatbuffers.Builder, attributesOffset: flatbuffers.Offset): void; + static createAttributesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startAttributesVector(builder: flatbuffers.Builder, numElems: number): void; + static addDocumentation(builder: flatbuffers.Builder, documentationOffset: flatbuffers.Offset): void; + static createDocumentationVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startDocumentationVector(builder: flatbuffers.Builder, numElems: number): void; + static addDeclarationFile(builder: flatbuffers.Builder, declarationFileOffset: flatbuffers.Offset): void; + static endObject(builder: flatbuffers.Builder): flatbuffers.Offset; + static createObject(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset, fieldsOffset: flatbuffers.Offset, isStruct: boolean, minalign: number, bytesize: number, attributesOffset: flatbuffers.Offset, documentationOffset: flatbuffers.Offset, declarationFileOffset: flatbuffers.Offset): flatbuffers.Offset; + unpack(): Object_T; + unpackTo(_o: Object_T): void; } export declare class Object_T implements flatbuffers.IGeneratedObject { - name: string | Uint8Array | null; - fields: FieldT[]; - isStruct: boolean; - minalign: number; - bytesize: number; - attributes: KeyValueT[]; - documentation: string[]; - declarationFile: string | Uint8Array | null; - constructor( - name?: string | Uint8Array | null, - fields?: FieldT[], - isStruct?: boolean, - minalign?: number, - bytesize?: number, - attributes?: KeyValueT[], - documentation?: string[], - declarationFile?: string | Uint8Array | null, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + name: string | Uint8Array | null; + fields: (FieldT)[]; + isStruct: boolean; + minalign: number; + bytesize: number; + attributes: (KeyValueT)[]; + documentation: (string)[]; + declarationFile: string | Uint8Array | null; + constructor(name?: string | Uint8Array | null, fields?: (FieldT)[], isStruct?: boolean, minalign?: number, bytesize?: number, attributes?: (KeyValueT)[], documentation?: (string)[], declarationFile?: string | Uint8Array | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/object.js b/tests/ts/reflection/object.js index a308253b3..090032f51 100644 --- a/tests/ts/reflection/object.js +++ b/tests/ts/reflection/object.js @@ -1,247 +1,202 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {Field} from '../reflection/field.js'; -import {KeyValue} from '../reflection/key-value.js'; - +import { Field } from './field.js'; +import { KeyValue } from './key-value.js'; export class Object_ { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsObject(bb, obj) { - return (obj || new Object_()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsObject(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Object_()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - fields(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? - (obj || new Field()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - fieldsLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - isStruct() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_is_struct(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - minalign() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_minalign(value) { - const offset = this.bb.__offset(this.bb_pos, 10); - if (offset === 0) { - return false; + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - bytesize() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_bytesize(value) { - const offset = this.bb.__offset(this.bb_pos, 12); - if (offset === 0) { - return false; + static getRootAsObject(bb, obj) { + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - attributes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? - (obj || new KeyValue()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - attributesLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - documentation(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - documentationLength() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - declarationFile(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - static getFullyQualifiedName() { - return 'reflection.Object'; - } - static startObject(builder) { - builder.startObject(8); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(0, nameOffset, 0); - } - static addFields(builder, fieldsOffset) { - builder.addFieldOffset(1, fieldsOffset, 0); - } - static createFieldsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static getSizePrefixedRootAsObject(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - return builder.endVector(); - } - static startFieldsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addIsStruct(builder, isStruct) { - builder.addFieldInt8(2, +isStruct, +false); - } - static addMinalign(builder, minalign) { - builder.addFieldInt32(3, minalign, 0); - } - static addBytesize(builder, bytesize) { - builder.addFieldInt32(4, bytesize, 0); - } - static addAttributes(builder, attributesOffset) { - builder.addFieldOffset(5, attributesOffset, 0); - } - static createAttributesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } - return builder.endVector(); - } - static startAttributesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDocumentation(builder, documentationOffset) { - builder.addFieldOffset(6, documentationOffset, 0); - } - static createDocumentationVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + fields(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new Field()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + fieldsLength() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + isStruct() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_is_struct(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + minalign() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_minalign(value) { + const offset = this.bb.__offset(this.bb_pos, 10); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + bytesize() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_bytesize(value) { + const offset = this.bb.__offset(this.bb_pos, 12); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + attributes(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + attributesLength() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + documentation(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + documentationLength() { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + declarationFile(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 18); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + static getFullyQualifiedName() { + return 'reflection.Object'; + } + static startObject(builder) { + builder.startObject(8); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + static addFields(builder, fieldsOffset) { + builder.addFieldOffset(1, fieldsOffset, 0); + } + static createFieldsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startFieldsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addIsStruct(builder, isStruct) { + builder.addFieldInt8(2, +isStruct, +false); + } + static addMinalign(builder, minalign) { + builder.addFieldInt32(3, minalign, 0); + } + static addBytesize(builder, bytesize) { + builder.addFieldInt32(4, bytesize, 0); + } + static addAttributes(builder, attributesOffset) { + builder.addFieldOffset(5, attributesOffset, 0); + } + static createAttributesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startAttributesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDocumentation(builder, documentationOffset) { + builder.addFieldOffset(6, documentationOffset, 0); + } + static createDocumentationVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startDocumentationVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDeclarationFile(builder, declarationFileOffset) { + builder.addFieldOffset(7, declarationFileOffset, 0); + } + static endObject(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // name + builder.requiredField(offset, 6); // fields + return offset; + } + static createObject(builder, nameOffset, fieldsOffset, isStruct, minalign, bytesize, attributesOffset, documentationOffset, declarationFileOffset) { + Object_.startObject(builder); + Object_.addName(builder, nameOffset); + Object_.addFields(builder, fieldsOffset); + Object_.addIsStruct(builder, isStruct); + Object_.addMinalign(builder, minalign); + Object_.addBytesize(builder, bytesize); + Object_.addAttributes(builder, attributesOffset); + Object_.addDocumentation(builder, documentationOffset); + Object_.addDeclarationFile(builder, declarationFileOffset); + return Object_.endObject(builder); + } + unpack() { + return new Object_T(this.name(), this.bb.createObjList(this.fields.bind(this), this.fieldsLength()), this.isStruct(), this.minalign(), this.bytesize(), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.declarationFile()); + } + unpackTo(_o) { + _o.name = this.name(); + _o.fields = this.bb.createObjList(this.fields.bind(this), this.fieldsLength()); + _o.isStruct = this.isStruct(); + _o.minalign = this.minalign(); + _o.bytesize = this.bytesize(); + _o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.declarationFile = this.declarationFile(); } - return builder.endVector(); - } - static startDocumentationVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDeclarationFile(builder, declarationFileOffset) { - builder.addFieldOffset(7, declarationFileOffset, 0); - } - static endObject(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // fields - return offset; - } - static createObject( - builder, nameOffset, fieldsOffset, isStruct, minalign, bytesize, - attributesOffset, documentationOffset, declarationFileOffset) { - Object_.startObject(builder); - Object_.addName(builder, nameOffset); - Object_.addFields(builder, fieldsOffset); - Object_.addIsStruct(builder, isStruct); - Object_.addMinalign(builder, minalign); - Object_.addBytesize(builder, bytesize); - Object_.addAttributes(builder, attributesOffset); - Object_.addDocumentation(builder, documentationOffset); - Object_.addDeclarationFile(builder, declarationFileOffset); - return Object_.endObject(builder); - } - unpack() { - return new Object_T( - this.name(), - this.bb.createObjList(this.fields.bind(this), this.fieldsLength()), - this.isStruct(), this.minalign(), this.bytesize(), - this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()), - this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()), - this.declarationFile()); - } - unpackTo(_o) { - _o.name = this.name(); - _o.fields = - this.bb.createObjList(this.fields.bind(this), this.fieldsLength()); - _o.isStruct = this.isStruct(); - _o.minalign = this.minalign(); - _o.bytesize = this.bytesize(); - _o.attributes = this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()); - _o.documentation = this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()); - _o.declarationFile = this.declarationFile(); - } } export class Object_T { - constructor( - name = null, fields = [], isStruct = false, minalign = 0, bytesize = 0, - attributes = [], documentation = [], declarationFile = null) { - this.name = name; - this.fields = fields; - this.isStruct = isStruct; - this.minalign = minalign; - this.bytesize = bytesize; - this.attributes = attributes; - this.documentation = documentation; - this.declarationFile = declarationFile; - } - pack(builder) { - const name = (this.name !== null ? builder.createString(this.name) : 0); - const fields = Object_.createFieldsVector( - builder, builder.createObjectOffsetList(this.fields)); - const attributes = Object_.createAttributesVector( - builder, builder.createObjectOffsetList(this.attributes)); - const documentation = Object_.createDocumentationVector( - builder, builder.createObjectOffsetList(this.documentation)); - const declarationFile = - (this.declarationFile !== null ? - builder.createString(this.declarationFile) : - 0); - return Object_.createObject( - builder, name, fields, this.isStruct, this.minalign, this.bytesize, - attributes, documentation, declarationFile); - } + constructor(name = null, fields = [], isStruct = false, minalign = 0, bytesize = 0, attributes = [], documentation = [], declarationFile = null) { + this.name = name; + this.fields = fields; + this.isStruct = isStruct; + this.minalign = minalign; + this.bytesize = bytesize; + this.attributes = attributes; + this.documentation = documentation; + this.declarationFile = declarationFile; + } + pack(builder) { + const name = (this.name !== null ? builder.createString(this.name) : 0); + const fields = Object_.createFieldsVector(builder, builder.createObjectOffsetList(this.fields)); + const attributes = Object_.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Object_.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile) : 0); + return Object_.createObject(builder, name, fields, this.isStruct, this.minalign, this.bytesize, attributes, documentation, declarationFile); + } } diff --git a/tests/ts/reflection/object.ts b/tests/ts/reflection/object.ts index 27c909e5e..266f61dd9 100644 --- a/tests/ts/reflection/object.ts +++ b/tests/ts/reflection/object.ts @@ -4,378 +4,276 @@ import * as flatbuffers from 'flatbuffers'; -import {Field, FieldT} from '../reflection/field.js'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; +import { Field, FieldT } from './field.js'; +import { KeyValue, KeyValueT } from './key-value.js'; + export class Object_ implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Object_ { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Object_ { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ { + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +name():string +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +name(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} + +fields(index: number, obj?:Field):Field|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new Field()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +fieldsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +isStruct():boolean { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +mutate_is_struct(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 8); + + if (offset === 0) { + return false; } - static getRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_ { - return (obj || new Object_()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} + +minalign():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +mutate_minalign(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 10); + + if (offset === 0) { + return false; } - static getSizePrefixedRootAsObject( - bb: flatbuffers.ByteBuffer, - obj?: Object_, - ): Object_ { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Object_()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +bytesize():number { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +mutate_bytesize(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 12); + + if (offset === 0) { + return false; } - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +attributes(index: number, obj?:KeyValue):KeyValue|null { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +attributesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +documentation(index: number):string +documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +documentation(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} + +documentationLength():number { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +/** + * File that this Object is declared in. + */ +declarationFile():string|null +declarationFile(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +declarationFile(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} + +static getFullyQualifiedName(): "reflection.Object" { + return 'reflection.Object'; +} + +static startObject(builder:flatbuffers.Builder):void { + builder.startObject(8); +} + +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} + +static addFields(builder:flatbuffers.Builder, fieldsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, fieldsOffset, 0); +} + +static createFieldsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - fields(index: number, obj?: Field): Field | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? (obj || new Field()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; +static startFieldsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addIsStruct(builder:flatbuffers.Builder, isStruct:boolean):void { + builder.addFieldInt8(2, +isStruct, +false); +} + +static addMinalign(builder:flatbuffers.Builder, minalign:number):void { + builder.addFieldInt32(3, minalign, 0); +} + +static addBytesize(builder:flatbuffers.Builder, bytesize:number):void { + builder.addFieldInt32(4, bytesize, 0); +} + +static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(5, attributesOffset, 0); +} + +static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - fieldsLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +static startAttributesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset):void { + builder.addFieldOffset(6, documentationOffset, 0); +} + +static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - isStruct(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } +static startDocumentationVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - mutate_is_struct(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 8); +static addDeclarationFile(builder:flatbuffers.Builder, declarationFileOffset:flatbuffers.Offset):void { + builder.addFieldOffset(7, declarationFileOffset, 0); +} - if (offset === 0) { - return false; - } +static endObject(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // name + builder.requiredField(offset, 6) // fields + return offset; +} - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } +static createObject(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset, fieldsOffset:flatbuffers.Offset, isStruct:boolean, minalign:number, bytesize:number, attributesOffset:flatbuffers.Offset, documentationOffset:flatbuffers.Offset, declarationFileOffset:flatbuffers.Offset):flatbuffers.Offset { + Object_.startObject(builder); + Object_.addName(builder, nameOffset); + Object_.addFields(builder, fieldsOffset); + Object_.addIsStruct(builder, isStruct); + Object_.addMinalign(builder, minalign); + Object_.addBytesize(builder, bytesize); + Object_.addAttributes(builder, attributesOffset); + Object_.addDocumentation(builder, documentationOffset); + Object_.addDeclarationFile(builder, declarationFileOffset); + return Object_.endObject(builder); +} - minalign(): number { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; - } +unpack(): Object_T { + return new Object_T( + this.name(), + this.bb!.createObjList(this.fields.bind(this), this.fieldsLength()), + this.isStruct(), + this.minalign(), + this.bytesize(), + this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()), + this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()), + this.declarationFile() + ); +} - mutate_minalign(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 10); - if (offset === 0) { - return false; - } - - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } - - bytesize(): number { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; - } - - mutate_bytesize(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 12); - - if (offset === 0) { - return false; - } - - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } - - attributes(index: number, obj?: KeyValue): KeyValue | null { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset - ? (obj || new KeyValue()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } - - attributesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentation( - index: number, - optionalEncoding?: any, - ): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 16); - return offset - ? this.bb!.__string( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding, - ) - : null; - } - - documentationLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 16); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - /** - * File that this Object is declared in. - */ - declarationFile(): string | null; - declarationFile( - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array | null; - declarationFile(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 18); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } - - static getFullyQualifiedName(): string { - return 'reflection.Object'; - } - - static startObject(builder: flatbuffers.Builder) { - builder.startObject(8); - } - - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } - - static addFields( - builder: flatbuffers.Builder, - fieldsOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, fieldsOffset, 0); - } - - static createFieldsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startFieldsVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addIsStruct(builder: flatbuffers.Builder, isStruct: boolean) { - builder.addFieldInt8(2, +isStruct, +false); - } - - static addMinalign(builder: flatbuffers.Builder, minalign: number) { - builder.addFieldInt32(3, minalign, 0); - } - - static addBytesize(builder: flatbuffers.Builder, bytesize: number) { - builder.addFieldInt32(4, bytesize, 0); - } - - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(5, attributesOffset, 0); - } - - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startAttributesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(6, documentationOffset, 0); - } - - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } - - static addDeclarationFile( - builder: flatbuffers.Builder, - declarationFileOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(7, declarationFileOffset, 0); - } - - static endObject(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // fields - return offset; - } - - static createObject( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - fieldsOffset: flatbuffers.Offset, - isStruct: boolean, - minalign: number, - bytesize: number, - attributesOffset: flatbuffers.Offset, - documentationOffset: flatbuffers.Offset, - declarationFileOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - Object_.startObject(builder); - Object_.addName(builder, nameOffset); - Object_.addFields(builder, fieldsOffset); - Object_.addIsStruct(builder, isStruct); - Object_.addMinalign(builder, minalign); - Object_.addBytesize(builder, bytesize); - Object_.addAttributes(builder, attributesOffset); - Object_.addDocumentation(builder, documentationOffset); - Object_.addDeclarationFile(builder, declarationFileOffset); - return Object_.endObject(builder); - } - - unpack(): Object_T { - return new Object_T( - this.name(), - this.bb!.createObjList( - this.fields.bind(this), - this.fieldsLength(), - ), - this.isStruct(), - this.minalign(), - this.bytesize(), - this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ), - this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ), - this.declarationFile(), - ); - } - - unpackTo(_o: Object_T): void { - _o.name = this.name(); - _o.fields = this.bb!.createObjList( - this.fields.bind(this), - this.fieldsLength(), - ); - _o.isStruct = this.isStruct(); - _o.minalign = this.minalign(); - _o.bytesize = this.bytesize(); - _o.attributes = this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ); - _o.documentation = this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ); - _o.declarationFile = this.declarationFile(); - } +unpackTo(_o: Object_T): void { + _o.name = this.name(); + _o.fields = this.bb!.createObjList(this.fields.bind(this), this.fieldsLength()); + _o.isStruct = this.isStruct(); + _o.minalign = this.minalign(); + _o.bytesize = this.bytesize(); + _o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.declarationFile = this.declarationFile(); +} } export class Object_T implements flatbuffers.IGeneratedObject { - constructor( - public name: string | Uint8Array | null = null, - public fields: FieldT[] = [], - public isStruct: boolean = false, - public minalign: number = 0, - public bytesize: number = 0, - public attributes: KeyValueT[] = [], - public documentation: string[] = [], - public declarationFile: string | Uint8Array | null = null, - ) {} +constructor( + public name: string|Uint8Array|null = null, + public fields: (FieldT)[] = [], + public isStruct: boolean = false, + public minalign: number = 0, + public bytesize: number = 0, + public attributes: (KeyValueT)[] = [], + public documentation: (string)[] = [], + public declarationFile: string|Uint8Array|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const name = this.name !== null ? builder.createString(this.name!) : 0; - const fields = Object_.createFieldsVector( - builder, - builder.createObjectOffsetList(this.fields), - ); - const attributes = Object_.createAttributesVector( - builder, - builder.createObjectOffsetList(this.attributes), - ); - const documentation = Object_.createDocumentationVector( - builder, - builder.createObjectOffsetList(this.documentation), - ); - const declarationFile = - this.declarationFile !== null - ? builder.createString(this.declarationFile!) - : 0; - return Object_.createObject( - builder, - name, - fields, - this.isStruct, - this.minalign, - this.bytesize, - attributes, - documentation, - declarationFile, - ); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const name = (this.name !== null ? builder.createString(this.name!) : 0); + const fields = Object_.createFieldsVector(builder, builder.createObjectOffsetList(this.fields)); + const attributes = Object_.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Object_.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile!) : 0); + + return Object_.createObject(builder, + name, + fields, + this.isStruct, + this.minalign, + this.bytesize, + attributes, + documentation, + declarationFile + ); +} } diff --git a/tests/ts/reflection/rpccall.d.ts b/tests/ts/reflection/rpccall.d.ts index 40014cd51..18f1e8b7d 100644 --- a/tests/ts/reflection/rpccall.d.ts +++ b/tests/ts/reflection/rpccall.d.ts @@ -1,83 +1,42 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Object_, Object_T} from '../reflection/object.js'; -export declare class RPCCall - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): RPCCall; - static getRootAsRPCCall(bb: flatbuffers.ByteBuffer, obj?: RPCCall): RPCCall; - static getSizePrefixedRootAsRPCCall( - bb: flatbuffers.ByteBuffer, - obj?: RPCCall, - ): RPCCall; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - request(obj?: Object_): Object_ | null; - response(obj?: Object_): Object_ | null; - attributes(index: number, obj?: KeyValue): KeyValue | null; - attributesLength(): number; - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentationLength(): number; - static getFullyQualifiedName(): string; - static startRPCCall(builder: flatbuffers.Builder): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addRequest( - builder: flatbuffers.Builder, - requestOffset: flatbuffers.Offset, - ): void; - static addResponse( - builder: flatbuffers.Builder, - responseOffset: flatbuffers.Offset, - ): void; - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ): void; - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startAttributesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ): void; - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static endRPCCall(builder: flatbuffers.Builder): flatbuffers.Offset; - unpack(): RPCCallT; - unpackTo(_o: RPCCallT): void; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Object_, Object_T } from './object.js'; +export declare class RPCCall implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): RPCCall; + static getRootAsRPCCall(bb: flatbuffers.ByteBuffer, obj?: RPCCall): RPCCall; + static getSizePrefixedRootAsRPCCall(bb: flatbuffers.ByteBuffer, obj?: RPCCall): RPCCall; + name(): string; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + request(obj?: Object_): Object_ | null; + response(obj?: Object_): Object_ | null; + attributes(index: number, obj?: KeyValue): KeyValue | null; + attributesLength(): number; + documentation(index: number): string; + documentation(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + documentationLength(): number; + static getFullyQualifiedName(): "reflection.RPCCall"; + static startRPCCall(builder: flatbuffers.Builder): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addRequest(builder: flatbuffers.Builder, requestOffset: flatbuffers.Offset): void; + static addResponse(builder: flatbuffers.Builder, responseOffset: flatbuffers.Offset): void; + static addAttributes(builder: flatbuffers.Builder, attributesOffset: flatbuffers.Offset): void; + static createAttributesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startAttributesVector(builder: flatbuffers.Builder, numElems: number): void; + static addDocumentation(builder: flatbuffers.Builder, documentationOffset: flatbuffers.Offset): void; + static createDocumentationVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startDocumentationVector(builder: flatbuffers.Builder, numElems: number): void; + static endRPCCall(builder: flatbuffers.Builder): flatbuffers.Offset; + unpack(): RPCCallT; + unpackTo(_o: RPCCallT): void; } export declare class RPCCallT implements flatbuffers.IGeneratedObject { - name: string | Uint8Array | null; - request: Object_T | null; - response: Object_T | null; - attributes: KeyValueT[]; - documentation: string[]; - constructor( - name?: string | Uint8Array | null, - request?: Object_T | null, - response?: Object_T | null, - attributes?: KeyValueT[], - documentation?: string[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + name: string | Uint8Array | null; + request: Object_T | null; + response: Object_T | null; + attributes: (KeyValueT)[]; + documentation: (string)[]; + constructor(name?: string | Uint8Array | null, request?: Object_T | null, response?: Object_T | null, attributes?: (KeyValueT)[], documentation?: (string)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/rpccall.js b/tests/ts/reflection/rpccall.js index a512e0654..782f38dd3 100644 --- a/tests/ts/reflection/rpccall.js +++ b/tests/ts/reflection/rpccall.js @@ -1,165 +1,132 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {KeyValue} from '../reflection/key-value.js'; -import {Object_} from '../reflection/object.js'; - +import { KeyValue } from './key-value.js'; +import { Object_ } from './object.js'; export class RPCCall { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsRPCCall(bb, obj) { - return (obj || new RPCCall()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsRPCCall(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new RPCCall()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - request(obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? - (obj || new Object_()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - response(obj) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? - (obj || new Object_()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - attributes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? - (obj || new KeyValue()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - attributesLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - documentation(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - documentationLength() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static getFullyQualifiedName() { - return 'reflection.RPCCall'; - } - static startRPCCall(builder) { - builder.startObject(5); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(0, nameOffset, 0); - } - static addRequest(builder, requestOffset) { - builder.addFieldOffset(1, requestOffset, 0); - } - static addResponse(builder, responseOffset) { - builder.addFieldOffset(2, responseOffset, 0); - } - static addAttributes(builder, attributesOffset) { - builder.addFieldOffset(3, attributesOffset, 0); - } - static createAttributesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + constructor() { + this.bb = null; + this.bb_pos = 0; } - return builder.endVector(); - } - static startAttributesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDocumentation(builder, documentationOffset) { - builder.addFieldOffset(4, documentationOffset, 0); - } - static createDocumentationVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsRPCCall(bb, obj) { + return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsRPCCall(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); + } + request(obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + response(obj) { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + attributes(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + attributesLength() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + documentation(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + documentationLength() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + static getFullyQualifiedName() { + return 'reflection.RPCCall'; + } + static startRPCCall(builder) { + builder.startObject(5); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + static addRequest(builder, requestOffset) { + builder.addFieldOffset(1, requestOffset, 0); + } + static addResponse(builder, responseOffset) { + builder.addFieldOffset(2, responseOffset, 0); + } + static addAttributes(builder, attributesOffset) { + builder.addFieldOffset(3, attributesOffset, 0); + } + static createAttributesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startAttributesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDocumentation(builder, documentationOffset) { + builder.addFieldOffset(4, documentationOffset, 0); + } + static createDocumentationVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startDocumentationVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static endRPCCall(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // name + builder.requiredField(offset, 6); // request + builder.requiredField(offset, 8); // response + return offset; + } + unpack() { + return new RPCCallT(this.name(), (this.request() !== null ? this.request().unpack() : null), (this.response() !== null ? this.response().unpack() : null), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength())); + } + unpackTo(_o) { + _o.name = this.name(); + _o.request = (this.request() !== null ? this.request().unpack() : null); + _o.response = (this.response() !== null ? this.response().unpack() : null); + _o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()); } - return builder.endVector(); - } - static startDocumentationVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endRPCCall(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // request - builder.requiredField(offset, 8); // response - return offset; - } - unpack() { - return new RPCCallT( - this.name(), (this.request() !== null ? this.request().unpack() : null), - (this.response() !== null ? this.response().unpack() : null), - this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()), - this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength())); - } - unpackTo(_o) { - _o.name = this.name(); - _o.request = (this.request() !== null ? this.request().unpack() : null); - _o.response = (this.response() !== null ? this.response().unpack() : null); - _o.attributes = this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()); - _o.documentation = this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()); - } } export class RPCCallT { - constructor( - name = null, request = null, response = null, attributes = [], - documentation = []) { - this.name = name; - this.request = request; - this.response = response; - this.attributes = attributes; - this.documentation = documentation; - } - pack(builder) { - const name = (this.name !== null ? builder.createString(this.name) : 0); - const request = (this.request !== null ? this.request.pack(builder) : 0); - const response = (this.response !== null ? this.response.pack(builder) : 0); - const attributes = RPCCall.createAttributesVector( - builder, builder.createObjectOffsetList(this.attributes)); - const documentation = RPCCall.createDocumentationVector( - builder, builder.createObjectOffsetList(this.documentation)); - RPCCall.startRPCCall(builder); - RPCCall.addName(builder, name); - RPCCall.addRequest(builder, request); - RPCCall.addResponse(builder, response); - RPCCall.addAttributes(builder, attributes); - RPCCall.addDocumentation(builder, documentation); - return RPCCall.endRPCCall(builder); - } + constructor(name = null, request = null, response = null, attributes = [], documentation = []) { + this.name = name; + this.request = request; + this.response = response; + this.attributes = attributes; + this.documentation = documentation; + } + pack(builder) { + const name = (this.name !== null ? builder.createString(this.name) : 0); + const request = (this.request !== null ? this.request.pack(builder) : 0); + const response = (this.response !== null ? this.response.pack(builder) : 0); + const attributes = RPCCall.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = RPCCall.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + RPCCall.startRPCCall(builder); + RPCCall.addName(builder, name); + RPCCall.addRequest(builder, request); + RPCCall.addResponse(builder, response); + RPCCall.addAttributes(builder, attributes); + RPCCall.addDocumentation(builder, documentation); + return RPCCall.endRPCCall(builder); + } } diff --git a/tests/ts/reflection/rpccall.ts b/tests/ts/reflection/rpccall.ts index 33771c2f8..48ab6bcdd 100644 --- a/tests/ts/reflection/rpccall.ts +++ b/tests/ts/reflection/rpccall.ts @@ -4,246 +4,172 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {Object_, Object_T} from '../reflection/object.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +import { Object_, Object_T } from './object.js'; + export class RPCCall implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): RPCCall { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):RPCCall { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsRPCCall(bb: flatbuffers.ByteBuffer, obj?: RPCCall): RPCCall { - return (obj || new RPCCall()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsRPCCall(bb:flatbuffers.ByteBuffer, obj?:RPCCall):RPCCall { + return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsRPCCall( - bb: flatbuffers.ByteBuffer, - obj?: RPCCall, - ): RPCCall { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new RPCCall()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsRPCCall(bb:flatbuffers.ByteBuffer, obj?:RPCCall):RPCCall { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new RPCCall()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +name():string +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +name(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} - request(obj?: Object_): Object_ | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? (obj || new Object_()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } +request(obj?:Object_):Object_|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} - response(obj?: Object_): Object_ | null { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset - ? (obj || new Object_()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } +response(obj?:Object_):Object_|null { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} - attributes(index: number, obj?: KeyValue): KeyValue | null { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset - ? (obj || new KeyValue()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } +attributes(index: number, obj?:KeyValue):KeyValue|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} - attributesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +attributesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentation( - index: number, - optionalEncoding?: any, - ): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset - ? this.bb!.__string( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding, - ) - : null; - } +documentation(index: number):string +documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +documentation(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} - documentationLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +documentationLength():number { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} - static getFullyQualifiedName(): string { - return 'reflection.RPCCall'; - } +static getFullyQualifiedName(): "reflection.RPCCall" { + return 'reflection.RPCCall'; +} - static startRPCCall(builder: flatbuffers.Builder) { - builder.startObject(5); - } +static startRPCCall(builder:flatbuffers.Builder):void { + builder.startObject(5); +} - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} - static addRequest( - builder: flatbuffers.Builder, - requestOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, requestOffset, 0); - } +static addRequest(builder:flatbuffers.Builder, requestOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, requestOffset, 0); +} - static addResponse( - builder: flatbuffers.Builder, - responseOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(2, responseOffset, 0); - } +static addResponse(builder:flatbuffers.Builder, responseOffset:flatbuffers.Offset):void { + builder.addFieldOffset(2, responseOffset, 0); +} - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(3, attributesOffset, 0); - } +static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(3, attributesOffset, 0); +} - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); +static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static startAttributesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } +static startAttributesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(4, documentationOffset, 0); - } +static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset):void { + builder.addFieldOffset(4, documentationOffset, 0); +} - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); +static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } +static startDocumentationVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - static endRPCCall(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - builder.requiredField(offset, 6); // request - builder.requiredField(offset, 8); // response - return offset; - } +static endRPCCall(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // name + builder.requiredField(offset, 6) // request + builder.requiredField(offset, 8) // response + return offset; +} - unpack(): RPCCallT { - return new RPCCallT( - this.name(), - this.request() !== null ? this.request()!.unpack() : null, - this.response() !== null ? this.response()!.unpack() : null, - this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ), - this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ), - ); - } - unpackTo(_o: RPCCallT): void { - _o.name = this.name(); - _o.request = this.request() !== null ? this.request()!.unpack() : null; - _o.response = this.response() !== null ? this.response()!.unpack() : null; - _o.attributes = this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ); - _o.documentation = this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ); - } +unpack(): RPCCallT { + return new RPCCallT( + this.name(), + (this.request() !== null ? this.request()!.unpack() : null), + (this.response() !== null ? this.response()!.unpack() : null), + this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()), + this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()) + ); +} + + +unpackTo(_o: RPCCallT): void { + _o.name = this.name(); + _o.request = (this.request() !== null ? this.request()!.unpack() : null); + _o.response = (this.response() !== null ? this.response()!.unpack() : null); + _o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()); +} } export class RPCCallT implements flatbuffers.IGeneratedObject { - constructor( - public name: string | Uint8Array | null = null, - public request: Object_T | null = null, - public response: Object_T | null = null, - public attributes: KeyValueT[] = [], - public documentation: string[] = [], - ) {} +constructor( + public name: string|Uint8Array|null = null, + public request: Object_T|null = null, + public response: Object_T|null = null, + public attributes: (KeyValueT)[] = [], + public documentation: (string)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const name = this.name !== null ? builder.createString(this.name!) : 0; - const request = this.request !== null ? this.request!.pack(builder) : 0; - const response = this.response !== null ? this.response!.pack(builder) : 0; - const attributes = RPCCall.createAttributesVector( - builder, - builder.createObjectOffsetList(this.attributes), - ); - const documentation = RPCCall.createDocumentationVector( - builder, - builder.createObjectOffsetList(this.documentation), - ); - RPCCall.startRPCCall(builder); - RPCCall.addName(builder, name); - RPCCall.addRequest(builder, request); - RPCCall.addResponse(builder, response); - RPCCall.addAttributes(builder, attributes); - RPCCall.addDocumentation(builder, documentation); +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const name = (this.name !== null ? builder.createString(this.name!) : 0); + const request = (this.request !== null ? this.request!.pack(builder) : 0); + const response = (this.response !== null ? this.response!.pack(builder) : 0); + const attributes = RPCCall.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = RPCCall.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); - return RPCCall.endRPCCall(builder); - } + RPCCall.startRPCCall(builder); + RPCCall.addName(builder, name); + RPCCall.addRequest(builder, request); + RPCCall.addResponse(builder, response); + RPCCall.addAttributes(builder, attributes); + RPCCall.addDocumentation(builder, documentation); + + return RPCCall.endRPCCall(builder); +} } diff --git a/tests/ts/reflection/schema-file.d.ts b/tests/ts/reflection/schema-file.d.ts index c252ded5c..5320b721b 100644 --- a/tests/ts/reflection/schema-file.d.ts +++ b/tests/ts/reflection/schema-file.d.ts @@ -4,67 +4,37 @@ import * as flatbuffers from 'flatbuffers'; * Symbols declared within a file may be recovered by iterating over all * symbols and examining the `declaration_file` field. */ -export declare class SchemaFile - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): SchemaFile; - static getRootAsSchemaFile( - bb: flatbuffers.ByteBuffer, - obj?: SchemaFile, - ): SchemaFile; - static getSizePrefixedRootAsSchemaFile( - bb: flatbuffers.ByteBuffer, - obj?: SchemaFile, - ): SchemaFile; - /** - * Filename, relative to project root. - */ - filename(): string | null; - filename(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - /** - * Names of included files, relative to project root. - */ - includedFilenames(index: number): string; - includedFilenames( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - includedFilenamesLength(): number; - static getFullyQualifiedName(): string; - static startSchemaFile(builder: flatbuffers.Builder): void; - static addFilename( - builder: flatbuffers.Builder, - filenameOffset: flatbuffers.Offset, - ): void; - static addIncludedFilenames( - builder: flatbuffers.Builder, - includedFilenamesOffset: flatbuffers.Offset, - ): void; - static createIncludedFilenamesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startIncludedFilenamesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static endSchemaFile(builder: flatbuffers.Builder): flatbuffers.Offset; - static createSchemaFile( - builder: flatbuffers.Builder, - filenameOffset: flatbuffers.Offset, - includedFilenamesOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - unpack(): SchemaFileT; - unpackTo(_o: SchemaFileT): void; +export declare class SchemaFile implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): SchemaFile; + static getRootAsSchemaFile(bb: flatbuffers.ByteBuffer, obj?: SchemaFile): SchemaFile; + static getSizePrefixedRootAsSchemaFile(bb: flatbuffers.ByteBuffer, obj?: SchemaFile): SchemaFile; + /** + * Filename, relative to project root. + */ + filename(): string; + filename(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + /** + * Names of included files, relative to project root. + */ + includedFilenames(index: number): string; + includedFilenames(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + includedFilenamesLength(): number; + static getFullyQualifiedName(): "reflection.SchemaFile"; + static startSchemaFile(builder: flatbuffers.Builder): void; + static addFilename(builder: flatbuffers.Builder, filenameOffset: flatbuffers.Offset): void; + static addIncludedFilenames(builder: flatbuffers.Builder, includedFilenamesOffset: flatbuffers.Offset): void; + static createIncludedFilenamesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startIncludedFilenamesVector(builder: flatbuffers.Builder, numElems: number): void; + static endSchemaFile(builder: flatbuffers.Builder): flatbuffers.Offset; + static createSchemaFile(builder: flatbuffers.Builder, filenameOffset: flatbuffers.Offset, includedFilenamesOffset: flatbuffers.Offset): flatbuffers.Offset; + unpack(): SchemaFileT; + unpackTo(_o: SchemaFileT): void; } export declare class SchemaFileT implements flatbuffers.IGeneratedObject { - filename: string | Uint8Array | null; - includedFilenames: string[]; - constructor( - filename?: string | Uint8Array | null, - includedFilenames?: string[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + filename: string | Uint8Array | null; + includedFilenames: (string)[]; + constructor(filename?: string | Uint8Array | null, includedFilenames?: (string)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/schema-file.js b/tests/ts/reflection/schema-file.js index 51c976eba..3790cfd3e 100644 --- a/tests/ts/reflection/schema-file.js +++ b/tests/ts/reflection/schema-file.js @@ -1,6 +1,5 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; /** * File specific information. @@ -8,95 +7,83 @@ import * as flatbuffers from 'flatbuffers'; * symbols and examining the `declaration_file` field. */ export class SchemaFile { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsSchemaFile(bb, obj) { - return (obj || new SchemaFile()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsSchemaFile(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new SchemaFile()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - filename(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - includedFilenames(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - includedFilenamesLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static getFullyQualifiedName() { - return 'reflection.SchemaFile'; - } - static startSchemaFile(builder) { - builder.startObject(2); - } - static addFilename(builder, filenameOffset) { - builder.addFieldOffset(0, filenameOffset, 0); - } - static addIncludedFilenames(builder, includedFilenamesOffset) { - builder.addFieldOffset(1, includedFilenamesOffset, 0); - } - static createIncludedFilenamesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsSchemaFile(bb, obj) { + return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsSchemaFile(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + filename(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); + } + includedFilenames(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + includedFilenamesLength() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + static getFullyQualifiedName() { + return 'reflection.SchemaFile'; + } + static startSchemaFile(builder) { + builder.startObject(2); + } + static addFilename(builder, filenameOffset) { + builder.addFieldOffset(0, filenameOffset, 0); + } + static addIncludedFilenames(builder, includedFilenamesOffset) { + builder.addFieldOffset(1, includedFilenamesOffset, 0); + } + static createIncludedFilenamesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startIncludedFilenamesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static endSchemaFile(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // filename + return offset; + } + static createSchemaFile(builder, filenameOffset, includedFilenamesOffset) { + SchemaFile.startSchemaFile(builder); + SchemaFile.addFilename(builder, filenameOffset); + SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset); + return SchemaFile.endSchemaFile(builder); + } + unpack() { + return new SchemaFileT(this.filename(), this.bb.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength())); + } + unpackTo(_o) { + _o.filename = this.filename(); + _o.includedFilenames = this.bb.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength()); } - return builder.endVector(); - } - static startIncludedFilenamesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endSchemaFile(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // filename - return offset; - } - static createSchemaFile(builder, filenameOffset, includedFilenamesOffset) { - SchemaFile.startSchemaFile(builder); - SchemaFile.addFilename(builder, filenameOffset); - SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset); - return SchemaFile.endSchemaFile(builder); - } - unpack() { - return new SchemaFileT( - this.filename(), - this.bb.createScalarList( - this.includedFilenames.bind(this), this.includedFilenamesLength())); - } - unpackTo(_o) { - _o.filename = this.filename(); - _o.includedFilenames = this.bb.createScalarList( - this.includedFilenames.bind(this), this.includedFilenamesLength()); - } } export class SchemaFileT { - constructor(filename = null, includedFilenames = []) { - this.filename = filename; - this.includedFilenames = includedFilenames; - } - pack(builder) { - const filename = - (this.filename !== null ? builder.createString(this.filename) : 0); - const includedFilenames = SchemaFile.createIncludedFilenamesVector( - builder, builder.createObjectOffsetList(this.includedFilenames)); - return SchemaFile.createSchemaFile(builder, filename, includedFilenames); - } + constructor(filename = null, includedFilenames = []) { + this.filename = filename; + this.includedFilenames = includedFilenames; + } + pack(builder) { + const filename = (this.filename !== null ? builder.createString(this.filename) : 0); + const includedFilenames = SchemaFile.createIncludedFilenamesVector(builder, builder.createObjectOffsetList(this.includedFilenames)); + return SchemaFile.createSchemaFile(builder, filename, includedFilenames); + } } diff --git a/tests/ts/reflection/schema-file.ts b/tests/ts/reflection/schema-file.ts index 9248c4b10..3d01c6925 100644 --- a/tests/ts/reflection/schema-file.ts +++ b/tests/ts/reflection/schema-file.ts @@ -4,169 +4,125 @@ import * as flatbuffers from 'flatbuffers'; + + /** * File specific information. * Symbols declared within a file may be recovered by iterating over all * symbols and examining the `declaration_file` field. */ export class SchemaFile implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): SchemaFile { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):SchemaFile { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsSchemaFile( - bb: flatbuffers.ByteBuffer, - obj?: SchemaFile, - ): SchemaFile { - return (obj || new SchemaFile()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsSchemaFile(bb:flatbuffers.ByteBuffer, obj?:SchemaFile):SchemaFile { + return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsSchemaFile( - bb: flatbuffers.ByteBuffer, - obj?: SchemaFile, - ): SchemaFile { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new SchemaFile()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsSchemaFile(bb:flatbuffers.ByteBuffer, obj?:SchemaFile):SchemaFile { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new SchemaFile()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - /** - * Filename, relative to project root. - */ - filename(): string | null; - filename(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - filename(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +/** + * Filename, relative to project root. + */ +filename():string +filename(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +filename(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} - /** - * Names of included files, relative to project root. - */ - includedFilenames(index: number): string; - includedFilenames( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - includedFilenames( - index: number, - optionalEncoding?: any, - ): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? this.bb!.__string( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding, - ) - : null; - } +/** + * Names of included files, relative to project root. + */ +includedFilenames(index: number):string +includedFilenames(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +includedFilenames(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} - includedFilenamesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +includedFilenamesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} - static getFullyQualifiedName(): string { - return 'reflection.SchemaFile'; - } +static getFullyQualifiedName(): "reflection.SchemaFile" { + return 'reflection.SchemaFile'; +} - static startSchemaFile(builder: flatbuffers.Builder) { - builder.startObject(2); - } +static startSchemaFile(builder:flatbuffers.Builder):void { + builder.startObject(2); +} - static addFilename( - builder: flatbuffers.Builder, - filenameOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(0, filenameOffset, 0); - } +static addFilename(builder:flatbuffers.Builder, filenameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, filenameOffset, 0); +} - static addIncludedFilenames( - builder: flatbuffers.Builder, - includedFilenamesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, includedFilenamesOffset, 0); - } +static addIncludedFilenames(builder:flatbuffers.Builder, includedFilenamesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, includedFilenamesOffset, 0); +} - static createIncludedFilenamesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); +static createIncludedFilenamesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static startIncludedFilenamesVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } +static startIncludedFilenamesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - static endSchemaFile(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // filename - return offset; - } +static endSchemaFile(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // filename + return offset; +} - static createSchemaFile( - builder: flatbuffers.Builder, - filenameOffset: flatbuffers.Offset, - includedFilenamesOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - SchemaFile.startSchemaFile(builder); - SchemaFile.addFilename(builder, filenameOffset); - SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset); - return SchemaFile.endSchemaFile(builder); - } +static createSchemaFile(builder:flatbuffers.Builder, filenameOffset:flatbuffers.Offset, includedFilenamesOffset:flatbuffers.Offset):flatbuffers.Offset { + SchemaFile.startSchemaFile(builder); + SchemaFile.addFilename(builder, filenameOffset); + SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset); + return SchemaFile.endSchemaFile(builder); +} - unpack(): SchemaFileT { - return new SchemaFileT( - this.filename(), - this.bb!.createScalarList( - this.includedFilenames.bind(this), - this.includedFilenamesLength(), - ), - ); - } +unpack(): SchemaFileT { + return new SchemaFileT( + this.filename(), + this.bb!.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength()) + ); +} - unpackTo(_o: SchemaFileT): void { - _o.filename = this.filename(); - _o.includedFilenames = this.bb!.createScalarList( - this.includedFilenames.bind(this), - this.includedFilenamesLength(), - ); - } + +unpackTo(_o: SchemaFileT): void { + _o.filename = this.filename(); + _o.includedFilenames = this.bb!.createScalarList(this.includedFilenames.bind(this), this.includedFilenamesLength()); +} } export class SchemaFileT implements flatbuffers.IGeneratedObject { - constructor( - public filename: string | Uint8Array | null = null, - public includedFilenames: string[] = [], - ) {} +constructor( + public filename: string|Uint8Array|null = null, + public includedFilenames: (string)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const filename = - this.filename !== null ? builder.createString(this.filename!) : 0; - const includedFilenames = SchemaFile.createIncludedFilenamesVector( - builder, - builder.createObjectOffsetList(this.includedFilenames), - ); - return SchemaFile.createSchemaFile(builder, filename, includedFilenames); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const filename = (this.filename !== null ? builder.createString(this.filename!) : 0); + const includedFilenames = SchemaFile.createIncludedFilenamesVector(builder, builder.createObjectOffsetList(this.includedFilenames)); + + return SchemaFile.createSchemaFile(builder, + filename, + includedFilenames + ); +} } diff --git a/tests/ts/reflection/schema.d.ts b/tests/ts/reflection/schema.d.ts index caf9973f8..aabe79d5d 100644 --- a/tests/ts/reflection/schema.d.ts +++ b/tests/ts/reflection/schema.d.ts @@ -1,130 +1,67 @@ import * as flatbuffers from 'flatbuffers'; -import {Enum, EnumT} from '../reflection/enum.js'; -import {Object_, Object_T} from '../reflection/object.js'; -import {SchemaFile, SchemaFileT} from '../reflection/schema-file.js'; -import {Service, ServiceT} from '../reflection/service.js'; +import { Enum, EnumT } from './enum.js'; +import { Object_, Object_T } from './object.js'; +import { SchemaFile, SchemaFileT } from './schema-file.js'; +import { Service, ServiceT } from './service.js'; export declare class Schema implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Schema; - static getRootAsSchema(bb: flatbuffers.ByteBuffer, obj?: Schema): Schema; - static getSizePrefixedRootAsSchema( - bb: flatbuffers.ByteBuffer, - obj?: Schema, - ): Schema; - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; - objects(index: number, obj?: Object_): Object_ | null; - objectsLength(): number; - enums(index: number, obj?: Enum): Enum | null; - enumsLength(): number; - fileIdent(): string | null; - fileIdent(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - fileExt(): string | null; - fileExt(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - rootTable(obj?: Object_): Object_ | null; - services(index: number, obj?: Service): Service | null; - servicesLength(): number; - advancedFeatures(): bigint; - mutate_advanced_features(value: bigint): boolean; - /** - * All the files used in this compilation. Files are relative to where - * flatc was invoked. - */ - fbsFiles(index: number, obj?: SchemaFile): SchemaFile | null; - fbsFilesLength(): number; - static getFullyQualifiedName(): string; - static startSchema(builder: flatbuffers.Builder): void; - static addObjects( - builder: flatbuffers.Builder, - objectsOffset: flatbuffers.Offset, - ): void; - static createObjectsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startObjectsVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addEnums( - builder: flatbuffers.Builder, - enumsOffset: flatbuffers.Offset, - ): void; - static createEnumsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startEnumsVector(builder: flatbuffers.Builder, numElems: number): void; - static addFileIdent( - builder: flatbuffers.Builder, - fileIdentOffset: flatbuffers.Offset, - ): void; - static addFileExt( - builder: flatbuffers.Builder, - fileExtOffset: flatbuffers.Offset, - ): void; - static addRootTable( - builder: flatbuffers.Builder, - rootTableOffset: flatbuffers.Offset, - ): void; - static addServices( - builder: flatbuffers.Builder, - servicesOffset: flatbuffers.Offset, - ): void; - static createServicesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startServicesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addAdvancedFeatures( - builder: flatbuffers.Builder, - advancedFeatures: bigint, - ): void; - static addFbsFiles( - builder: flatbuffers.Builder, - fbsFilesOffset: flatbuffers.Offset, - ): void; - static createFbsFilesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startFbsFilesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static endSchema(builder: flatbuffers.Builder): flatbuffers.Offset; - static finishSchemaBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static finishSizePrefixedSchemaBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - unpack(): SchemaT; - unpackTo(_o: SchemaT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Schema; + static getRootAsSchema(bb: flatbuffers.ByteBuffer, obj?: Schema): Schema; + static getSizePrefixedRootAsSchema(bb: flatbuffers.ByteBuffer, obj?: Schema): Schema; + static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; + objects(index: number, obj?: Object_): Object_ | null; + objectsLength(): number; + enums(index: number, obj?: Enum): Enum | null; + enumsLength(): number; + fileIdent(): string | null; + fileIdent(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + fileExt(): string | null; + fileExt(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + rootTable(obj?: Object_): Object_ | null; + services(index: number, obj?: Service): Service | null; + servicesLength(): number; + advancedFeatures(): bigint; + mutate_advanced_features(value: bigint): boolean; + /** + * All the files used in this compilation. Files are relative to where + * flatc was invoked. + */ + fbsFiles(index: number, obj?: SchemaFile): SchemaFile | null; + fbsFilesLength(): number; + static getFullyQualifiedName(): "reflection.Schema"; + static startSchema(builder: flatbuffers.Builder): void; + static addObjects(builder: flatbuffers.Builder, objectsOffset: flatbuffers.Offset): void; + static createObjectsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startObjectsVector(builder: flatbuffers.Builder, numElems: number): void; + static addEnums(builder: flatbuffers.Builder, enumsOffset: flatbuffers.Offset): void; + static createEnumsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startEnumsVector(builder: flatbuffers.Builder, numElems: number): void; + static addFileIdent(builder: flatbuffers.Builder, fileIdentOffset: flatbuffers.Offset): void; + static addFileExt(builder: flatbuffers.Builder, fileExtOffset: flatbuffers.Offset): void; + static addRootTable(builder: flatbuffers.Builder, rootTableOffset: flatbuffers.Offset): void; + static addServices(builder: flatbuffers.Builder, servicesOffset: flatbuffers.Offset): void; + static createServicesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startServicesVector(builder: flatbuffers.Builder, numElems: number): void; + static addAdvancedFeatures(builder: flatbuffers.Builder, advancedFeatures: bigint): void; + static addFbsFiles(builder: flatbuffers.Builder, fbsFilesOffset: flatbuffers.Offset): void; + static createFbsFilesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startFbsFilesVector(builder: flatbuffers.Builder, numElems: number): void; + static endSchema(builder: flatbuffers.Builder): flatbuffers.Offset; + static finishSchemaBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static finishSizePrefixedSchemaBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + unpack(): SchemaT; + unpackTo(_o: SchemaT): void; } export declare class SchemaT implements flatbuffers.IGeneratedObject { - objects: Object_T[]; - enums: EnumT[]; - fileIdent: string | Uint8Array | null; - fileExt: string | Uint8Array | null; - rootTable: Object_T | null; - services: ServiceT[]; - advancedFeatures: bigint; - fbsFiles: SchemaFileT[]; - constructor( - objects?: Object_T[], - enums?: EnumT[], - fileIdent?: string | Uint8Array | null, - fileExt?: string | Uint8Array | null, - rootTable?: Object_T | null, - services?: ServiceT[], - advancedFeatures?: bigint, - fbsFiles?: SchemaFileT[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + objects: (Object_T)[]; + enums: (EnumT)[]; + fileIdent: string | Uint8Array | null; + fileExt: string | Uint8Array | null; + rootTable: Object_T | null; + services: (ServiceT)[]; + advancedFeatures: bigint; + fbsFiles: (SchemaFileT)[]; + constructor(objects?: (Object_T)[], enums?: (EnumT)[], fileIdent?: string | Uint8Array | null, fileExt?: string | Uint8Array | null, rootTable?: Object_T | null, services?: (ServiceT)[], advancedFeatures?: bigint, fbsFiles?: (SchemaFileT)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/schema.js b/tests/ts/reflection/schema.js index e738cef9d..dc1730cfa 100644 --- a/tests/ts/reflection/schema.js +++ b/tests/ts/reflection/schema.js @@ -1,269 +1,214 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {Enum} from '../reflection/enum.js'; -import {Object_} from '../reflection/object.js'; -import {SchemaFile} from '../reflection/schema-file.js'; -import {Service} from '../reflection/service.js'; - +import { Enum } from './enum.js'; +import { Object_ } from './object.js'; +import { SchemaFile } from './schema-file.js'; +import { Service } from './service.js'; export class Schema { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsSchema(bb, obj) { - return (obj || new Schema()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsSchema(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Schema()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static bufferHasIdentifier(bb) { - return bb.__has_identifier('BFBS'); - } - objects(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? - (obj || new Object_()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - objectsLength() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - enums(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? - (obj || new Enum()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - enumsLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - fileIdent(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - fileExt(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - rootTable(obj) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? - (obj || new Object_()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - services(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? - (obj || new Service()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - servicesLength() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - advancedFeatures() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); - } - mutate_advanced_features(value) { - const offset = this.bb.__offset(this.bb_pos, 16); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeUint64(this.bb_pos + offset, value); - return true; - } - /** - * All the files used in this compilation. Files are relative to where - * flatc was invoked. - */ - fbsFiles(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? - (obj || new SchemaFile()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - fbsFilesLength() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static getFullyQualifiedName() { - return 'reflection.Schema'; - } - static startSchema(builder) { - builder.startObject(8); - } - static addObjects(builder, objectsOffset) { - builder.addFieldOffset(0, objectsOffset, 0); - } - static createObjectsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - return builder.endVector(); - } - static startObjectsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addEnums(builder, enumsOffset) { - builder.addFieldOffset(1, enumsOffset, 0); - } - static createEnumsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static getRootAsSchema(bb, obj) { + return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - return builder.endVector(); - } - static startEnumsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addFileIdent(builder, fileIdentOffset) { - builder.addFieldOffset(2, fileIdentOffset, 0); - } - static addFileExt(builder, fileExtOffset) { - builder.addFieldOffset(3, fileExtOffset, 0); - } - static addRootTable(builder, rootTableOffset) { - builder.addFieldOffset(4, rootTableOffset, 0); - } - static addServices(builder, servicesOffset) { - builder.addFieldOffset(5, servicesOffset, 0); - } - static createServicesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static getSizePrefixedRootAsSchema(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - return builder.endVector(); - } - static startServicesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addAdvancedFeatures(builder, advancedFeatures) { - builder.addFieldInt64(6, advancedFeatures, BigInt('0')); - } - static addFbsFiles(builder, fbsFilesOffset) { - builder.addFieldOffset(7, fbsFilesOffset, 0); - } - static createFbsFilesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static bufferHasIdentifier(bb) { + return bb.__has_identifier('BFBS'); + } + objects(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + objectsLength() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + enums(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new Enum()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + enumsLength() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + fileIdent(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + fileExt(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + rootTable(obj) { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? (obj || new Object_()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + services(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? (obj || new Service()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + servicesLength() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + advancedFeatures() { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); + } + mutate_advanced_features(value) { + const offset = this.bb.__offset(this.bb_pos, 16); + if (offset === 0) { + return false; + } + this.bb.writeUint64(this.bb_pos + offset, value); + return true; + } + /** + * All the files used in this compilation. Files are relative to where + * flatc was invoked. + */ + fbsFiles(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 18); + return offset ? (obj || new SchemaFile()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + fbsFilesLength() { + const offset = this.bb.__offset(this.bb_pos, 18); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + static getFullyQualifiedName() { + return 'reflection.Schema'; + } + static startSchema(builder) { + builder.startObject(8); + } + static addObjects(builder, objectsOffset) { + builder.addFieldOffset(0, objectsOffset, 0); + } + static createObjectsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startObjectsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addEnums(builder, enumsOffset) { + builder.addFieldOffset(1, enumsOffset, 0); + } + static createEnumsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startEnumsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addFileIdent(builder, fileIdentOffset) { + builder.addFieldOffset(2, fileIdentOffset, 0); + } + static addFileExt(builder, fileExtOffset) { + builder.addFieldOffset(3, fileExtOffset, 0); + } + static addRootTable(builder, rootTableOffset) { + builder.addFieldOffset(4, rootTableOffset, 0); + } + static addServices(builder, servicesOffset) { + builder.addFieldOffset(5, servicesOffset, 0); + } + static createServicesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startServicesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addAdvancedFeatures(builder, advancedFeatures) { + builder.addFieldInt64(6, advancedFeatures, BigInt('0')); + } + static addFbsFiles(builder, fbsFilesOffset) { + builder.addFieldOffset(7, fbsFilesOffset, 0); + } + static createFbsFilesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startFbsFilesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static endSchema(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // objects + builder.requiredField(offset, 6); // enums + return offset; + } + static finishSchemaBuffer(builder, offset) { + builder.finish(offset, 'BFBS'); + } + static finishSizePrefixedSchemaBuffer(builder, offset) { + builder.finish(offset, 'BFBS', true); + } + unpack() { + return new SchemaT(this.bb.createObjList(this.objects.bind(this), this.objectsLength()), this.bb.createObjList(this.enums.bind(this), this.enumsLength()), this.fileIdent(), this.fileExt(), (this.rootTable() !== null ? this.rootTable().unpack() : null), this.bb.createObjList(this.services.bind(this), this.servicesLength()), this.advancedFeatures(), this.bb.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength())); + } + unpackTo(_o) { + _o.objects = this.bb.createObjList(this.objects.bind(this), this.objectsLength()); + _o.enums = this.bb.createObjList(this.enums.bind(this), this.enumsLength()); + _o.fileIdent = this.fileIdent(); + _o.fileExt = this.fileExt(); + _o.rootTable = (this.rootTable() !== null ? this.rootTable().unpack() : null); + _o.services = this.bb.createObjList(this.services.bind(this), this.servicesLength()); + _o.advancedFeatures = this.advancedFeatures(); + _o.fbsFiles = this.bb.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength()); } - return builder.endVector(); - } - static startFbsFilesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endSchema(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // objects - builder.requiredField(offset, 6); // enums - return offset; - } - static finishSchemaBuffer(builder, offset) { - builder.finish(offset, 'BFBS'); - } - static finishSizePrefixedSchemaBuffer(builder, offset) { - builder.finish(offset, 'BFBS', true); - } - unpack() { - return new SchemaT( - this.bb.createObjList(this.objects.bind(this), this.objectsLength()), - this.bb.createObjList(this.enums.bind(this), this.enumsLength()), - this.fileIdent(), this.fileExt(), - (this.rootTable() !== null ? this.rootTable().unpack() : null), - this.bb.createObjList(this.services.bind(this), this.servicesLength()), - this.advancedFeatures(), - this.bb.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength())); - } - unpackTo(_o) { - _o.objects = - this.bb.createObjList(this.objects.bind(this), this.objectsLength()); - _o.enums = this.bb.createObjList(this.enums.bind(this), this.enumsLength()); - _o.fileIdent = this.fileIdent(); - _o.fileExt = this.fileExt(); - _o.rootTable = - (this.rootTable() !== null ? this.rootTable().unpack() : null); - _o.services = - this.bb.createObjList(this.services.bind(this), this.servicesLength()); - _o.advancedFeatures = this.advancedFeatures(); - _o.fbsFiles = - this.bb.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength()); - } } export class SchemaT { - constructor( - objects = [], enums = [], fileIdent = null, fileExt = null, - rootTable = null, services = [], advancedFeatures = BigInt('0'), - fbsFiles = []) { - this.objects = objects; - this.enums = enums; - this.fileIdent = fileIdent; - this.fileExt = fileExt; - this.rootTable = rootTable; - this.services = services; - this.advancedFeatures = advancedFeatures; - this.fbsFiles = fbsFiles; - } - pack(builder) { - const objects = Schema.createObjectsVector( - builder, builder.createObjectOffsetList(this.objects)); - const enums = Schema.createEnumsVector( - builder, builder.createObjectOffsetList(this.enums)); - const fileIdent = - (this.fileIdent !== null ? builder.createString(this.fileIdent) : 0); - const fileExt = - (this.fileExt !== null ? builder.createString(this.fileExt) : 0); - const rootTable = - (this.rootTable !== null ? this.rootTable.pack(builder) : 0); - const services = Schema.createServicesVector( - builder, builder.createObjectOffsetList(this.services)); - const fbsFiles = Schema.createFbsFilesVector( - builder, builder.createObjectOffsetList(this.fbsFiles)); - Schema.startSchema(builder); - Schema.addObjects(builder, objects); - Schema.addEnums(builder, enums); - Schema.addFileIdent(builder, fileIdent); - Schema.addFileExt(builder, fileExt); - Schema.addRootTable(builder, rootTable); - Schema.addServices(builder, services); - Schema.addAdvancedFeatures(builder, this.advancedFeatures); - Schema.addFbsFiles(builder, fbsFiles); - return Schema.endSchema(builder); - } + constructor(objects = [], enums = [], fileIdent = null, fileExt = null, rootTable = null, services = [], advancedFeatures = BigInt('0'), fbsFiles = []) { + this.objects = objects; + this.enums = enums; + this.fileIdent = fileIdent; + this.fileExt = fileExt; + this.rootTable = rootTable; + this.services = services; + this.advancedFeatures = advancedFeatures; + this.fbsFiles = fbsFiles; + } + pack(builder) { + const objects = Schema.createObjectsVector(builder, builder.createObjectOffsetList(this.objects)); + const enums = Schema.createEnumsVector(builder, builder.createObjectOffsetList(this.enums)); + const fileIdent = (this.fileIdent !== null ? builder.createString(this.fileIdent) : 0); + const fileExt = (this.fileExt !== null ? builder.createString(this.fileExt) : 0); + const rootTable = (this.rootTable !== null ? this.rootTable.pack(builder) : 0); + const services = Schema.createServicesVector(builder, builder.createObjectOffsetList(this.services)); + const fbsFiles = Schema.createFbsFilesVector(builder, builder.createObjectOffsetList(this.fbsFiles)); + Schema.startSchema(builder); + Schema.addObjects(builder, objects); + Schema.addEnums(builder, enums); + Schema.addFileIdent(builder, fileIdent); + Schema.addFileExt(builder, fileExt); + Schema.addRootTable(builder, rootTable); + Schema.addServices(builder, services); + Schema.addAdvancedFeatures(builder, this.advancedFeatures); + Schema.addFbsFiles(builder, fbsFiles); + return Schema.endSchema(builder); + } } diff --git a/tests/ts/reflection/schema.ts b/tests/ts/reflection/schema.ts index 019daea38..4911fcd0a 100644 --- a/tests/ts/reflection/schema.ts +++ b/tests/ts/reflection/schema.ts @@ -4,399 +4,275 @@ import * as flatbuffers from 'flatbuffers'; -import {Enum, EnumT} from '../reflection/enum.js'; -import {Object_, Object_T} from '../reflection/object.js'; -import {SchemaFile, SchemaFileT} from '../reflection/schema-file.js'; -import {Service, ServiceT} from '../reflection/service.js'; +import { Enum, EnumT } from './enum.js'; +import { Object_, Object_T } from './object.js'; +import { SchemaFile, SchemaFileT } from './schema-file.js'; +import { Service, ServiceT } from './service.js'; + export class Schema implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Schema { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Schema { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsSchema(bb:flatbuffers.ByteBuffer, obj?:Schema):Schema { + return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsSchema(bb:flatbuffers.ByteBuffer, obj?:Schema):Schema { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Schema()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean { + return bb.__has_identifier('BFBS'); +} + +objects(index: number, obj?:Object_):Object_|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +objectsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +enums(index: number, obj?:Enum):Enum|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new Enum()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +enumsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +fileIdent():string|null +fileIdent(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +fileIdent(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} + +fileExt():string|null +fileExt(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +fileExt(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} + +rootTable(obj?:Object_):Object_|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? (obj || new Object_()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} + +services(index: number, obj?:Service):Service|null { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? (obj || new Service()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +servicesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +advancedFeatures():bigint { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +mutate_advanced_features(value:bigint):boolean { + const offset = this.bb!.__offset(this.bb_pos, 16); + + if (offset === 0) { + return false; } - static getRootAsSchema(bb: flatbuffers.ByteBuffer, obj?: Schema): Schema { - return (obj || new Schema()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeUint64(this.bb_pos + offset, value); + return true; +} + +/** + * All the files used in this compilation. Files are relative to where + * flatc was invoked. + */ +fbsFiles(index: number, obj?:SchemaFile):SchemaFile|null { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? (obj || new SchemaFile()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} + +fbsFilesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +static getFullyQualifiedName(): "reflection.Schema" { + return 'reflection.Schema'; +} + +static startSchema(builder:flatbuffers.Builder):void { + builder.startObject(8); +} + +static addObjects(builder:flatbuffers.Builder, objectsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, objectsOffset, 0); +} + +static createObjectsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static getSizePrefixedRootAsSchema( - bb: flatbuffers.ByteBuffer, - obj?: Schema, - ): Schema { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Schema()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); +static startObjectsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addEnums(builder:flatbuffers.Builder, enumsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, enumsOffset, 0); +} + +static createEnumsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean { - return bb.__has_identifier('BFBS'); +static startEnumsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addFileIdent(builder:flatbuffers.Builder, fileIdentOffset:flatbuffers.Offset):void { + builder.addFieldOffset(2, fileIdentOffset, 0); +} + +static addFileExt(builder:flatbuffers.Builder, fileExtOffset:flatbuffers.Offset):void { + builder.addFieldOffset(3, fileExtOffset, 0); +} + +static addRootTable(builder:flatbuffers.Builder, rootTableOffset:flatbuffers.Offset):void { + builder.addFieldOffset(4, rootTableOffset, 0); +} + +static addServices(builder:flatbuffers.Builder, servicesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(5, servicesOffset, 0); +} + +static createServicesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - objects(index: number, obj?: Object_): Object_ | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? (obj || new Object_()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; +static startServicesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addAdvancedFeatures(builder:flatbuffers.Builder, advancedFeatures:bigint):void { + builder.addFieldInt64(6, advancedFeatures, BigInt('0')); +} + +static addFbsFiles(builder:flatbuffers.Builder, fbsFilesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(7, fbsFilesOffset, 0); +} + +static createFbsFilesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - objectsLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +static startFbsFilesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - enums(index: number, obj?: Enum): Enum | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? (obj || new Enum()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } +static endSchema(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // objects + builder.requiredField(offset, 6) // enums + return offset; +} - enumsLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +static finishSchemaBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, 'BFBS'); +} - fileIdent(): string | null; - fileIdent(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - fileIdent(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +static finishSizePrefixedSchemaBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, 'BFBS', true); +} - fileExt(): string | null; - fileExt(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - fileExt(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } - rootTable(obj?: Object_): Object_ | null { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset - ? (obj || new Object_()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } +unpack(): SchemaT { + return new SchemaT( + this.bb!.createObjList(this.objects.bind(this), this.objectsLength()), + this.bb!.createObjList(this.enums.bind(this), this.enumsLength()), + this.fileIdent(), + this.fileExt(), + (this.rootTable() !== null ? this.rootTable()!.unpack() : null), + this.bb!.createObjList(this.services.bind(this), this.servicesLength()), + this.advancedFeatures(), + this.bb!.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength()) + ); +} - services(index: number, obj?: Service): Service | null { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset - ? (obj || new Service()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } - servicesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - advancedFeatures(): bigint { - const offset = this.bb!.__offset(this.bb_pos, 16); - return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); - } - - mutate_advanced_features(value: bigint): boolean { - const offset = this.bb!.__offset(this.bb_pos, 16); - - if (offset === 0) { - return false; - } - - this.bb!.writeUint64(this.bb_pos + offset, value); - return true; - } - - /** - * All the files used in this compilation. Files are relative to where - * flatc was invoked. - */ - fbsFiles(index: number, obj?: SchemaFile): SchemaFile | null { - const offset = this.bb!.__offset(this.bb_pos, 18); - return offset - ? (obj || new SchemaFile()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } - - fbsFilesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 18); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - static getFullyQualifiedName(): string { - return 'reflection.Schema'; - } - - static startSchema(builder: flatbuffers.Builder) { - builder.startObject(8); - } - - static addObjects( - builder: flatbuffers.Builder, - objectsOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(0, objectsOffset, 0); - } - - static createObjectsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startObjectsVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addEnums( - builder: flatbuffers.Builder, - enumsOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, enumsOffset, 0); - } - - static createEnumsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startEnumsVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addFileIdent( - builder: flatbuffers.Builder, - fileIdentOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(2, fileIdentOffset, 0); - } - - static addFileExt( - builder: flatbuffers.Builder, - fileExtOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(3, fileExtOffset, 0); - } - - static addRootTable( - builder: flatbuffers.Builder, - rootTableOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(4, rootTableOffset, 0); - } - - static addServices( - builder: flatbuffers.Builder, - servicesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(5, servicesOffset, 0); - } - - static createServicesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startServicesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static addAdvancedFeatures( - builder: flatbuffers.Builder, - advancedFeatures: bigint, - ) { - builder.addFieldInt64(6, advancedFeatures, BigInt('0')); - } - - static addFbsFiles( - builder: flatbuffers.Builder, - fbsFilesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(7, fbsFilesOffset, 0); - } - - static createFbsFilesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startFbsFilesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } - - static endSchema(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // objects - builder.requiredField(offset, 6); // enums - return offset; - } - - static finishSchemaBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, 'BFBS'); - } - - static finishSizePrefixedSchemaBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ) { - builder.finish(offset, 'BFBS', true); - } - - unpack(): SchemaT { - return new SchemaT( - this.bb!.createObjList( - this.objects.bind(this), - this.objectsLength(), - ), - this.bb!.createObjList( - this.enums.bind(this), - this.enumsLength(), - ), - this.fileIdent(), - this.fileExt(), - this.rootTable() !== null ? this.rootTable()!.unpack() : null, - this.bb!.createObjList( - this.services.bind(this), - this.servicesLength(), - ), - this.advancedFeatures(), - this.bb!.createObjList( - this.fbsFiles.bind(this), - this.fbsFilesLength(), - ), - ); - } - - unpackTo(_o: SchemaT): void { - _o.objects = this.bb!.createObjList( - this.objects.bind(this), - this.objectsLength(), - ); - _o.enums = this.bb!.createObjList( - this.enums.bind(this), - this.enumsLength(), - ); - _o.fileIdent = this.fileIdent(); - _o.fileExt = this.fileExt(); - _o.rootTable = - this.rootTable() !== null ? this.rootTable()!.unpack() : null; - _o.services = this.bb!.createObjList( - this.services.bind(this), - this.servicesLength(), - ); - _o.advancedFeatures = this.advancedFeatures(); - _o.fbsFiles = this.bb!.createObjList( - this.fbsFiles.bind(this), - this.fbsFilesLength(), - ); - } +unpackTo(_o: SchemaT): void { + _o.objects = this.bb!.createObjList(this.objects.bind(this), this.objectsLength()); + _o.enums = this.bb!.createObjList(this.enums.bind(this), this.enumsLength()); + _o.fileIdent = this.fileIdent(); + _o.fileExt = this.fileExt(); + _o.rootTable = (this.rootTable() !== null ? this.rootTable()!.unpack() : null); + _o.services = this.bb!.createObjList(this.services.bind(this), this.servicesLength()); + _o.advancedFeatures = this.advancedFeatures(); + _o.fbsFiles = this.bb!.createObjList(this.fbsFiles.bind(this), this.fbsFilesLength()); +} } export class SchemaT implements flatbuffers.IGeneratedObject { - constructor( - public objects: Object_T[] = [], - public enums: EnumT[] = [], - public fileIdent: string | Uint8Array | null = null, - public fileExt: string | Uint8Array | null = null, - public rootTable: Object_T | null = null, - public services: ServiceT[] = [], - public advancedFeatures: bigint = BigInt('0'), - public fbsFiles: SchemaFileT[] = [], - ) {} +constructor( + public objects: (Object_T)[] = [], + public enums: (EnumT)[] = [], + public fileIdent: string|Uint8Array|null = null, + public fileExt: string|Uint8Array|null = null, + public rootTable: Object_T|null = null, + public services: (ServiceT)[] = [], + public advancedFeatures: bigint = BigInt('0'), + public fbsFiles: (SchemaFileT)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const objects = Schema.createObjectsVector( - builder, - builder.createObjectOffsetList(this.objects), - ); - const enums = Schema.createEnumsVector( - builder, - builder.createObjectOffsetList(this.enums), - ); - const fileIdent = - this.fileIdent !== null ? builder.createString(this.fileIdent!) : 0; - const fileExt = - this.fileExt !== null ? builder.createString(this.fileExt!) : 0; - const rootTable = - this.rootTable !== null ? this.rootTable!.pack(builder) : 0; - const services = Schema.createServicesVector( - builder, - builder.createObjectOffsetList(this.services), - ); - const fbsFiles = Schema.createFbsFilesVector( - builder, - builder.createObjectOffsetList(this.fbsFiles), - ); - Schema.startSchema(builder); - Schema.addObjects(builder, objects); - Schema.addEnums(builder, enums); - Schema.addFileIdent(builder, fileIdent); - Schema.addFileExt(builder, fileExt); - Schema.addRootTable(builder, rootTable); - Schema.addServices(builder, services); - Schema.addAdvancedFeatures(builder, this.advancedFeatures); - Schema.addFbsFiles(builder, fbsFiles); +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const objects = Schema.createObjectsVector(builder, builder.createObjectOffsetList(this.objects)); + const enums = Schema.createEnumsVector(builder, builder.createObjectOffsetList(this.enums)); + const fileIdent = (this.fileIdent !== null ? builder.createString(this.fileIdent!) : 0); + const fileExt = (this.fileExt !== null ? builder.createString(this.fileExt!) : 0); + const rootTable = (this.rootTable !== null ? this.rootTable!.pack(builder) : 0); + const services = Schema.createServicesVector(builder, builder.createObjectOffsetList(this.services)); + const fbsFiles = Schema.createFbsFilesVector(builder, builder.createObjectOffsetList(this.fbsFiles)); - return Schema.endSchema(builder); - } + Schema.startSchema(builder); + Schema.addObjects(builder, objects); + Schema.addEnums(builder, enums); + Schema.addFileIdent(builder, fileIdent); + Schema.addFileExt(builder, fileExt); + Schema.addRootTable(builder, rootTable); + Schema.addServices(builder, services); + Schema.addAdvancedFeatures(builder, this.advancedFeatures); + Schema.addFbsFiles(builder, fbsFiles); + + return Schema.endSchema(builder); +} } diff --git a/tests/ts/reflection/service.d.ts b/tests/ts/reflection/service.d.ts index bfe4181de..22127eca3 100644 --- a/tests/ts/reflection/service.d.ts +++ b/tests/ts/reflection/service.d.ts @@ -1,103 +1,50 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {RPCCall, RPCCallT} from '../reflection/rpccall.js'; -export declare class Service - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Service; - static getRootAsService(bb: flatbuffers.ByteBuffer, obj?: Service): Service; - static getSizePrefixedRootAsService( - bb: flatbuffers.ByteBuffer, - obj?: Service, - ): Service; - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - calls(index: number, obj?: RPCCall): RPCCall | null; - callsLength(): number; - attributes(index: number, obj?: KeyValue): KeyValue | null; - attributesLength(): number; - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentationLength(): number; - /** - * File that this Service is declared in. - */ - declarationFile(): string | null; - declarationFile( - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array | null; - static getFullyQualifiedName(): string; - static startService(builder: flatbuffers.Builder): void; - static addName( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - ): void; - static addCalls( - builder: flatbuffers.Builder, - callsOffset: flatbuffers.Offset, - ): void; - static createCallsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startCallsVector(builder: flatbuffers.Builder, numElems: number): void; - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ): void; - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startAttributesVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ): void; - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addDeclarationFile( - builder: flatbuffers.Builder, - declarationFileOffset: flatbuffers.Offset, - ): void; - static endService(builder: flatbuffers.Builder): flatbuffers.Offset; - static createService( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - callsOffset: flatbuffers.Offset, - attributesOffset: flatbuffers.Offset, - documentationOffset: flatbuffers.Offset, - declarationFileOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - unpack(): ServiceT; - unpackTo(_o: ServiceT): void; +import { KeyValue, KeyValueT } from './key-value.js'; +import { RPCCall, RPCCallT } from './rpccall.js'; +export declare class Service implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Service; + static getRootAsService(bb: flatbuffers.ByteBuffer, obj?: Service): Service; + static getSizePrefixedRootAsService(bb: flatbuffers.ByteBuffer, obj?: Service): Service; + name(): string; + name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + calls(index: number, obj?: RPCCall): RPCCall | null; + callsLength(): number; + attributes(index: number, obj?: KeyValue): KeyValue | null; + attributesLength(): number; + documentation(index: number): string; + documentation(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array; + documentationLength(): number; + /** + * File that this Service is declared in. + */ + declarationFile(): string | null; + declarationFile(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + static getFullyQualifiedName(): "reflection.Service"; + static startService(builder: flatbuffers.Builder): void; + static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset): void; + static addCalls(builder: flatbuffers.Builder, callsOffset: flatbuffers.Offset): void; + static createCallsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startCallsVector(builder: flatbuffers.Builder, numElems: number): void; + static addAttributes(builder: flatbuffers.Builder, attributesOffset: flatbuffers.Offset): void; + static createAttributesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startAttributesVector(builder: flatbuffers.Builder, numElems: number): void; + static addDocumentation(builder: flatbuffers.Builder, documentationOffset: flatbuffers.Offset): void; + static createDocumentationVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startDocumentationVector(builder: flatbuffers.Builder, numElems: number): void; + static addDeclarationFile(builder: flatbuffers.Builder, declarationFileOffset: flatbuffers.Offset): void; + static endService(builder: flatbuffers.Builder): flatbuffers.Offset; + static createService(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset, callsOffset: flatbuffers.Offset, attributesOffset: flatbuffers.Offset, documentationOffset: flatbuffers.Offset, declarationFileOffset: flatbuffers.Offset): flatbuffers.Offset; + unpack(): ServiceT; + unpackTo(_o: ServiceT): void; } export declare class ServiceT implements flatbuffers.IGeneratedObject { - name: string | Uint8Array | null; - calls: RPCCallT[]; - attributes: KeyValueT[]; - documentation: string[]; - declarationFile: string | Uint8Array | null; - constructor( - name?: string | Uint8Array | null, - calls?: RPCCallT[], - attributes?: KeyValueT[], - documentation?: string[], - declarationFile?: string | Uint8Array | null, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + name: string | Uint8Array | null; + calls: (RPCCallT)[]; + attributes: (KeyValueT)[]; + documentation: (string)[]; + declarationFile: string | Uint8Array | null; + constructor(name?: string | Uint8Array | null, calls?: (RPCCallT)[], attributes?: (KeyValueT)[], documentation?: (string)[], declarationFile?: string | Uint8Array | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/service.js b/tests/ts/reflection/service.js index 5ce881534..16030948d 100644 --- a/tests/ts/reflection/service.js +++ b/tests/ts/reflection/service.js @@ -1,189 +1,147 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {KeyValue} from '../reflection/key-value.js'; -import {RPCCall} from '../reflection/rpccall.js'; - +import { KeyValue } from './key-value.js'; +import { RPCCall } from './rpccall.js'; export class Service { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsService(bb, obj) { - return (obj || new Service()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsService(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Service()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - name(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - calls(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? - (obj || new RPCCall()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - callsLength() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - attributes(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? - (obj || new KeyValue()) - .__init( - this.bb.__indirect( - this.bb.__vector(this.bb_pos + offset) + index * 4), - this.bb) : - null; - } - attributesLength() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - documentation(index, optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__string( - this.bb.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding) : - null; - } - documentationLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - declarationFile(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - static getFullyQualifiedName() { - return 'reflection.Service'; - } - static startService(builder) { - builder.startObject(5); - } - static addName(builder, nameOffset) { - builder.addFieldOffset(0, nameOffset, 0); - } - static addCalls(builder, callsOffset) { - builder.addFieldOffset(1, callsOffset, 0); - } - static createCallsVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + constructor() { + this.bb = null; + this.bb_pos = 0; } - return builder.endVector(); - } - static startCallsVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addAttributes(builder, attributesOffset) { - builder.addFieldOffset(2, attributesOffset, 0); - } - static createAttributesVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - return builder.endVector(); - } - static startAttributesVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDocumentation(builder, documentationOffset) { - builder.addFieldOffset(3, documentationOffset, 0); - } - static createDocumentationVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + static getRootAsService(bb, obj) { + return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsService(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + name(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return this.bb.__string(this.bb_pos + offset, optionalEncoding); + } + calls(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new RPCCall()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + callsLength() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + attributes(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? (obj || new KeyValue()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; + } + attributesLength() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + documentation(index, optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; + } + documentationLength() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + declarationFile(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + static getFullyQualifiedName() { + return 'reflection.Service'; + } + static startService(builder) { + builder.startObject(5); + } + static addName(builder, nameOffset) { + builder.addFieldOffset(0, nameOffset, 0); + } + static addCalls(builder, callsOffset) { + builder.addFieldOffset(1, callsOffset, 0); + } + static createCallsVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startCallsVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addAttributes(builder, attributesOffset) { + builder.addFieldOffset(2, attributesOffset, 0); + } + static createAttributesVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startAttributesVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDocumentation(builder, documentationOffset) { + builder.addFieldOffset(3, documentationOffset, 0); + } + static createDocumentationVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startDocumentationVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addDeclarationFile(builder, declarationFileOffset) { + builder.addFieldOffset(4, declarationFileOffset, 0); + } + static endService(builder) { + const offset = builder.endObject(); + builder.requiredField(offset, 4); // name + return offset; + } + static createService(builder, nameOffset, callsOffset, attributesOffset, documentationOffset, declarationFileOffset) { + Service.startService(builder); + Service.addName(builder, nameOffset); + Service.addCalls(builder, callsOffset); + Service.addAttributes(builder, attributesOffset); + Service.addDocumentation(builder, documentationOffset); + Service.addDeclarationFile(builder, declarationFileOffset); + return Service.endService(builder); + } + unpack() { + return new ServiceT(this.name(), this.bb.createObjList(this.calls.bind(this), this.callsLength()), this.bb.createObjList(this.attributes.bind(this), this.attributesLength()), this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()), this.declarationFile()); + } + unpackTo(_o) { + _o.name = this.name(); + _o.calls = this.bb.createObjList(this.calls.bind(this), this.callsLength()); + _o.attributes = this.bb.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.declarationFile = this.declarationFile(); } - return builder.endVector(); - } - static startDocumentationVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addDeclarationFile(builder, declarationFileOffset) { - builder.addFieldOffset(4, declarationFileOffset, 0); - } - static endService(builder) { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - return offset; - } - static createService( - builder, nameOffset, callsOffset, attributesOffset, documentationOffset, - declarationFileOffset) { - Service.startService(builder); - Service.addName(builder, nameOffset); - Service.addCalls(builder, callsOffset); - Service.addAttributes(builder, attributesOffset); - Service.addDocumentation(builder, documentationOffset); - Service.addDeclarationFile(builder, declarationFileOffset); - return Service.endService(builder); - } - unpack() { - return new ServiceT( - this.name(), - this.bb.createObjList(this.calls.bind(this), this.callsLength()), - this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()), - this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()), - this.declarationFile()); - } - unpackTo(_o) { - _o.name = this.name(); - _o.calls = this.bb.createObjList(this.calls.bind(this), this.callsLength()); - _o.attributes = this.bb.createObjList( - this.attributes.bind(this), this.attributesLength()); - _o.documentation = this.bb.createScalarList( - this.documentation.bind(this), this.documentationLength()); - _o.declarationFile = this.declarationFile(); - } } export class ServiceT { - constructor( - name = null, calls = [], attributes = [], documentation = [], - declarationFile = null) { - this.name = name; - this.calls = calls; - this.attributes = attributes; - this.documentation = documentation; - this.declarationFile = declarationFile; - } - pack(builder) { - const name = (this.name !== null ? builder.createString(this.name) : 0); - const calls = Service.createCallsVector( - builder, builder.createObjectOffsetList(this.calls)); - const attributes = Service.createAttributesVector( - builder, builder.createObjectOffsetList(this.attributes)); - const documentation = Service.createDocumentationVector( - builder, builder.createObjectOffsetList(this.documentation)); - const declarationFile = - (this.declarationFile !== null ? - builder.createString(this.declarationFile) : - 0); - return Service.createService( - builder, name, calls, attributes, documentation, declarationFile); - } + constructor(name = null, calls = [], attributes = [], documentation = [], declarationFile = null) { + this.name = name; + this.calls = calls; + this.attributes = attributes; + this.documentation = documentation; + this.declarationFile = declarationFile; + } + pack(builder) { + const name = (this.name !== null ? builder.createString(this.name) : 0); + const calls = Service.createCallsVector(builder, builder.createObjectOffsetList(this.calls)); + const attributes = Service.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Service.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile) : 0); + return Service.createService(builder, name, calls, attributes, documentation, declarationFile); + } } diff --git a/tests/ts/reflection/service.ts b/tests/ts/reflection/service.ts index 49afdff1b..1e4d04e13 100644 --- a/tests/ts/reflection/service.ts +++ b/tests/ts/reflection/service.ts @@ -4,299 +4,200 @@ import * as flatbuffers from 'flatbuffers'; -import {KeyValue, KeyValueT} from '../reflection/key-value.js'; -import {RPCCall, RPCCallT} from '../reflection/rpccall.js'; +import { KeyValue, KeyValueT } from './key-value.js'; +import { RPCCall, RPCCallT } from './rpccall.js'; + export class Service implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Service { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Service { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsService(bb: flatbuffers.ByteBuffer, obj?: Service): Service { - return (obj || new Service()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsService(bb:flatbuffers.ByteBuffer, obj?:Service):Service { + return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsService( - bb: flatbuffers.ByteBuffer, - obj?: Service, - ): Service { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Service()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsService(bb:flatbuffers.ByteBuffer, obj?:Service):Service { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Service()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - name(): string | null; - name(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - name(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +name():string +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array +name(optionalEncoding?:any):string|Uint8Array { + const offset = this.bb!.__offset(this.bb_pos, 4); + return this.bb!.__string(this.bb_pos + offset, optionalEncoding); +} - calls(index: number, obj?: RPCCall): RPCCall | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset - ? (obj || new RPCCall()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } +calls(index: number, obj?:RPCCall):RPCCall|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new RPCCall()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} - callsLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +callsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} - attributes(index: number, obj?: KeyValue): KeyValue | null { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset - ? (obj || new KeyValue()).__init( - this.bb!.__indirect( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ), - this.bb!, - ) - : null; - } +attributes(index: number, obj?:KeyValue):KeyValue|null { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? (obj || new KeyValue()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null; +} - attributesLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +attributesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} - documentation(index: number): string; - documentation( - index: number, - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array; - documentation( - index: number, - optionalEncoding?: any, - ): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset - ? this.bb!.__string( - this.bb!.__vector(this.bb_pos + offset) + index * 4, - optionalEncoding, - ) - : null; - } +documentation(index: number):string +documentation(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +documentation(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} - documentationLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } +documentationLength():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} - /** - * File that this Service is declared in. - */ - declarationFile(): string | null; - declarationFile( - optionalEncoding: flatbuffers.Encoding, - ): string | Uint8Array | null; - declarationFile(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +/** + * File that this Service is declared in. + */ +declarationFile():string|null +declarationFile(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +declarationFile(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} - static getFullyQualifiedName(): string { - return 'reflection.Service'; - } +static getFullyQualifiedName(): "reflection.Service" { + return 'reflection.Service'; +} - static startService(builder: flatbuffers.Builder) { - builder.startObject(5); - } +static startService(builder:flatbuffers.Builder):void { + builder.startObject(5); +} - static addName(builder: flatbuffers.Builder, nameOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, nameOffset, 0); - } +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, nameOffset, 0); +} - static addCalls( - builder: flatbuffers.Builder, - callsOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, callsOffset, 0); - } +static addCalls(builder:flatbuffers.Builder, callsOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, callsOffset, 0); +} - static createCallsVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); +static createCallsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static startCallsVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } +static startCallsVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - static addAttributes( - builder: flatbuffers.Builder, - attributesOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(2, attributesOffset, 0); - } +static addAttributes(builder:flatbuffers.Builder, attributesOffset:flatbuffers.Offset):void { + builder.addFieldOffset(2, attributesOffset, 0); +} - static createAttributesVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); +static createAttributesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static startAttributesVector(builder: flatbuffers.Builder, numElems: number) { - builder.startVector(4, numElems, 4); - } +static startAttributesVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - static addDocumentation( - builder: flatbuffers.Builder, - documentationOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(3, documentationOffset, 0); - } +static addDocumentation(builder:flatbuffers.Builder, documentationOffset:flatbuffers.Offset):void { + builder.addFieldOffset(3, documentationOffset, 0); +} - static createDocumentationVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); +static createDocumentationVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static startDocumentationVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } +static startDocumentationVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - static addDeclarationFile( - builder: flatbuffers.Builder, - declarationFileOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(4, declarationFileOffset, 0); - } +static addDeclarationFile(builder:flatbuffers.Builder, declarationFileOffset:flatbuffers.Offset):void { + builder.addFieldOffset(4, declarationFileOffset, 0); +} - static endService(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - builder.requiredField(offset, 4); // name - return offset; - } +static endService(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 4) // name + return offset; +} - static createService( - builder: flatbuffers.Builder, - nameOffset: flatbuffers.Offset, - callsOffset: flatbuffers.Offset, - attributesOffset: flatbuffers.Offset, - documentationOffset: flatbuffers.Offset, - declarationFileOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - Service.startService(builder); - Service.addName(builder, nameOffset); - Service.addCalls(builder, callsOffset); - Service.addAttributes(builder, attributesOffset); - Service.addDocumentation(builder, documentationOffset); - Service.addDeclarationFile(builder, declarationFileOffset); - return Service.endService(builder); - } +static createService(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset, callsOffset:flatbuffers.Offset, attributesOffset:flatbuffers.Offset, documentationOffset:flatbuffers.Offset, declarationFileOffset:flatbuffers.Offset):flatbuffers.Offset { + Service.startService(builder); + Service.addName(builder, nameOffset); + Service.addCalls(builder, callsOffset); + Service.addAttributes(builder, attributesOffset); + Service.addDocumentation(builder, documentationOffset); + Service.addDeclarationFile(builder, declarationFileOffset); + return Service.endService(builder); +} - unpack(): ServiceT { - return new ServiceT( - this.name(), - this.bb!.createObjList( - this.calls.bind(this), - this.callsLength(), - ), - this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ), - this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ), - this.declarationFile(), - ); - } +unpack(): ServiceT { + return new ServiceT( + this.name(), + this.bb!.createObjList(this.calls.bind(this), this.callsLength()), + this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()), + this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()), + this.declarationFile() + ); +} - unpackTo(_o: ServiceT): void { - _o.name = this.name(); - _o.calls = this.bb!.createObjList( - this.calls.bind(this), - this.callsLength(), - ); - _o.attributes = this.bb!.createObjList( - this.attributes.bind(this), - this.attributesLength(), - ); - _o.documentation = this.bb!.createScalarList( - this.documentation.bind(this), - this.documentationLength(), - ); - _o.declarationFile = this.declarationFile(); - } + +unpackTo(_o: ServiceT): void { + _o.name = this.name(); + _o.calls = this.bb!.createObjList(this.calls.bind(this), this.callsLength()); + _o.attributes = this.bb!.createObjList(this.attributes.bind(this), this.attributesLength()); + _o.documentation = this.bb!.createScalarList(this.documentation.bind(this), this.documentationLength()); + _o.declarationFile = this.declarationFile(); +} } export class ServiceT implements flatbuffers.IGeneratedObject { - constructor( - public name: string | Uint8Array | null = null, - public calls: RPCCallT[] = [], - public attributes: KeyValueT[] = [], - public documentation: string[] = [], - public declarationFile: string | Uint8Array | null = null, - ) {} +constructor( + public name: string|Uint8Array|null = null, + public calls: (RPCCallT)[] = [], + public attributes: (KeyValueT)[] = [], + public documentation: (string)[] = [], + public declarationFile: string|Uint8Array|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const name = this.name !== null ? builder.createString(this.name!) : 0; - const calls = Service.createCallsVector( - builder, - builder.createObjectOffsetList(this.calls), - ); - const attributes = Service.createAttributesVector( - builder, - builder.createObjectOffsetList(this.attributes), - ); - const documentation = Service.createDocumentationVector( - builder, - builder.createObjectOffsetList(this.documentation), - ); - const declarationFile = - this.declarationFile !== null - ? builder.createString(this.declarationFile!) - : 0; - return Service.createService( - builder, - name, - calls, - attributes, - documentation, - declarationFile, - ); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const name = (this.name !== null ? builder.createString(this.name!) : 0); + const calls = Service.createCallsVector(builder, builder.createObjectOffsetList(this.calls)); + const attributes = Service.createAttributesVector(builder, builder.createObjectOffsetList(this.attributes)); + const documentation = Service.createDocumentationVector(builder, builder.createObjectOffsetList(this.documentation)); + const declarationFile = (this.declarationFile !== null ? builder.createString(this.declarationFile!) : 0); + + return Service.createService(builder, + name, + calls, + attributes, + documentation, + declarationFile + ); +} } diff --git a/tests/ts/reflection/type.d.ts b/tests/ts/reflection/type.d.ts index ce080e953..f198ad940 100644 --- a/tests/ts/reflection/type.d.ts +++ b/tests/ts/reflection/type.d.ts @@ -1,73 +1,49 @@ import * as flatbuffers from 'flatbuffers'; -import {BaseType} from '../reflection/base-type.js'; +import { BaseType } from './base-type.js'; export declare class Type implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Type; - static getRootAsType(bb: flatbuffers.ByteBuffer, obj?: Type): Type; - static getSizePrefixedRootAsType( - bb: flatbuffers.ByteBuffer, - obj?: Type, - ): Type; - baseType(): BaseType; - mutate_base_type(value: BaseType): boolean; - element(): BaseType; - mutate_element(value: BaseType): boolean; - index(): number; - mutate_index(value: number): boolean; - fixedLength(): number; - mutate_fixed_length(value: number): boolean; - /** - * The size (octets) of the `base_type` field. - */ - baseSize(): number; - mutate_base_size(value: number): boolean; - /** - * The size (octets) of the `element` field, if present. - */ - elementSize(): number; - mutate_element_size(value: number): boolean; - static getFullyQualifiedName(): string; - static startType(builder: flatbuffers.Builder): void; - static addBaseType(builder: flatbuffers.Builder, baseType: BaseType): void; - static addElement(builder: flatbuffers.Builder, element: BaseType): void; - static addIndex(builder: flatbuffers.Builder, index: number): void; - static addFixedLength( - builder: flatbuffers.Builder, - fixedLength: number, - ): void; - static addBaseSize(builder: flatbuffers.Builder, baseSize: number): void; - static addElementSize( - builder: flatbuffers.Builder, - elementSize: number, - ): void; - static endType(builder: flatbuffers.Builder): flatbuffers.Offset; - static createType( - builder: flatbuffers.Builder, - baseType: BaseType, - element: BaseType, - index: number, - fixedLength: number, - baseSize: number, - elementSize: number, - ): flatbuffers.Offset; - unpack(): TypeT; - unpackTo(_o: TypeT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Type; + static getRootAsType(bb: flatbuffers.ByteBuffer, obj?: Type): Type; + static getSizePrefixedRootAsType(bb: flatbuffers.ByteBuffer, obj?: Type): Type; + baseType(): BaseType; + mutate_base_type(value: BaseType): boolean; + element(): BaseType; + mutate_element(value: BaseType): boolean; + index(): number; + mutate_index(value: number): boolean; + fixedLength(): number; + mutate_fixed_length(value: number): boolean; + /** + * The size (octets) of the `base_type` field. + */ + baseSize(): number; + mutate_base_size(value: number): boolean; + /** + * The size (octets) of the `element` field, if present. + */ + elementSize(): number; + mutate_element_size(value: number): boolean; + static getFullyQualifiedName(): "reflection.Type"; + static startType(builder: flatbuffers.Builder): void; + static addBaseType(builder: flatbuffers.Builder, baseType: BaseType): void; + static addElement(builder: flatbuffers.Builder, element: BaseType): void; + static addIndex(builder: flatbuffers.Builder, index: number): void; + static addFixedLength(builder: flatbuffers.Builder, fixedLength: number): void; + static addBaseSize(builder: flatbuffers.Builder, baseSize: number): void; + static addElementSize(builder: flatbuffers.Builder, elementSize: number): void; + static endType(builder: flatbuffers.Builder): flatbuffers.Offset; + static createType(builder: flatbuffers.Builder, baseType: BaseType, element: BaseType, index: number, fixedLength: number, baseSize: number, elementSize: number): flatbuffers.Offset; + unpack(): TypeT; + unpackTo(_o: TypeT): void; } export declare class TypeT implements flatbuffers.IGeneratedObject { - baseType: BaseType; - element: BaseType; - index: number; - fixedLength: number; - baseSize: number; - elementSize: number; - constructor( - baseType?: BaseType, - element?: BaseType, - index?: number, - fixedLength?: number, - baseSize?: number, - elementSize?: number, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + baseType: BaseType; + element: BaseType; + index: number; + fixedLength: number; + baseSize: number; + elementSize: number; + constructor(baseType?: BaseType, element?: BaseType, index?: number, fixedLength?: number, baseSize?: number, elementSize?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/reflection/type.js b/tests/ts/reflection/type.js index c5ab96347..cab64028d 100644 --- a/tests/ts/reflection/type.js +++ b/tests/ts/reflection/type.js @@ -1,174 +1,162 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {BaseType} from '../reflection/base-type.js'; - +import { BaseType } from './base-type.js'; export class Type { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsType(bb, obj) { - return (obj || new Type()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsType(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Type()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - baseType() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt8(this.bb_pos + offset) : BaseType.None; - } - mutate_base_type(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt8(this.bb_pos + offset, value); - return true; - } - element() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt8(this.bb_pos + offset) : BaseType.None; - } - mutate_element(value) { - const offset = this.bb.__offset(this.bb_pos, 6); - if (offset === 0) { - return false; + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - this.bb.writeInt8(this.bb_pos + offset, value); - return true; - } - index() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readInt32(this.bb_pos + offset) : -1; - } - mutate_index(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + static getRootAsType(bb, obj) { + return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - fixedLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; - } - mutate_fixed_length(value) { - const offset = this.bb.__offset(this.bb_pos, 10); - if (offset === 0) { - return false; + static getSizePrefixedRootAsType(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeUint16(this.bb_pos + offset, value); - return true; - } - /** - * The size (octets) of the `base_type` field. - */ - baseSize() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 4; - } - mutate_base_size(value) { - const offset = this.bb.__offset(this.bb_pos, 12); - if (offset === 0) { - return false; + baseType() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt8(this.bb_pos + offset) : BaseType.None; } - this.bb.writeUint32(this.bb_pos + offset, value); - return true; - } - /** - * The size (octets) of the `element` field, if present. - */ - elementSize() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; - } - mutate_element_size(value) { - const offset = this.bb.__offset(this.bb_pos, 14); - if (offset === 0) { - return false; + mutate_base_type(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, value); + return true; + } + element() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt8(this.bb_pos + offset) : BaseType.None; + } + mutate_element(value) { + const offset = this.bb.__offset(this.bb_pos, 6); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, value); + return true; + } + index() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt32(this.bb_pos + offset) : -1; + } + mutate_index(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + fixedLength() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; + } + mutate_fixed_length(value) { + const offset = this.bb.__offset(this.bb_pos, 10); + if (offset === 0) { + return false; + } + this.bb.writeUint16(this.bb_pos + offset, value); + return true; + } + /** + * The size (octets) of the `base_type` field. + */ + baseSize() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 4; + } + mutate_base_size(value) { + const offset = this.bb.__offset(this.bb_pos, 12); + if (offset === 0) { + return false; + } + this.bb.writeUint32(this.bb_pos + offset, value); + return true; + } + /** + * The size (octets) of the `element` field, if present. + */ + elementSize() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; + } + mutate_element_size(value) { + const offset = this.bb.__offset(this.bb_pos, 14); + if (offset === 0) { + return false; + } + this.bb.writeUint32(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'reflection.Type'; + } + static startType(builder) { + builder.startObject(6); + } + static addBaseType(builder, baseType) { + builder.addFieldInt8(0, baseType, BaseType.None); + } + static addElement(builder, element) { + builder.addFieldInt8(1, element, BaseType.None); + } + static addIndex(builder, index) { + builder.addFieldInt32(2, index, -1); + } + static addFixedLength(builder, fixedLength) { + builder.addFieldInt16(3, fixedLength, 0); + } + static addBaseSize(builder, baseSize) { + builder.addFieldInt32(4, baseSize, 4); + } + static addElementSize(builder, elementSize) { + builder.addFieldInt32(5, elementSize, 0); + } + static endType(builder) { + const offset = builder.endObject(); + return offset; + } + static createType(builder, baseType, element, index, fixedLength, baseSize, elementSize) { + Type.startType(builder); + Type.addBaseType(builder, baseType); + Type.addElement(builder, element); + Type.addIndex(builder, index); + Type.addFixedLength(builder, fixedLength); + Type.addBaseSize(builder, baseSize); + Type.addElementSize(builder, elementSize); + return Type.endType(builder); + } + unpack() { + return new TypeT(this.baseType(), this.element(), this.index(), this.fixedLength(), this.baseSize(), this.elementSize()); + } + unpackTo(_o) { + _o.baseType = this.baseType(); + _o.element = this.element(); + _o.index = this.index(); + _o.fixedLength = this.fixedLength(); + _o.baseSize = this.baseSize(); + _o.elementSize = this.elementSize(); } - this.bb.writeUint32(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'reflection.Type'; - } - static startType(builder) { - builder.startObject(6); - } - static addBaseType(builder, baseType) { - builder.addFieldInt8(0, baseType, BaseType.None); - } - static addElement(builder, element) { - builder.addFieldInt8(1, element, BaseType.None); - } - static addIndex(builder, index) { - builder.addFieldInt32(2, index, -1); - } - static addFixedLength(builder, fixedLength) { - builder.addFieldInt16(3, fixedLength, 0); - } - static addBaseSize(builder, baseSize) { - builder.addFieldInt32(4, baseSize, 4); - } - static addElementSize(builder, elementSize) { - builder.addFieldInt32(5, elementSize, 0); - } - static endType(builder) { - const offset = builder.endObject(); - return offset; - } - static createType( - builder, baseType, element, index, fixedLength, baseSize, elementSize) { - Type.startType(builder); - Type.addBaseType(builder, baseType); - Type.addElement(builder, element); - Type.addIndex(builder, index); - Type.addFixedLength(builder, fixedLength); - Type.addBaseSize(builder, baseSize); - Type.addElementSize(builder, elementSize); - return Type.endType(builder); - } - unpack() { - return new TypeT( - this.baseType(), this.element(), this.index(), this.fixedLength(), - this.baseSize(), this.elementSize()); - } - unpackTo(_o) { - _o.baseType = this.baseType(); - _o.element = this.element(); - _o.index = this.index(); - _o.fixedLength = this.fixedLength(); - _o.baseSize = this.baseSize(); - _o.elementSize = this.elementSize(); - } } export class TypeT { - constructor( - baseType = BaseType.None, element = BaseType.None, index = -1, - fixedLength = 0, baseSize = 4, elementSize = 0) { - this.baseType = baseType; - this.element = element; - this.index = index; - this.fixedLength = fixedLength; - this.baseSize = baseSize; - this.elementSize = elementSize; - } - pack(builder) { - return Type.createType( - builder, this.baseType, this.element, this.index, this.fixedLength, - this.baseSize, this.elementSize); - } + constructor(baseType = BaseType.None, element = BaseType.None, index = -1, fixedLength = 0, baseSize = 4, elementSize = 0) { + this.baseType = baseType; + this.element = element; + this.index = index; + this.fixedLength = fixedLength; + this.baseSize = baseSize; + this.elementSize = elementSize; + } + pack(builder) { + return Type.createType(builder, this.baseType, this.element, this.index, this.fixedLength, this.baseSize, this.elementSize); + } } diff --git a/tests/ts/reflection/type.ts b/tests/ts/reflection/type.ts index 214fceb50..5fafd045a 100644 --- a/tests/ts/reflection/type.ts +++ b/tests/ts/reflection/type.ts @@ -4,233 +4,218 @@ import * as flatbuffers from 'flatbuffers'; -import {BaseType} from '../reflection/base-type.js'; +import { BaseType } from './base-type.js'; + export class Type implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Type { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Type { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsType(bb:flatbuffers.ByteBuffer, obj?:Type):Type { + return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsType(bb:flatbuffers.ByteBuffer, obj?:Type):Type { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Type()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +baseType():BaseType { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : BaseType.None; +} + +mutate_base_type(value:BaseType):boolean { + const offset = this.bb!.__offset(this.bb_pos, 4); + + if (offset === 0) { + return false; } - static getRootAsType(bb: flatbuffers.ByteBuffer, obj?: Type): Type { - return (obj || new Type()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt8(this.bb_pos + offset, value); + return true; +} + +element():BaseType { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : BaseType.None; +} + +mutate_element(value:BaseType):boolean { + const offset = this.bb!.__offset(this.bb_pos, 6); + + if (offset === 0) { + return false; } - static getSizePrefixedRootAsType( - bb: flatbuffers.ByteBuffer, - obj?: Type, - ): Type { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Type()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt8(this.bb_pos + offset, value); + return true; +} + +index():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : -1; +} + +mutate_index(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 8); + + if (offset === 0) { + return false; } - baseType(): BaseType { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : BaseType.None; + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +fixedLength():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; +} + +mutate_fixed_length(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 10); + + if (offset === 0) { + return false; } - mutate_base_type(value: BaseType): boolean { - const offset = this.bb!.__offset(this.bb_pos, 4); + this.bb!.writeUint16(this.bb_pos + offset, value); + return true; +} - if (offset === 0) { - return false; - } +/** + * The size (octets) of the `base_type` field. + */ +baseSize():number { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 4; +} - this.bb!.writeInt8(this.bb_pos + offset, value); - return true; +mutate_base_size(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 12); + + if (offset === 0) { + return false; } - element(): BaseType { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.readInt8(this.bb_pos + offset) : BaseType.None; + this.bb!.writeUint32(this.bb_pos + offset, value); + return true; +} + +/** + * The size (octets) of the `element` field, if present. + */ +elementSize():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; +} + +mutate_element_size(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 14); + + if (offset === 0) { + return false; } - mutate_element(value: BaseType): boolean { - const offset = this.bb!.__offset(this.bb_pos, 6); + this.bb!.writeUint32(this.bb_pos + offset, value); + return true; +} - if (offset === 0) { - return false; - } +static getFullyQualifiedName(): "reflection.Type" { + return 'reflection.Type'; +} - this.bb!.writeInt8(this.bb_pos + offset, value); - return true; - } +static startType(builder:flatbuffers.Builder):void { + builder.startObject(6); +} - index(): number { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : -1; - } +static addBaseType(builder:flatbuffers.Builder, baseType:BaseType):void { + builder.addFieldInt8(0, baseType, BaseType.None); +} - mutate_index(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 8); +static addElement(builder:flatbuffers.Builder, element:BaseType):void { + builder.addFieldInt8(1, element, BaseType.None); +} - if (offset === 0) { - return false; - } +static addIndex(builder:flatbuffers.Builder, index:number):void { + builder.addFieldInt32(2, index, -1); +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } +static addFixedLength(builder:flatbuffers.Builder, fixedLength:number):void { + builder.addFieldInt16(3, fixedLength, 0); +} - fixedLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; - } +static addBaseSize(builder:flatbuffers.Builder, baseSize:number):void { + builder.addFieldInt32(4, baseSize, 4); +} - mutate_fixed_length(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 10); +static addElementSize(builder:flatbuffers.Builder, elementSize:number):void { + builder.addFieldInt32(5, elementSize, 0); +} - if (offset === 0) { - return false; - } +static endType(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - this.bb!.writeUint16(this.bb_pos + offset, value); - return true; - } +static createType(builder:flatbuffers.Builder, baseType:BaseType, element:BaseType, index:number, fixedLength:number, baseSize:number, elementSize:number):flatbuffers.Offset { + Type.startType(builder); + Type.addBaseType(builder, baseType); + Type.addElement(builder, element); + Type.addIndex(builder, index); + Type.addFixedLength(builder, fixedLength); + Type.addBaseSize(builder, baseSize); + Type.addElementSize(builder, elementSize); + return Type.endType(builder); +} - /** - * The size (octets) of the `base_type` field. - */ - baseSize(): number { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset ? this.bb!.readUint32(this.bb_pos + offset) : 4; - } +unpack(): TypeT { + return new TypeT( + this.baseType(), + this.element(), + this.index(), + this.fixedLength(), + this.baseSize(), + this.elementSize() + ); +} - mutate_base_size(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 12); - if (offset === 0) { - return false; - } - - this.bb!.writeUint32(this.bb_pos + offset, value); - return true; - } - - /** - * The size (octets) of the `element` field, if present. - */ - elementSize(): number { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; - } - - mutate_element_size(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 14); - - if (offset === 0) { - return false; - } - - this.bb!.writeUint32(this.bb_pos + offset, value); - return true; - } - - static getFullyQualifiedName(): string { - return 'reflection.Type'; - } - - static startType(builder: flatbuffers.Builder) { - builder.startObject(6); - } - - static addBaseType(builder: flatbuffers.Builder, baseType: BaseType) { - builder.addFieldInt8(0, baseType, BaseType.None); - } - - static addElement(builder: flatbuffers.Builder, element: BaseType) { - builder.addFieldInt8(1, element, BaseType.None); - } - - static addIndex(builder: flatbuffers.Builder, index: number) { - builder.addFieldInt32(2, index, -1); - } - - static addFixedLength(builder: flatbuffers.Builder, fixedLength: number) { - builder.addFieldInt16(3, fixedLength, 0); - } - - static addBaseSize(builder: flatbuffers.Builder, baseSize: number) { - builder.addFieldInt32(4, baseSize, 4); - } - - static addElementSize(builder: flatbuffers.Builder, elementSize: number) { - builder.addFieldInt32(5, elementSize, 0); - } - - static endType(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static createType( - builder: flatbuffers.Builder, - baseType: BaseType, - element: BaseType, - index: number, - fixedLength: number, - baseSize: number, - elementSize: number, - ): flatbuffers.Offset { - Type.startType(builder); - Type.addBaseType(builder, baseType); - Type.addElement(builder, element); - Type.addIndex(builder, index); - Type.addFixedLength(builder, fixedLength); - Type.addBaseSize(builder, baseSize); - Type.addElementSize(builder, elementSize); - return Type.endType(builder); - } - - unpack(): TypeT { - return new TypeT( - this.baseType(), - this.element(), - this.index(), - this.fixedLength(), - this.baseSize(), - this.elementSize(), - ); - } - - unpackTo(_o: TypeT): void { - _o.baseType = this.baseType(); - _o.element = this.element(); - _o.index = this.index(); - _o.fixedLength = this.fixedLength(); - _o.baseSize = this.baseSize(); - _o.elementSize = this.elementSize(); - } +unpackTo(_o: TypeT): void { + _o.baseType = this.baseType(); + _o.element = this.element(); + _o.index = this.index(); + _o.fixedLength = this.fixedLength(); + _o.baseSize = this.baseSize(); + _o.elementSize = this.elementSize(); +} } export class TypeT implements flatbuffers.IGeneratedObject { - constructor( - public baseType: BaseType = BaseType.None, - public element: BaseType = BaseType.None, - public index: number = -1, - public fixedLength: number = 0, - public baseSize: number = 4, - public elementSize: number = 0, - ) {} +constructor( + public baseType: BaseType = BaseType.None, + public element: BaseType = BaseType.None, + public index: number = -1, + public fixedLength: number = 0, + public baseSize: number = 4, + public elementSize: number = 0 +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return Type.createType( - builder, - this.baseType, - this.element, - this.index, - this.fixedLength, - this.baseSize, - this.elementSize, - ); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return Type.createType(builder, + this.baseType, + this.element, + this.index, + this.fixedLength, + this.baseSize, + this.elementSize + ); +} } diff --git a/tests/ts/relative_imports/transit/one.d.ts b/tests/ts/relative_imports/transit/one.d.ts new file mode 100644 index 000000000..d6228263a --- /dev/null +++ b/tests/ts/relative_imports/transit/one.d.ts @@ -0,0 +1 @@ +export { Info, InfoT } from './one/info.js'; diff --git a/tests/ts/relative_imports/transit/one.js b/tests/ts/relative_imports/transit/one.js new file mode 100644 index 000000000..fb5ecc26a --- /dev/null +++ b/tests/ts/relative_imports/transit/one.js @@ -0,0 +1,3 @@ +// automatically generated by the FlatBuffers compiler, do not modify +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Info, InfoT } from './one/info.js'; diff --git a/tests/ts/relative_imports/transit/one.ts b/tests/ts/relative_imports/transit/one.ts new file mode 100644 index 000000000..faa13bbc7 --- /dev/null +++ b/tests/ts/relative_imports/transit/one.ts @@ -0,0 +1,5 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +export { Info, InfoT } from './one/info.js'; diff --git a/tests/ts/relative_imports/transit/one/info.d.ts b/tests/ts/relative_imports/transit/one/info.d.ts new file mode 100644 index 000000000..9be33d48f --- /dev/null +++ b/tests/ts/relative_imports/transit/one/info.d.ts @@ -0,0 +1,21 @@ +import * as flatbuffers from 'flatbuffers'; +export declare class Info implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Info; + static getRootAsInfo(bb: flatbuffers.ByteBuffer, obj?: Info): Info; + static getSizePrefixedRootAsInfo(bb: flatbuffers.ByteBuffer, obj?: Info): Info; + timestamp(): bigint; + static getFullyQualifiedName(): "Transit.One.Info"; + static startInfo(builder: flatbuffers.Builder): void; + static addTimestamp(builder: flatbuffers.Builder, timestamp: bigint): void; + static endInfo(builder: flatbuffers.Builder): flatbuffers.Offset; + static createInfo(builder: flatbuffers.Builder, timestamp: bigint): flatbuffers.Offset; + unpack(): InfoT; + unpackTo(_o: InfoT): void; +} +export declare class InfoT implements flatbuffers.IGeneratedObject { + timestamp: bigint; + constructor(timestamp?: bigint); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; +} diff --git a/tests/ts/relative_imports/transit/one/info.js b/tests/ts/relative_imports/transit/one/info.js new file mode 100644 index 000000000..5ffda83c5 --- /dev/null +++ b/tests/ts/relative_imports/transit/one/info.js @@ -0,0 +1,57 @@ +// automatically generated by the FlatBuffers compiler, do not modify +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import * as flatbuffers from 'flatbuffers'; +export class Info { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsInfo(bb, obj) { + return (obj || new Info()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsInfo(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Info()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + timestamp() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0'); + } + static getFullyQualifiedName() { + return 'Transit.One.Info'; + } + static startInfo(builder) { + builder.startObject(1); + } + static addTimestamp(builder, timestamp) { + builder.addFieldInt64(0, timestamp, BigInt('0')); + } + static endInfo(builder) { + const offset = builder.endObject(); + return offset; + } + static createInfo(builder, timestamp) { + Info.startInfo(builder); + Info.addTimestamp(builder, timestamp); + return Info.endInfo(builder); + } + unpack() { + return new InfoT(this.timestamp()); + } + unpackTo(_o) { + _o.timestamp = this.timestamp(); + } +} +export class InfoT { + constructor(timestamp = BigInt('0')) { + this.timestamp = timestamp; + } + pack(builder) { + return Info.createInfo(builder, this.timestamp); + } +} diff --git a/tests/ts/relative_imports/transit/one/info.ts b/tests/ts/relative_imports/transit/one/info.ts new file mode 100644 index 000000000..867d3f631 --- /dev/null +++ b/tests/ts/relative_imports/transit/one/info.ts @@ -0,0 +1,78 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +import * as flatbuffers from 'flatbuffers'; + + + +export class Info implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Info { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsInfo(bb:flatbuffers.ByteBuffer, obj?:Info):Info { + return (obj || new Info()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsInfo(bb:flatbuffers.ByteBuffer, obj?:Info):Info { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Info()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +timestamp():bigint { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +static getFullyQualifiedName(): "Transit.One.Info" { + return 'Transit.One.Info'; +} + +static startInfo(builder:flatbuffers.Builder):void { + builder.startObject(1); +} + +static addTimestamp(builder:flatbuffers.Builder, timestamp:bigint):void { + builder.addFieldInt64(0, timestamp, BigInt('0')); +} + +static endInfo(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createInfo(builder:flatbuffers.Builder, timestamp:bigint):flatbuffers.Offset { + Info.startInfo(builder); + Info.addTimestamp(builder, timestamp); + return Info.endInfo(builder); +} + +unpack(): InfoT { + return new InfoT( + this.timestamp() + ); +} + + +unpackTo(_o: InfoT): void { + _o.timestamp = this.timestamp(); +} +} + +export class InfoT implements flatbuffers.IGeneratedObject { +constructor( + public timestamp: bigint = BigInt('0') +){} + + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return Info.createInfo(builder, + this.timestamp + ); +} +} diff --git a/tests/ts/relative_imports/transit/three.d.ts b/tests/ts/relative_imports/transit/three.d.ts new file mode 100644 index 000000000..4ace863d0 --- /dev/null +++ b/tests/ts/relative_imports/transit/three.d.ts @@ -0,0 +1 @@ +export { Header, HeaderT } from './three/header.js'; diff --git a/tests/ts/relative_imports/transit/three.js b/tests/ts/relative_imports/transit/three.js new file mode 100644 index 000000000..613191488 --- /dev/null +++ b/tests/ts/relative_imports/transit/three.js @@ -0,0 +1,3 @@ +// automatically generated by the FlatBuffers compiler, do not modify +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Header, HeaderT } from './three/header.js'; diff --git a/tests/ts/relative_imports/transit/three.ts b/tests/ts/relative_imports/transit/three.ts new file mode 100644 index 000000000..353bf9e80 --- /dev/null +++ b/tests/ts/relative_imports/transit/three.ts @@ -0,0 +1,5 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +export { Header, HeaderT } from './three/header.js'; diff --git a/tests/ts/relative_imports/transit/three/header.d.ts b/tests/ts/relative_imports/transit/three/header.d.ts new file mode 100644 index 000000000..ac7113b08 --- /dev/null +++ b/tests/ts/relative_imports/transit/three/header.d.ts @@ -0,0 +1,27 @@ +import * as flatbuffers from 'flatbuffers'; +import { Info, InfoT } from '../one/info.js'; +import { Identity, IdentityT } from '../two/identity.js'; +export declare class Header implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Header; + static getRootAsHeader(bb: flatbuffers.ByteBuffer, obj?: Header): Header; + static getSizePrefixedRootAsHeader(bb: flatbuffers.ByteBuffer, obj?: Header): Header; + info(obj?: Info): Info | null; + id(obj?: Identity): Identity | null; + static getFullyQualifiedName(): "Transit.Three.Header"; + static startHeader(builder: flatbuffers.Builder): void; + static addInfo(builder: flatbuffers.Builder, infoOffset: flatbuffers.Offset): void; + static addId(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset): void; + static endHeader(builder: flatbuffers.Builder): flatbuffers.Offset; + static finishHeaderBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static finishSizePrefixedHeaderBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + unpack(): HeaderT; + unpackTo(_o: HeaderT): void; +} +export declare class HeaderT implements flatbuffers.IGeneratedObject { + info: InfoT | null; + id: IdentityT | null; + constructor(info?: InfoT | null, id?: IdentityT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; +} diff --git a/tests/ts/relative_imports/transit/three/header.js b/tests/ts/relative_imports/transit/three/header.js new file mode 100644 index 000000000..6e4efbe8f --- /dev/null +++ b/tests/ts/relative_imports/transit/three/header.js @@ -0,0 +1,74 @@ +// automatically generated by the FlatBuffers compiler, do not modify +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import * as flatbuffers from 'flatbuffers'; +import { Info } from '../one/info.js'; +import { Identity } from '../two/identity.js'; +export class Header { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsHeader(bb, obj) { + return (obj || new Header()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsHeader(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Header()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + info(obj) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new Info()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + id(obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? (obj || new Identity()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + static getFullyQualifiedName() { + return 'Transit.Three.Header'; + } + static startHeader(builder) { + builder.startObject(2); + } + static addInfo(builder, infoOffset) { + builder.addFieldOffset(0, infoOffset, 0); + } + static addId(builder, idOffset) { + builder.addFieldOffset(1, idOffset, 0); + } + static endHeader(builder) { + const offset = builder.endObject(); + return offset; + } + static finishHeaderBuffer(builder, offset) { + builder.finish(offset); + } + static finishSizePrefixedHeaderBuffer(builder, offset) { + builder.finish(offset, undefined, true); + } + unpack() { + return new HeaderT((this.info() !== null ? this.info().unpack() : null), (this.id() !== null ? this.id().unpack() : null)); + } + unpackTo(_o) { + _o.info = (this.info() !== null ? this.info().unpack() : null); + _o.id = (this.id() !== null ? this.id().unpack() : null); + } +} +export class HeaderT { + constructor(info = null, id = null) { + this.info = info; + this.id = id; + } + pack(builder) { + const info = (this.info !== null ? this.info.pack(builder) : 0); + const id = (this.id !== null ? this.id.pack(builder) : 0); + Header.startHeader(builder); + Header.addInfo(builder, info); + Header.addId(builder, id); + return Header.endHeader(builder); + } +} diff --git a/tests/ts/relative_imports/transit/three/header.ts b/tests/ts/relative_imports/transit/three/header.ts new file mode 100644 index 000000000..963da1be0 --- /dev/null +++ b/tests/ts/relative_imports/transit/three/header.ts @@ -0,0 +1,100 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +import * as flatbuffers from 'flatbuffers'; + +import { Info, InfoT } from '../one/info.js'; +import { Identity, IdentityT } from '../two/identity.js'; + + +export class Header implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Header { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsHeader(bb:flatbuffers.ByteBuffer, obj?:Header):Header { + return (obj || new Header()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsHeader(bb:flatbuffers.ByteBuffer, obj?:Header):Header { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Header()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +info(obj?:Info):Info|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new Info()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} + +id(obj?:Identity):Identity|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? (obj || new Identity()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} + +static getFullyQualifiedName(): "Transit.Three.Header" { + return 'Transit.Three.Header'; +} + +static startHeader(builder:flatbuffers.Builder):void { + builder.startObject(2); +} + +static addInfo(builder:flatbuffers.Builder, infoOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, infoOffset, 0); +} + +static addId(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, idOffset, 0); +} + +static endHeader(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static finishHeaderBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset); +} + +static finishSizePrefixedHeaderBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { + builder.finish(offset, undefined, true); +} + + +unpack(): HeaderT { + return new HeaderT( + (this.info() !== null ? this.info()!.unpack() : null), + (this.id() !== null ? this.id()!.unpack() : null) + ); +} + + +unpackTo(_o: HeaderT): void { + _o.info = (this.info() !== null ? this.info()!.unpack() : null); + _o.id = (this.id() !== null ? this.id()!.unpack() : null); +} +} + +export class HeaderT implements flatbuffers.IGeneratedObject { +constructor( + public info: InfoT|null = null, + public id: IdentityT|null = null +){} + + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const info = (this.info !== null ? this.info!.pack(builder) : 0); + const id = (this.id !== null ? this.id!.pack(builder) : 0); + + Header.startHeader(builder); + Header.addInfo(builder, info); + Header.addId(builder, id); + + return Header.endHeader(builder); +} +} diff --git a/tests/ts/relative_imports/transit/two.d.ts b/tests/ts/relative_imports/transit/two.d.ts new file mode 100644 index 000000000..1f7a90a3c --- /dev/null +++ b/tests/ts/relative_imports/transit/two.d.ts @@ -0,0 +1 @@ +export { Identity, IdentityT } from './two/identity.js'; diff --git a/tests/ts/relative_imports/transit/two.js b/tests/ts/relative_imports/transit/two.js new file mode 100644 index 000000000..32bd363c3 --- /dev/null +++ b/tests/ts/relative_imports/transit/two.js @@ -0,0 +1,3 @@ +// automatically generated by the FlatBuffers compiler, do not modify +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Identity, IdentityT } from './two/identity.js'; diff --git a/tests/ts/relative_imports/transit/two.ts b/tests/ts/relative_imports/transit/two.ts new file mode 100644 index 000000000..9522eb616 --- /dev/null +++ b/tests/ts/relative_imports/transit/two.ts @@ -0,0 +1,5 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +export { Identity, IdentityT } from './two/identity.js'; diff --git a/tests/ts/relative_imports/transit/two/identity.d.ts b/tests/ts/relative_imports/transit/two/identity.d.ts new file mode 100644 index 000000000..a8f284e71 --- /dev/null +++ b/tests/ts/relative_imports/transit/two/identity.d.ts @@ -0,0 +1,21 @@ +import * as flatbuffers from 'flatbuffers'; +export declare class Identity implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Identity; + static getRootAsIdentity(bb: flatbuffers.ByteBuffer, obj?: Identity): Identity; + static getSizePrefixedRootAsIdentity(bb: flatbuffers.ByteBuffer, obj?: Identity): Identity; + id(): number; + static getFullyQualifiedName(): "Transit.Two.Identity"; + static startIdentity(builder: flatbuffers.Builder): void; + static addId(builder: flatbuffers.Builder, id: number): void; + static endIdentity(builder: flatbuffers.Builder): flatbuffers.Offset; + static createIdentity(builder: flatbuffers.Builder, id: number): flatbuffers.Offset; + unpack(): IdentityT; + unpackTo(_o: IdentityT): void; +} +export declare class IdentityT implements flatbuffers.IGeneratedObject { + id: number; + constructor(id?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; +} diff --git a/tests/ts/relative_imports/transit/two/identity.js b/tests/ts/relative_imports/transit/two/identity.js new file mode 100644 index 000000000..3fcb0efbc --- /dev/null +++ b/tests/ts/relative_imports/transit/two/identity.js @@ -0,0 +1,57 @@ +// automatically generated by the FlatBuffers compiler, do not modify +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import * as flatbuffers from 'flatbuffers'; +export class Identity { + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsIdentity(bb, obj) { + return (obj || new Identity()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsIdentity(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Identity()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + id() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; + } + static getFullyQualifiedName() { + return 'Transit.Two.Identity'; + } + static startIdentity(builder) { + builder.startObject(1); + } + static addId(builder, id) { + builder.addFieldInt32(0, id, 0); + } + static endIdentity(builder) { + const offset = builder.endObject(); + return offset; + } + static createIdentity(builder, id) { + Identity.startIdentity(builder); + Identity.addId(builder, id); + return Identity.endIdentity(builder); + } + unpack() { + return new IdentityT(this.id()); + } + unpackTo(_o) { + _o.id = this.id(); + } +} +export class IdentityT { + constructor(id = 0) { + this.id = id; + } + pack(builder) { + return Identity.createIdentity(builder, this.id); + } +} diff --git a/tests/ts/relative_imports/transit/two/identity.ts b/tests/ts/relative_imports/transit/two/identity.ts new file mode 100644 index 000000000..9f3483ceb --- /dev/null +++ b/tests/ts/relative_imports/transit/two/identity.ts @@ -0,0 +1,78 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ + +import * as flatbuffers from 'flatbuffers'; + + + +export class Identity implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Identity { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsIdentity(bb:flatbuffers.ByteBuffer, obj?:Identity):Identity { + return (obj || new Identity()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsIdentity(bb:flatbuffers.ByteBuffer, obj?:Identity):Identity { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Identity()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +id():number { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; +} + +static getFullyQualifiedName(): "Transit.Two.Identity" { + return 'Transit.Two.Identity'; +} + +static startIdentity(builder:flatbuffers.Builder):void { + builder.startObject(1); +} + +static addId(builder:flatbuffers.Builder, id:number):void { + builder.addFieldInt32(0, id, 0); +} + +static endIdentity(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createIdentity(builder:flatbuffers.Builder, id:number):flatbuffers.Offset { + Identity.startIdentity(builder); + Identity.addId(builder, id); + return Identity.endIdentity(builder); +} + +unpack(): IdentityT { + return new IdentityT( + this.id() + ); +} + + +unpackTo(_o: IdentityT): void { + _o.id = this.id(); +} +} + +export class IdentityT implements flatbuffers.IGeneratedObject { +constructor( + public id: number = 0 +){} + + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return Identity.createIdentity(builder, + this.id + ); +} +} diff --git a/tests/ts/table-a.d.ts b/tests/ts/table-a.d.ts index 009a186ba..a4dc999b9 100644 --- a/tests/ts/table-a.d.ts +++ b/tests/ts/table-a.d.ts @@ -1,30 +1,24 @@ import * as flatbuffers from 'flatbuffers'; -import {TableB, TableBT} from './my-game/other-name-space/table-b.js'; +import { TableB, TableBT } from './my-game/other-name-space/table-b.js'; export declare class TableA implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): TableA; - static getRootAsTableA(bb: flatbuffers.ByteBuffer, obj?: TableA): TableA; - static getSizePrefixedRootAsTableA( - bb: flatbuffers.ByteBuffer, - obj?: TableA, - ): TableA; - b(obj?: TableB): TableB | null; - static getFullyQualifiedName(): string; - static startTableA(builder: flatbuffers.Builder): void; - static addB(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset): void; - static endTableA(builder: flatbuffers.Builder): flatbuffers.Offset; - static createTableA( - builder: flatbuffers.Builder, - bOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - serialize(): Uint8Array; - static deserialize(buffer: Uint8Array): TableA; - unpack(): TableAT; - unpackTo(_o: TableAT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): TableA; + static getRootAsTableA(bb: flatbuffers.ByteBuffer, obj?: TableA): TableA; + static getSizePrefixedRootAsTableA(bb: flatbuffers.ByteBuffer, obj?: TableA): TableA; + b(obj?: TableB): TableB | null; + static getFullyQualifiedName(): "TableA"; + static startTableA(builder: flatbuffers.Builder): void; + static addB(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset): void; + static endTableA(builder: flatbuffers.Builder): flatbuffers.Offset; + static createTableA(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset): flatbuffers.Offset; + serialize(): Uint8Array; + static deserialize(buffer: Uint8Array): TableA; + unpack(): TableAT; + unpackTo(_o: TableAT): void; } export declare class TableAT implements flatbuffers.IGeneratedObject { - b: TableBT | null; - constructor(b?: TableBT | null); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + b: TableBT | null; + constructor(b?: TableBT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/table-a.js b/tests/ts/table-a.js index 5cffe8b7f..b3bff4ada 100644 --- a/tests/ts/table-a.js +++ b/tests/ts/table-a.js @@ -1,73 +1,65 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {TableB} from './my-game/other-name-space/table-b.js'; - +import { TableB } from './my-game/other-name-space/table-b.js'; export class TableA { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsTableA(bb, obj) { - return (obj || new TableA()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsTableA(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new TableA()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - b(obj) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? - (obj || new TableB()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - static getFullyQualifiedName() { - return 'TableA'; - } - static startTableA(builder) { - builder.startObject(1); - } - static addB(builder, bOffset) { - builder.addFieldOffset(0, bOffset, 0); - } - static endTableA(builder) { - const offset = builder.endObject(); - return offset; - } - static createTableA(builder, bOffset) { - TableA.startTableA(builder); - TableA.addB(builder, bOffset); - return TableA.endTableA(builder); - } - serialize() { - return this.bb.bytes(); - } - static deserialize(buffer) { - return TableA.getRootAsTableA(new flatbuffers.ByteBuffer(buffer)); - } - unpack() { - return new TableAT((this.b() !== null ? this.b().unpack() : null)); - } - unpackTo(_o) { - _o.b = (this.b() !== null ? this.b().unpack() : null); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsTableA(bb, obj) { + return (obj || new TableA()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsTableA(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TableA()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + b(obj) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? (obj || new TableB()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + static getFullyQualifiedName() { + return 'TableA'; + } + static startTableA(builder) { + builder.startObject(1); + } + static addB(builder, bOffset) { + builder.addFieldOffset(0, bOffset, 0); + } + static endTableA(builder) { + const offset = builder.endObject(); + return offset; + } + static createTableA(builder, bOffset) { + TableA.startTableA(builder); + TableA.addB(builder, bOffset); + return TableA.endTableA(builder); + } + serialize() { + return this.bb.bytes(); + } + static deserialize(buffer) { + return TableA.getRootAsTableA(new flatbuffers.ByteBuffer(buffer)); + } + unpack() { + return new TableAT((this.b() !== null ? this.b().unpack() : null)); + } + unpackTo(_o) { + _o.b = (this.b() !== null ? this.b().unpack() : null); + } } export class TableAT { - constructor(b = null) { - this.b = b; - } - pack(builder) { - const b = (this.b !== null ? this.b.pack(builder) : 0); - return TableA.createTableA(builder, b); - } + constructor(b = null) { + this.b = b; + } + pack(builder) { + const b = (this.b !== null ? this.b.pack(builder) : 0); + return TableA.createTableA(builder, b); + } } diff --git a/tests/ts/table-a.ts b/tests/ts/table-a.ts index b3e864868..5bcf2f091 100644 --- a/tests/ts/table-a.ts +++ b/tests/ts/table-a.ts @@ -4,94 +4,86 @@ import * as flatbuffers from 'flatbuffers'; -import {TableB, TableBT} from './my-game/other-name-space/table-b.js'; +import { TableB, TableBT } from './my-game/other-name-space/table-b.js'; + export class TableA implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): TableA { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):TableA { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsTableA(bb: flatbuffers.ByteBuffer, obj?: TableA): TableA { - return (obj || new TableA()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsTableA(bb:flatbuffers.ByteBuffer, obj?:TableA):TableA { + return (obj || new TableA()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsTableA( - bb: flatbuffers.ByteBuffer, - obj?: TableA, - ): TableA { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new TableA()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsTableA(bb:flatbuffers.ByteBuffer, obj?:TableA):TableA { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new TableA()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - b(obj?: TableB): TableB | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? (obj || new TableB()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } +b(obj?:TableB):TableB|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new TableB()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} - static getFullyQualifiedName(): string { - return 'TableA'; - } +static getFullyQualifiedName(): "TableA" { + return 'TableA'; +} - static startTableA(builder: flatbuffers.Builder) { - builder.startObject(1); - } +static startTableA(builder:flatbuffers.Builder):void { + builder.startObject(1); +} - static addB(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, bOffset, 0); - } +static addB(builder:flatbuffers.Builder, bOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, bOffset, 0); +} - static endTableA(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } +static endTableA(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - static createTableA( - builder: flatbuffers.Builder, - bOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - TableA.startTableA(builder); - TableA.addB(builder, bOffset); - return TableA.endTableA(builder); - } +static createTableA(builder:flatbuffers.Builder, bOffset:flatbuffers.Offset):flatbuffers.Offset { + TableA.startTableA(builder); + TableA.addB(builder, bOffset); + return TableA.endTableA(builder); +} - serialize(): Uint8Array { - return this.bb!.bytes(); - } +serialize():Uint8Array { + return this.bb!.bytes(); +} - static deserialize(buffer: Uint8Array): TableA { - return TableA.getRootAsTableA(new flatbuffers.ByteBuffer(buffer)); - } +static deserialize(buffer: Uint8Array):TableA { + return TableA.getRootAsTableA(new flatbuffers.ByteBuffer(buffer)) +} - unpack(): TableAT { - return new TableAT(this.b() !== null ? this.b()!.unpack() : null); - } +unpack(): TableAT { + return new TableAT( + (this.b() !== null ? this.b()!.unpack() : null) + ); +} - unpackTo(_o: TableAT): void { - _o.b = this.b() !== null ? this.b()!.unpack() : null; - } + +unpackTo(_o: TableAT): void { + _o.b = (this.b() !== null ? this.b()!.unpack() : null); +} } export class TableAT implements flatbuffers.IGeneratedObject { - constructor(public b: TableBT | null = null) {} +constructor( + public b: TableBT|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const b = this.b !== null ? this.b!.pack(builder) : 0; - return TableA.createTableA(builder, b); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const b = (this.b !== null ? this.b!.pack(builder) : 0); + + return TableA.createTableA(builder, + b + ); +} } diff --git a/tests/ts/ts-undefined-for-optionals/optional-scalars/scalar-stuff.ts b/tests/ts/ts-undefined-for-optionals/optional-scalars/scalar-stuff.ts index 448b9d6b6..24b237295 100644 --- a/tests/ts/ts-undefined-for-optionals/optional-scalars/scalar-stuff.ts +++ b/tests/ts/ts-undefined-for-optionals/optional-scalars/scalar-stuff.ts @@ -4,12 +4,12 @@ import * as flatbuffers from 'flatbuffers'; -import { OptionalByte } from '../optional-scalars/optional-byte.js'; +import { OptionalByte } from './optional-byte.js'; export class ScalarStuff implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|undefined = undefined; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):ScalarStuff { this.bb_pos = i; this.bb = bb; @@ -209,151 +209,151 @@ defaultEnum():OptionalByte { return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.One; } -static startScalarStuff(builder:flatbuffers.Builder) { +static startScalarStuff(builder:flatbuffers.Builder):void { builder.startObject(36); } -static addJustI8(builder:flatbuffers.Builder, justI8:number) { +static addJustI8(builder:flatbuffers.Builder, justI8:number):void { builder.addFieldInt8(0, justI8, 0); } -static addMaybeI8(builder:flatbuffers.Builder, maybeI8:number) { +static addMaybeI8(builder:flatbuffers.Builder, maybeI8:number):void { builder.addFieldInt8(1, maybeI8, undefined); } -static addDefaultI8(builder:flatbuffers.Builder, defaultI8:number) { +static addDefaultI8(builder:flatbuffers.Builder, defaultI8:number):void { builder.addFieldInt8(2, defaultI8, 42); } -static addJustU8(builder:flatbuffers.Builder, justU8:number) { +static addJustU8(builder:flatbuffers.Builder, justU8:number):void { builder.addFieldInt8(3, justU8, 0); } -static addMaybeU8(builder:flatbuffers.Builder, maybeU8:number) { +static addMaybeU8(builder:flatbuffers.Builder, maybeU8:number):void { builder.addFieldInt8(4, maybeU8, undefined); } -static addDefaultU8(builder:flatbuffers.Builder, defaultU8:number) { +static addDefaultU8(builder:flatbuffers.Builder, defaultU8:number):void { builder.addFieldInt8(5, defaultU8, 42); } -static addJustI16(builder:flatbuffers.Builder, justI16:number) { +static addJustI16(builder:flatbuffers.Builder, justI16:number):void { builder.addFieldInt16(6, justI16, 0); } -static addMaybeI16(builder:flatbuffers.Builder, maybeI16:number) { +static addMaybeI16(builder:flatbuffers.Builder, maybeI16:number):void { builder.addFieldInt16(7, maybeI16, undefined); } -static addDefaultI16(builder:flatbuffers.Builder, defaultI16:number) { +static addDefaultI16(builder:flatbuffers.Builder, defaultI16:number):void { builder.addFieldInt16(8, defaultI16, 42); } -static addJustU16(builder:flatbuffers.Builder, justU16:number) { +static addJustU16(builder:flatbuffers.Builder, justU16:number):void { builder.addFieldInt16(9, justU16, 0); } -static addMaybeU16(builder:flatbuffers.Builder, maybeU16:number) { +static addMaybeU16(builder:flatbuffers.Builder, maybeU16:number):void { builder.addFieldInt16(10, maybeU16, undefined); } -static addDefaultU16(builder:flatbuffers.Builder, defaultU16:number) { +static addDefaultU16(builder:flatbuffers.Builder, defaultU16:number):void { builder.addFieldInt16(11, defaultU16, 42); } -static addJustI32(builder:flatbuffers.Builder, justI32:number) { +static addJustI32(builder:flatbuffers.Builder, justI32:number):void { builder.addFieldInt32(12, justI32, 0); } -static addMaybeI32(builder:flatbuffers.Builder, maybeI32:number) { +static addMaybeI32(builder:flatbuffers.Builder, maybeI32:number):void { builder.addFieldInt32(13, maybeI32, undefined); } -static addDefaultI32(builder:flatbuffers.Builder, defaultI32:number) { +static addDefaultI32(builder:flatbuffers.Builder, defaultI32:number):void { builder.addFieldInt32(14, defaultI32, 42); } -static addJustU32(builder:flatbuffers.Builder, justU32:number) { +static addJustU32(builder:flatbuffers.Builder, justU32:number):void { builder.addFieldInt32(15, justU32, 0); } -static addMaybeU32(builder:flatbuffers.Builder, maybeU32:number) { +static addMaybeU32(builder:flatbuffers.Builder, maybeU32:number):void { builder.addFieldInt32(16, maybeU32, undefined); } -static addDefaultU32(builder:flatbuffers.Builder, defaultU32:number) { +static addDefaultU32(builder:flatbuffers.Builder, defaultU32:number):void { builder.addFieldInt32(17, defaultU32, 42); } -static addJustI64(builder:flatbuffers.Builder, justI64:bigint) { +static addJustI64(builder:flatbuffers.Builder, justI64:bigint):void { builder.addFieldInt64(18, justI64, BigInt('0')); } -static addMaybeI64(builder:flatbuffers.Builder, maybeI64:bigint) { +static addMaybeI64(builder:flatbuffers.Builder, maybeI64:bigint):void { builder.addFieldInt64(19, maybeI64, undefined); } -static addDefaultI64(builder:flatbuffers.Builder, defaultI64:bigint) { +static addDefaultI64(builder:flatbuffers.Builder, defaultI64:bigint):void { builder.addFieldInt64(20, defaultI64, BigInt('42')); } -static addJustU64(builder:flatbuffers.Builder, justU64:bigint) { +static addJustU64(builder:flatbuffers.Builder, justU64:bigint):void { builder.addFieldInt64(21, justU64, BigInt('0')); } -static addMaybeU64(builder:flatbuffers.Builder, maybeU64:bigint) { +static addMaybeU64(builder:flatbuffers.Builder, maybeU64:bigint):void { builder.addFieldInt64(22, maybeU64, undefined); } -static addDefaultU64(builder:flatbuffers.Builder, defaultU64:bigint) { +static addDefaultU64(builder:flatbuffers.Builder, defaultU64:bigint):void { builder.addFieldInt64(23, defaultU64, BigInt('42')); } -static addJustF32(builder:flatbuffers.Builder, justF32:number) { +static addJustF32(builder:flatbuffers.Builder, justF32:number):void { builder.addFieldFloat32(24, justF32, 0.0); } -static addMaybeF32(builder:flatbuffers.Builder, maybeF32:number) { +static addMaybeF32(builder:flatbuffers.Builder, maybeF32:number):void { builder.addFieldFloat32(25, maybeF32, undefined); } -static addDefaultF32(builder:flatbuffers.Builder, defaultF32:number) { +static addDefaultF32(builder:flatbuffers.Builder, defaultF32:number):void { builder.addFieldFloat32(26, defaultF32, 42.0); } -static addJustF64(builder:flatbuffers.Builder, justF64:number) { +static addJustF64(builder:flatbuffers.Builder, justF64:number):void { builder.addFieldFloat64(27, justF64, 0.0); } -static addMaybeF64(builder:flatbuffers.Builder, maybeF64:number) { +static addMaybeF64(builder:flatbuffers.Builder, maybeF64:number):void { builder.addFieldFloat64(28, maybeF64, undefined); } -static addDefaultF64(builder:flatbuffers.Builder, defaultF64:number) { +static addDefaultF64(builder:flatbuffers.Builder, defaultF64:number):void { builder.addFieldFloat64(29, defaultF64, 42.0); } -static addJustBool(builder:flatbuffers.Builder, justBool:boolean) { +static addJustBool(builder:flatbuffers.Builder, justBool:boolean):void { builder.addFieldInt8(30, +justBool, +false); } -static addMaybeBool(builder:flatbuffers.Builder, maybeBool:boolean) { +static addMaybeBool(builder:flatbuffers.Builder, maybeBool:boolean):void { builder.addFieldInt8(31, +maybeBool, undefined); } -static addDefaultBool(builder:flatbuffers.Builder, defaultBool:boolean) { +static addDefaultBool(builder:flatbuffers.Builder, defaultBool:boolean):void { builder.addFieldInt8(32, +defaultBool, +true); } -static addJustEnum(builder:flatbuffers.Builder, justEnum:OptionalByte) { +static addJustEnum(builder:flatbuffers.Builder, justEnum:OptionalByte):void { builder.addFieldInt8(33, justEnum, OptionalByte.None); } -static addMaybeEnum(builder:flatbuffers.Builder, maybeEnum:OptionalByte) { +static addMaybeEnum(builder:flatbuffers.Builder, maybeEnum:OptionalByte):void { builder.addFieldInt8(34, maybeEnum, undefined); } -static addDefaultEnum(builder:flatbuffers.Builder, defaultEnum:OptionalByte) { +static addDefaultEnum(builder:flatbuffers.Builder, defaultEnum:OptionalByte):void { builder.addFieldInt8(35, defaultEnum, OptionalByte.One); } @@ -362,11 +362,11 @@ static endScalarStuff(builder:flatbuffers.Builder):flatbuffers.Offset { return offset; } -static finishScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'NULL'); } -static finishSizePrefixedScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishSizePrefixedScalarStuffBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'NULL', true); } diff --git a/tests/ts/tsconfig.isolated.json b/tests/ts/tsconfig.isolated.json new file mode 100644 index 000000000..16f01a401 --- /dev/null +++ b/tests/ts/tsconfig.isolated.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "isolatedDeclarations": true, + "isolatedModules": true, + "skipLibCheck": false + } +} diff --git a/tests/ts/tsconfig.json b/tests/ts/tsconfig.json index 113fb3767..103ff7587 100644 --- a/tests/ts/tsconfig.json +++ b/tests/ts/tsconfig.json @@ -7,7 +7,9 @@ ], "module": "NodeNext", "declaration": true, - "strict": true + "strict": true, + "isolatedModules": true, + "isolatedDeclarations": true }, "include": [ "monster_test.ts", @@ -23,4 +25,4 @@ "longer-namespace/**/*.ts", "relative_imports/**/*.ts" ] -} \ No newline at end of file +} diff --git a/tests/ts/typescript.d.ts b/tests/ts/typescript.d.ts index eefa66f5e..3c9fcbf2f 100644 --- a/tests/ts/typescript.d.ts +++ b/tests/ts/typescript.d.ts @@ -1,2 +1,2 @@ -export {class_} from './typescript/class.js'; -export {Object_} from './typescript/object.js'; +export { Object_ } from './typescript/object.js'; +export { class_ } from './typescript/class.js'; diff --git a/tests/ts/typescript.js b/tests/ts/typescript.js index 59d15e39c..aaa77b6f4 100644 --- a/tests/ts/typescript.js +++ b/tests/ts/typescript.js @@ -1,5 +1,4 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {class_} from './typescript/class.js'; -export {Object_} from './typescript/object.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Object_ } from './typescript/object.js'; +export { class_ } from './typescript/class.js'; diff --git a/tests/ts/typescript.ts b/tests/ts/typescript.ts index 783517e0a..da50d1539 100644 --- a/tests/ts/typescript.ts +++ b/tests/ts/typescript.ts @@ -2,5 +2,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {class_} from './typescript/class.js'; -export {Object_} from './typescript/object.js'; +export { Object_ } from './typescript/object.js'; +export { class_ } from './typescript/class.js'; diff --git a/tests/ts/typescript/class.d.ts b/tests/ts/typescript/class.d.ts index defd960a8..ff6c54222 100644 --- a/tests/ts/typescript/class.d.ts +++ b/tests/ts/typescript/class.d.ts @@ -1,4 +1,4 @@ export declare enum class_ { - new_ = 0, - instanceof_ = 1, + new_ = 0, + instanceof_ = 1 } diff --git a/tests/ts/typescript/class.js b/tests/ts/typescript/class.js index efb593b51..2dba0365e 100644 --- a/tests/ts/typescript/class.js +++ b/tests/ts/typescript/class.js @@ -1,8 +1,7 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export var class_; -(function(class_) { -class_[class_['new_'] = 0] = 'new_'; -class_[class_['instanceof_'] = 1] = 'instanceof_'; +(function (class_) { + class_[class_["new_"] = 0] = "new_"; + class_[class_["instanceof_"] = 1] = "instanceof_"; })(class_ || (class_ = {})); diff --git a/tests/ts/typescript/class.ts b/tests/ts/typescript/class.ts index 7043771fb..69b4a0ae6 100644 --- a/tests/ts/typescript/class.ts +++ b/tests/ts/typescript/class.ts @@ -4,5 +4,5 @@ export enum class_ { new_ = 0, - instanceof_ = 1, + instanceof_ = 1 } diff --git a/tests/ts/typescript/object.d.ts b/tests/ts/typescript/object.d.ts index ce6ce7090..dbb4e08cf 100644 --- a/tests/ts/typescript/object.d.ts +++ b/tests/ts/typescript/object.d.ts @@ -1,64 +1,48 @@ import * as flatbuffers from 'flatbuffers'; -import {Abc} from '../foobar/abc.js'; -import {class_ as foobar_class_} from '../foobar/class.js'; -import {Schema, SchemaT} from '../reflection/schema.js'; -import {class_} from '../typescript/class.js'; -export declare class Object_ - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Object_; - static getRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_; - static getSizePrefixedRootAsObject( - bb: flatbuffers.ByteBuffer, - obj?: Object_, - ): Object_; - return_(): number; - mutate_return(value: number): boolean; - if_(): number; - mutate_if(value: number): boolean; - switch_(): number; - mutate_switch(value: number): boolean; - enum_(): class_; - mutate_enum(value: class_): boolean; - enum2(): foobar_class_; - mutate_enum2(value: foobar_class_): boolean; - enum3(): Abc; - mutate_enum3(value: Abc): boolean; - reflect(obj?: Schema): Schema | null; - static getFullyQualifiedName(): string; - static startObject(builder: flatbuffers.Builder): void; - static addReturn(builder: flatbuffers.Builder, return_: number): void; - static addIf(builder: flatbuffers.Builder, if_: number): void; - static addSwitch(builder: flatbuffers.Builder, switch_: number): void; - static addEnum(builder: flatbuffers.Builder, enum_: class_): void; - static addEnum2(builder: flatbuffers.Builder, enum2: foobar_class_): void; - static addEnum3(builder: flatbuffers.Builder, enum3: Abc): void; - static addReflect( - builder: flatbuffers.Builder, - reflectOffset: flatbuffers.Offset, - ): void; - static endObject(builder: flatbuffers.Builder): flatbuffers.Offset; - unpack(): Object_T; - unpackTo(_o: Object_T): void; +import { Abc } from '../foobar/abc.js'; +import { class_ as foobar_class_ } from '../foobar/class.js'; +import { Schema, SchemaT } from '../reflection/schema.js'; +import { class_ } from './class.js'; +export declare class Object_ implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Object_; + static getRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_; + static getSizePrefixedRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_; + return_(): number; + mutate_return(value: number): boolean; + if_(): number; + mutate_if(value: number): boolean; + switch_(): number; + mutate_switch(value: number): boolean; + enum_(): class_; + mutate_enum(value: class_): boolean; + enum2(): foobar_class_; + mutate_enum2(value: foobar_class_): boolean; + enum3(): Abc; + mutate_enum3(value: Abc): boolean; + reflect(obj?: Schema): Schema | null; + static getFullyQualifiedName(): "typescript.Object"; + static startObject(builder: flatbuffers.Builder): void; + static addReturn(builder: flatbuffers.Builder, return_: number): void; + static addIf(builder: flatbuffers.Builder, if_: number): void; + static addSwitch(builder: flatbuffers.Builder, switch_: number): void; + static addEnum(builder: flatbuffers.Builder, enum_: class_): void; + static addEnum2(builder: flatbuffers.Builder, enum2: foobar_class_): void; + static addEnum3(builder: flatbuffers.Builder, enum3: Abc): void; + static addReflect(builder: flatbuffers.Builder, reflectOffset: flatbuffers.Offset): void; + static endObject(builder: flatbuffers.Builder): flatbuffers.Offset; + unpack(): Object_T; + unpackTo(_o: Object_T): void; } export declare class Object_T implements flatbuffers.IGeneratedObject { - return_: number; - if_: number; - switch_: number; - enum_: class_; - enum2: foobar_class_; - enum3: Abc; - reflect: SchemaT | null; - constructor( - return_?: number, - if_?: number, - switch_?: number, - enum_?: class_, - enum2?: foobar_class_, - enum3?: Abc, - reflect?: SchemaT | null, - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + return_: number; + if_: number; + switch_: number; + enum_: class_; + enum2: foobar_class_; + enum3: Abc; + reflect: SchemaT | null; + constructor(return_?: number, if_?: number, switch_?: number, enum_?: class_, enum2?: foobar_class_, enum3?: Abc, reflect?: SchemaT | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/typescript/object.js b/tests/ts/typescript/object.js index 122b19234..96b785572 100644 --- a/tests/ts/typescript/object.js +++ b/tests/ts/typescript/object.js @@ -1,181 +1,167 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {Abc} from '../foobar/abc.js'; -import {class_ as foobar_class_} from '../foobar/class.js'; -import {Schema} from '../reflection/schema.js'; -import {class_} from '../typescript/class.js'; - +import { Abc } from '../foobar/abc.js'; +import { class_ as foobar_class_ } from '../foobar/class.js'; +import { Schema } from '../reflection/schema.js'; +import { class_ } from './class.js'; export class Object_ { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsObject(bb, obj) { - return (obj || new Object_()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsObject(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Object_()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - return_() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_return(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - if_() { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_if(value) { - const offset = this.bb.__offset(this.bb_pos, 6); - if (offset === 0) { - return false; + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - switch_() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_switch(value) { - const offset = this.bb.__offset(this.bb_pos, 8); - if (offset === 0) { - return false; + static getRootAsObject(bb, obj) { + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - enum_() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readInt32(this.bb_pos + offset) : class_.new_; - } - mutate_enum(value) { - const offset = this.bb.__offset(this.bb_pos, 10); - if (offset === 0) { - return false; + static getSizePrefixedRootAsObject(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - enum2() { - const offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readInt32(this.bb_pos + offset) : - foobar_class_.arguments_; - } - mutate_enum2(value) { - const offset = this.bb.__offset(this.bb_pos, 12); - if (offset === 0) { - return false; + return_() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - enum3() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readInt32(this.bb_pos + offset) : Abc.a; - } - mutate_enum3(value) { - const offset = this.bb.__offset(this.bb_pos, 14); - if (offset === 0) { - return false; + mutate_return(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + if_() { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_if(value) { + const offset = this.bb.__offset(this.bb_pos, 6); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + switch_() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_switch(value) { + const offset = this.bb.__offset(this.bb_pos, 8); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + enum_() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.readInt32(this.bb_pos + offset) : class_.new_; + } + mutate_enum(value) { + const offset = this.bb.__offset(this.bb_pos, 10); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + enum2() { + const offset = this.bb.__offset(this.bb_pos, 12); + return offset ? this.bb.readInt32(this.bb_pos + offset) : foobar_class_.arguments_; + } + mutate_enum2(value) { + const offset = this.bb.__offset(this.bb_pos, 12); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + enum3() { + const offset = this.bb.__offset(this.bb_pos, 14); + return offset ? this.bb.readInt32(this.bb_pos + offset) : Abc.a; + } + mutate_enum3(value) { + const offset = this.bb.__offset(this.bb_pos, 14); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + reflect(obj) { + const offset = this.bb.__offset(this.bb_pos, 16); + return offset ? (obj || new Schema()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; + } + static getFullyQualifiedName() { + return 'typescript.Object'; + } + static startObject(builder) { + builder.startObject(7); + } + static addReturn(builder, return_) { + builder.addFieldInt32(0, return_, 0); + } + static addIf(builder, if_) { + builder.addFieldInt32(1, if_, 0); + } + static addSwitch(builder, switch_) { + builder.addFieldInt32(2, switch_, 0); + } + static addEnum(builder, enum_) { + builder.addFieldInt32(3, enum_, class_.new_); + } + static addEnum2(builder, enum2) { + builder.addFieldInt32(4, enum2, foobar_class_.arguments_); + } + static addEnum3(builder, enum3) { + builder.addFieldInt32(5, enum3, Abc.a); + } + static addReflect(builder, reflectOffset) { + builder.addFieldOffset(6, reflectOffset, 0); + } + static endObject(builder) { + const offset = builder.endObject(); + return offset; + } + unpack() { + return new Object_T(this.return_(), this.if_(), this.switch_(), this.enum_(), this.enum2(), this.enum3(), (this.reflect() !== null ? this.reflect().unpack() : null)); + } + unpackTo(_o) { + _o.return_ = this.return_(); + _o.if_ = this.if_(); + _o.switch_ = this.switch_(); + _o.enum_ = this.enum_(); + _o.enum2 = this.enum2(); + _o.enum3 = this.enum3(); + _o.reflect = (this.reflect() !== null ? this.reflect().unpack() : null); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - reflect(obj) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? - (obj || new Schema()) - .__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : - null; - } - static getFullyQualifiedName() { - return 'typescript.Object'; - } - static startObject(builder) { - builder.startObject(7); - } - static addReturn(builder, return_) { - builder.addFieldInt32(0, return_, 0); - } - static addIf(builder, if_) { - builder.addFieldInt32(1, if_, 0); - } - static addSwitch(builder, switch_) { - builder.addFieldInt32(2, switch_, 0); - } - static addEnum(builder, enum_) { - builder.addFieldInt32(3, enum_, class_.new_); - } - static addEnum2(builder, enum2) { - builder.addFieldInt32(4, enum2, foobar_class_.arguments_); - } - static addEnum3(builder, enum3) { - builder.addFieldInt32(5, enum3, Abc.a); - } - static addReflect(builder, reflectOffset) { - builder.addFieldOffset(6, reflectOffset, 0); - } - static endObject(builder) { - const offset = builder.endObject(); - return offset; - } - unpack() { - return new Object_T( - this.return_(), this.if_(), this.switch_(), this.enum_(), this.enum2(), - this.enum3(), - (this.reflect() !== null ? this.reflect().unpack() : null)); - } - unpackTo(_o) { - _o.return_ = this.return_(); - _o.if_ = this.if_(); - _o.switch_ = this.switch_(); - _o.enum_ = this.enum_(); - _o.enum2 = this.enum2(); - _o.enum3 = this.enum3(); - _o.reflect = (this.reflect() !== null ? this.reflect().unpack() : null); - } } export class Object_T { - constructor( - return_ = 0, if_ = 0, switch_ = 0, enum_ = class_.new_, - enum2 = foobar_class_.arguments_, enum3 = Abc.a, reflect = null) { - this.return_ = return_; - this.if_ = if_; - this.switch_ = switch_; - this.enum_ = enum_; - this.enum2 = enum2; - this.enum3 = enum3; - this.reflect = reflect; - } - pack(builder) { - const reflect = (this.reflect !== null ? this.reflect.pack(builder) : 0); - Object_.startObject(builder); - Object_.addReturn(builder, this.return_); - Object_.addIf(builder, this.if_); - Object_.addSwitch(builder, this.switch_); - Object_.addEnum(builder, this.enum_); - Object_.addEnum2(builder, this.enum2); - Object_.addEnum3(builder, this.enum3); - Object_.addReflect(builder, reflect); - return Object_.endObject(builder); - } + constructor(return_ = 0, if_ = 0, switch_ = 0, enum_ = class_.new_, enum2 = foobar_class_.arguments_, enum3 = Abc.a, reflect = null) { + this.return_ = return_; + this.if_ = if_; + this.switch_ = switch_; + this.enum_ = enum_; + this.enum2 = enum2; + this.enum3 = enum3; + this.reflect = reflect; + } + pack(builder) { + const reflect = (this.reflect !== null ? this.reflect.pack(builder) : 0); + Object_.startObject(builder); + Object_.addReturn(builder, this.return_); + Object_.addIf(builder, this.if_); + Object_.addSwitch(builder, this.switch_); + Object_.addEnum(builder, this.enum_); + Object_.addEnum2(builder, this.enum2); + Object_.addEnum3(builder, this.enum3); + Object_.addReflect(builder, reflect); + return Object_.endObject(builder); + } } diff --git a/tests/ts/typescript/object.ts b/tests/ts/typescript/object.ts index e894bb08e..2d41125ce 100644 --- a/tests/ts/typescript/object.ts +++ b/tests/ts/typescript/object.ts @@ -4,236 +4,221 @@ import * as flatbuffers from 'flatbuffers'; -import {Abc} from '../foobar/abc.js'; -import {class_ as foobar_class_} from '../foobar/class.js'; -import {Schema, SchemaT} from '../reflection/schema.js'; -import {class_} from '../typescript/class.js'; +import { Abc } from '../foobar/abc.js'; +import { class_ as foobar_class_ } from '../foobar/class.js'; +import { Schema, SchemaT } from '../reflection/schema.js'; +import { class_ } from './class.js'; + export class Object_ implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): Object_ { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):Object_ { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ { + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +return_():number { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +mutate_return(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 4); + + if (offset === 0) { + return false; } - static getRootAsObject(bb: flatbuffers.ByteBuffer, obj?: Object_): Object_ { - return (obj || new Object_()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +if_():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +mutate_if(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 6); + + if (offset === 0) { + return false; } - static getSizePrefixedRootAsObject( - bb: flatbuffers.ByteBuffer, - obj?: Object_, - ): Object_ { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Object_()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +switch_():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +mutate_switch(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 8); + + if (offset === 0) { + return false; } - return_(): number { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +enum_():class_ { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.new_; +} + +mutate_enum(value:class_):boolean { + const offset = this.bb!.__offset(this.bb_pos, 10); + + if (offset === 0) { + return false; } - mutate_return(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 4); + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} - if (offset === 0) { - return false; - } +enum2():foobar_class_ { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : foobar_class_.arguments_; +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; +mutate_enum2(value:foobar_class_):boolean { + const offset = this.bb!.__offset(this.bb_pos, 12); + + if (offset === 0) { + return false; } - if_(): number { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} + +enum3():Abc { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a; +} + +mutate_enum3(value:Abc):boolean { + const offset = this.bb!.__offset(this.bb_pos, 14); + + if (offset === 0) { + return false; } - mutate_if(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 6); + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} - if (offset === 0) { - return false; - } +reflect(obj?:Schema):Schema|null { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? (obj || new Schema()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } +static getFullyQualifiedName(): "typescript.Object" { + return 'typescript.Object'; +} - switch_(): number { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; - } +static startObject(builder:flatbuffers.Builder):void { + builder.startObject(7); +} - mutate_switch(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 8); +static addReturn(builder:flatbuffers.Builder, return_:number):void { + builder.addFieldInt32(0, return_, 0); +} - if (offset === 0) { - return false; - } +static addIf(builder:flatbuffers.Builder, if_:number):void { + builder.addFieldInt32(1, if_, 0); +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } +static addSwitch(builder:flatbuffers.Builder, switch_:number):void { + builder.addFieldInt32(2, switch_, 0); +} - enum_(): class_ { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.new_; - } +static addEnum(builder:flatbuffers.Builder, enum_:class_):void { + builder.addFieldInt32(3, enum_, class_.new_); +} - mutate_enum(value: class_): boolean { - const offset = this.bb!.__offset(this.bb_pos, 10); +static addEnum2(builder:flatbuffers.Builder, enum2:foobar_class_):void { + builder.addFieldInt32(4, enum2, foobar_class_.arguments_); +} - if (offset === 0) { - return false; - } +static addEnum3(builder:flatbuffers.Builder, enum3:Abc):void { + builder.addFieldInt32(5, enum3, Abc.a); +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } +static addReflect(builder:flatbuffers.Builder, reflectOffset:flatbuffers.Offset):void { + builder.addFieldOffset(6, reflectOffset, 0); +} - enum2(): foobar_class_ { - const offset = this.bb!.__offset(this.bb_pos, 12); - return offset - ? this.bb!.readInt32(this.bb_pos + offset) - : foobar_class_.arguments_; - } +static endObject(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - mutate_enum2(value: foobar_class_): boolean { - const offset = this.bb!.__offset(this.bb_pos, 12); - if (offset === 0) { - return false; - } +unpack(): Object_T { + return new Object_T( + this.return_(), + this.if_(), + this.switch_(), + this.enum_(), + this.enum2(), + this.enum3(), + (this.reflect() !== null ? this.reflect()!.unpack() : null) + ); +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } - enum3(): Abc { - const offset = this.bb!.__offset(this.bb_pos, 14); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a; - } - - mutate_enum3(value: Abc): boolean { - const offset = this.bb!.__offset(this.bb_pos, 14); - - if (offset === 0) { - return false; - } - - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } - - reflect(obj?: Schema): Schema | null { - const offset = this.bb!.__offset(this.bb_pos, 16); - return offset - ? (obj || new Schema()).__init( - this.bb!.__indirect(this.bb_pos + offset), - this.bb!, - ) - : null; - } - - static getFullyQualifiedName(): string { - return 'typescript.Object'; - } - - static startObject(builder: flatbuffers.Builder) { - builder.startObject(7); - } - - static addReturn(builder: flatbuffers.Builder, return_: number) { - builder.addFieldInt32(0, return_, 0); - } - - static addIf(builder: flatbuffers.Builder, if_: number) { - builder.addFieldInt32(1, if_, 0); - } - - static addSwitch(builder: flatbuffers.Builder, switch_: number) { - builder.addFieldInt32(2, switch_, 0); - } - - static addEnum(builder: flatbuffers.Builder, enum_: class_) { - builder.addFieldInt32(3, enum_, class_.new_); - } - - static addEnum2(builder: flatbuffers.Builder, enum2: foobar_class_) { - builder.addFieldInt32(4, enum2, foobar_class_.arguments_); - } - - static addEnum3(builder: flatbuffers.Builder, enum3: Abc) { - builder.addFieldInt32(5, enum3, Abc.a); - } - - static addReflect( - builder: flatbuffers.Builder, - reflectOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(6, reflectOffset, 0); - } - - static endObject(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - unpack(): Object_T { - return new Object_T( - this.return_(), - this.if_(), - this.switch_(), - this.enum_(), - this.enum2(), - this.enum3(), - this.reflect() !== null ? this.reflect()!.unpack() : null, - ); - } - - unpackTo(_o: Object_T): void { - _o.return_ = this.return_(); - _o.if_ = this.if_(); - _o.switch_ = this.switch_(); - _o.enum_ = this.enum_(); - _o.enum2 = this.enum2(); - _o.enum3 = this.enum3(); - _o.reflect = this.reflect() !== null ? this.reflect()!.unpack() : null; - } +unpackTo(_o: Object_T): void { + _o.return_ = this.return_(); + _o.if_ = this.if_(); + _o.switch_ = this.switch_(); + _o.enum_ = this.enum_(); + _o.enum2 = this.enum2(); + _o.enum3 = this.enum3(); + _o.reflect = (this.reflect() !== null ? this.reflect()!.unpack() : null); +} } export class Object_T implements flatbuffers.IGeneratedObject { - constructor( - public return_: number = 0, - public if_: number = 0, - public switch_: number = 0, - public enum_: class_ = class_.new_, - public enum2: foobar_class_ = foobar_class_.arguments_, - public enum3: Abc = Abc.a, - public reflect: SchemaT | null = null, - ) {} +constructor( + public return_: number = 0, + public if_: number = 0, + public switch_: number = 0, + public enum_: class_ = class_.new_, + public enum2: foobar_class_ = foobar_class_.arguments_, + public enum3: Abc = Abc.a, + public reflect: SchemaT|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const reflect = this.reflect !== null ? this.reflect!.pack(builder) : 0; - Object_.startObject(builder); - Object_.addReturn(builder, this.return_); - Object_.addIf(builder, this.if_); - Object_.addSwitch(builder, this.switch_); - Object_.addEnum(builder, this.enum_); - Object_.addEnum2(builder, this.enum2); - Object_.addEnum3(builder, this.enum3); - Object_.addReflect(builder, reflect); +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const reflect = (this.reflect !== null ? this.reflect!.pack(builder) : 0); - return Object_.endObject(builder); - } + Object_.startObject(builder); + Object_.addReturn(builder, this.return_); + Object_.addIf(builder, this.if_); + Object_.addSwitch(builder, this.switch_); + Object_.addEnum(builder, this.enum_); + Object_.addEnum2(builder, this.enum2); + Object_.addEnum3(builder, this.enum3); + Object_.addReflect(builder, reflect); + + return Object_.endObject(builder); +} } diff --git a/tests/ts/typescript_keywords.js b/tests/ts/typescript_keywords.js index 42518fe51..60b7e5751 100644 --- a/tests/ts/typescript_keywords.js +++ b/tests/ts/typescript_keywords.js @@ -1,6 +1,5 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export * as foobar from './foobar.js'; export * as reflection from './reflection.js'; export * as typescript from './typescript.js'; diff --git a/tests/ts/typescript_keywords_generated.cjs b/tests/ts/typescript_keywords_generated.cjs index cc89f84c4..01c8ec7b8 100644 --- a/tests/ts/typescript_keywords_generated.cjs +++ b/tests/ts/typescript_keywords_generated.cjs @@ -135,7 +135,7 @@ var KeyValue = class _KeyValue { } key(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } value(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 6); @@ -365,7 +365,7 @@ var EnumVal = class _EnumVal { } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } value() { const offset = this.bb.__offset(this.bb_pos, 6); @@ -499,7 +499,7 @@ var Enum = class _Enum { } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } values(index, obj) { const offset = this.bb.__offset(this.bb_pos, 6); @@ -672,7 +672,7 @@ var Field = class _Field { } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } type(obj) { const offset = this.bb.__offset(this.bb_pos, 6); @@ -976,7 +976,7 @@ var Object_ = class _Object_ { } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } fields(index, obj) { const offset = this.bb.__offset(this.bb_pos, 6); @@ -1176,7 +1176,7 @@ var RPCCall = class _RPCCall { } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } request(obj) { const offset = this.bb.__offset(this.bb_pos, 6); @@ -1309,7 +1309,7 @@ var SchemaFile = class _SchemaFile { } filename(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } includedFilenames(index, optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 6); @@ -1393,7 +1393,7 @@ var Service = class _Service { } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + return this.bb.__string(this.bb_pos + offset, optionalEncoding); } calls(index, obj) { const offset = this.bb.__offset(this.bb_pos, 6); diff --git a/tests/ts/union-underlying-type.d.ts b/tests/ts/union-underlying-type.d.ts index c835923c4..41a06b5a4 100644 --- a/tests/ts/union-underlying-type.d.ts +++ b/tests/ts/union-underlying-type.d.ts @@ -1,5 +1,5 @@ -export {A, AT} from './union-underlying-type/a.js'; -export {ABC} from './union-underlying-type/abc.js'; -export {B, BT} from './union-underlying-type/b.js'; -export {C, CT} from './union-underlying-type/c.js'; -export {D, DT} from './union-underlying-type/d.js'; +export { A, AT } from './union-underlying-type/a.js'; +export { ABC } from './union-underlying-type/abc.js'; +export { B, BT } from './union-underlying-type/b.js'; +export { C, CT } from './union-underlying-type/c.js'; +export { D, DT } from './union-underlying-type/d.js'; diff --git a/tests/ts/union-underlying-type.js b/tests/ts/union-underlying-type.js index 543e03e20..554813416 100644 --- a/tests/ts/union-underlying-type.js +++ b/tests/ts/union-underlying-type.js @@ -1,8 +1,7 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {A, AT} from './union-underlying-type/a.js'; -export {ABC} from './union-underlying-type/abc.js'; -export {B, BT} from './union-underlying-type/b.js'; -export {C, CT} from './union-underlying-type/c.js'; -export {D, DT} from './union-underlying-type/d.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { A, AT } from './union-underlying-type/a.js'; +export { ABC } from './union-underlying-type/abc.js'; +export { B, BT } from './union-underlying-type/b.js'; +export { C, CT } from './union-underlying-type/c.js'; +export { D, DT } from './union-underlying-type/d.js'; diff --git a/tests/ts/union-underlying-type.ts b/tests/ts/union-underlying-type.ts index 3125d067a..df14f067f 100644 --- a/tests/ts/union-underlying-type.ts +++ b/tests/ts/union-underlying-type.ts @@ -2,8 +2,8 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -export {A, AT} from './union-underlying-type/a.js'; -export {ABC} from './union-underlying-type/abc.js'; -export {B, BT} from './union-underlying-type/b.js'; -export {C, CT} from './union-underlying-type/c.js'; -export {D, DT} from './union-underlying-type/d.js'; +export { A, AT } from './union-underlying-type/a.js'; +export { ABC } from './union-underlying-type/abc.js'; +export { B, BT } from './union-underlying-type/b.js'; +export { C, CT } from './union-underlying-type/c.js'; +export { D, DT } from './union-underlying-type/d.js'; diff --git a/tests/ts/union-underlying-type/a.d.ts b/tests/ts/union-underlying-type/a.d.ts index 1870ecdb4..b835d024a 100644 --- a/tests/ts/union-underlying-type/a.d.ts +++ b/tests/ts/union-underlying-type/a.d.ts @@ -1,22 +1,22 @@ import * as flatbuffers from 'flatbuffers'; export declare class A implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): A; - static getRootAsA(bb: flatbuffers.ByteBuffer, obj?: A): A; - static getSizePrefixedRootAsA(bb: flatbuffers.ByteBuffer, obj?: A): A; - a(): number; - mutate_a(value: number): boolean; - static getFullyQualifiedName(): string; - static startA(builder: flatbuffers.Builder): void; - static addA(builder: flatbuffers.Builder, a: number): void; - static endA(builder: flatbuffers.Builder): flatbuffers.Offset; - static createA(builder: flatbuffers.Builder, a: number): flatbuffers.Offset; - unpack(): AT; - unpackTo(_o: AT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): A; + static getRootAsA(bb: flatbuffers.ByteBuffer, obj?: A): A; + static getSizePrefixedRootAsA(bb: flatbuffers.ByteBuffer, obj?: A): A; + a(): number; + mutate_a(value: number): boolean; + static getFullyQualifiedName(): "UnionUnderlyingType.A"; + static startA(builder: flatbuffers.Builder): void; + static addA(builder: flatbuffers.Builder, a: number): void; + static endA(builder: flatbuffers.Builder): flatbuffers.Offset; + static createA(builder: flatbuffers.Builder, a: number): flatbuffers.Offset; + unpack(): AT; + unpackTo(_o: AT): void; } export declare class AT implements flatbuffers.IGeneratedObject { - a: number; - constructor(a?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + a: number; + constructor(a?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union-underlying-type/a.js b/tests/ts/union-underlying-type/a.js index 570d0b477..728545732 100644 --- a/tests/ts/union-underlying-type/a.js +++ b/tests/ts/union-underlying-type/a.js @@ -1,68 +1,65 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class A { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsA(bb, obj) { - return (obj || new A()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsA(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new A()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - a() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_a(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsA(bb, obj) { + return (obj || new A()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsA(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new A()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + a() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_a(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'UnionUnderlyingType.A'; + } + static startA(builder) { + builder.startObject(1); + } + static addA(builder, a) { + builder.addFieldInt32(0, a, 0); + } + static endA(builder) { + const offset = builder.endObject(); + return offset; + } + static createA(builder, a) { + A.startA(builder); + A.addA(builder, a); + return A.endA(builder); + } + unpack() { + return new AT(this.a()); + } + unpackTo(_o) { + _o.a = this.a(); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'UnionUnderlyingType.A'; - } - static startA(builder) { - builder.startObject(1); - } - static addA(builder, a) { - builder.addFieldInt32(0, a, 0); - } - static endA(builder) { - const offset = builder.endObject(); - return offset; - } - static createA(builder, a) { - A.startA(builder); - A.addA(builder, a); - return A.endA(builder); - } - unpack() { - return new AT(this.a()); - } - unpackTo(_o) { - _o.a = this.a(); - } } export class AT { - constructor(a = 0) { - this.a = a; - } - pack(builder) { - return A.createA(builder, this.a); - } + constructor(a = 0) { + this.a = a; + } + pack(builder) { + return A.createA(builder, this.a); + } } diff --git a/tests/ts/union-underlying-type/a.ts b/tests/ts/union-underlying-type/a.ts index 3732b62be..051ab8fa5 100644 --- a/tests/ts/union-underlying-type/a.ts +++ b/tests/ts/union-underlying-type/a.ts @@ -4,82 +4,86 @@ import * as flatbuffers from 'flatbuffers'; + + export class A implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): A { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):A { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsA(bb:flatbuffers.ByteBuffer, obj?:A):A { + return (obj || new A()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsA(bb:flatbuffers.ByteBuffer, obj?:A):A { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new A()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +a():number { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +mutate_a(value:number):boolean { + const offset = this.bb!.__offset(this.bb_pos, 4); + + if (offset === 0) { + return false; } - static getRootAsA(bb: flatbuffers.ByteBuffer, obj?: A): A { - return (obj || new A()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } + this.bb!.writeInt32(this.bb_pos + offset, value); + return true; +} - static getSizePrefixedRootAsA(bb: flatbuffers.ByteBuffer, obj?: A): A { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new A()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getFullyQualifiedName(): "UnionUnderlyingType.A" { + return 'UnionUnderlyingType.A'; +} - a(): number { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; - } +static startA(builder:flatbuffers.Builder):void { + builder.startObject(1); +} - mutate_a(value: number): boolean { - const offset = this.bb!.__offset(this.bb_pos, 4); +static addA(builder:flatbuffers.Builder, a:number):void { + builder.addFieldInt32(0, a, 0); +} - if (offset === 0) { - return false; - } +static endA(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - this.bb!.writeInt32(this.bb_pos + offset, value); - return true; - } +static createA(builder:flatbuffers.Builder, a:number):flatbuffers.Offset { + A.startA(builder); + A.addA(builder, a); + return A.endA(builder); +} - static getFullyQualifiedName(): string { - return 'UnionUnderlyingType.A'; - } +unpack(): AT { + return new AT( + this.a() + ); +} - static startA(builder: flatbuffers.Builder) { - builder.startObject(1); - } - static addA(builder: flatbuffers.Builder, a: number) { - builder.addFieldInt32(0, a, 0); - } - - static endA(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static createA(builder: flatbuffers.Builder, a: number): flatbuffers.Offset { - A.startA(builder); - A.addA(builder, a); - return A.endA(builder); - } - - unpack(): AT { - return new AT(this.a()); - } - - unpackTo(_o: AT): void { - _o.a = this.a(); - } +unpackTo(_o: AT): void { + _o.a = this.a(); +} } export class AT implements flatbuffers.IGeneratedObject { - constructor(public a: number = 0) {} +constructor( + public a: number = 0 +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return A.createA(builder, this.a); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return A.createA(builder, + this.a + ); +} } diff --git a/tests/ts/union-underlying-type/abc.d.ts b/tests/ts/union-underlying-type/abc.d.ts index 91737e4a7..ccaa98a52 100644 --- a/tests/ts/union-underlying-type/abc.d.ts +++ b/tests/ts/union-underlying-type/abc.d.ts @@ -1,18 +1,11 @@ -import {A} from '../union-underlying-type/a.js'; -import {B} from '../union-underlying-type/b.js'; -import {C} from '../union-underlying-type/c.js'; +import { A } from './a.js'; +import { B } from './b.js'; +import { C } from './c.js'; export declare enum ABC { - NONE = 0, - A = 555, - B = 666, - C = 777, + NONE = 0, + A = 555, + B = 666, + C = 777 } -export declare function unionToAbc( - type: ABC, - accessor: (obj: A | B | C) => A | B | C | null, -): A | B | C | null; -export declare function unionListToAbc( - type: ABC, - accessor: (index: number, obj: A | B | C) => A | B | C | null, - index: number, -): A | B | C | null; +export declare function unionToAbc(type: ABC, accessor: (obj: A | B | C) => A | B | C | null): A | B | C | null; +export declare function unionListToAbc(type: ABC, accessor: (index: number, obj: A | B | C) => A | B | C | null, index: number): A | B | C | null; diff --git a/tests/ts/union-underlying-type/abc.js b/tests/ts/union-underlying-type/abc.js index 6e5e10c59..96a4b6735 100644 --- a/tests/ts/union-underlying-type/abc.js +++ b/tests/ts/union-underlying-type/abc.js @@ -1,41 +1,30 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -import {A} from '../union-underlying-type/a.js'; -import {B} from '../union-underlying-type/b.js'; -import {C} from '../union-underlying-type/c.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import { A } from './a.js'; +import { B } from './b.js'; +import { C } from './c.js'; export var ABC; -(function(ABC) { -ABC[ABC['NONE'] = 0] = 'NONE'; -ABC[ABC['A'] = 555] = 'A'; -ABC[ABC['B'] = 666] = 'B'; -ABC[ABC['C'] = 777] = 'C'; +(function (ABC) { + ABC[ABC["NONE"] = 0] = "NONE"; + ABC[ABC["A"] = 555] = "A"; + ABC[ABC["B"] = 666] = "B"; + ABC[ABC["C"] = 777] = "C"; })(ABC || (ABC = {})); export function unionToAbc(type, accessor) { - switch (ABC[type]) { - case 'NONE': - return null; - case 'A': - return accessor(new A()); - case 'B': - return accessor(new B()); - case 'C': - return accessor(new C()); - default: - return null; - } + switch (ABC[type]) { + case 'NONE': return null; + case 'A': return accessor(new A()); + case 'B': return accessor(new B()); + case 'C': return accessor(new C()); + default: return null; + } } export function unionListToAbc(type, accessor, index) { - switch (ABC[type]) { - case 'NONE': - return null; - case 'A': - return accessor(index, new A()); - case 'B': - return accessor(index, new B()); - case 'C': - return accessor(index, new C()); - default: - return null; - } + switch (ABC[type]) { + case 'NONE': return null; + case 'A': return accessor(index, new A()); + case 'B': return accessor(index, new B()); + case 'C': return accessor(index, new C()); + default: return null; + } } diff --git a/tests/ts/union-underlying-type/abc.ts b/tests/ts/union-underlying-type/abc.ts index bf6f7a97c..ac0e809f2 100644 --- a/tests/ts/union-underlying-type/abc.ts +++ b/tests/ts/union-underlying-type/abc.ts @@ -2,50 +2,41 @@ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ -import {A, AT} from '../union-underlying-type/a.js'; -import {B, BT} from '../union-underlying-type/b.js'; -import {C, CT} from '../union-underlying-type/c.js'; +import { A, AT } from './a.js'; +import { B, BT } from './b.js'; +import { C, CT } from './c.js'; + export enum ABC { NONE = 0, A = 555, B = 666, - C = 777, + C = 777 } export function unionToAbc( type: ABC, - accessor: (obj: A | B | C) => A | B | C | null, -): A | B | C | null { - switch (ABC[type]) { - case 'NONE': - return null; - case 'A': - return accessor(new A())! as A; - case 'B': - return accessor(new B())! as B; - case 'C': - return accessor(new C())! as C; - default: - return null; + accessor: (obj:A|B|C) => A|B|C|null +): A|B|C|null { + switch(ABC[type]) { + case 'NONE': return null; + case 'A': return accessor(new A())! as A; + case 'B': return accessor(new B())! as B; + case 'C': return accessor(new C())! as C; + default: return null; } } export function unionListToAbc( - type: ABC, - accessor: (index: number, obj: A | B | C) => A | B | C | null, - index: number, -): A | B | C | null { - switch (ABC[type]) { - case 'NONE': - return null; - case 'A': - return accessor(index, new A())! as A; - case 'B': - return accessor(index, new B())! as B; - case 'C': - return accessor(index, new C())! as C; - default: - return null; + type: ABC, + accessor: (index: number, obj:A|B|C) => A|B|C|null, + index: number +): A|B|C|null { + switch(ABC[type]) { + case 'NONE': return null; + case 'A': return accessor(index, new A())! as A; + case 'B': return accessor(index, new B())! as B; + case 'C': return accessor(index, new C())! as C; + default: return null; } } diff --git a/tests/ts/union-underlying-type/b.d.ts b/tests/ts/union-underlying-type/b.d.ts index 5114804fc..a3e648f30 100644 --- a/tests/ts/union-underlying-type/b.d.ts +++ b/tests/ts/union-underlying-type/b.d.ts @@ -1,25 +1,22 @@ import * as flatbuffers from 'flatbuffers'; export declare class B implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): B; - static getRootAsB(bb: flatbuffers.ByteBuffer, obj?: B): B; - static getSizePrefixedRootAsB(bb: flatbuffers.ByteBuffer, obj?: B): B; - b(): string | null; - b(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - static getFullyQualifiedName(): string; - static startB(builder: flatbuffers.Builder): void; - static addB(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset): void; - static endB(builder: flatbuffers.Builder): flatbuffers.Offset; - static createB( - builder: flatbuffers.Builder, - bOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - unpack(): BT; - unpackTo(_o: BT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): B; + static getRootAsB(bb: flatbuffers.ByteBuffer, obj?: B): B; + static getSizePrefixedRootAsB(bb: flatbuffers.ByteBuffer, obj?: B): B; + b(): string | null; + b(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; + static getFullyQualifiedName(): "UnionUnderlyingType.B"; + static startB(builder: flatbuffers.Builder): void; + static addB(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset): void; + static endB(builder: flatbuffers.Builder): flatbuffers.Offset; + static createB(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset): flatbuffers.Offset; + unpack(): BT; + unpackTo(_o: BT): void; } export declare class BT implements flatbuffers.IGeneratedObject { - b: string | Uint8Array | null; - constructor(b?: string | Uint8Array | null); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + b: string | Uint8Array | null; + constructor(b?: string | Uint8Array | null); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union-underlying-type/b.js b/tests/ts/union-underlying-type/b.js index 5dcf1c805..85e67b224 100644 --- a/tests/ts/union-underlying-type/b.js +++ b/tests/ts/union-underlying-type/b.js @@ -1,62 +1,58 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class B { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsB(bb, obj) { - return (obj || new B()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsB(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new B()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - b(optionalEncoding) { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : - null; - } - static getFullyQualifiedName() { - return 'UnionUnderlyingType.B'; - } - static startB(builder) { - builder.startObject(1); - } - static addB(builder, bOffset) { - builder.addFieldOffset(0, bOffset, 0); - } - static endB(builder) { - const offset = builder.endObject(); - return offset; - } - static createB(builder, bOffset) { - B.startB(builder); - B.addB(builder, bOffset); - return B.endB(builder); - } - unpack() { - return new BT(this.b()); - } - unpackTo(_o) { - _o.b = this.b(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsB(bb, obj) { + return (obj || new B()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsB(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new B()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + b(optionalEncoding) { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; + } + static getFullyQualifiedName() { + return 'UnionUnderlyingType.B'; + } + static startB(builder) { + builder.startObject(1); + } + static addB(builder, bOffset) { + builder.addFieldOffset(0, bOffset, 0); + } + static endB(builder) { + const offset = builder.endObject(); + return offset; + } + static createB(builder, bOffset) { + B.startB(builder); + B.addB(builder, bOffset); + return B.endB(builder); + } + unpack() { + return new BT(this.b()); + } + unpackTo(_o) { + _o.b = this.b(); + } } export class BT { - constructor(b = null) { - this.b = b; - } - pack(builder) { - const b = (this.b !== null ? builder.createString(this.b) : 0); - return B.createB(builder, b); - } + constructor(b = null) { + this.b = b; + } + pack(builder) { + const b = (this.b !== null ? builder.createString(this.b) : 0); + return B.createB(builder, b); + } } diff --git a/tests/ts/union-underlying-type/b.ts b/tests/ts/union-underlying-type/b.ts index dfa63ef61..223961fd6 100644 --- a/tests/ts/union-underlying-type/b.ts +++ b/tests/ts/union-underlying-type/b.ts @@ -4,80 +4,79 @@ import * as flatbuffers from 'flatbuffers'; + + export class B implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): B { - this.bb_pos = i; - this.bb = bb; - return this; - } + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):B { + this.bb_pos = i; + this.bb = bb; + return this; +} - static getRootAsB(bb: flatbuffers.ByteBuffer, obj?: B): B { - return (obj || new B()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getRootAsB(bb:flatbuffers.ByteBuffer, obj?:B):B { + return (obj || new B()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - static getSizePrefixedRootAsB(bb: flatbuffers.ByteBuffer, obj?: B): B { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new B()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getSizePrefixedRootAsB(bb:flatbuffers.ByteBuffer, obj?:B):B { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new B()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} - b(): string | null; - b(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null; - b(optionalEncoding?: any): string | Uint8Array | null { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset - ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) - : null; - } +b():string|null +b(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +b(optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null; +} - static getFullyQualifiedName(): string { - return 'UnionUnderlyingType.B'; - } +static getFullyQualifiedName(): "UnionUnderlyingType.B" { + return 'UnionUnderlyingType.B'; +} - static startB(builder: flatbuffers.Builder) { - builder.startObject(1); - } +static startB(builder:flatbuffers.Builder):void { + builder.startObject(1); +} - static addB(builder: flatbuffers.Builder, bOffset: flatbuffers.Offset) { - builder.addFieldOffset(0, bOffset, 0); - } +static addB(builder:flatbuffers.Builder, bOffset:flatbuffers.Offset):void { + builder.addFieldOffset(0, bOffset, 0); +} - static endB(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } +static endB(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - static createB( - builder: flatbuffers.Builder, - bOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - B.startB(builder); - B.addB(builder, bOffset); - return B.endB(builder); - } +static createB(builder:flatbuffers.Builder, bOffset:flatbuffers.Offset):flatbuffers.Offset { + B.startB(builder); + B.addB(builder, bOffset); + return B.endB(builder); +} - unpack(): BT { - return new BT(this.b()); - } +unpack(): BT { + return new BT( + this.b() + ); +} - unpackTo(_o: BT): void { - _o.b = this.b(); - } + +unpackTo(_o: BT): void { + _o.b = this.b(); +} } export class BT implements flatbuffers.IGeneratedObject { - constructor(public b: string | Uint8Array | null = null) {} +constructor( + public b: string|Uint8Array|null = null +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const b = this.b !== null ? builder.createString(this.b!) : 0; - return B.createB(builder, b); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const b = (this.b !== null ? builder.createString(this.b!) : 0); + + return B.createB(builder, + b + ); +} } diff --git a/tests/ts/union-underlying-type/c.d.ts b/tests/ts/union-underlying-type/c.d.ts index b7f92bb8d..bdce4fc78 100644 --- a/tests/ts/union-underlying-type/c.d.ts +++ b/tests/ts/union-underlying-type/c.d.ts @@ -1,22 +1,22 @@ import * as flatbuffers from 'flatbuffers'; export declare class C implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): C; - static getRootAsC(bb: flatbuffers.ByteBuffer, obj?: C): C; - static getSizePrefixedRootAsC(bb: flatbuffers.ByteBuffer, obj?: C): C; - c(): boolean; - mutate_c(value: boolean): boolean; - static getFullyQualifiedName(): string; - static startC(builder: flatbuffers.Builder): void; - static addC(builder: flatbuffers.Builder, c: boolean): void; - static endC(builder: flatbuffers.Builder): flatbuffers.Offset; - static createC(builder: flatbuffers.Builder, c: boolean): flatbuffers.Offset; - unpack(): CT; - unpackTo(_o: CT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): C; + static getRootAsC(bb: flatbuffers.ByteBuffer, obj?: C): C; + static getSizePrefixedRootAsC(bb: flatbuffers.ByteBuffer, obj?: C): C; + c(): boolean; + mutate_c(value: boolean): boolean; + static getFullyQualifiedName(): "UnionUnderlyingType.C"; + static startC(builder: flatbuffers.Builder): void; + static addC(builder: flatbuffers.Builder, c: boolean): void; + static endC(builder: flatbuffers.Builder): flatbuffers.Offset; + static createC(builder: flatbuffers.Builder, c: boolean): flatbuffers.Offset; + unpack(): CT; + unpackTo(_o: CT): void; } export declare class CT implements flatbuffers.IGeneratedObject { - c: boolean; - constructor(c?: boolean); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + c: boolean; + constructor(c?: boolean); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union-underlying-type/c.js b/tests/ts/union-underlying-type/c.js index aedd74729..48c38b78f 100644 --- a/tests/ts/union-underlying-type/c.js +++ b/tests/ts/union-underlying-type/c.js @@ -1,68 +1,65 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class C { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsC(bb, obj) { - return (obj || new C()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsC(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new C()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - c() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; - } - mutate_c(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsC(bb, obj) { + return (obj || new C()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsC(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new C()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + c() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false; + } + mutate_c(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeInt8(this.bb_pos + offset, +value); + return true; + } + static getFullyQualifiedName() { + return 'UnionUnderlyingType.C'; + } + static startC(builder) { + builder.startObject(1); + } + static addC(builder, c) { + builder.addFieldInt8(0, +c, +false); + } + static endC(builder) { + const offset = builder.endObject(); + return offset; + } + static createC(builder, c) { + C.startC(builder); + C.addC(builder, c); + return C.endC(builder); + } + unpack() { + return new CT(this.c()); + } + unpackTo(_o) { + _o.c = this.c(); } - this.bb.writeInt8(this.bb_pos + offset, +value); - return true; - } - static getFullyQualifiedName() { - return 'UnionUnderlyingType.C'; - } - static startC(builder) { - builder.startObject(1); - } - static addC(builder, c) { - builder.addFieldInt8(0, +c, +false); - } - static endC(builder) { - const offset = builder.endObject(); - return offset; - } - static createC(builder, c) { - C.startC(builder); - C.addC(builder, c); - return C.endC(builder); - } - unpack() { - return new CT(this.c()); - } - unpackTo(_o) { - _o.c = this.c(); - } } export class CT { - constructor(c = false) { - this.c = c; - } - pack(builder) { - return C.createC(builder, this.c); - } + constructor(c = false) { + this.c = c; + } + pack(builder) { + return C.createC(builder, this.c); + } } diff --git a/tests/ts/union-underlying-type/c.ts b/tests/ts/union-underlying-type/c.ts index 20c2b1c5e..3dd1882dd 100644 --- a/tests/ts/union-underlying-type/c.ts +++ b/tests/ts/union-underlying-type/c.ts @@ -4,82 +4,86 @@ import * as flatbuffers from 'flatbuffers'; + + export class C implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): C { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):C { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsC(bb:flatbuffers.ByteBuffer, obj?:C):C { + return (obj || new C()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsC(bb:flatbuffers.ByteBuffer, obj?:C):C { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new C()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +c():boolean { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +mutate_c(value:boolean):boolean { + const offset = this.bb!.__offset(this.bb_pos, 4); + + if (offset === 0) { + return false; } - static getRootAsC(bb: flatbuffers.ByteBuffer, obj?: C): C { - return (obj || new C()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } + this.bb!.writeInt8(this.bb_pos + offset, +value); + return true; +} - static getSizePrefixedRootAsC(bb: flatbuffers.ByteBuffer, obj?: C): C { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new C()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static getFullyQualifiedName(): "UnionUnderlyingType.C" { + return 'UnionUnderlyingType.C'; +} - c(): boolean { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; - } +static startC(builder:flatbuffers.Builder):void { + builder.startObject(1); +} - mutate_c(value: boolean): boolean { - const offset = this.bb!.__offset(this.bb_pos, 4); +static addC(builder:flatbuffers.Builder, c:boolean):void { + builder.addFieldInt8(0, +c, +false); +} - if (offset === 0) { - return false; - } +static endC(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - this.bb!.writeInt8(this.bb_pos + offset, +value); - return true; - } +static createC(builder:flatbuffers.Builder, c:boolean):flatbuffers.Offset { + C.startC(builder); + C.addC(builder, c); + return C.endC(builder); +} - static getFullyQualifiedName(): string { - return 'UnionUnderlyingType.C'; - } +unpack(): CT { + return new CT( + this.c() + ); +} - static startC(builder: flatbuffers.Builder) { - builder.startObject(1); - } - static addC(builder: flatbuffers.Builder, c: boolean) { - builder.addFieldInt8(0, +c, +false); - } - - static endC(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static createC(builder: flatbuffers.Builder, c: boolean): flatbuffers.Offset { - C.startC(builder); - C.addC(builder, c); - return C.endC(builder); - } - - unpack(): CT { - return new CT(this.c()); - } - - unpackTo(_o: CT): void { - _o.c = this.c(); - } +unpackTo(_o: CT): void { + _o.c = this.c(); +} } export class CT implements flatbuffers.IGeneratedObject { - constructor(public c: boolean = false) {} +constructor( + public c: boolean = false +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - return C.createC(builder, this.c); - } + +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + return C.createC(builder, + this.c + ); +} } diff --git a/tests/ts/union-underlying-type/d.d.ts b/tests/ts/union-underlying-type/d.d.ts index ef13a4f0c..d0274c0cd 100644 --- a/tests/ts/union-underlying-type/d.d.ts +++ b/tests/ts/union-underlying-type/d.d.ts @@ -1,76 +1,41 @@ import * as flatbuffers from 'flatbuffers'; -import {AT} from '../union-underlying-type/a.js'; -import {ABC} from '../union-underlying-type/abc.js'; -import {BT} from '../union-underlying-type/b.js'; -import {CT} from '../union-underlying-type/c.js'; +import { AT } from './a.js'; +import { ABC } from './abc.js'; +import { BT } from './b.js'; +import { CT } from './c.js'; export declare class D implements flatbuffers.IUnpackableObject
{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): D; - static getRootAsD(bb: flatbuffers.ByteBuffer, obj?: D): D; - static getSizePrefixedRootAsD(bb: flatbuffers.ByteBuffer, obj?: D): D; - testUnionType(): ABC; - testUnion(obj: any): any | null; - testVectorOfUnionType(index: number): ABC | null; - testVectorOfUnionTypeLength(): number; - testVectorOfUnionTypeArray(): Int32Array | null; - testVectorOfUnion(index: number, obj: any): any | null; - testVectorOfUnionLength(): number; - static getFullyQualifiedName(): string; - static startD(builder: flatbuffers.Builder): void; - static addTestUnionType( - builder: flatbuffers.Builder, - testUnionType: ABC, - ): void; - static addTestUnion( - builder: flatbuffers.Builder, - testUnionOffset: flatbuffers.Offset, - ): void; - static addTestVectorOfUnionType( - builder: flatbuffers.Builder, - testVectorOfUnionTypeOffset: flatbuffers.Offset, - ): void; - static createTestVectorOfUnionTypeVector( - builder: flatbuffers.Builder, - data: ABC[], - ): flatbuffers.Offset; - static startTestVectorOfUnionTypeVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addTestVectorOfUnion( - builder: flatbuffers.Builder, - testVectorOfUnionOffset: flatbuffers.Offset, - ): void; - static createTestVectorOfUnionVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startTestVectorOfUnionVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static endD(builder: flatbuffers.Builder): flatbuffers.Offset; - static createD( - builder: flatbuffers.Builder, - testUnionType: ABC, - testUnionOffset: flatbuffers.Offset, - testVectorOfUnionTypeOffset: flatbuffers.Offset, - testVectorOfUnionOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - unpack(): DT; - unpackTo(_o: DT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): D; + static getRootAsD(bb: flatbuffers.ByteBuffer, obj?: D): D; + static getSizePrefixedRootAsD(bb: flatbuffers.ByteBuffer, obj?: D): D; + testUnionType(): ABC; + testUnion(obj: any): any | null; + testVectorOfUnionType(index: number): ABC | null; + testVectorOfUnionTypeLength(): number; + testVectorOfUnionTypeArray(): Int32Array | null; + testVectorOfUnion(index: number, obj: any): any | null; + testVectorOfUnionLength(): number; + static getFullyQualifiedName(): "UnionUnderlyingType.D"; + static startD(builder: flatbuffers.Builder): void; + static addTestUnionType(builder: flatbuffers.Builder, testUnionType: ABC): void; + static addTestUnion(builder: flatbuffers.Builder, testUnionOffset: flatbuffers.Offset): void; + static addTestVectorOfUnionType(builder: flatbuffers.Builder, testVectorOfUnionTypeOffset: flatbuffers.Offset): void; + static createTestVectorOfUnionTypeVector(builder: flatbuffers.Builder, data: ABC[]): flatbuffers.Offset; + static startTestVectorOfUnionTypeVector(builder: flatbuffers.Builder, numElems: number): void; + static addTestVectorOfUnion(builder: flatbuffers.Builder, testVectorOfUnionOffset: flatbuffers.Offset): void; + static createTestVectorOfUnionVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startTestVectorOfUnionVector(builder: flatbuffers.Builder, numElems: number): void; + static endD(builder: flatbuffers.Builder): flatbuffers.Offset; + static createD(builder: flatbuffers.Builder, testUnionType: ABC, testUnionOffset: flatbuffers.Offset, testVectorOfUnionTypeOffset: flatbuffers.Offset, testVectorOfUnionOffset: flatbuffers.Offset): flatbuffers.Offset; + unpack(): DT; + unpackTo(_o: DT): void; } export declare class DT implements flatbuffers.IGeneratedObject { - testUnionType: ABC; - testUnion: AT | BT | CT | null; - testVectorOfUnionType: ABC[]; - testVectorOfUnion: (AT | BT | CT)[]; - constructor( - testUnionType?: ABC, - testUnion?: AT | BT | CT | null, - testVectorOfUnionType?: ABC[], - testVectorOfUnion?: (AT | BT | CT)[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + testUnionType: ABC; + testUnion: AT | BT | CT | null; + testVectorOfUnionType: (ABC)[]; + testVectorOfUnion: (AT | BT | CT)[]; + constructor(testUnionType?: ABC, testUnion?: AT | BT | CT | null, testVectorOfUnionType?: (ABC)[], testVectorOfUnion?: (AT | BT | CT)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union-underlying-type/d.js b/tests/ts/union-underlying-type/d.js index 0f387b213..475e429f5 100644 --- a/tests/ts/union-underlying-type/d.js +++ b/tests/ts/union-underlying-type/d.js @@ -1,200 +1,163 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {ABC, unionListToAbc, unionToAbc} from '../union-underlying-type/abc.js'; - +import { ABC, unionToAbc, unionListToAbc } from './abc.js'; export class D { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsD(bb, obj) { - return (obj || new D()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsD(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new D()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - testUnionType() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt32(this.bb_pos + offset) : ABC.NONE; - } - testUnion(obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; - } - testVectorOfUnionType(index) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? - this.bb.readInt32(this.bb.__vector(this.bb_pos + offset) + index * 4) : - null; - } - testVectorOfUnionTypeLength() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - testVectorOfUnionTypeArray() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? - new Int32Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - testVectorOfUnion(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? - this.bb.__union( - obj, this.bb.__vector(this.bb_pos + offset) + index * 4) : - null; - } - testVectorOfUnionLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static getFullyQualifiedName() { - return 'UnionUnderlyingType.D'; - } - static startD(builder) { - builder.startObject(4); - } - static addTestUnionType(builder, testUnionType) { - builder.addFieldInt32(0, testUnionType, ABC.NONE); - } - static addTestUnion(builder, testUnionOffset) { - builder.addFieldOffset(1, testUnionOffset, 0); - } - static addTestVectorOfUnionType(builder, testVectorOfUnionTypeOffset) { - builder.addFieldOffset(2, testVectorOfUnionTypeOffset, 0); - } - static createTestVectorOfUnionTypeVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); + constructor() { + this.bb = null; + this.bb_pos = 0; } - return builder.endVector(); - } - static startTestVectorOfUnionTypeVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static addTestVectorOfUnion(builder, testVectorOfUnionOffset) { - builder.addFieldOffset(3, testVectorOfUnionOffset, 0); - } - static createTestVectorOfUnionVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - return builder.endVector(); - } - static startTestVectorOfUnionVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endD(builder) { - const offset = builder.endObject(); - return offset; - } - static createD( - builder, testUnionType, testUnionOffset, testVectorOfUnionTypeOffset, - testVectorOfUnionOffset) { - D.startD(builder); - D.addTestUnionType(builder, testUnionType); - D.addTestUnion(builder, testUnionOffset); - D.addTestVectorOfUnionType(builder, testVectorOfUnionTypeOffset); - D.addTestVectorOfUnion(builder, testVectorOfUnionOffset); - return D.endD(builder); - } - unpack() { - return new DT( - this.testUnionType(), (() => { - const temp = - unionToAbc(this.testUnionType(), this.testUnion.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(), - this.bb.createScalarList( - this.testVectorOfUnionType.bind(this), - this.testVectorOfUnionTypeLength()), - (() => { - const ret = []; - for (let targetEnumIndex = 0; - targetEnumIndex < this.testVectorOfUnionTypeLength(); - ++targetEnumIndex) { - const targetEnum = this.testVectorOfUnionType(targetEnumIndex); - if (targetEnum === null || ABC[targetEnum] === 'NONE') { - continue; - } - const temp = unionListToAbc( - targetEnum, this.testVectorOfUnion.bind(this), targetEnumIndex); + static getRootAsD(bb, obj) { + return (obj || new D()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsD(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new D()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + testUnionType() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt32(this.bb_pos + offset) : ABC.NONE; + } + testUnion(obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__union(obj, this.bb_pos + offset) : null; + } + testVectorOfUnionType(index) { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readInt32(this.bb.__vector(this.bb_pos + offset) + index * 4) : null; + } + testVectorOfUnionTypeLength() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + testVectorOfUnionTypeArray() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? new Int32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + testVectorOfUnion(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__union(obj, this.bb.__vector(this.bb_pos + offset) + index * 4) : null; + } + testVectorOfUnionLength() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + static getFullyQualifiedName() { + return 'UnionUnderlyingType.D'; + } + static startD(builder) { + builder.startObject(4); + } + static addTestUnionType(builder, testUnionType) { + builder.addFieldInt32(0, testUnionType, ABC.NONE); + } + static addTestUnion(builder, testUnionOffset) { + builder.addFieldOffset(1, testUnionOffset, 0); + } + static addTestVectorOfUnionType(builder, testVectorOfUnionTypeOffset) { + builder.addFieldOffset(2, testVectorOfUnionTypeOffset, 0); + } + static createTestVectorOfUnionTypeVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt32(data[i]); + } + return builder.endVector(); + } + static startTestVectorOfUnionTypeVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static addTestVectorOfUnion(builder, testVectorOfUnionOffset) { + builder.addFieldOffset(3, testVectorOfUnionOffset, 0); + } + static createTestVectorOfUnionVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startTestVectorOfUnionVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static endD(builder) { + const offset = builder.endObject(); + return offset; + } + static createD(builder, testUnionType, testUnionOffset, testVectorOfUnionTypeOffset, testVectorOfUnionOffset) { + D.startD(builder); + D.addTestUnionType(builder, testUnionType); + D.addTestUnion(builder, testUnionOffset); + D.addTestVectorOfUnionType(builder, testVectorOfUnionTypeOffset); + D.addTestVectorOfUnion(builder, testVectorOfUnionOffset); + return D.endD(builder); + } + unpack() { + return new DT(this.testUnionType(), (() => { + const temp = unionToAbc(this.testUnionType(), this.testUnion.bind(this)); if (temp === null) { - continue; + return null; } - ret.push(temp.unpack()); - } - return ret; + return temp.unpack(); + })(), this.bb.createScalarList(this.testVectorOfUnionType.bind(this), this.testVectorOfUnionTypeLength()), (() => { + const ret = []; + for (let targetEnumIndex = 0; targetEnumIndex < this.testVectorOfUnionTypeLength(); ++targetEnumIndex) { + const targetEnum = this.testVectorOfUnionType(targetEnumIndex); + if (targetEnum === null || ABC[targetEnum] === 'NONE') { + continue; + } + const temp = unionListToAbc(targetEnum, this.testVectorOfUnion.bind(this), targetEnumIndex); + if (temp === null) { + continue; + } + ret.push(temp.unpack()); + } + return ret; })()); - } - unpackTo(_o) { - _o.testUnionType = this.testUnionType(); - _o.testUnion = (() => { - const temp = unionToAbc(this.testUnionType(), this.testUnion.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(); - _o.testVectorOfUnionType = this.bb.createScalarList( - this.testVectorOfUnionType.bind(this), - this.testVectorOfUnionTypeLength()); - _o.testVectorOfUnion = (() => { - const ret = []; - for (let targetEnumIndex = 0; - targetEnumIndex < this.testVectorOfUnionTypeLength(); - ++targetEnumIndex) { - const targetEnum = this.testVectorOfUnionType(targetEnumIndex); - if (targetEnum === null || ABC[targetEnum] === 'NONE') { - continue; - } - const temp = unionListToAbc( - targetEnum, this.testVectorOfUnion.bind(this), targetEnumIndex); - if (temp === null) { - continue; - } - ret.push(temp.unpack()); - } - return ret; - })(); - } + } + unpackTo(_o) { + _o.testUnionType = this.testUnionType(); + _o.testUnion = (() => { + const temp = unionToAbc(this.testUnionType(), this.testUnion.bind(this)); + if (temp === null) { + return null; + } + return temp.unpack(); + })(); + _o.testVectorOfUnionType = this.bb.createScalarList(this.testVectorOfUnionType.bind(this), this.testVectorOfUnionTypeLength()); + _o.testVectorOfUnion = (() => { + const ret = []; + for (let targetEnumIndex = 0; targetEnumIndex < this.testVectorOfUnionTypeLength(); ++targetEnumIndex) { + const targetEnum = this.testVectorOfUnionType(targetEnumIndex); + if (targetEnum === null || ABC[targetEnum] === 'NONE') { + continue; + } + const temp = unionListToAbc(targetEnum, this.testVectorOfUnion.bind(this), targetEnumIndex); + if (temp === null) { + continue; + } + ret.push(temp.unpack()); + } + return ret; + })(); + } } export class DT { - constructor( - testUnionType = ABC.NONE, testUnion = null, testVectorOfUnionType = [], - testVectorOfUnion = []) { - this.testUnionType = testUnionType; - this.testUnion = testUnion; - this.testVectorOfUnionType = testVectorOfUnionType; - this.testVectorOfUnion = testVectorOfUnion; - } - pack(builder) { - const testUnion = builder.createObjectOffset(this.testUnion); - const testVectorOfUnionType = D.createTestVectorOfUnionTypeVector( - builder, this.testVectorOfUnionType); - const testVectorOfUnion = D.createTestVectorOfUnionVector( - builder, builder.createObjectOffsetList(this.testVectorOfUnion)); - return D.createD( - builder, this.testUnionType, testUnion, testVectorOfUnionType, - testVectorOfUnion); - } + constructor(testUnionType = ABC.NONE, testUnion = null, testVectorOfUnionType = [], testVectorOfUnion = []) { + this.testUnionType = testUnionType; + this.testUnion = testUnion; + this.testVectorOfUnionType = testVectorOfUnionType; + this.testVectorOfUnion = testVectorOfUnion; + } + pack(builder) { + const testUnion = builder.createObjectOffset(this.testUnion); + const testVectorOfUnionType = D.createTestVectorOfUnionTypeVector(builder, this.testVectorOfUnionType); + const testVectorOfUnion = D.createTestVectorOfUnionVector(builder, builder.createObjectOffsetList(this.testVectorOfUnion)); + return D.createD(builder, this.testUnionType, testUnion, testVectorOfUnionType, testVectorOfUnion); + } } diff --git a/tests/ts/union-underlying-type/d.ts b/tests/ts/union-underlying-type/d.ts index 18c181a1a..e6ccb21d4 100644 --- a/tests/ts/union-underlying-type/d.ts +++ b/tests/ts/union-underlying-type/d.ts @@ -4,281 +4,194 @@ import * as flatbuffers from 'flatbuffers'; -import {A, AT} from '../union-underlying-type/a.js'; -import {ABC, unionListToAbc, unionToAbc} from '../union-underlying-type/abc.js'; -import {B, BT} from '../union-underlying-type/b.js'; -import {C, CT} from '../union-underlying-type/c.js'; +import { A, AT } from './a.js'; +import { ABC, unionToAbc, unionListToAbc } from './abc.js'; +import { B, BT } from './b.js'; +import { C, CT } from './c.js'; + export class D implements flatbuffers.IUnpackableObject
{ - bb: flatbuffers.ByteBuffer | null = null; - bb_pos = 0; - __init(i: number, bb: flatbuffers.ByteBuffer): D { - this.bb_pos = i; - this.bb = bb; - return this; + bb: flatbuffers.ByteBuffer|null = null; + bb_pos: number = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):D { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsD(bb:flatbuffers.ByteBuffer, obj?:D):D { + return (obj || new D()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsD(bb:flatbuffers.ByteBuffer, obj?:D):D { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new D()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +testUnionType():ABC { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : ABC.NONE; +} + +testUnion(obj:any):any|null { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null; +} + +testVectorOfUnionType(index: number):ABC|null { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readInt32(this.bb!.__vector(this.bb_pos + offset) + index * 4) : null; +} + +testVectorOfUnionTypeLength():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +testVectorOfUnionTypeArray():Int32Array|null { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? new Int32Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null; +} + +testVectorOfUnion(index: number, obj:any):any|null { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.__union(obj, this.bb!.__vector(this.bb_pos + offset) + index * 4) : null; +} + +testVectorOfUnionLength():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +static getFullyQualifiedName(): "UnionUnderlyingType.D" { + return 'UnionUnderlyingType.D'; +} + +static startD(builder:flatbuffers.Builder):void { + builder.startObject(4); +} + +static addTestUnionType(builder:flatbuffers.Builder, testUnionType:ABC):void { + builder.addFieldInt32(0, testUnionType, ABC.NONE); +} + +static addTestUnion(builder:flatbuffers.Builder, testUnionOffset:flatbuffers.Offset):void { + builder.addFieldOffset(1, testUnionOffset, 0); +} + +static addTestVectorOfUnionType(builder:flatbuffers.Builder, testVectorOfUnionTypeOffset:flatbuffers.Offset):void { + builder.addFieldOffset(2, testVectorOfUnionTypeOffset, 0); +} + +static createTestVectorOfUnionTypeVector(builder:flatbuffers.Builder, data:ABC[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt32(data[i]!); } + return builder.endVector(); +} - static getRootAsD(bb: flatbuffers.ByteBuffer, obj?: D): D { - return (obj || new D()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); +static startTestVectorOfUnionTypeVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} + +static addTestVectorOfUnion(builder:flatbuffers.Builder, testVectorOfUnionOffset:flatbuffers.Offset):void { + builder.addFieldOffset(3, testVectorOfUnionOffset, 0); +} + +static createTestVectorOfUnionVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); } + return builder.endVector(); +} - static getSizePrefixedRootAsD(bb: flatbuffers.ByteBuffer, obj?: D): D { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new D()).__init( - bb.readInt32(bb.position()) + bb.position(), - bb, - ); - } +static startTestVectorOfUnionVector(builder:flatbuffers.Builder, numElems:number):void { + builder.startVector(4, numElems, 4); +} - testUnionType(): ABC { - const offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? this.bb!.readInt32(this.bb_pos + offset) : ABC.NONE; - } +static endD(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} - testUnion(obj: any): any | null { - const offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null; - } +static createD(builder:flatbuffers.Builder, testUnionType:ABC, testUnionOffset:flatbuffers.Offset, testVectorOfUnionTypeOffset:flatbuffers.Offset, testVectorOfUnionOffset:flatbuffers.Offset):flatbuffers.Offset { + D.startD(builder); + D.addTestUnionType(builder, testUnionType); + D.addTestUnion(builder, testUnionOffset); + D.addTestVectorOfUnionType(builder, testVectorOfUnionTypeOffset); + D.addTestVectorOfUnion(builder, testVectorOfUnionOffset); + return D.endD(builder); +} - testVectorOfUnionType(index: number): ABC | null { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset - ? this.bb!.readInt32(this.bb!.__vector(this.bb_pos + offset) + index * 4) - : null; - } - - testVectorOfUnionTypeLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - testVectorOfUnionTypeArray(): Int32Array | null { - const offset = this.bb!.__offset(this.bb_pos, 8); - return offset - ? new Int32Array( - this.bb!.bytes().buffer, - this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), - this.bb!.__vector_len(this.bb_pos + offset), - ) - : null; - } - - testVectorOfUnion(index: number, obj: any): any | null { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset - ? this.bb!.__union( - obj, - this.bb!.__vector(this.bb_pos + offset) + index * 4, - ) - : null; - } - - testVectorOfUnionLength(): number { - const offset = this.bb!.__offset(this.bb_pos, 10); - return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; - } - - static getFullyQualifiedName(): string { - return 'UnionUnderlyingType.D'; - } - - static startD(builder: flatbuffers.Builder) { - builder.startObject(4); - } - - static addTestUnionType(builder: flatbuffers.Builder, testUnionType: ABC) { - builder.addFieldInt32(0, testUnionType, ABC.NONE); - } - - static addTestUnion( - builder: flatbuffers.Builder, - testUnionOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(1, testUnionOffset, 0); - } - - static addTestVectorOfUnionType( - builder: flatbuffers.Builder, - testVectorOfUnionTypeOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(2, testVectorOfUnionTypeOffset, 0); - } - - static createTestVectorOfUnionTypeVector( - builder: flatbuffers.Builder, - data: ABC[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]!); - } - return builder.endVector(); - } - - static startTestVectorOfUnionTypeVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } - - static addTestVectorOfUnion( - builder: flatbuffers.Builder, - testVectorOfUnionOffset: flatbuffers.Offset, - ) { - builder.addFieldOffset(3, testVectorOfUnionOffset, 0); - } - - static createTestVectorOfUnionVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]!); - } - return builder.endVector(); - } - - static startTestVectorOfUnionVector( - builder: flatbuffers.Builder, - numElems: number, - ) { - builder.startVector(4, numElems, 4); - } - - static endD(builder: flatbuffers.Builder): flatbuffers.Offset { - const offset = builder.endObject(); - return offset; - } - - static createD( - builder: flatbuffers.Builder, - testUnionType: ABC, - testUnionOffset: flatbuffers.Offset, - testVectorOfUnionTypeOffset: flatbuffers.Offset, - testVectorOfUnionOffset: flatbuffers.Offset, - ): flatbuffers.Offset { - D.startD(builder); - D.addTestUnionType(builder, testUnionType); - D.addTestUnion(builder, testUnionOffset); - D.addTestVectorOfUnionType(builder, testVectorOfUnionTypeOffset); - D.addTestVectorOfUnion(builder, testVectorOfUnionOffset); - return D.endD(builder); - } - - unpack(): DT { - return new DT( - this.testUnionType(), - (() => { - const temp = unionToAbc( - this.testUnionType(), - this.testUnion.bind(this), - ); - if (temp === null) { - return null; - } - return temp.unpack(); - })(), - this.bb!.createScalarList( - this.testVectorOfUnionType.bind(this), - this.testVectorOfUnionTypeLength(), - ), - (() => { - const ret: (AT | BT | CT)[] = []; - for ( - let targetEnumIndex = 0; - targetEnumIndex < this.testVectorOfUnionTypeLength(); - ++targetEnumIndex - ) { - const targetEnum = this.testVectorOfUnionType(targetEnumIndex); - if (targetEnum === null || ABC[targetEnum!] === 'NONE') { - continue; - } - - const temp = unionListToAbc( - targetEnum, - this.testVectorOfUnion.bind(this), - targetEnumIndex, - ); - if (temp === null) { - continue; - } - ret.push(temp.unpack()); - } - return ret; - })(), - ); - } - - unpackTo(_o: DT): void { - _o.testUnionType = this.testUnionType(); - _o.testUnion = (() => { +unpack(): DT { + return new DT( + this.testUnionType(), + (() => { const temp = unionToAbc(this.testUnionType(), this.testUnion.bind(this)); - if (temp === null) { - return null; - } - return temp.unpack(); - })(); - _o.testVectorOfUnionType = this.bb!.createScalarList( - this.testVectorOfUnionType.bind(this), - this.testVectorOfUnionTypeLength(), - ); - _o.testVectorOfUnion = (() => { - const ret: (AT | BT | CT)[] = []; - for ( - let targetEnumIndex = 0; - targetEnumIndex < this.testVectorOfUnionTypeLength(); - ++targetEnumIndex - ) { - const targetEnum = this.testVectorOfUnionType(targetEnumIndex); - if (targetEnum === null || ABC[targetEnum!] === 'NONE') { - continue; - } + if(temp === null) { return null; } + return temp.unpack() + })(), + this.bb!.createScalarList(this.testVectorOfUnionType.bind(this), this.testVectorOfUnionTypeLength()), + (() => { + const ret: (AT|BT|CT)[] = []; + for(let targetEnumIndex = 0; targetEnumIndex < this.testVectorOfUnionTypeLength(); ++targetEnumIndex) { + const targetEnum = this.testVectorOfUnionType(targetEnumIndex); + if(targetEnum === null || ABC[targetEnum!] === 'NONE') { continue; } - const temp = unionListToAbc( - targetEnum, - this.testVectorOfUnion.bind(this), - targetEnumIndex, - ); - if (temp === null) { - continue; - } - ret.push(temp.unpack()); - } - return ret; - })(); - } + const temp = unionListToAbc(targetEnum, this.testVectorOfUnion.bind(this), targetEnumIndex); + if(temp === null) { continue; } + ret.push(temp.unpack()); + } + return ret; + })() + ); +} + + +unpackTo(_o: DT): void { + _o.testUnionType = this.testUnionType(); + _o.testUnion = (() => { + const temp = unionToAbc(this.testUnionType(), this.testUnion.bind(this)); + if(temp === null) { return null; } + return temp.unpack() + })(); + _o.testVectorOfUnionType = this.bb!.createScalarList(this.testVectorOfUnionType.bind(this), this.testVectorOfUnionTypeLength()); + _o.testVectorOfUnion = (() => { + const ret: (AT|BT|CT)[] = []; + for(let targetEnumIndex = 0; targetEnumIndex < this.testVectorOfUnionTypeLength(); ++targetEnumIndex) { + const targetEnum = this.testVectorOfUnionType(targetEnumIndex); + if(targetEnum === null || ABC[targetEnum!] === 'NONE') { continue; } + + const temp = unionListToAbc(targetEnum, this.testVectorOfUnion.bind(this), targetEnumIndex); + if(temp === null) { continue; } + ret.push(temp.unpack()); + } + return ret; + })(); +} } export class DT implements flatbuffers.IGeneratedObject { - constructor( - public testUnionType: ABC = ABC.NONE, - public testUnion: AT | BT | CT | null = null, - public testVectorOfUnionType: ABC[] = [], - public testVectorOfUnion: (AT | BT | CT)[] = [], - ) {} +constructor( + public testUnionType: ABC = ABC.NONE, + public testUnion: AT|BT|CT|null = null, + public testVectorOfUnionType: (ABC)[] = [], + public testVectorOfUnion: (AT|BT|CT)[] = [] +){} - pack(builder: flatbuffers.Builder): flatbuffers.Offset { - const testUnion = builder.createObjectOffset(this.testUnion); - const testVectorOfUnionType = D.createTestVectorOfUnionTypeVector( - builder, - this.testVectorOfUnionType, - ); - const testVectorOfUnion = D.createTestVectorOfUnionVector( - builder, - builder.createObjectOffsetList(this.testVectorOfUnion), - ); - return D.createD( - builder, - this.testUnionType, - testUnion, - testVectorOfUnionType, - testVectorOfUnion, - ); - } +pack(builder:flatbuffers.Builder): flatbuffers.Offset { + const testUnion = builder.createObjectOffset(this.testUnion); + const testVectorOfUnionType = D.createTestVectorOfUnionTypeVector(builder, this.testVectorOfUnionType); + const testVectorOfUnion = D.createTestVectorOfUnionVector(builder, builder.createObjectOffsetList(this.testVectorOfUnion)); + + return D.createD(builder, + this.testUnionType, + testUnion, + testVectorOfUnionType, + testVectorOfUnion + ); +} } diff --git a/tests/ts/union_underlying_type_test.js b/tests/ts/union_underlying_type_test.js index 6577c0b24..d4649b336 100644 --- a/tests/ts/union_underlying_type_test.js +++ b/tests/ts/union_underlying_type_test.js @@ -1,4 +1,3 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ export * as UnionUnderlyingType from './union-underlying-type.js'; diff --git a/tests/ts/union_vector/attacker.d.ts b/tests/ts/union_vector/attacker.d.ts index 893083329..01fd2c141 100644 --- a/tests/ts/union_vector/attacker.d.ts +++ b/tests/ts/union_vector/attacker.d.ts @@ -1,36 +1,22 @@ import * as flatbuffers from 'flatbuffers'; -export declare class Attacker - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Attacker; - static getRootAsAttacker( - bb: flatbuffers.ByteBuffer, - obj?: Attacker, - ): Attacker; - static getSizePrefixedRootAsAttacker( - bb: flatbuffers.ByteBuffer, - obj?: Attacker, - ): Attacker; - swordAttackDamage(): number; - mutate_sword_attack_damage(value: number): boolean; - static getFullyQualifiedName(): string; - static startAttacker(builder: flatbuffers.Builder): void; - static addSwordAttackDamage( - builder: flatbuffers.Builder, - swordAttackDamage: number, - ): void; - static endAttacker(builder: flatbuffers.Builder): flatbuffers.Offset; - static createAttacker( - builder: flatbuffers.Builder, - swordAttackDamage: number, - ): flatbuffers.Offset; - unpack(): AttackerT; - unpackTo(_o: AttackerT): void; +export declare class Attacker implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Attacker; + static getRootAsAttacker(bb: flatbuffers.ByteBuffer, obj?: Attacker): Attacker; + static getSizePrefixedRootAsAttacker(bb: flatbuffers.ByteBuffer, obj?: Attacker): Attacker; + swordAttackDamage(): number; + mutate_sword_attack_damage(value: number): boolean; + static getFullyQualifiedName(): "Attacker"; + static startAttacker(builder: flatbuffers.Builder): void; + static addSwordAttackDamage(builder: flatbuffers.Builder, swordAttackDamage: number): void; + static endAttacker(builder: flatbuffers.Builder): flatbuffers.Offset; + static createAttacker(builder: flatbuffers.Builder, swordAttackDamage: number): flatbuffers.Offset; + unpack(): AttackerT; + unpackTo(_o: AttackerT): void; } export declare class AttackerT implements flatbuffers.IGeneratedObject { - swordAttackDamage: number; - constructor(swordAttackDamage?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + swordAttackDamage: number; + constructor(swordAttackDamage?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union_vector/attacker.js b/tests/ts/union_vector/attacker.js index 1e72815f0..28ffc4a77 100644 --- a/tests/ts/union_vector/attacker.js +++ b/tests/ts/union_vector/attacker.js @@ -1,68 +1,65 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class Attacker { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsAttacker(bb, obj) { - return (obj || new Attacker()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsAttacker(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Attacker()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - swordAttackDamage() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_sword_attack_damage(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsAttacker(bb, obj) { + return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsAttacker(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Attacker()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + swordAttackDamage() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_sword_attack_damage(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'Attacker'; + } + static startAttacker(builder) { + builder.startObject(1); + } + static addSwordAttackDamage(builder, swordAttackDamage) { + builder.addFieldInt32(0, swordAttackDamage, 0); + } + static endAttacker(builder) { + const offset = builder.endObject(); + return offset; + } + static createAttacker(builder, swordAttackDamage) { + Attacker.startAttacker(builder); + Attacker.addSwordAttackDamage(builder, swordAttackDamage); + return Attacker.endAttacker(builder); + } + unpack() { + return new AttackerT(this.swordAttackDamage()); + } + unpackTo(_o) { + _o.swordAttackDamage = this.swordAttackDamage(); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'Attacker'; - } - static startAttacker(builder) { - builder.startObject(1); - } - static addSwordAttackDamage(builder, swordAttackDamage) { - builder.addFieldInt32(0, swordAttackDamage, 0); - } - static endAttacker(builder) { - const offset = builder.endObject(); - return offset; - } - static createAttacker(builder, swordAttackDamage) { - Attacker.startAttacker(builder); - Attacker.addSwordAttackDamage(builder, swordAttackDamage); - return Attacker.endAttacker(builder); - } - unpack() { - return new AttackerT(this.swordAttackDamage()); - } - unpackTo(_o) { - _o.swordAttackDamage = this.swordAttackDamage(); - } } export class AttackerT { - constructor(swordAttackDamage = 0) { - this.swordAttackDamage = swordAttackDamage; - } - pack(builder) { - return Attacker.createAttacker(builder, this.swordAttackDamage); - } + constructor(swordAttackDamage = 0) { + this.swordAttackDamage = swordAttackDamage; + } + pack(builder) { + return Attacker.createAttacker(builder, this.swordAttackDamage); + } } diff --git a/tests/ts/union_vector/attacker.ts b/tests/ts/union_vector/attacker.ts index aecd4152a..05d766be2 100644 --- a/tests/ts/union_vector/attacker.ts +++ b/tests/ts/union_vector/attacker.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class Attacker implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Attacker { this.bb_pos = i; this.bb = bb; @@ -44,11 +44,11 @@ static getFullyQualifiedName(): "Attacker" { return 'Attacker'; } -static startAttacker(builder:flatbuffers.Builder) { +static startAttacker(builder:flatbuffers.Builder):void { builder.startObject(1); } -static addSwordAttackDamage(builder:flatbuffers.Builder, swordAttackDamage:number) { +static addSwordAttackDamage(builder:flatbuffers.Builder, swordAttackDamage:number):void { builder.addFieldInt32(0, swordAttackDamage, 0); } diff --git a/tests/ts/union_vector/book-reader.d.ts b/tests/ts/union_vector/book-reader.d.ts index dd14e1f3b..95bbe30b7 100644 --- a/tests/ts/union_vector/book-reader.d.ts +++ b/tests/ts/union_vector/book-reader.d.ts @@ -1,23 +1,18 @@ import * as flatbuffers from 'flatbuffers'; -export declare class BookReader - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): BookReader; - booksRead(): number; - mutate_books_read(value: number): boolean; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createBookReader( - builder: flatbuffers.Builder, - books_read: number, - ): flatbuffers.Offset; - unpack(): BookReaderT; - unpackTo(_o: BookReaderT): void; +export declare class BookReader implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): BookReader; + booksRead(): number; + mutate_books_read(value: number): boolean; + static getFullyQualifiedName(): "BookReader"; + static sizeOf(): number; + static createBookReader(builder: flatbuffers.Builder, books_read: number): flatbuffers.Offset; + unpack(): BookReaderT; + unpackTo(_o: BookReaderT): void; } export declare class BookReaderT implements flatbuffers.IGeneratedObject { - booksRead: number; - constructor(booksRead?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + booksRead: number; + constructor(booksRead?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union_vector/book-reader.js b/tests/ts/union_vector/book-reader.js index 94482438e..0d9e1a57c 100644 --- a/tests/ts/union_vector/book-reader.js +++ b/tests/ts/union_vector/book-reader.js @@ -1,44 +1,44 @@ // automatically generated by the FlatBuffers compiler, do not modify export class BookReader { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - booksRead() { - return this.bb.readInt32(this.bb_pos); - } - mutate_books_read(value) { - this.bb.writeInt32(this.bb_pos + 0, value); - return true; - } - static getFullyQualifiedName() { - return 'BookReader'; - } - static sizeOf() { - return 4; - } - static createBookReader(builder, books_read) { - builder.prep(4, 4); - builder.writeInt32(books_read); - return builder.offset(); - } - unpack() { - return new BookReaderT(this.booksRead()); - } - unpackTo(_o) { - _o.booksRead = this.booksRead(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + booksRead() { + return this.bb.readInt32(this.bb_pos); + } + mutate_books_read(value) { + this.bb.writeInt32(this.bb_pos + 0, value); + return true; + } + static getFullyQualifiedName() { + return 'BookReader'; + } + static sizeOf() { + return 4; + } + static createBookReader(builder, books_read) { + builder.prep(4, 4); + builder.writeInt32(books_read); + return builder.offset(); + } + unpack() { + return new BookReaderT(this.booksRead()); + } + unpackTo(_o) { + _o.booksRead = this.booksRead(); + } } export class BookReaderT { - constructor(booksRead = 0) { - this.booksRead = booksRead; - } - pack(builder) { - return BookReader.createBookReader(builder, this.booksRead); - } + constructor(booksRead = 0) { + this.booksRead = booksRead; + } + pack(builder) { + return BookReader.createBookReader(builder, this.booksRead); + } } diff --git a/tests/ts/union_vector/book-reader.ts b/tests/ts/union_vector/book-reader.ts index 0fbb4c894..fcbccc36f 100644 --- a/tests/ts/union_vector/book-reader.ts +++ b/tests/ts/union_vector/book-reader.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class BookReader implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):BookReader { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/union_vector/character.d.ts b/tests/ts/union_vector/character.d.ts index 3b644bb94..dbdb4d960 100644 --- a/tests/ts/union_vector/character.d.ts +++ b/tests/ts/union_vector/character.d.ts @@ -1,26 +1,14 @@ -import {Attacker} from './attacker.js'; -import {BookReader} from './book-reader.js'; -import {Rapunzel} from './rapunzel.js'; +import { Attacker } from './attacker.js'; +import { BookReader } from './book-reader.js'; +import { Rapunzel } from './rapunzel.js'; export declare enum Character { - NONE = 0, - MuLan = 1, - Rapunzel = 2, - Belle = 3, - BookFan = 4, - Other = 5, - Unused = 6, + NONE = 0, + MuLan = 1, + Rapunzel = 2, + Belle = 3, + BookFan = 4, + Other = 5, + Unused = 6 } -export declare function unionToCharacter( - type: Character, - accessor: ( - obj: Attacker | BookReader | Rapunzel | string, - ) => Attacker | BookReader | Rapunzel | string | null, -): Attacker | BookReader | Rapunzel | string | null; -export declare function unionListToCharacter( - type: Character, - accessor: ( - index: number, - obj: Attacker | BookReader | Rapunzel | string, - ) => Attacker | BookReader | Rapunzel | string | null, - index: number, -): Attacker | BookReader | Rapunzel | string | null; +export declare function unionToCharacter(type: Character, accessor: (obj: Attacker | BookReader | Rapunzel | string) => Attacker | BookReader | Rapunzel | string | null): Attacker | BookReader | Rapunzel | string | null; +export declare function unionListToCharacter(type: Character, accessor: (index: number, obj: Attacker | BookReader | Rapunzel | string) => Attacker | BookReader | Rapunzel | string | null, index: number): Attacker | BookReader | Rapunzel | string | null; diff --git a/tests/ts/union_vector/character.js b/tests/ts/union_vector/character.js index b3c64421d..dfa7a1914 100644 --- a/tests/ts/union_vector/character.js +++ b/tests/ts/union_vector/character.js @@ -1,56 +1,39 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -import {Attacker} from './attacker.js'; -import {BookReader} from './book-reader.js'; -import {Rapunzel} from './rapunzel.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import { Attacker } from './attacker.js'; +import { BookReader } from './book-reader.js'; +import { Rapunzel } from './rapunzel.js'; export var Character; -(function(Character) { -Character[Character['NONE'] = 0] = 'NONE'; -Character[Character['MuLan'] = 1] = 'MuLan'; -Character[Character['Rapunzel'] = 2] = 'Rapunzel'; -Character[Character['Belle'] = 3] = 'Belle'; -Character[Character['BookFan'] = 4] = 'BookFan'; -Character[Character['Other'] = 5] = 'Other'; -Character[Character['Unused'] = 6] = 'Unused'; +(function (Character) { + Character[Character["NONE"] = 0] = "NONE"; + Character[Character["MuLan"] = 1] = "MuLan"; + Character[Character["Rapunzel"] = 2] = "Rapunzel"; + Character[Character["Belle"] = 3] = "Belle"; + Character[Character["BookFan"] = 4] = "BookFan"; + Character[Character["Other"] = 5] = "Other"; + Character[Character["Unused"] = 6] = "Unused"; })(Character || (Character = {})); export function unionToCharacter(type, accessor) { - switch (Character[type]) { - case 'NONE': - return null; - case 'MuLan': - return accessor(new Attacker()); - case 'Rapunzel': - return accessor(new Rapunzel()); - case 'Belle': - return accessor(new BookReader()); - case 'BookFan': - return accessor(new BookReader()); - case 'Other': - return accessor(''); - case 'Unused': - return accessor(''); - default: - return null; - } + switch (Character[type]) { + case 'NONE': return null; + case 'MuLan': return accessor(new Attacker()); + case 'Rapunzel': return accessor(new Rapunzel()); + case 'Belle': return accessor(new BookReader()); + case 'BookFan': return accessor(new BookReader()); + case 'Other': return accessor(''); + case 'Unused': return accessor(''); + default: return null; + } } export function unionListToCharacter(type, accessor, index) { - switch (Character[type]) { - case 'NONE': - return null; - case 'MuLan': - return accessor(index, new Attacker()); - case 'Rapunzel': - return accessor(index, new Rapunzel()); - case 'Belle': - return accessor(index, new BookReader()); - case 'BookFan': - return accessor(index, new BookReader()); - case 'Other': - return accessor(index, ''); - case 'Unused': - return accessor(index, ''); - default: - return null; - } + switch (Character[type]) { + case 'NONE': return null; + case 'MuLan': return accessor(index, new Attacker()); + case 'Rapunzel': return accessor(index, new Rapunzel()); + case 'Belle': return accessor(index, new BookReader()); + case 'BookFan': return accessor(index, new BookReader()); + case 'Other': return accessor(index, ''); + case 'Unused': return accessor(index, ''); + default: return null; + } } diff --git a/tests/ts/union_vector/falling-tub.d.ts b/tests/ts/union_vector/falling-tub.d.ts index dc773ec54..4346f8c81 100644 --- a/tests/ts/union_vector/falling-tub.d.ts +++ b/tests/ts/union_vector/falling-tub.d.ts @@ -1,23 +1,18 @@ import * as flatbuffers from 'flatbuffers'; -export declare class FallingTub - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): FallingTub; - weight(): number; - mutate_weight(value: number): boolean; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createFallingTub( - builder: flatbuffers.Builder, - weight: number, - ): flatbuffers.Offset; - unpack(): FallingTubT; - unpackTo(_o: FallingTubT): void; +export declare class FallingTub implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): FallingTub; + weight(): number; + mutate_weight(value: number): boolean; + static getFullyQualifiedName(): "FallingTub"; + static sizeOf(): number; + static createFallingTub(builder: flatbuffers.Builder, weight: number): flatbuffers.Offset; + unpack(): FallingTubT; + unpackTo(_o: FallingTubT): void; } export declare class FallingTubT implements flatbuffers.IGeneratedObject { - weight: number; - constructor(weight?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + weight: number; + constructor(weight?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union_vector/falling-tub.js b/tests/ts/union_vector/falling-tub.js index 407055aa8..d3c4dfe05 100644 --- a/tests/ts/union_vector/falling-tub.js +++ b/tests/ts/union_vector/falling-tub.js @@ -1,44 +1,44 @@ // automatically generated by the FlatBuffers compiler, do not modify export class FallingTub { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - weight() { - return this.bb.readInt32(this.bb_pos); - } - mutate_weight(value) { - this.bb.writeInt32(this.bb_pos + 0, value); - return true; - } - static getFullyQualifiedName() { - return 'FallingTub'; - } - static sizeOf() { - return 4; - } - static createFallingTub(builder, weight) { - builder.prep(4, 4); - builder.writeInt32(weight); - return builder.offset(); - } - unpack() { - return new FallingTubT(this.weight()); - } - unpackTo(_o) { - _o.weight = this.weight(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + weight() { + return this.bb.readInt32(this.bb_pos); + } + mutate_weight(value) { + this.bb.writeInt32(this.bb_pos + 0, value); + return true; + } + static getFullyQualifiedName() { + return 'FallingTub'; + } + static sizeOf() { + return 4; + } + static createFallingTub(builder, weight) { + builder.prep(4, 4); + builder.writeInt32(weight); + return builder.offset(); + } + unpack() { + return new FallingTubT(this.weight()); + } + unpackTo(_o) { + _o.weight = this.weight(); + } } export class FallingTubT { - constructor(weight = 0) { - this.weight = weight; - } - pack(builder) { - return FallingTub.createFallingTub(builder, this.weight); - } + constructor(weight = 0) { + this.weight = weight; + } + pack(builder) { + return FallingTub.createFallingTub(builder, this.weight); + } } diff --git a/tests/ts/union_vector/falling-tub.ts b/tests/ts/union_vector/falling-tub.ts index 999a87ea0..b01d3401a 100644 --- a/tests/ts/union_vector/falling-tub.ts +++ b/tests/ts/union_vector/falling-tub.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class FallingTub implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):FallingTub { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/union_vector/gadget.d.ts b/tests/ts/union_vector/gadget.d.ts index b0f018dd7..46eaa5e7c 100644 --- a/tests/ts/union_vector/gadget.d.ts +++ b/tests/ts/union_vector/gadget.d.ts @@ -1,19 +1,9 @@ -import {FallingTub} from './falling-tub.js'; -import {HandFan} from './hand-fan.js'; +import { FallingTub } from './falling-tub.js'; +import { HandFan } from './hand-fan.js'; export declare enum Gadget { - NONE = 0, - FallingTub = 1, - HandFan = 2, + NONE = 0, + FallingTub = 1, + HandFan = 2 } -export declare function unionToGadget( - type: Gadget, - accessor: (obj: FallingTub | HandFan) => FallingTub | HandFan | null, -): FallingTub | HandFan | null; -export declare function unionListToGadget( - type: Gadget, - accessor: ( - index: number, - obj: FallingTub | HandFan, - ) => FallingTub | HandFan | null, - index: number, -): FallingTub | HandFan | null; +export declare function unionToGadget(type: Gadget, accessor: (obj: FallingTub | HandFan) => FallingTub | HandFan | null): FallingTub | HandFan | null; +export declare function unionListToGadget(type: Gadget, accessor: (index: number, obj: FallingTub | HandFan) => FallingTub | HandFan | null, index: number): FallingTub | HandFan | null; diff --git a/tests/ts/union_vector/gadget.js b/tests/ts/union_vector/gadget.js index 46b8ea700..1618ccce0 100644 --- a/tests/ts/union_vector/gadget.js +++ b/tests/ts/union_vector/gadget.js @@ -1,35 +1,26 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -import {FallingTub} from './falling-tub.js'; -import {HandFan} from './hand-fan.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +import { FallingTub } from './falling-tub.js'; +import { HandFan } from './hand-fan.js'; export var Gadget; -(function(Gadget) { -Gadget[Gadget['NONE'] = 0] = 'NONE'; -Gadget[Gadget['FallingTub'] = 1] = 'FallingTub'; -Gadget[Gadget['HandFan'] = 2] = 'HandFan'; +(function (Gadget) { + Gadget[Gadget["NONE"] = 0] = "NONE"; + Gadget[Gadget["FallingTub"] = 1] = "FallingTub"; + Gadget[Gadget["HandFan"] = 2] = "HandFan"; })(Gadget || (Gadget = {})); export function unionToGadget(type, accessor) { - switch (Gadget[type]) { - case 'NONE': - return null; - case 'FallingTub': - return accessor(new FallingTub()); - case 'HandFan': - return accessor(new HandFan()); - default: - return null; - } + switch (Gadget[type]) { + case 'NONE': return null; + case 'FallingTub': return accessor(new FallingTub()); + case 'HandFan': return accessor(new HandFan()); + default: return null; + } } export function unionListToGadget(type, accessor, index) { - switch (Gadget[type]) { - case 'NONE': - return null; - case 'FallingTub': - return accessor(index, new FallingTub()); - case 'HandFan': - return accessor(index, new HandFan()); - default: - return null; - } + switch (Gadget[type]) { + case 'NONE': return null; + case 'FallingTub': return accessor(index, new FallingTub()); + case 'HandFan': return accessor(index, new HandFan()); + default: return null; + } } diff --git a/tests/ts/union_vector/hand-fan.d.ts b/tests/ts/union_vector/hand-fan.d.ts index 7a815b4a5..0e54e72ec 100644 --- a/tests/ts/union_vector/hand-fan.d.ts +++ b/tests/ts/union_vector/hand-fan.d.ts @@ -1,30 +1,22 @@ import * as flatbuffers from 'flatbuffers'; -export declare class HandFan - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): HandFan; - static getRootAsHandFan(bb: flatbuffers.ByteBuffer, obj?: HandFan): HandFan; - static getSizePrefixedRootAsHandFan( - bb: flatbuffers.ByteBuffer, - obj?: HandFan, - ): HandFan; - length(): number; - mutate_length(value: number): boolean; - static getFullyQualifiedName(): string; - static startHandFan(builder: flatbuffers.Builder): void; - static addLength(builder: flatbuffers.Builder, length: number): void; - static endHandFan(builder: flatbuffers.Builder): flatbuffers.Offset; - static createHandFan( - builder: flatbuffers.Builder, - length: number, - ): flatbuffers.Offset; - unpack(): HandFanT; - unpackTo(_o: HandFanT): void; +export declare class HandFan implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): HandFan; + static getRootAsHandFan(bb: flatbuffers.ByteBuffer, obj?: HandFan): HandFan; + static getSizePrefixedRootAsHandFan(bb: flatbuffers.ByteBuffer, obj?: HandFan): HandFan; + length(): number; + mutate_length(value: number): boolean; + static getFullyQualifiedName(): "HandFan"; + static startHandFan(builder: flatbuffers.Builder): void; + static addLength(builder: flatbuffers.Builder, length: number): void; + static endHandFan(builder: flatbuffers.Builder): flatbuffers.Offset; + static createHandFan(builder: flatbuffers.Builder, length: number): flatbuffers.Offset; + unpack(): HandFanT; + unpackTo(_o: HandFanT): void; } export declare class HandFanT implements flatbuffers.IGeneratedObject { - length: number; - constructor(length?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + length: number; + constructor(length?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union_vector/hand-fan.js b/tests/ts/union_vector/hand-fan.js index d1b04e537..b85b6d38c 100644 --- a/tests/ts/union_vector/hand-fan.js +++ b/tests/ts/union_vector/hand-fan.js @@ -1,68 +1,65 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; export class HandFan { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsHandFan(bb, obj) { - return (obj || new HandFan()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsHandFan(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new HandFan()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - length() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; - } - mutate_length(value) { - const offset = this.bb.__offset(this.bb_pos, 4); - if (offset === 0) { - return false; + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + static getRootAsHandFan(bb, obj) { + return (obj || new HandFan()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsHandFan(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new HandFan()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + length() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readInt32(this.bb_pos + offset) : 0; + } + mutate_length(value) { + const offset = this.bb.__offset(this.bb_pos, 4); + if (offset === 0) { + return false; + } + this.bb.writeInt32(this.bb_pos + offset, value); + return true; + } + static getFullyQualifiedName() { + return 'HandFan'; + } + static startHandFan(builder) { + builder.startObject(1); + } + static addLength(builder, length) { + builder.addFieldInt32(0, length, 0); + } + static endHandFan(builder) { + const offset = builder.endObject(); + return offset; + } + static createHandFan(builder, length) { + HandFan.startHandFan(builder); + HandFan.addLength(builder, length); + return HandFan.endHandFan(builder); + } + unpack() { + return new HandFanT(this.length()); + } + unpackTo(_o) { + _o.length = this.length(); } - this.bb.writeInt32(this.bb_pos + offset, value); - return true; - } - static getFullyQualifiedName() { - return 'HandFan'; - } - static startHandFan(builder) { - builder.startObject(1); - } - static addLength(builder, length) { - builder.addFieldInt32(0, length, 0); - } - static endHandFan(builder) { - const offset = builder.endObject(); - return offset; - } - static createHandFan(builder, length) { - HandFan.startHandFan(builder); - HandFan.addLength(builder, length); - return HandFan.endHandFan(builder); - } - unpack() { - return new HandFanT(this.length()); - } - unpackTo(_o) { - _o.length = this.length(); - } } export class HandFanT { - constructor(length = 0) { - this.length = length; - } - pack(builder) { - return HandFan.createHandFan(builder, this.length); - } + constructor(length = 0) { + this.length = length; + } + pack(builder) { + return HandFan.createHandFan(builder, this.length); + } } diff --git a/tests/ts/union_vector/hand-fan.ts b/tests/ts/union_vector/hand-fan.ts index ca0d2e702..9393fa299 100644 --- a/tests/ts/union_vector/hand-fan.ts +++ b/tests/ts/union_vector/hand-fan.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class HandFan implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):HandFan { this.bb_pos = i; this.bb = bb; @@ -44,11 +44,11 @@ static getFullyQualifiedName(): "HandFan" { return 'HandFan'; } -static startHandFan(builder:flatbuffers.Builder) { +static startHandFan(builder:flatbuffers.Builder):void { builder.startObject(1); } -static addLength(builder:flatbuffers.Builder, length:number) { +static addLength(builder:flatbuffers.Builder, length:number):void { builder.addFieldInt32(0, length, 0); } diff --git a/tests/ts/union_vector/movie.d.ts b/tests/ts/union_vector/movie.d.ts index a28d0cecc..83327e325 100644 --- a/tests/ts/union_vector/movie.d.ts +++ b/tests/ts/union_vector/movie.d.ts @@ -1,90 +1,44 @@ import * as flatbuffers from 'flatbuffers'; -import {AttackerT} from './attacker.js'; -import {BookReaderT} from './book-reader.js'; -import {Character} from './character.js'; -import {RapunzelT} from './rapunzel.js'; +import { AttackerT } from './attacker.js'; +import { BookReaderT } from './book-reader.js'; +import { Character } from './character.js'; +import { RapunzelT } from './rapunzel.js'; export declare class Movie implements flatbuffers.IUnpackableObject { - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Movie; - static getRootAsMovie(bb: flatbuffers.ByteBuffer, obj?: Movie): Movie; - static getSizePrefixedRootAsMovie( - bb: flatbuffers.ByteBuffer, - obj?: Movie, - ): Movie; - static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; - mainCharacterType(): Character; - mainCharacter( - obj: any | string, - ): any | string | null; - charactersType(index: number): Character | null; - charactersTypeLength(): number; - charactersTypeArray(): Uint8Array | null; - characters(index: number, obj: any | string): any | string | null; - charactersLength(): number; - static getFullyQualifiedName(): string; - static startMovie(builder: flatbuffers.Builder): void; - static addMainCharacterType( - builder: flatbuffers.Builder, - mainCharacterType: Character, - ): void; - static addMainCharacter( - builder: flatbuffers.Builder, - mainCharacterOffset: flatbuffers.Offset, - ): void; - static addCharactersType( - builder: flatbuffers.Builder, - charactersTypeOffset: flatbuffers.Offset, - ): void; - static createCharactersTypeVector( - builder: flatbuffers.Builder, - data: Character[], - ): flatbuffers.Offset; - static startCharactersTypeVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static addCharacters( - builder: flatbuffers.Builder, - charactersOffset: flatbuffers.Offset, - ): void; - static createCharactersVector( - builder: flatbuffers.Builder, - data: flatbuffers.Offset[], - ): flatbuffers.Offset; - static startCharactersVector( - builder: flatbuffers.Builder, - numElems: number, - ): void; - static endMovie(builder: flatbuffers.Builder): flatbuffers.Offset; - static finishMovieBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static finishSizePrefixedMovieBuffer( - builder: flatbuffers.Builder, - offset: flatbuffers.Offset, - ): void; - static createMovie( - builder: flatbuffers.Builder, - mainCharacterType: Character, - mainCharacterOffset: flatbuffers.Offset, - charactersTypeOffset: flatbuffers.Offset, - charactersOffset: flatbuffers.Offset, - ): flatbuffers.Offset; - unpack(): MovieT; - unpackTo(_o: MovieT): void; + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Movie; + static getRootAsMovie(bb: flatbuffers.ByteBuffer, obj?: Movie): Movie; + static getSizePrefixedRootAsMovie(bb: flatbuffers.ByteBuffer, obj?: Movie): Movie; + static bufferHasIdentifier(bb: flatbuffers.ByteBuffer): boolean; + mainCharacterType(): Character; + mainCharacter(obj: any | string): any | string | null; + charactersType(index: number): Character | null; + charactersTypeLength(): number; + charactersTypeArray(): Uint8Array | null; + characters(index: number, obj: any | string): any | string | null; + charactersLength(): number; + static getFullyQualifiedName(): "Movie"; + static startMovie(builder: flatbuffers.Builder): void; + static addMainCharacterType(builder: flatbuffers.Builder, mainCharacterType: Character): void; + static addMainCharacter(builder: flatbuffers.Builder, mainCharacterOffset: flatbuffers.Offset): void; + static addCharactersType(builder: flatbuffers.Builder, charactersTypeOffset: flatbuffers.Offset): void; + static createCharactersTypeVector(builder: flatbuffers.Builder, data: Character[]): flatbuffers.Offset; + static startCharactersTypeVector(builder: flatbuffers.Builder, numElems: number): void; + static addCharacters(builder: flatbuffers.Builder, charactersOffset: flatbuffers.Offset): void; + static createCharactersVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset; + static startCharactersVector(builder: flatbuffers.Builder, numElems: number): void; + static endMovie(builder: flatbuffers.Builder): flatbuffers.Offset; + static finishMovieBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static finishSizePrefixedMovieBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void; + static createMovie(builder: flatbuffers.Builder, mainCharacterType: Character, mainCharacterOffset: flatbuffers.Offset, charactersTypeOffset: flatbuffers.Offset, charactersOffset: flatbuffers.Offset): flatbuffers.Offset; + unpack(): MovieT; + unpackTo(_o: MovieT): void; } export declare class MovieT implements flatbuffers.IGeneratedObject { - mainCharacterType: Character; - mainCharacter: AttackerT | BookReaderT | RapunzelT | string | null; - charactersType: Character[]; - characters: (AttackerT | BookReaderT | RapunzelT | string)[]; - constructor( - mainCharacterType?: Character, - mainCharacter?: AttackerT | BookReaderT | RapunzelT | string | null, - charactersType?: Character[], - characters?: (AttackerT | BookReaderT | RapunzelT | string)[], - ); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + mainCharacterType: Character; + mainCharacter: AttackerT | BookReaderT | RapunzelT | string | null; + charactersType: (Character)[]; + characters: (AttackerT | BookReaderT | RapunzelT | string)[]; + constructor(mainCharacterType?: Character, mainCharacter?: AttackerT | BookReaderT | RapunzelT | string | null, charactersType?: (Character)[], characters?: (AttackerT | BookReaderT | RapunzelT | string)[]); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union_vector/movie.js b/tests/ts/union_vector/movie.js index 36bcd3f23..81dee0e67 100644 --- a/tests/ts/union_vector/movie.js +++ b/tests/ts/union_vector/movie.js @@ -1,222 +1,186 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ import * as flatbuffers from 'flatbuffers'; - -import {Character, unionListToCharacter, unionToCharacter} from './character.js'; - +import { Character, unionToCharacter, unionListToCharacter } from './character.js'; export class Movie { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - static getRootAsMovie(bb, obj) { - return (obj || new Movie()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static getSizePrefixedRootAsMovie(bb, obj) { - bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); - return (obj || new Movie()) - .__init(bb.readInt32(bb.position()) + bb.position(), bb); - } - static bufferHasIdentifier(bb) { - return bb.__has_identifier('MOVI'); - } - mainCharacterType() { - const offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : Character.NONE; - } - mainCharacter(obj) { - const offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__union_with_string(obj, this.bb_pos + offset) : - null; - } - charactersType(index) { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? - this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : - null; - } - charactersTypeLength() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - charactersTypeArray() { - const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? - new Uint8Array( - this.bb.bytes().buffer, - this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), - this.bb.__vector_len(this.bb_pos + offset)) : - null; - } - characters(index, obj) { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? - this.bb.__union_with_string( - obj, this.bb.__vector(this.bb_pos + offset) + index * 4) : - null; - } - charactersLength() { - const offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; - } - static getFullyQualifiedName() { - return 'Movie'; - } - static startMovie(builder) { - builder.startObject(4); - } - static addMainCharacterType(builder, mainCharacterType) { - builder.addFieldInt8(0, mainCharacterType, Character.NONE); - } - static addMainCharacter(builder, mainCharacterOffset) { - builder.addFieldOffset(1, mainCharacterOffset, 0); - } - static addCharactersType(builder, charactersTypeOffset) { - builder.addFieldOffset(2, charactersTypeOffset, 0); - } - static createCharactersTypeVector(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); + constructor() { + this.bb = null; + this.bb_pos = 0; } - return builder.endVector(); - } - static startCharactersTypeVector(builder, numElems) { - builder.startVector(1, numElems, 1); - } - static addCharacters(builder, charactersOffset) { - builder.addFieldOffset(3, charactersOffset, 0); - } - static createCharactersVector(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; } - return builder.endVector(); - } - static startCharactersVector(builder, numElems) { - builder.startVector(4, numElems, 4); - } - static endMovie(builder) { - const offset = builder.endObject(); - return offset; - } - static finishMovieBuffer(builder, offset) { - builder.finish(offset, 'MOVI'); - } - static finishSizePrefixedMovieBuffer(builder, offset) { - builder.finish(offset, 'MOVI', true); - } - static createMovie( - builder, mainCharacterType, mainCharacterOffset, charactersTypeOffset, - charactersOffset) { - Movie.startMovie(builder); - Movie.addMainCharacterType(builder, mainCharacterType); - Movie.addMainCharacter(builder, mainCharacterOffset); - Movie.addCharactersType(builder, charactersTypeOffset); - Movie.addCharacters(builder, charactersOffset); - return Movie.endMovie(builder); - } - unpack() { - return new MovieT( - this.mainCharacterType(), (() => { - const temp = unionToCharacter( - this.mainCharacterType(), this.mainCharacter.bind(this)); - if (temp === null) { - return null; - } - if (typeof temp === 'string') { - return temp; - } - return temp.unpack(); - })(), - this.bb.createScalarList( - this.charactersType.bind(this), this.charactersTypeLength()), - (() => { - const ret = []; - for (let targetEnumIndex = 0; - targetEnumIndex < this.charactersTypeLength(); - ++targetEnumIndex) { - const targetEnum = this.charactersType(targetEnumIndex); - if (targetEnum === null || Character[targetEnum] === 'NONE') { - continue; - } - const temp = unionListToCharacter( - targetEnum, this.characters.bind(this), targetEnumIndex); + static getRootAsMovie(bb, obj) { + return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static getSizePrefixedRootAsMovie(bb, obj) { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new Movie()).__init(bb.readInt32(bb.position()) + bb.position(), bb); + } + static bufferHasIdentifier(bb) { + return bb.__has_identifier('MOVI'); + } + mainCharacterType() { + const offset = this.bb.__offset(this.bb_pos, 4); + return offset ? this.bb.readUint8(this.bb_pos + offset) : Character.NONE; + } + mainCharacter(obj) { + const offset = this.bb.__offset(this.bb_pos, 6); + return offset ? this.bb.__union_with_string(obj, this.bb_pos + offset) : null; + } + charactersType(index) { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : null; + } + charactersTypeLength() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + charactersTypeArray() { + const offset = this.bb.__offset(this.bb_pos, 8); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + } + characters(index, obj) { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__union_with_string(obj, this.bb.__vector(this.bb_pos + offset) + index * 4) : null; + } + charactersLength() { + const offset = this.bb.__offset(this.bb_pos, 10); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; + } + static getFullyQualifiedName() { + return 'Movie'; + } + static startMovie(builder) { + builder.startObject(4); + } + static addMainCharacterType(builder, mainCharacterType) { + builder.addFieldInt8(0, mainCharacterType, Character.NONE); + } + static addMainCharacter(builder, mainCharacterOffset) { + builder.addFieldOffset(1, mainCharacterOffset, 0); + } + static addCharactersType(builder, charactersTypeOffset) { + builder.addFieldOffset(2, charactersTypeOffset, 0); + } + static createCharactersTypeVector(builder, data) { + builder.startVector(1, data.length, 1); + for (let i = data.length - 1; i >= 0; i--) { + builder.addInt8(data[i]); + } + return builder.endVector(); + } + static startCharactersTypeVector(builder, numElems) { + builder.startVector(1, numElems, 1); + } + static addCharacters(builder, charactersOffset) { + builder.addFieldOffset(3, charactersOffset, 0); + } + static createCharactersVector(builder, data) { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]); + } + return builder.endVector(); + } + static startCharactersVector(builder, numElems) { + builder.startVector(4, numElems, 4); + } + static endMovie(builder) { + const offset = builder.endObject(); + return offset; + } + static finishMovieBuffer(builder, offset) { + builder.finish(offset, 'MOVI'); + } + static finishSizePrefixedMovieBuffer(builder, offset) { + builder.finish(offset, 'MOVI', true); + } + static createMovie(builder, mainCharacterType, mainCharacterOffset, charactersTypeOffset, charactersOffset) { + Movie.startMovie(builder); + Movie.addMainCharacterType(builder, mainCharacterType); + Movie.addMainCharacter(builder, mainCharacterOffset); + Movie.addCharactersType(builder, charactersTypeOffset); + Movie.addCharacters(builder, charactersOffset); + return Movie.endMovie(builder); + } + unpack() { + return new MovieT(this.mainCharacterType(), (() => { + const temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this)); if (temp === null) { - continue; + return null; } if (typeof temp === 'string') { - ret.push(temp); - continue; + return temp; } - ret.push(temp.unpack()); - } - return ret; + return temp.unpack(); + })(), this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()), (() => { + const ret = []; + for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) { + const targetEnum = this.charactersType(targetEnumIndex); + if (targetEnum === null || Character[targetEnum] === 'NONE') { + continue; + } + const temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex); + if (temp === null) { + continue; + } + if (typeof temp === 'string') { + ret.push(temp); + continue; + } + ret.push(temp.unpack()); + } + return ret; })()); - } - unpackTo(_o) { - _o.mainCharacterType = this.mainCharacterType(); - _o.mainCharacter = (() => { - const temp = unionToCharacter( - this.mainCharacterType(), this.mainCharacter.bind(this)); - if (temp === null) { - return null; - } - if (typeof temp === 'string') { - return temp; - } - return temp.unpack(); - })(); - _o.charactersType = this.bb.createScalarList( - this.charactersType.bind(this), this.charactersTypeLength()); - _o.characters = (() => { - const ret = []; - for (let targetEnumIndex = 0; - targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) { - const targetEnum = this.charactersType(targetEnumIndex); - if (targetEnum === null || Character[targetEnum] === 'NONE') { - continue; - } - const temp = unionListToCharacter( - targetEnum, this.characters.bind(this), targetEnumIndex); - if (temp === null) { - continue; - } - if (typeof temp === 'string') { - ret.push(temp); - continue; - } - ret.push(temp.unpack()); - } - return ret; - })(); - } + } + unpackTo(_o) { + _o.mainCharacterType = this.mainCharacterType(); + _o.mainCharacter = (() => { + const temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this)); + if (temp === null) { + return null; + } + if (typeof temp === 'string') { + return temp; + } + return temp.unpack(); + })(); + _o.charactersType = this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()); + _o.characters = (() => { + const ret = []; + for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) { + const targetEnum = this.charactersType(targetEnumIndex); + if (targetEnum === null || Character[targetEnum] === 'NONE') { + continue; + } + const temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex); + if (temp === null) { + continue; + } + if (typeof temp === 'string') { + ret.push(temp); + continue; + } + ret.push(temp.unpack()); + } + return ret; + })(); + } } export class MovieT { - constructor( - mainCharacterType = Character.NONE, mainCharacter = null, - charactersType = [], characters = []) { - this.mainCharacterType = mainCharacterType; - this.mainCharacter = mainCharacter; - this.charactersType = charactersType; - this.characters = characters; - } - pack(builder) { - const mainCharacter = builder.createObjectOffset(this.mainCharacter); - const charactersType = - Movie.createCharactersTypeVector(builder, this.charactersType); - const characters = Movie.createCharactersVector( - builder, builder.createObjectOffsetList(this.characters)); - return Movie.createMovie( - builder, this.mainCharacterType, mainCharacter, charactersType, - characters); - } + constructor(mainCharacterType = Character.NONE, mainCharacter = null, charactersType = [], characters = []) { + this.mainCharacterType = mainCharacterType; + this.mainCharacter = mainCharacter; + this.charactersType = charactersType; + this.characters = characters; + } + pack(builder) { + const mainCharacter = builder.createObjectOffset(this.mainCharacter); + const charactersType = Movie.createCharactersTypeVector(builder, this.charactersType); + const characters = Movie.createCharactersVector(builder, builder.createObjectOffsetList(this.characters)); + return Movie.createMovie(builder, this.mainCharacterType, mainCharacter, charactersType, characters); + } } diff --git a/tests/ts/union_vector/movie.ts b/tests/ts/union_vector/movie.ts index 2c6235e20..9d140c614 100644 --- a/tests/ts/union_vector/movie.ts +++ b/tests/ts/union_vector/movie.ts @@ -12,7 +12,7 @@ import { Rapunzel, RapunzelT } from './rapunzel.js'; export class Movie implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Movie { this.bb_pos = i; this.bb = bb; @@ -71,19 +71,19 @@ static getFullyQualifiedName(): "Movie" { return 'Movie'; } -static startMovie(builder:flatbuffers.Builder) { +static startMovie(builder:flatbuffers.Builder):void { builder.startObject(4); } -static addMainCharacterType(builder:flatbuffers.Builder, mainCharacterType:Character) { +static addMainCharacterType(builder:flatbuffers.Builder, mainCharacterType:Character):void { builder.addFieldInt8(0, mainCharacterType, Character.NONE); } -static addMainCharacter(builder:flatbuffers.Builder, mainCharacterOffset:flatbuffers.Offset) { +static addMainCharacter(builder:flatbuffers.Builder, mainCharacterOffset:flatbuffers.Offset):void { builder.addFieldOffset(1, mainCharacterOffset, 0); } -static addCharactersType(builder:flatbuffers.Builder, charactersTypeOffset:flatbuffers.Offset) { +static addCharactersType(builder:flatbuffers.Builder, charactersTypeOffset:flatbuffers.Offset):void { builder.addFieldOffset(2, charactersTypeOffset, 0); } @@ -95,11 +95,11 @@ static createCharactersTypeVector(builder:flatbuffers.Builder, data:Character[]) return builder.endVector(); } -static startCharactersTypeVector(builder:flatbuffers.Builder, numElems:number) { +static startCharactersTypeVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(1, numElems, 1); } -static addCharacters(builder:flatbuffers.Builder, charactersOffset:flatbuffers.Offset) { +static addCharacters(builder:flatbuffers.Builder, charactersOffset:flatbuffers.Offset):void { builder.addFieldOffset(3, charactersOffset, 0); } @@ -111,7 +111,7 @@ static createCharactersVector(builder:flatbuffers.Builder, data:flatbuffers.Offs return builder.endVector(); } -static startCharactersVector(builder:flatbuffers.Builder, numElems:number) { +static startCharactersVector(builder:flatbuffers.Builder, numElems:number):void { builder.startVector(4, numElems, 4); } @@ -120,11 +120,11 @@ static endMovie(builder:flatbuffers.Builder):flatbuffers.Offset { return offset; } -static finishMovieBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishMovieBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'MOVI'); } -static finishSizePrefixedMovieBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { +static finishSizePrefixedMovieBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset):void { builder.finish(offset, 'MOVI', true); } diff --git a/tests/ts/union_vector/rapunzel.d.ts b/tests/ts/union_vector/rapunzel.d.ts index 60b3e5ff2..7eff8c72a 100644 --- a/tests/ts/union_vector/rapunzel.d.ts +++ b/tests/ts/union_vector/rapunzel.d.ts @@ -1,23 +1,18 @@ import * as flatbuffers from 'flatbuffers'; -export declare class Rapunzel - implements flatbuffers.IUnpackableObject -{ - bb: flatbuffers.ByteBuffer | null; - bb_pos: number; - __init(i: number, bb: flatbuffers.ByteBuffer): Rapunzel; - hairLength(): number; - mutate_hair_length(value: number): boolean; - static getFullyQualifiedName(): string; - static sizeOf(): number; - static createRapunzel( - builder: flatbuffers.Builder, - hair_length: number, - ): flatbuffers.Offset; - unpack(): RapunzelT; - unpackTo(_o: RapunzelT): void; +export declare class Rapunzel implements flatbuffers.IUnpackableObject { + bb: flatbuffers.ByteBuffer | null; + bb_pos: number; + __init(i: number, bb: flatbuffers.ByteBuffer): Rapunzel; + hairLength(): number; + mutate_hair_length(value: number): boolean; + static getFullyQualifiedName(): "Rapunzel"; + static sizeOf(): number; + static createRapunzel(builder: flatbuffers.Builder, hair_length: number): flatbuffers.Offset; + unpack(): RapunzelT; + unpackTo(_o: RapunzelT): void; } export declare class RapunzelT implements flatbuffers.IGeneratedObject { - hairLength: number; - constructor(hairLength?: number); - pack(builder: flatbuffers.Builder): flatbuffers.Offset; + hairLength: number; + constructor(hairLength?: number); + pack(builder: flatbuffers.Builder): flatbuffers.Offset; } diff --git a/tests/ts/union_vector/rapunzel.js b/tests/ts/union_vector/rapunzel.js index 51614eb36..67a5e4453 100644 --- a/tests/ts/union_vector/rapunzel.js +++ b/tests/ts/union_vector/rapunzel.js @@ -1,44 +1,44 @@ // automatically generated by the FlatBuffers compiler, do not modify export class Rapunzel { - constructor() { - this.bb = null; - this.bb_pos = 0; - } - __init(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; - } - hairLength() { - return this.bb.readInt32(this.bb_pos); - } - mutate_hair_length(value) { - this.bb.writeInt32(this.bb_pos + 0, value); - return true; - } - static getFullyQualifiedName() { - return 'Rapunzel'; - } - static sizeOf() { - return 4; - } - static createRapunzel(builder, hair_length) { - builder.prep(4, 4); - builder.writeInt32(hair_length); - return builder.offset(); - } - unpack() { - return new RapunzelT(this.hairLength()); - } - unpackTo(_o) { - _o.hairLength = this.hairLength(); - } + constructor() { + this.bb = null; + this.bb_pos = 0; + } + __init(i, bb) { + this.bb_pos = i; + this.bb = bb; + return this; + } + hairLength() { + return this.bb.readInt32(this.bb_pos); + } + mutate_hair_length(value) { + this.bb.writeInt32(this.bb_pos + 0, value); + return true; + } + static getFullyQualifiedName() { + return 'Rapunzel'; + } + static sizeOf() { + return 4; + } + static createRapunzel(builder, hair_length) { + builder.prep(4, 4); + builder.writeInt32(hair_length); + return builder.offset(); + } + unpack() { + return new RapunzelT(this.hairLength()); + } + unpackTo(_o) { + _o.hairLength = this.hairLength(); + } } export class RapunzelT { - constructor(hairLength = 0) { - this.hairLength = hairLength; - } - pack(builder) { - return Rapunzel.createRapunzel(builder, this.hairLength); - } + constructor(hairLength = 0) { + this.hairLength = hairLength; + } + pack(builder) { + return Rapunzel.createRapunzel(builder, this.hairLength); + } } diff --git a/tests/ts/union_vector/rapunzel.ts b/tests/ts/union_vector/rapunzel.ts index 8affb9671..73d9edee4 100644 --- a/tests/ts/union_vector/rapunzel.ts +++ b/tests/ts/union_vector/rapunzel.ts @@ -8,7 +8,7 @@ import * as flatbuffers from 'flatbuffers'; export class Rapunzel implements flatbuffers.IUnpackableObject { bb: flatbuffers.ByteBuffer|null = null; - bb_pos = 0; + bb_pos: number = 0; __init(i:number, bb:flatbuffers.ByteBuffer):Rapunzel { this.bb_pos = i; this.bb = bb; diff --git a/tests/ts/union_vector/union_vector.d.ts b/tests/ts/union_vector/union_vector.d.ts index ae13e6d38..ebd93797f 100644 --- a/tests/ts/union_vector/union_vector.d.ts +++ b/tests/ts/union_vector/union_vector.d.ts @@ -1,8 +1,8 @@ -export {Attacker, AttackerT} from './attacker.js'; -export {BookReader, BookReaderT} from './book-reader.js'; -export {Character} from './character.js'; -export {FallingTub, FallingTubT} from './falling-tub.js'; -export {Gadget} from './gadget.js'; -export {HandFan, HandFanT} from './hand-fan.js'; -export {Movie, MovieT} from './movie.js'; -export {Rapunzel, RapunzelT} from './rapunzel.js'; +export { Attacker, AttackerT } from './attacker.js'; +export { BookReader, BookReaderT } from './book-reader.js'; +export { Character } from './character.js'; +export { FallingTub, FallingTubT } from './falling-tub.js'; +export { Gadget } from './gadget.js'; +export { HandFan, HandFanT } from './hand-fan.js'; +export { Movie, MovieT } from './movie.js'; +export { Rapunzel, RapunzelT } from './rapunzel.js'; diff --git a/tests/ts/union_vector/union_vector.js b/tests/ts/union_vector/union_vector.js index fc7b8ecf5..63b782e7d 100644 --- a/tests/ts/union_vector/union_vector.js +++ b/tests/ts/union_vector/union_vector.js @@ -1,11 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, - * @typescript-eslint/no-non-null-assertion */ -export {Attacker, AttackerT} from './attacker.js'; -export {BookReader, BookReaderT} from './book-reader.js'; -export {Character} from './character.js'; -export {FallingTub, FallingTubT} from './falling-tub.js'; -export {Gadget} from './gadget.js'; -export {HandFan, HandFanT} from './hand-fan.js'; -export {Movie, MovieT} from './movie.js'; -export {Rapunzel, RapunzelT} from './rapunzel.js'; +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ +export { Attacker, AttackerT } from './attacker.js'; +export { BookReader, BookReaderT } from './book-reader.js'; +export { Character } from './character.js'; +export { FallingTub, FallingTubT } from './falling-tub.js'; +export { Gadget } from './gadget.js'; +export { HandFan, HandFanT } from './hand-fan.js'; +export { Movie, MovieT } from './movie.js'; +export { Rapunzel, RapunzelT } from './rapunzel.js'; diff --git a/tests/ts/union_vector/union_vector_generated.cjs b/tests/ts/union_vector/union_vector_generated.cjs index 3144fdaa1..9fc824ec2 100644 --- a/tests/ts/union_vector/union_vector_generated.cjs +++ b/tests/ts/union_vector/union_vector_generated.cjs @@ -404,7 +404,7 @@ var Movie = class _Movie { } charactersType(index) { const offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; + return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : null; } charactersTypeLength() { const offset = this.bb.__offset(this.bb_pos, 8); diff --git a/ts/flatbuffers.ts b/ts/flatbuffers.ts index 26b128a27..18d4e9c52 100644 --- a/ts/flatbuffers.ts +++ b/ts/flatbuffers.ts @@ -5,7 +5,7 @@ export { SIZE_PREFIX_LENGTH, } from './constants.js'; -export {IGeneratedObject, IUnpackableObject, Offset, Table} from './types.js'; +export type {IGeneratedObject, IUnpackableObject, Offset, Table} from './types.js'; export {float32, float64, int32, isLittleEndian} from './utils.js'; diff --git a/ts/flexbuffers/stack-value.ts b/ts/flexbuffers/stack-value.ts index 3edf7b3ad..ef28046de 100644 --- a/ts/flexbuffers/stack-value.ts +++ b/ts/flexbuffers/stack-value.ts @@ -59,11 +59,11 @@ export class StackValue { this.offset = newOffset; } - storedWidth(width = BitWidth.WIDTH8): BitWidth { + storedWidth(width: BitWidth = BitWidth.WIDTH8): BitWidth { return isInline(this.type) ? Math.max(width, this.width) : this.width; } - storedPackedType(width = BitWidth.WIDTH8): ValueType { + storedPackedType(width: BitWidth = BitWidth.WIDTH8): ValueType { return packedType(this.type, this.storedWidth(width)); } diff --git a/ts/utils.ts b/ts/utils.ts index bf028d256..f1695fab7 100644 --- a/ts/utils.ts +++ b/ts/utils.ts @@ -1,5 +1,5 @@ -export const int32 = new Int32Array(2); -export const float32 = new Float32Array(int32.buffer); -export const float64 = new Float64Array(int32.buffer); -export const isLittleEndian = +export const int32: Int32Array = new Int32Array(2); +export const float32: Float32Array = new Float32Array(int32.buffer); +export const float64: Float64Array = new Float64Array(int32.buffer); +export const isLittleEndian: boolean = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1; diff --git a/tsconfig.json b/tsconfig.json index a8c89f5ad..4f99f8e9e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,9 @@ "outDir": "./js", "strict": true, "esModuleInterop": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "isolatedDeclarations": true }, "include": [ "ts/**/*.ts"