diff --git a/include/flatbuffers/code_generators.h b/include/flatbuffers/code_generators.h index 71ad0df7a..727552118 100644 --- a/include/flatbuffers/code_generators.h +++ b/include/flatbuffers/code_generators.h @@ -138,7 +138,8 @@ class BaseGenerator { std::string WrapInNameSpace(const Namespace *ns, const std::string &name) const; - std::string WrapInNameSpace(const Definition &def) const; + std::string WrapInNameSpace(const Definition &def, + const std::string &suffix = "") const; std::string GetNameSpace(const Definition &def) const; diff --git a/scripts/generate_code.py b/scripts/generate_code.py index 01d65df78..4ddb3daff 100755 --- a/scripts/generate_code.py +++ b/scripts/generate_code.py @@ -245,6 +245,14 @@ flatc( schema="monster_test.fbs", ) +# Generate the complete flat file TS of monster. +flatc( + ["--ts", "--gen-all", "--ts-flat-files"], + include="include_test", + schema="monster_test.fbs", + prefix="ts/ts-flat-files" +) + flatc( BASE_OPTS + TS_OPTS + ["-b"], include="include_test", diff --git a/src/code_generators.cpp b/src/code_generators.cpp index 1589d9575..73057f3ee 100644 --- a/src/code_generators.cpp +++ b/src/code_generators.cpp @@ -131,8 +131,9 @@ std::string BaseGenerator::WrapInNameSpace(const Namespace *ns, return qualified_name + name; } -std::string BaseGenerator::WrapInNameSpace(const Definition &def) const { - return WrapInNameSpace(def.defined_namespace, def.name); +std::string BaseGenerator::WrapInNameSpace(const Definition &def, + const std::string &suffix) const { + return WrapInNameSpace(def.defined_namespace, def.name + suffix); } std::string BaseGenerator::GetNameSpace(const Definition &def) const { diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index cdfa5135e..7f0060a0a 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -// independent from idl_parser, since this code is not needed for most clients #include #include #include @@ -33,6 +32,7 @@ struct ImportDefinition { std::string export_statement; std::string bare_file_path; std::string rel_file_path; + std::string object_name; const Definition *dependent = nullptr; const Definition *dependency = nullptr; }; @@ -49,7 +49,7 @@ class TsGenerator : public BaseGenerator { TsGenerator(const Parser &parser, const std::string &path, const std::string &file_name) - : BaseGenerator(parser, path, file_name, "", ".", "ts") { + : BaseGenerator(parser, path, file_name, "", "_", "ts") { // clang-format off // List of keywords retrieved from here: @@ -117,6 +117,47 @@ class TsGenerator : public BaseGenerator { return true; } + bool IncludeNamespace() const { + // When generating a single flat file and all its includes, namespaces are + // important to avoid type name clashes. + return parser_.opts.ts_flat_file && parser_.opts.generate_all; + } + + // Make the provided def wrapped in namespaced if configured to do so, + // otherwise just return the name. + std::string MakeNamespaced(const Definition &def, + const std::string &suffix = "") { + if (IncludeNamespace()) { return WrapInNameSpace(def, suffix); } + return def.name + suffix; + } + + std::string GetTypeName(const EnumDef &def, const bool = false, + const bool force_ns_wrap = false) { + std::string base_name = def.name; + + if (IncludeNamespace() || force_ns_wrap) { + base_name = WrapInNameSpace(def.defined_namespace, base_name); + } + + return EscapeKeyword(base_name); + } + + std::string GetTypeName(const StructDef &def, const bool object_api = false, + const bool force_ns_wrap = false) { + std::string base_name = def.name; + + if (object_api && parser_.opts.generate_object_based_api) { + base_name = + parser_.opts.object_prefix + base_name + parser_.opts.object_suffix; + } + + if (IncludeNamespace() || force_ns_wrap) { + base_name = WrapInNameSpace(def.defined_namespace, base_name); + } + + return EscapeKeyword(base_name); + } + // Save out the generated code for a single class while adding // declaration boilerplate. bool SaveType(const Definition &definition, const std::string &class_code, @@ -145,6 +186,7 @@ class TsGenerator : public BaseGenerator { if (parser_.opts.ts_flat_file) { flat_file_ += code; + flat_file_ += "\n"; flat_file_definitions_.insert(&definition); return true; } else { @@ -152,15 +194,6 @@ class TsGenerator : public BaseGenerator { NamespaceDir(*definition.defined_namespace, true) + ConvertCase(definition.name, Case::kDasher, Case::kUpperCamel); - // Special case for the root table, generate an export statement - if (&definition == parser_.root_struct_def_) { - ImportDefinition import; - import.name = definition.name; - import.export_statement = - "export { " + import.name + " } from './" + basename + "';"; - imports.insert(std::make_pair(import.name, import)); - } - return SaveFile((basename + ".ts").c_str(), code, false); } } @@ -308,8 +341,8 @@ class TsGenerator : public BaseGenerator { std::string &code = *code_ptr; GenDocComment(enum_def.doc_comment, code_ptr); code += "export enum "; - // TODO(7445): figure out if the export needs a namespace for ts-flat-files - code += EscapeKeyword(enum_def.name) + " {\n"; + code += GetTypeName(enum_def); + code += " {\n"; for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { auto &ev = **it; if (!ev.doc_comment.empty()) { @@ -347,7 +380,7 @@ class TsGenerator : public BaseGenerator { code += GenUnionConvFunc(enum_def.underlying_type, imports); } - code += "\n\n"; + code += "\n"; } static std::string GenType(const Type &type) { @@ -408,8 +441,9 @@ class TsGenerator : public BaseGenerator { } default: { if (auto val = value.type.enum_def->FindByValue(value.constant)) { - return EscapeKeyword(AddImport(imports, *value.type.enum_def, - *value.type.enum_def)) + + return AddImport(imports, *value.type.enum_def, + *value.type.enum_def) + .name + "." + EscapeKeyword(val->name); } else { return value.constant; @@ -447,7 +481,7 @@ class TsGenerator : public BaseGenerator { if (IsString(type)) { name = "string|Uint8Array"; } else { - name = EscapeKeyword(AddImport(imports, owner, *type.struct_def)); + name = AddImport(imports, owner, *type.struct_def).name; } return allowNull ? (name + "|null") : name; } @@ -460,7 +494,8 @@ class TsGenerator : public BaseGenerator { default: if (IsScalar(type.base_type)) { if (type.enum_def) { - const auto enum_name = AddImport(imports, owner, *type.enum_def); + const auto enum_name = + AddImport(imports, owner, *type.enum_def).name; return allowNull ? (enum_name + "|null") : enum_name; } return allowNull ? "number|null" : "number"; @@ -586,16 +621,6 @@ class TsGenerator : public BaseGenerator { } } - static std::string GetObjApiClassName(const StructDef &sd, - const IDLOptions &opts) { - return GetObjApiClassName(sd.name, opts); - } - - static std::string GetObjApiClassName(const std::string &name, - const IDLOptions &opts) { - return opts.object_prefix + name + opts.object_suffix; - } - bool UnionHasStringType(const EnumDef &union_enum) { return std::any_of(union_enum.Vals().begin(), union_enum.Vals().end(), [](const EnumVal *ev) { @@ -624,7 +649,7 @@ class TsGenerator : public BaseGenerator { if (IsString(ev.union_type)) { type = "string"; // no need to wrap string type in namespace } else if (ev.union_type.base_type == BASE_TYPE_STRUCT) { - type = AddImport(imports, union_enum, *ev.union_type.struct_def); + type = AddImport(imports, union_enum, *ev.union_type.struct_def).name; } else { FLATBUFFERS_ASSERT(false); } @@ -638,173 +663,142 @@ class TsGenerator : public BaseGenerator { return ret; } - std::string AddImport(import_set &imports, const Definition &dependent, - const StructDef &dependency) { - std::string ns; - const auto &depc_comps = dependency.defined_namespace->components; - for (auto it = depc_comps.begin(); it != depc_comps.end(); it++) { - ns += *it; - } - std::string unique_name = ns + dependency.name; - std::string import_name = dependency.name; - std::string long_import_name; - if (imports.find(unique_name) != imports.end()) - return imports.find(unique_name)->second.name; + static bool CheckIfNameClashes(const import_set &imports, + const std::string &name) { + // TODO: this would be better as a hashset. for (auto it = imports.begin(); it != imports.end(); it++) { - if (it->second.name == import_name) { - long_import_name = ns + import_name; - break; + if (it->second.name == name) { return true; } + } + return false; + } + + std::string GenSymbolExpression(const StructDef &struct_def, + const bool has_name_clash, + const std::string &import_name, + const std::string &name, + const std::string &object_name) { + std::string symbols_expression; + + if (has_name_clash) { + // We have a name clash + symbols_expression += import_name + " as " + name; + + if (parser_.opts.generate_object_based_api) { + symbols_expression += ", " + + GetTypeName(struct_def, /*object_api =*/true) + + " as " + object_name; + } + } else { + // No name clash, use the provided name + symbols_expression += name; + + if (parser_.opts.generate_object_based_api) { + symbols_expression += ", " + object_name; } } + return symbols_expression; + } + + std::string GenSymbolExpression(const EnumDef &enum_def, + const bool has_name_clash, + const std::string &import_name, + const std::string &name, + const std::string &) { + std::string symbols_expression; + if (has_name_clash) { + symbols_expression += import_name + " as " + name; + } else { + symbols_expression += name; + } + + if (enum_def.is_union) { + symbols_expression += ", unionTo" + name; + symbols_expression += ", unionListTo" + name; + } + + return symbols_expression; + } + + template + ImportDefinition AddImport(import_set &imports, const Definition &dependent, + const DefintionT &dependency) { + // The unique name of the dependency, fully qualified in its namespace. + const std::string unique_name = GetTypeName( + dependency, /*object_api = */ false, /*force_ns_wrap=*/true); + + // Look if we have already added this import and return its name if found. + const auto import_pair = imports.find(unique_name); + if (import_pair != imports.end()) { return import_pair->second; } + + // Check if this name would have a name clash with another type. Just use + // the "base" name (properlly escaped) without any namespacing applied. + const std::string import_name = EscapeKeyword(dependency.name); + const bool has_name_clash = CheckIfNameClashes(imports, import_name); + + // If we have a name clash, use the unique name, otherwise use simple name. + std::string name = has_name_clash ? unique_name : import_name; + + const std::string object_name = + GetTypeName(dependency, /*object_api=*/true, has_name_clash); + if (parser_.opts.ts_flat_file) { // In flat-file generation, do not attempt to import things from ourselves // *and* do not wrap namespaces (note that this does override the logic // above, but since we force all non-self-imports to use namespace-based // names in flat file generation, it's fine). if (dependent.file == dependency.file) { - long_import_name = import_name; + name = import_name; } else { - long_import_name = ns + import_name; - std::string file = + const std::string file = RelativeToRootPath(StripFileName(AbsolutePath(dependent.file)), dependency.file) // Strip the leading // .substr(2); - flat_file_import_declarations_[file][import_name] = long_import_name; - if (parser_.opts.generate_object_based_api) { - flat_file_import_declarations_[file][import_name + "T"] = - long_import_name + "T"; + flat_file_import_declarations_[file][import_name] = name; + if (parser_.opts.generate_object_based_api && + typeid(dependency) == typeid(StructDef)) { + flat_file_import_declarations_[file][import_name + "T"] = object_name; } } } - std::string import_statement; - std::string export_statement; - import_statement += "import { "; - export_statement += "export { "; - std::string symbols_expression; - if (long_import_name.empty()) { - symbols_expression += EscapeKeyword(import_name); - if (parser_.opts.generate_object_based_api) - symbols_expression += ", " + import_name + "T"; - } else { - symbols_expression += EscapeKeyword(dependency.name) + " as " + - EscapeKeyword(long_import_name); - if (parser_.opts.generate_object_based_api) - symbols_expression += - ", " + dependency.name + "T as " + long_import_name + "T"; - } - import_statement += symbols_expression + " } from '"; - export_statement += symbols_expression + " } from '"; + const std::string symbols_expression = GenSymbolExpression( + dependency, has_name_clash, import_name, name, object_name); + std::string bare_file_path; std::string rel_file_path; const auto &dep_comps = dependent.defined_namespace->components; - for (size_t i = 0; i < dep_comps.size(); i++) + for (size_t i = 0; i < dep_comps.size(); i++) { rel_file_path += i == 0 ? ".." : (kPathSeparator + std::string("..")); - if (dep_comps.size() == 0) rel_file_path += "."; - for (auto it = depc_comps.begin(); it != depc_comps.end(); it++) - bare_file_path += - kPathSeparator + ConvertCase(*it, Case::kDasher, Case::kUpperCamel); - bare_file_path += - kPathSeparator + - ConvertCase(dependency.name, Case::kDasher, Case::kUpperCamel); - rel_file_path += bare_file_path; - import_statement += rel_file_path + "';"; - export_statement += "." + bare_file_path + "';"; - ImportDefinition import; - import.name = long_import_name.empty() ? import_name : long_import_name; - import.bare_file_path = bare_file_path; - import.rel_file_path = rel_file_path; - import.import_statement = import_statement; - import.export_statement = export_statement; - import.dependency = &dependency; - import.dependent = &dependent; - imports.insert(std::make_pair(unique_name, import)); - return import.name; - } + } + if (dep_comps.size() == 0) { rel_file_path += "."; } - // TODO: largely (but not identical) duplicated code from above couln't find a - // good way to refactor - std::string AddImport(import_set &imports, const Definition &dependent, - const EnumDef &dependency) { - std::string ns; const auto &depc_comps = dependency.defined_namespace->components; for (auto it = depc_comps.begin(); it != depc_comps.end(); it++) { - ns += *it; - } - std::string unique_name = ns + dependency.name; - std::string import_name = EscapeKeyword(dependency.name); - std::string long_import_name; - if (imports.find(unique_name) != imports.end()) { - return imports.find(unique_name)->second.name; - } - for (auto it = imports.begin(); it != imports.end(); it++) { - if (it->second.name == import_name) { - long_import_name = ns + import_name; - break; - } - } - - if (parser_.opts.ts_flat_file) { - // In flat-file generation, do not attempt to import things from ourselves - // *and* do not wrap namespaces (note that this does override the logic - // above, but since we force all non-self-imports to use namespace-based - // names in flat file generation, it's fine). - if (dependent.file == dependency.file) { - long_import_name = import_name; - } else { - long_import_name = ns + import_name; - std::string file = - RelativeToRootPath(StripFileName(AbsolutePath(dependent.file)), - dependency.file) - // Strip the leading // - .substr(2); - flat_file_import_declarations_[file][import_name] = long_import_name; - } - } - - std::string import_statement; - std::string export_statement; - import_statement += "import { "; - export_statement += "export { "; - std::string symbols_expression; - if (long_import_name.empty()) - symbols_expression += import_name; - else - symbols_expression += EscapeKeyword(dependency.name) + " as " + - EscapeKeyword(long_import_name); - if (dependency.is_union) { - symbols_expression += ", unionTo" + import_name; - symbols_expression += ", unionListTo" + import_name; - } - import_statement += symbols_expression + " } from '"; - export_statement += symbols_expression + " } from '"; - std::string bare_file_path; - std::string rel_file_path; - const auto &dep_comps = dependent.defined_namespace->components; - for (size_t i = 0; i < dep_comps.size(); i++) - rel_file_path += i == 0 ? ".." : (kPathSeparator + std::string("..")); - if (dep_comps.size() == 0) rel_file_path += "."; - for (auto it = depc_comps.begin(); it != depc_comps.end(); it++) bare_file_path += kPathSeparator + ConvertCase(*it, Case::kDasher, Case::kUpperCamel); + } bare_file_path += kPathSeparator + ConvertCase(dependency.name, Case::kDasher, Case::kUpperCamel); rel_file_path += bare_file_path; - import_statement += rel_file_path + "';"; - export_statement += "." + bare_file_path + "';"; + ImportDefinition import; - import.name = long_import_name.empty() ? import_name : long_import_name; + import.name = name; + import.object_name = object_name; import.bare_file_path = bare_file_path; import.rel_file_path = rel_file_path; - import.import_statement = import_statement; - import.export_statement = export_statement; + import.import_statement = + "import { " + symbols_expression + " } from '" + rel_file_path + "';"; + import.export_statement = + "export { " + symbols_expression + " } from '." + bare_file_path + "';"; import.dependency = &dependency; import.dependent = &dependent; + imports.insert(std::make_pair(unique_name, import)); - return import.name; + + return import; } void AddImport(import_set &imports, std::string import_name, @@ -819,7 +813,7 @@ class TsGenerator : public BaseGenerator { // Generate a TS union type based on a union's enum std::string GenObjApiUnionTypeTS(import_set &imports, const StructDef &dependent, - const IDLOptions &opts, + const IDLOptions &, const EnumDef &union_enum) { std::string ret = ""; std::set type_list; @@ -833,8 +827,8 @@ class TsGenerator : public BaseGenerator { if (IsString(ev.union_type)) { type = "string"; // no need to wrap string type in namespace } else if (ev.union_type.base_type == BASE_TYPE_STRUCT) { - type = GetObjApiClassName( - AddImport(imports, dependent, *ev.union_type.struct_def), opts); + type = AddImport(imports, dependent, *ev.union_type.struct_def) + .object_name; } else { FLATBUFFERS_ASSERT(false); } @@ -866,12 +860,12 @@ class TsGenerator : public BaseGenerator { const auto valid_union_type_with_null = valid_union_type + "|null"; auto ret = "\n\nexport function " + GenUnionConvFuncName(enum_def) + - "(\n type: " + enum_def.name + + "(\n type: " + GetTypeName(enum_def) + ",\n accessor: (obj:" + valid_union_type + ") => " + valid_union_type_with_null + "\n): " + valid_union_type_with_null + " {\n"; - const auto enum_type = AddImport(imports, enum_def, enum_def); + const auto enum_type = AddImport(imports, enum_def, enum_def).name; const auto union_enum_loop = [&](const std::string &accessor_str) { ret += " switch(" + enum_type + "[type]) {\n"; @@ -888,7 +882,7 @@ class TsGenerator : public BaseGenerator { ret += "return " + accessor_str + "'') as string;"; } else if (ev.union_type.base_type == BASE_TYPE_STRUCT) { const auto type = - AddImport(imports, enum_def, *ev.union_type.struct_def); + AddImport(imports, enum_def, *ev.union_type.struct_def).name; ret += "return " + accessor_str + "new " + type + "())! as " + type + ";"; } else { @@ -905,7 +899,7 @@ class TsGenerator : public BaseGenerator { ret += "}"; ret += "\n\nexport function " + GenUnionListConvFuncName(enum_def) + - "(\n type: " + enum_def.name + + "(\n type: " + GetTypeName(enum_def) + ", \n accessor: (index: number, obj:" + valid_union_type + ") => " + valid_union_type_with_null + ", \n index: number\n): " + valid_union_type_with_null + " {\n"; @@ -927,7 +921,7 @@ class TsGenerator : public BaseGenerator { const bool is_array = false) { if (union_type.enum_def) { const auto &enum_def = *union_type.enum_def; - const auto enum_type = AddImport(imports, dependent, enum_def); + const auto enum_type = AddImport(imports, dependent, enum_def).name; const std::string union_accessor = "this." + field_name; const auto union_has_string = UnionHasStringType(enum_def); @@ -1029,7 +1023,7 @@ class TsGenerator : public BaseGenerator { void GenObjApi(const Parser &parser, StructDef &struct_def, std::string &obj_api_unpack_func, std::string &obj_api_class, import_set &imports) { - const auto class_name = GetObjApiClassName(struct_def, parser.opts); + const auto class_name = GetTypeName(struct_def, /*object_api=*/true); std::string unpack_func = "\nunpack(): " + class_name + " {\n return new " + class_name + "(" + @@ -1049,8 +1043,7 @@ class TsGenerator : public BaseGenerator { std::string pack_func_offset_decl; std::string pack_func_create_call; - const auto struct_name = - EscapeKeyword(AddImport(imports, struct_def, struct_def)); + const auto struct_name = AddImport(imports, struct_def, struct_def).name; if (has_create) { pack_func_create_call = " return " + struct_name + ".create" + @@ -1113,8 +1106,7 @@ class TsGenerator : public BaseGenerator { switch (field.value.type.base_type) { case BASE_TYPE_STRUCT: { const auto &sd = *field.value.type.struct_def; - field_type += GetObjApiClassName(AddImport(imports, struct_def, sd), - parser.opts); + field_type += AddImport(imports, struct_def, sd).object_name; const std::string field_accessor = "this." + field_name + "()"; field_val = GenNullCheckConditional(field_accessor, @@ -1143,7 +1135,8 @@ class TsGenerator : public BaseGenerator { switch (vectortype.base_type) { case BASE_TYPE_STRUCT: { const auto &sd = *field.value.type.struct_def; - field_type += GetObjApiClassName(sd, parser.opts); + field_type += GetTypeName(sd, /*object_api=*/true); + ; field_type += ")[]"; field_val = GenBBAccess() + ".createObjList(" + @@ -1154,14 +1147,12 @@ class TsGenerator : public BaseGenerator { field_offset_decl = "builder.createStructOffsetList(this." + field_name_escaped + ", " + - EscapeKeyword( - AddImport(imports, struct_def, struct_def)) + + AddImport(imports, struct_def, struct_def).name + ".start" + ConvertCase(field_name, Case::kUpperCamel) + "Vector)"; } else { field_offset_decl = - EscapeKeyword( - AddImport(imports, struct_def, struct_def)) + + AddImport(imports, struct_def, struct_def).name + ".create" + ConvertCase(field_name, Case::kUpperCamel) + "Vector(builder, builder.createObjectOffsetList(" + "this." + field_name_escaped + "))"; @@ -1176,7 +1167,7 @@ class TsGenerator : public BaseGenerator { field_binded_method + ", this." + field_name + "Length())"; field_offset_decl = - EscapeKeyword(AddImport(imports, struct_def, struct_def)) + + AddImport(imports, struct_def, struct_def).name + ".create" + ConvertCase(field_name, Case::kUpperCamel) + "Vector(builder, builder.createObjectOffsetList(" + "this." + field_name_escaped + "))"; @@ -1191,7 +1182,7 @@ class TsGenerator : public BaseGenerator { vectortype, true); field_offset_decl = - EscapeKeyword(AddImport(imports, struct_def, struct_def)) + + AddImport(imports, struct_def, struct_def).name + ".create" + ConvertCase(field_name, Case::kUpperCamel) + "Vector(builder, builder.createObjectOffsetList(" + "this." + field_name_escaped + "))"; @@ -1211,7 +1202,7 @@ class TsGenerator : public BaseGenerator { "Length())"; field_offset_decl = - EscapeKeyword(AddImport(imports, struct_def, struct_def)) + + AddImport(imports, struct_def, struct_def).name + ".create" + ConvertCase(field_name, Case::kUpperCamel) + "Vector(builder, this." + field_name_escaped + ")"; @@ -1301,10 +1292,10 @@ class TsGenerator : public BaseGenerator { pack_func_create_call += "return " + struct_name + ".end" + GetPrefixedName(struct_def) + "(builder);"; } - - obj_api_class = "\nexport class " + - GetObjApiClassName(struct_def, parser.opts) + " {\n"; - + obj_api_class = "\n"; + obj_api_class += "export class "; + obj_api_class += GetTypeName(struct_def, /*object_api=*/true); + obj_api_class += " {\n"; obj_api_class += constructor_func; obj_api_class += pack_func_prototype + pack_func_offset_decl + pack_func_create_call + "\n}"; @@ -1335,14 +1326,17 @@ class TsGenerator : public BaseGenerator { if (struct_def.generated) return; std::string &code = *code_ptr; - std::string object_name; - std::string object_namespace = GetNameSpace(struct_def); + // Special case for the root struct, since no one will necessarily reference + // it, we have to explicitly add it to the import list. + if (&struct_def == parser_.root_struct_def_) { + AddImport(imports, struct_def, struct_def); + } + + const std::string object_name = GetTypeName(struct_def); // Emit constructor - object_name = EscapeKeyword(struct_def.name); GenDocComment(struct_def.doc_comment, code_ptr); code += "export class "; - // TODO(7445): figure out if the export needs a namespace for ts-flat-files code += object_name; code += " {\n"; code += " bb: flatbuffers.ByteBuffer|null = null;\n"; @@ -1431,8 +1425,9 @@ class TsGenerator : public BaseGenerator { else { switch (field.value.type.base_type) { case BASE_TYPE_STRUCT: { - const auto type = EscapeKeyword( - AddImport(imports, struct_def, *field.value.type.struct_def)); + const auto type = + AddImport(imports, struct_def, *field.value.type.struct_def) + .name; GenDocComment(field.doc_comment, code_ptr); code += ConvertCase(field.name, Case::kLowerCamel); code += "(obj?:" + type + "):" + type + "|null {\n"; @@ -1810,8 +1805,7 @@ class TsGenerator : public BaseGenerator { code += "\n"; code += "static deserialize(buffer: Uint8Array):" + EscapeKeyword(name) + " {\n"; - code += " return " + - EscapeKeyword(AddImport(imports, struct_def, struct_def)) + + code += " return " + AddImport(imports, struct_def, struct_def).name + ".getRootAs" + name + "(new flatbuffers.ByteBuffer(buffer))\n"; code += "}\n"; } diff --git a/tests/TypeScriptTest.py b/tests/TypeScriptTest.py old mode 100644 new mode 100755 diff --git a/tests/flatc/bar/bar_with_ns.fbs b/tests/flatc/bar/bar_with_ns.fbs new file mode 100644 index 000000000..f5a800d07 --- /dev/null +++ b/tests/flatc/bar/bar_with_ns.fbs @@ -0,0 +1,14 @@ +include "baz/baz_with_ns.fbs"; +include "baz/baz.fbs"; + +namespace bar; + +table Bar { + baz:baz.Baz; + baz2:Baz; + foo:Foo; +} + +table Foo { + a:int; +} \ No newline at end of file diff --git a/tests/flatc/bar/baz/baz_with_ns.fbs b/tests/flatc/bar/baz/baz_with_ns.fbs new file mode 100644 index 000000000..d258413a4 --- /dev/null +++ b/tests/flatc/bar/baz/baz_with_ns.fbs @@ -0,0 +1,8 @@ +namespace baz; + +enum Baz : short { + None = 0, + Red, + Green, + Blue, +} \ No newline at end of file diff --git a/tests/flatc/flatc_ts_tests.py b/tests/flatc/flatc_ts_tests.py index 461236711..a0c7f823d 100755 --- a/tests/flatc/flatc_ts_tests.py +++ b/tests/flatc/flatc_ts_tests.py @@ -66,7 +66,7 @@ class TsTests(): assert_file_and_contents( "foo_with_ns_generated.ts", [ - "export { Bar } from './bar';", + "export { Bar } from './bar/bar';", "export { Foo } from './something/foo';", ], ) @@ -77,7 +77,7 @@ class TsTests(): "something/foo.ts", [ "export class Foo {", - "import { Bar } from '../bar';", + "import { Bar } from '../bar/bar';", ], ) @@ -142,6 +142,23 @@ class TsTests(): # The root type Foo should not be generated in its own file. assert_file_doesnt_exists("foo.ts") + def FlatFilesWithNamespace(self): + # Generate just foo with the flat files option + flatc(["--ts", "--ts-flat-files", "foo_with_ns.fbs"]) + + # Should generate a single file that imports bar as a single file, and + # exports the Foo table. + assert_file_and_contents( + "foo_with_ns_generated.ts", + [ + "import {Bar as Bar} from './bar_with_ns_generated';", + "export class Foo {", + ], + ) + + # The root type Foo should not be generated in its own file. + assert_file_doesnt_exists("foo.ts") + def FlatFilesMultipleFiles(self): # Generate both foo and bar with the flat files option flatc(["--ts", "--ts-flat-files", "foo.fbs", "bar/bar.fbs"]) @@ -194,3 +211,32 @@ class TsTests(): assert_file_doesnt_exists("foo.ts") assert_file_doesnt_exists("bar.ts") assert_file_doesnt_exists("baz.ts") + + + def ZFlatFilesGenAllWithNamespacing(self): + # Generate foo with all of its dependents with the flat files option + flatc(["--ts", "--ts-flat-files", "--gen-all", "foo_with_ns.fbs"]) + + # Should generate a single foo file + assert_file_and_contents( + "foo_with_ns_generated.ts", + # Should export each of the types within the single file + [ + "export class bar_Bar {", + "export class bar_Foo {", + "export enum Baz {", + "export enum baz_Baz {", + "export class something_Foo {" + ], + # No includes for the dependent types should be present. + doesnt_contain=[ + "import {Bar as Bar}", + "import {Baz as Baz}", + ], + ) + + # The types Foo, Bar and Baz should not be generated in their own files. + assert_file_doesnt_exists("foo.ts") + assert_file_doesnt_exists("bar.ts") + assert_file_doesnt_exists("baz.ts") + diff --git a/tests/flatc/foo.fbs b/tests/flatc/foo.fbs index 477fb9757..a2f27aab9 100644 --- a/tests/flatc/foo.fbs +++ b/tests/flatc/foo.fbs @@ -1,7 +1,9 @@ include "bar/bar.fbs"; +include "bar/bar_with_ns.fbs"; table Foo { bar:Bar; + bar2:bar.Bar; } root_type Foo; \ No newline at end of file diff --git a/tests/flatc/foo_with_ns.fbs b/tests/flatc/foo_with_ns.fbs index dd36fdc8c..c348d9b84 100644 --- a/tests/flatc/foo_with_ns.fbs +++ b/tests/flatc/foo_with_ns.fbs @@ -1,9 +1,9 @@ -include "bar/bar.fbs"; +include "bar/bar_with_ns.fbs"; namespace something; table Foo { - bar:Bar; + bar:bar.Bar; } root_type Foo; \ No newline at end of file diff --git a/tests/flatc/main.py b/tests/flatc/main.py index 1b6bee90d..656bc4698 100755 --- a/tests/flatc/main.py +++ b/tests/flatc/main.py @@ -27,3 +27,5 @@ print("{0} of {1} tests passed".format(passing, passing + failing)) if failing > 0: sys.exit(1) + +# TsTests().Base() \ No newline at end of file diff --git a/tests/monster_test_generated.ts b/tests/monster_test_generated.ts index 9e80d9199..5fd080eb4 100644 --- a/tests/monster_test_generated.ts +++ b/tests/monster_test_generated.ts @@ -1,7 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -export { Monster } from './my-game/example/monster'; -export { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from './my-game/example2/monster'; +export { Monster as MyGame_Example2_Monster, MonsterT as MyGame_Example2_MonsterT } from './my-game/example2/monster'; export { Ability, AbilityT } from './my-game/example/ability'; export { Any, unionToAny, unionListToAny } from './my-game/example/any'; export { AnyAmbiguousAliases, unionToAnyAmbiguousAliases, unionListToAnyAmbiguousAliases } from './my-game/example/any-ambiguous-aliases'; diff --git a/tests/my-game/example/ability.js b/tests/my-game/example/ability.js index 9fea3d6b4..4d7d3db72 100644 --- a/tests/my-game/example/ability.js +++ b/tests/my-game/example/ability.js @@ -24,7 +24,7 @@ export class Ability { return true; } static getFullyQualifiedName() { - return 'MyGame.Example.Ability'; + return 'MyGame_Example_Ability'; } static sizeOf() { return 8; diff --git a/tests/my-game/example/ability.ts b/tests/my-game/example/ability.ts index 805fe7b39..36b0eb810 100644 --- a/tests/my-game/example/ability.ts +++ b/tests/my-game/example/ability.ts @@ -32,7 +32,7 @@ mutate_distance(value:number):boolean { } static getFullyQualifiedName():string { - return 'MyGame.Example.Ability'; + return 'MyGame_Example_Ability'; } static sizeOf():number { diff --git a/tests/my-game/example/any-ambiguous-aliases.ts b/tests/my-game/example/any-ambiguous-aliases.ts index ff4ffa7f3..fb308fcdc 100644 --- a/tests/my-game/example/any-ambiguous-aliases.ts +++ b/tests/my-game/example/any-ambiguous-aliases.ts @@ -36,4 +36,3 @@ export function unionListToAnyAmbiguousAliases( default: return null; } } - diff --git a/tests/my-game/example/any-unique-aliases.js b/tests/my-game/example/any-unique-aliases.js index b5cc88208..98e559739 100644 --- a/tests/my-game/example/any-unique-aliases.js +++ b/tests/my-game/example/any-unique-aliases.js @@ -1,5 +1,5 @@ // automatically generated by the FlatBuffers compiler, do not modify -import { Monster as MyGameExample2Monster } from '../../my-game/example2/monster'; +import { Monster as MyGame_Example2_Monster } from '../../my-game/example2/monster'; import { Monster } from '../../my-game/example/monster'; import { TestSimpleTableWithEnum } from '../../my-game/example/test-simple-table-with-enum'; export var AnyUniqueAliases; @@ -14,7 +14,7 @@ export function unionToAnyUniqueAliases(type, accessor) { case 'NONE': return null; case 'M': return accessor(new Monster()); case 'TS': return accessor(new TestSimpleTableWithEnum()); - case 'M2': return accessor(new MyGameExample2Monster()); + case 'M2': return accessor(new MyGame_Example2_Monster()); default: return null; } } @@ -23,7 +23,7 @@ export function unionListToAnyUniqueAliases(type, accessor, index) { case 'NONE': return null; case 'M': return accessor(index, new Monster()); case 'TS': return accessor(index, new TestSimpleTableWithEnum()); - case 'M2': return accessor(index, new MyGameExample2Monster()); + case 'M2': return accessor(index, new MyGame_Example2_Monster()); default: return null; } } diff --git a/tests/my-game/example/any-unique-aliases.ts b/tests/my-game/example/any-unique-aliases.ts index 79cde0fad..7ca769f1e 100644 --- a/tests/my-game/example/any-unique-aliases.ts +++ b/tests/my-game/example/any-unique-aliases.ts @@ -1,6 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -import { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from '../../my-game/example2/monster'; +import { Monster as MyGame_Example2_Monster, MonsterT as MyGame_Example2_MonsterT } from '../../my-game/example2/monster'; import { Monster, MonsterT } from '../../my-game/example/monster'; import { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from '../../my-game/example/test-simple-table-with-enum'; @@ -14,28 +14,27 @@ export enum AnyUniqueAliases { export function unionToAnyUniqueAliases( type: AnyUniqueAliases, - accessor: (obj:Monster|MyGameExample2Monster|TestSimpleTableWithEnum) => Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null -): Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null { + accessor: (obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null +): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null { switch(AnyUniqueAliases[type]) { case 'NONE': return null; case 'M': return accessor(new Monster())! as Monster; case 'TS': return accessor(new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; - case 'M2': return accessor(new MyGameExample2Monster())! as MyGameExample2Monster; + case 'M2': return accessor(new MyGame_Example2_Monster())! as MyGame_Example2_Monster; default: return null; } } export function unionListToAnyUniqueAliases( type: AnyUniqueAliases, - accessor: (index: number, obj:Monster|MyGameExample2Monster|TestSimpleTableWithEnum) => Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null, + accessor: (index: number, obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null, index: number -): Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null { +): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null { switch(AnyUniqueAliases[type]) { case 'NONE': return null; case 'M': return accessor(index, new Monster())! as Monster; case 'TS': return accessor(index, new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; - case 'M2': return accessor(index, new MyGameExample2Monster())! as MyGameExample2Monster; + case 'M2': return accessor(index, new MyGame_Example2_Monster())! as MyGame_Example2_Monster; default: return null; } } - diff --git a/tests/my-game/example/any.js b/tests/my-game/example/any.js index 7349c076e..47bfb2511 100644 --- a/tests/my-game/example/any.js +++ b/tests/my-game/example/any.js @@ -1,5 +1,5 @@ // automatically generated by the FlatBuffers compiler, do not modify -import { Monster as MyGameExample2Monster } from '../../my-game/example2/monster'; +import { Monster as MyGame_Example2_Monster } from '../../my-game/example2/monster'; import { Monster } from '../../my-game/example/monster'; import { TestSimpleTableWithEnum } from '../../my-game/example/test-simple-table-with-enum'; export var Any; @@ -14,7 +14,7 @@ export function unionToAny(type, accessor) { case 'NONE': return null; case 'Monster': return accessor(new Monster()); case 'TestSimpleTableWithEnum': return accessor(new TestSimpleTableWithEnum()); - case 'MyGame_Example2_Monster': return accessor(new MyGameExample2Monster()); + case 'MyGame_Example2_Monster': return accessor(new MyGame_Example2_Monster()); default: return null; } } @@ -23,7 +23,7 @@ export function unionListToAny(type, accessor, index) { 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 MyGameExample2Monster()); + case 'MyGame_Example2_Monster': return accessor(index, new MyGame_Example2_Monster()); default: return null; } } diff --git a/tests/my-game/example/any.ts b/tests/my-game/example/any.ts index 19eceaeff..f7bb94fe3 100644 --- a/tests/my-game/example/any.ts +++ b/tests/my-game/example/any.ts @@ -1,6 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -import { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from '../../my-game/example2/monster'; +import { Monster as MyGame_Example2_Monster, MonsterT as MyGame_Example2_MonsterT } from '../../my-game/example2/monster'; import { Monster, MonsterT } from '../../my-game/example/monster'; import { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from '../../my-game/example/test-simple-table-with-enum'; @@ -14,28 +14,27 @@ export enum Any { export function unionToAny( type: Any, - accessor: (obj:Monster|MyGameExample2Monster|TestSimpleTableWithEnum) => Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null -): Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null { + accessor: (obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null +): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null { switch(Any[type]) { case 'NONE': return null; case 'Monster': return accessor(new Monster())! as Monster; case 'TestSimpleTableWithEnum': return accessor(new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; - case 'MyGame_Example2_Monster': return accessor(new MyGameExample2Monster())! as MyGameExample2Monster; + case 'MyGame_Example2_Monster': return accessor(new MyGame_Example2_Monster())! as MyGame_Example2_Monster; default: return null; } } export function unionListToAny( type: Any, - accessor: (index: number, obj:Monster|MyGameExample2Monster|TestSimpleTableWithEnum) => Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null, + accessor: (index: number, obj:Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum) => Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null, index: number -): Monster|MyGameExample2Monster|TestSimpleTableWithEnum|null { +): Monster|MyGame_Example2_Monster|TestSimpleTableWithEnum|null { switch(Any[type]) { case 'NONE': return null; case 'Monster': return accessor(index, new Monster())! as Monster; case 'TestSimpleTableWithEnum': return accessor(index, new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; - case 'MyGame_Example2_Monster': return accessor(index, new MyGameExample2Monster())! as MyGameExample2Monster; + case 'MyGame_Example2_Monster': return accessor(index, new MyGame_Example2_Monster())! as MyGame_Example2_Monster; default: return null; } } - diff --git a/tests/my-game/example/color.ts b/tests/my-game/example/color.ts index b9520a2c0..8ce58da67 100644 --- a/tests/my-game/example/color.ts +++ b/tests/my-game/example/color.ts @@ -17,4 +17,3 @@ export enum Color { */ Blue = 8 } - diff --git a/tests/my-game/example/long-enum.ts b/tests/my-game/example/long-enum.ts index 76e3a77b6..31ea18805 100644 --- a/tests/my-game/example/long-enum.ts +++ b/tests/my-game/example/long-enum.ts @@ -5,4 +5,3 @@ export enum LongEnum { LongTwo = '4', LongBig = '1099511627776' } - diff --git a/tests/my-game/example/monster.js b/tests/my-game/example/monster.js index 3c3c23be7..f9c8cca53 100644 --- a/tests/my-game/example/monster.js +++ b/tests/my-game/example/monster.js @@ -527,7 +527,7 @@ export class Monster { return true; } static getFullyQualifiedName() { - return 'MyGame.Example.Monster'; + return 'MyGame_Example_Monster'; } static startMonster(builder) { builder.startObject(54); diff --git a/tests/my-game/example/monster.ts b/tests/my-game/example/monster.ts index ddd99bcf0..d65b7c3a9 100644 --- a/tests/my-game/example/monster.ts +++ b/tests/my-game/example/monster.ts @@ -2,7 +2,7 @@ import * as flatbuffers from 'flatbuffers'; -import { Monster as MyGameExample2Monster, MonsterT as MyGameExample2MonsterT } from '../../my-game/example2/monster'; +import { Monster as MyGame_Example2_Monster, MonsterT as MyGame_Example2_MonsterT } from '../../my-game/example2/monster'; import { Ability, AbilityT } from '../../my-game/example/ability'; import { Any, unionToAny, unionListToAny } from '../../my-game/example/any'; import { AnyAmbiguousAliases, unionToAnyAmbiguousAliases, unionListToAnyAmbiguousAliases } from '../../my-game/example/any-ambiguous-aliases'; @@ -684,7 +684,7 @@ mutate_long_enum_normal_default(value:bigint):boolean { } static getFullyQualifiedName():string { - return 'MyGame.Example.Monster'; + return 'MyGame_Example_Monster'; } static startMonster(builder:flatbuffers.Builder) { @@ -1296,7 +1296,7 @@ constructor( public inventory: (number)[] = [], public color: Color = Color.Blue, public testType: Any = Any.NONE, - public test: MonsterT|MyGameExample2MonsterT|TestSimpleTableWithEnumT|null = null, + public test: MonsterT|MyGame_Example2_MonsterT|TestSimpleTableWithEnumT|null = null, public test4: (TestT)[] = [], public testarrayofstring: (string)[] = [], public testarrayoftables: (MonsterT)[] = [], @@ -1332,7 +1332,7 @@ constructor( public nonOwningReference: bigint = BigInt('0'), public vectorOfNonOwningReferences: (bigint)[] = [], public anyUniqueType: AnyUniqueAliases = AnyUniqueAliases.NONE, - public anyUnique: MonsterT|MyGameExample2MonsterT|TestSimpleTableWithEnumT|null = null, + public anyUnique: MonsterT|MyGame_Example2_MonsterT|TestSimpleTableWithEnumT|null = null, public anyAmbiguousType: AnyAmbiguousAliases = AnyAmbiguousAliases.NONE, public anyAmbiguous: MonsterT|null = null, public vectorOfEnums: (Color)[] = [], diff --git a/tests/my-game/example/race.ts b/tests/my-game/example/race.ts index 9c66d7a72..8cb9654ae 100644 --- a/tests/my-game/example/race.ts +++ b/tests/my-game/example/race.ts @@ -6,4 +6,3 @@ export enum Race { Dwarf = 1, Elf = 2 } - diff --git a/tests/my-game/example/referrable.js b/tests/my-game/example/referrable.js index 0370768dd..367034b06 100644 --- a/tests/my-game/example/referrable.js +++ b/tests/my-game/example/referrable.js @@ -30,7 +30,7 @@ export class Referrable { return true; } static getFullyQualifiedName() { - return 'MyGame.Example.Referrable'; + return 'MyGame_Example_Referrable'; } static startReferrable(builder) { builder.startObject(1); diff --git a/tests/my-game/example/referrable.ts b/tests/my-game/example/referrable.ts index 745800e7e..ec0298003 100644 --- a/tests/my-game/example/referrable.ts +++ b/tests/my-game/example/referrable.ts @@ -39,7 +39,7 @@ mutate_id(value:bigint):boolean { } static getFullyQualifiedName():string { - return 'MyGame.Example.Referrable'; + return 'MyGame_Example_Referrable'; } static startReferrable(builder:flatbuffers.Builder) { diff --git a/tests/my-game/example/stat.js b/tests/my-game/example/stat.js index 46eec4344..43b569f4e 100644 --- a/tests/my-game/example/stat.js +++ b/tests/my-game/example/stat.js @@ -46,7 +46,7 @@ export class Stat { return true; } static getFullyQualifiedName() { - return 'MyGame.Example.Stat'; + return 'MyGame_Example_Stat'; } static startStat(builder) { builder.startObject(3); diff --git a/tests/my-game/example/stat.ts b/tests/my-game/example/stat.ts index 1ba85a4f4..e45259950 100644 --- a/tests/my-game/example/stat.ts +++ b/tests/my-game/example/stat.ts @@ -62,7 +62,7 @@ mutate_count(value:number):boolean { } static getFullyQualifiedName():string { - return 'MyGame.Example.Stat'; + return 'MyGame_Example_Stat'; } static startStat(builder:flatbuffers.Builder) { diff --git a/tests/my-game/example/struct-of-structs-of-structs.ts b/tests/my-game/example/struct-of-structs-of-structs.ts index 20d6c739c..afe869fa7 100644 --- a/tests/my-game/example/struct-of-structs-of-structs.ts +++ b/tests/my-game/example/struct-of-structs-of-structs.ts @@ -19,7 +19,7 @@ a(obj?:StructOfStructs):StructOfStructs|null { } static getFullyQualifiedName():string { - return 'MyGame.Example.StructOfStructsOfStructs'; + return 'MyGame_Example_StructOfStructsOfStructs'; } static sizeOf():number { diff --git a/tests/my-game/example/struct-of-structs.js b/tests/my-game/example/struct-of-structs.js index f265ba508..09c79108f 100644 --- a/tests/my-game/example/struct-of-structs.js +++ b/tests/my-game/example/struct-of-structs.js @@ -21,7 +21,7 @@ export class StructOfStructs { return (obj || new Ability()).__init(this.bb_pos + 12, this.bb); } static getFullyQualifiedName() { - return 'MyGame.Example.StructOfStructs'; + return 'MyGame_Example_StructOfStructs'; } static sizeOf() { return 20; diff --git a/tests/my-game/example/struct-of-structs.ts b/tests/my-game/example/struct-of-structs.ts index c4a7c48bd..0cb87ded5 100644 --- a/tests/my-game/example/struct-of-structs.ts +++ b/tests/my-game/example/struct-of-structs.ts @@ -28,7 +28,7 @@ c(obj?:Ability):Ability|null { } static getFullyQualifiedName():string { - return 'MyGame.Example.StructOfStructs'; + return 'MyGame_Example_StructOfStructs'; } static sizeOf():number { diff --git a/tests/my-game/example/test-simple-table-with-enum.js b/tests/my-game/example/test-simple-table-with-enum.js index b56bda44d..a31d011ad 100644 --- a/tests/my-game/example/test-simple-table-with-enum.js +++ b/tests/my-game/example/test-simple-table-with-enum.js @@ -31,7 +31,7 @@ export class TestSimpleTableWithEnum { return true; } static getFullyQualifiedName() { - return 'MyGame.Example.TestSimpleTableWithEnum'; + return 'MyGame_Example_TestSimpleTableWithEnum'; } static startTestSimpleTableWithEnum(builder) { builder.startObject(1); diff --git a/tests/my-game/example/test-simple-table-with-enum.ts b/tests/my-game/example/test-simple-table-with-enum.ts index a34beecd0..86a19aa50 100644 --- a/tests/my-game/example/test-simple-table-with-enum.ts +++ b/tests/my-game/example/test-simple-table-with-enum.ts @@ -40,7 +40,7 @@ mutate_color(value:Color):boolean { } static getFullyQualifiedName():string { - return 'MyGame.Example.TestSimpleTableWithEnum'; + return 'MyGame_Example_TestSimpleTableWithEnum'; } static startTestSimpleTableWithEnum(builder:flatbuffers.Builder) { diff --git a/tests/my-game/example/test.js b/tests/my-game/example/test.js index ba6ebfb7a..9c43619e2 100644 --- a/tests/my-game/example/test.js +++ b/tests/my-game/example/test.js @@ -24,7 +24,7 @@ export class Test { return true; } static getFullyQualifiedName() { - return 'MyGame.Example.Test'; + return 'MyGame_Example_Test'; } static sizeOf() { return 4; diff --git a/tests/my-game/example/test.ts b/tests/my-game/example/test.ts index dc62c8cde..b3d84eece 100644 --- a/tests/my-game/example/test.ts +++ b/tests/my-game/example/test.ts @@ -32,7 +32,7 @@ mutate_b(value:number):boolean { } static getFullyQualifiedName():string { - return 'MyGame.Example.Test'; + return 'MyGame_Example_Test'; } static sizeOf():number { diff --git a/tests/my-game/example/type-aliases.js b/tests/my-game/example/type-aliases.js index f26f226c8..a4b5f89e3 100644 --- a/tests/my-game/example/type-aliases.js +++ b/tests/my-game/example/type-aliases.js @@ -162,7 +162,7 @@ export class TypeAliases { 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'; + return 'MyGame_Example_TypeAliases'; } static startTypeAliases(builder) { builder.startObject(12); diff --git a/tests/my-game/example/type-aliases.ts b/tests/my-game/example/type-aliases.ts index 1a2f45636..805c8cf3f 100644 --- a/tests/my-game/example/type-aliases.ts +++ b/tests/my-game/example/type-aliases.ts @@ -213,7 +213,7 @@ vf64Array():Float64Array|null { } static getFullyQualifiedName():string { - return 'MyGame.Example.TypeAliases'; + return 'MyGame_Example_TypeAliases'; } static startTypeAliases(builder:flatbuffers.Builder) { diff --git a/tests/my-game/example/vec3.js b/tests/my-game/example/vec3.js index 102ce4ada..82b2eab02 100644 --- a/tests/my-game/example/vec3.js +++ b/tests/my-game/example/vec3.js @@ -49,7 +49,7 @@ export class Vec3 { return (obj || new Test()).__init(this.bb_pos + 26, this.bb); } static getFullyQualifiedName() { - return 'MyGame.Example.Vec3'; + return 'MyGame_Example_Vec3'; } static sizeOf() { return 32; diff --git a/tests/my-game/example/vec3.ts b/tests/my-game/example/vec3.ts index 7a2f25a15..3c692e28d 100644 --- a/tests/my-game/example/vec3.ts +++ b/tests/my-game/example/vec3.ts @@ -65,7 +65,7 @@ test3(obj?:Test):Test|null { } static getFullyQualifiedName():string { - return 'MyGame.Example.Vec3'; + return 'MyGame_Example_Vec3'; } static sizeOf():number { diff --git a/tests/my-game/example2/monster.js b/tests/my-game/example2/monster.js index 17f02b11e..f50a2c85a 100644 --- a/tests/my-game/example2/monster.js +++ b/tests/my-game/example2/monster.js @@ -18,7 +18,7 @@ export class Monster { return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } static getFullyQualifiedName() { - return 'MyGame.Example2.Monster'; + return 'MyGame_Example2_Monster'; } static startMonster(builder) { builder.startObject(0); diff --git a/tests/my-game/example2/monster.ts b/tests/my-game/example2/monster.ts index 2d52f6c60..7240476be 100644 --- a/tests/my-game/example2/monster.ts +++ b/tests/my-game/example2/monster.ts @@ -23,7 +23,7 @@ static getSizePrefixedRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:Monster):Mon } static getFullyQualifiedName():string { - return 'MyGame.Example2.Monster'; + return 'MyGame_Example2_Monster'; } static startMonster(builder:flatbuffers.Builder) { diff --git a/tests/my-game/in-parent-namespace.js b/tests/my-game/in-parent-namespace.js index 48817411b..24b0ed787 100644 --- a/tests/my-game/in-parent-namespace.js +++ b/tests/my-game/in-parent-namespace.js @@ -18,7 +18,7 @@ export class InParentNamespace { return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } static getFullyQualifiedName() { - return 'MyGame.InParentNamespace'; + return 'MyGame_InParentNamespace'; } static startInParentNamespace(builder) { builder.startObject(0); diff --git a/tests/my-game/in-parent-namespace.ts b/tests/my-game/in-parent-namespace.ts index 1822e4d34..0de94df5e 100644 --- a/tests/my-game/in-parent-namespace.ts +++ b/tests/my-game/in-parent-namespace.ts @@ -23,7 +23,7 @@ static getSizePrefixedRootAsInParentNamespace(bb:flatbuffers.ByteBuffer, obj?:In } static getFullyQualifiedName():string { - return 'MyGame.InParentNamespace'; + return 'MyGame_InParentNamespace'; } static startInParentNamespace(builder:flatbuffers.Builder) { diff --git a/tests/optional-scalars/optional-byte.ts b/tests/optional-scalars/optional-byte.ts index 65e7105be..f4db265e2 100644 --- a/tests/optional-scalars/optional-byte.ts +++ b/tests/optional-scalars/optional-byte.ts @@ -5,4 +5,3 @@ export enum OptionalByte { One = 1, Two = 2 } - diff --git a/tests/optional_scalars_generated.ts b/tests/optional_scalars_generated.ts index 9eb0b31a9..4a83c439f 100644 --- a/tests/optional_scalars_generated.ts +++ b/tests/optional_scalars_generated.ts @@ -1,4 +1,4 @@ // automatically generated by the FlatBuffers compiler, do not modify -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/ts-flat-files/monster_test_generated.ts b/tests/ts/ts-flat-files/monster_test_generated.ts new file mode 100644 index 000000000..7bb8e23a4 --- /dev/null +++ b/tests/ts/ts-flat-files/monster_test_generated.ts @@ -0,0 +1,1830 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +import * as flatbuffers from 'flatbuffers'; + +export enum MyGame_OtherNameSpace_FromInclude { + IncludeVal = '0' +} + +/** + * Composite components of Monster color. + */ +export enum MyGame_Example_Color { + Red = 1, + + /** + * \brief color Green + * Green is bit_flag with value (1u << 1) + */ + Green = 2, + + /** + * \brief color Blue (1u << 3) + */ + Blue = 8 +} + +export enum MyGame_Example_Race { + None = -1, + Human = 0, + Dwarf = 1, + Elf = 2 +} + +export enum MyGame_Example_LongEnum { + LongOne = '2', + LongTwo = '4', + LongBig = '1099511627776' +} + +export enum MyGame_Example_Any { + NONE = 0, + Monster = 1, + TestSimpleTableWithEnum = 2, + MyGame_Example2_Monster = 3 +} + +export function unionToAny( + type: MyGame_Example_Any, + accessor: (obj:Monster|TestSimpleTableWithEnum) => Monster|TestSimpleTableWithEnum|null +): Monster|TestSimpleTableWithEnum|null { + switch(Any[type]) { + case 'NONE': return null; + case 'Monster': return accessor(new Monster())! as Monster; + case 'TestSimpleTableWithEnum': return accessor(new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; + case 'MyGame_Example2_Monster': return accessor(new Monster())! as Monster; + default: return null; + } +} + +export function unionListToAny( + type: MyGame_Example_Any, + accessor: (index: number, obj:Monster|TestSimpleTableWithEnum) => Monster|TestSimpleTableWithEnum|null, + index: number +): Monster|TestSimpleTableWithEnum|null { + switch(Any[type]) { + case 'NONE': return null; + case 'Monster': return accessor(index, new Monster())! as Monster; + case 'TestSimpleTableWithEnum': return accessor(index, new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; + case 'MyGame_Example2_Monster': return accessor(index, new Monster())! as Monster; + default: return null; + } +} + +export enum MyGame_Example_AnyUniqueAliases { + NONE = 0, + M = 1, + TS = 2, + M2 = 3 +} + +export function unionToAnyUniqueAliases( + type: MyGame_Example_AnyUniqueAliases, + accessor: (obj:Monster|TestSimpleTableWithEnum) => Monster|TestSimpleTableWithEnum|null +): Monster|TestSimpleTableWithEnum|null { + switch(AnyUniqueAliases[type]) { + case 'NONE': return null; + case 'M': return accessor(new Monster())! as Monster; + case 'TS': return accessor(new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; + case 'M2': return accessor(new Monster())! as Monster; + default: return null; + } +} + +export function unionListToAnyUniqueAliases( + type: MyGame_Example_AnyUniqueAliases, + accessor: (index: number, obj:Monster|TestSimpleTableWithEnum) => Monster|TestSimpleTableWithEnum|null, + index: number +): Monster|TestSimpleTableWithEnum|null { + switch(AnyUniqueAliases[type]) { + case 'NONE': return null; + case 'M': return accessor(index, new Monster())! as Monster; + case 'TS': return accessor(index, new TestSimpleTableWithEnum())! as TestSimpleTableWithEnum; + case 'M2': return accessor(index, new Monster())! as Monster; + default: return null; + } +} + +export enum MyGame_Example_AnyAmbiguousAliases { + NONE = 0, + M1 = 1, + M2 = 2, + M3 = 3 +} + +export function unionToAnyAmbiguousAliases( + type: MyGame_Example_AnyAmbiguousAliases, + accessor: (obj:Monster) => Monster|null +): Monster|null { + switch(AnyAmbiguousAliases[type]) { + case 'NONE': return null; + case 'M1': return accessor(new Monster())! as Monster; + case 'M2': return accessor(new Monster())! as Monster; + case 'M3': return accessor(new Monster())! as Monster; + default: return null; + } +} + +export function unionListToAnyAmbiguousAliases( + type: MyGame_Example_AnyAmbiguousAliases, + accessor: (index: number, obj:Monster) => Monster|null, + index: number +): Monster|null { + switch(AnyAmbiguousAliases[type]) { + case 'NONE': return null; + case 'M1': return accessor(index, new Monster())! as Monster; + case 'M2': return accessor(index, new Monster())! as Monster; + case 'M3': return accessor(index, new Monster())! as Monster; + default: return null; + } +} + +export class MyGame_OtherNameSpace_Unused { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_OtherNameSpace_Unused { + this.bb_pos = i; + this.bb = bb; + return this; +} + +a():number { + return this.bb!.readInt32(this.bb_pos); +} + +static sizeOf():number { + return 4; +} + +static createUnused(builder:flatbuffers.Builder, a: number):flatbuffers.Offset { + builder.prep(4, 4); + builder.writeInt32(a); + return builder.offset(); +} + +} + +export class MyGame_OtherNameSpace_TableB { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_OtherNameSpace_TableB { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsTableB(bb:flatbuffers.ByteBuffer, obj?:MyGame_OtherNameSpace_TableB):MyGame_OtherNameSpace_TableB { + return (obj || new MyGame_OtherNameSpace_TableB()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsTableB(bb:flatbuffers.ByteBuffer, obj?:MyGame_OtherNameSpace_TableB):MyGame_OtherNameSpace_TableB { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_OtherNameSpace_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; +} + +static startTableB(builder:flatbuffers.Builder) { + builder.startObject(1); +} + +static addA(builder:flatbuffers.Builder, aOffset:flatbuffers.Offset) { + builder.addFieldOffset(0, aOffset, 0); +} + +static endTableB(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createTableB(builder:flatbuffers.Builder, aOffset:flatbuffers.Offset):flatbuffers.Offset { + MyGame_OtherNameSpace_TableB.startTableB(builder); + MyGame_OtherNameSpace_TableB.addA(builder, aOffset); + return MyGame_OtherNameSpace_TableB.endTableB(builder); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):TableB { + return TableB.getRootAsTableB(new flatbuffers.ByteBuffer(buffer)) +} +} + +export class TableA { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 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 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; +} + +static startTableA(builder:flatbuffers.Builder) { + builder.startObject(1); +} + +static addB(builder:flatbuffers.Builder, bOffset:flatbuffers.Offset) { + builder.addFieldOffset(0, bOffset, 0); +} + +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); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):TableA { + return TableA.getRootAsTableA(new flatbuffers.ByteBuffer(buffer)) +} +} + +export class MyGame_InParentNamespace { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_InParentNamespace { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsInParentNamespace(bb:flatbuffers.ByteBuffer, obj?:MyGame_InParentNamespace):MyGame_InParentNamespace { + return (obj || new MyGame_InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsInParentNamespace(bb:flatbuffers.ByteBuffer, obj?:MyGame_InParentNamespace):MyGame_InParentNamespace { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static startInParentNamespace(builder:flatbuffers.Builder) { + builder.startObject(0); +} + +static endInParentNamespace(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createInParentNamespace(builder:flatbuffers.Builder):flatbuffers.Offset { + MyGame_InParentNamespace.startInParentNamespace(builder); + return MyGame_InParentNamespace.endInParentNamespace(builder); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):InParentNamespace { + return InParentNamespace.getRootAsInParentNamespace(new flatbuffers.ByteBuffer(buffer)) +} +} + +export class MyGame_Example2_Monster { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example2_Monster { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example2_Monster):MyGame_Example2_Monster { + return (obj || new MyGame_Example2_Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example2_Monster):MyGame_Example2_Monster { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_Example2_Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static startMonster(builder:flatbuffers.Builder) { + builder.startObject(0); +} + +static endMonster(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createMonster(builder:flatbuffers.Builder):flatbuffers.Offset { + MyGame_Example2_Monster.startMonster(builder); + return MyGame_Example2_Monster.endMonster(builder); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):Monster { + return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer)) +} +} + +export class MyGame_Example_Test { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_Test { + this.bb_pos = i; + this.bb = bb; + return this; +} + +a():number { + return this.bb!.readInt16(this.bb_pos); +} + +b():number { + return this.bb!.readInt8(this.bb_pos + 2); +} + +static sizeOf():number { + return 4; +} + +static createTest(builder:flatbuffers.Builder, a: number, b: number):flatbuffers.Offset { + builder.prep(2, 4); + builder.pad(1); + builder.writeInt8(b); + builder.writeInt16(a); + return builder.offset(); +} + +} + +export class MyGame_Example_TestSimpleTableWithEnum { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_TestSimpleTableWithEnum { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_TestSimpleTableWithEnum):MyGame_Example_TestSimpleTableWithEnum { + return (obj || new MyGame_Example_TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_TestSimpleTableWithEnum):MyGame_Example_TestSimpleTableWithEnum { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_Example_TestSimpleTableWithEnum()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +color():Color { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : Color.Green; +} + +static startTestSimpleTableWithEnum(builder:flatbuffers.Builder) { + builder.startObject(1); +} + +static addColor(builder:flatbuffers.Builder, color:Color) { + builder.addFieldInt8(0, color, Color.Green); +} + +static endTestSimpleTableWithEnum(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createTestSimpleTableWithEnum(builder:flatbuffers.Builder, color:Color):flatbuffers.Offset { + MyGame_Example_TestSimpleTableWithEnum.startTestSimpleTableWithEnum(builder); + MyGame_Example_TestSimpleTableWithEnum.addColor(builder, color); + return MyGame_Example_TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):TestSimpleTableWithEnum { + return TestSimpleTableWithEnum.getRootAsTestSimpleTableWithEnum(new flatbuffers.ByteBuffer(buffer)) +} +} + +export class MyGame_Example_Vec3 { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_Vec3 { + this.bb_pos = i; + this.bb = bb; + return this; +} + +x():number { + return this.bb!.readFloat32(this.bb_pos); +} + +y():number { + return this.bb!.readFloat32(this.bb_pos + 4); +} + +z():number { + return this.bb!.readFloat32(this.bb_pos + 8); +} + +test1():number { + return this.bb!.readFloat64(this.bb_pos + 16); +} + +test2():Color { + return this.bb!.readUint8(this.bb_pos + 24); +} + +test3(obj?:Test):Test|null { + return (obj || new Test()).__init(this.bb_pos + 26, this.bb!); +} + +static sizeOf():number { + return 32; +} + +static createVec3(builder:flatbuffers.Builder, x: number, y: number, z: number, test1: number, test2: Color, test3_a: number, test3_b: number):flatbuffers.Offset { + 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(); +} + +} + +export class MyGame_Example_Ability { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_Ability { + this.bb_pos = i; + this.bb = bb; + return this; +} + +id():number { + return this.bb!.readUint32(this.bb_pos); +} + +distance():number { + return this.bb!.readUint32(this.bb_pos + 4); +} + +static sizeOf():number { + return 8; +} + +static createAbility(builder:flatbuffers.Builder, id: number, distance: number):flatbuffers.Offset { + builder.prep(4, 8); + builder.writeInt32(distance); + builder.writeInt32(id); + return builder.offset(); +} + +} + +export class MyGame_Example_StructOfStructs { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_StructOfStructs { + this.bb_pos = i; + this.bb = bb; + return this; +} + +a(obj?:Ability):Ability|null { + return (obj || new Ability()).__init(this.bb_pos, this.bb!); +} + +b(obj?:Test):Test|null { + return (obj || new Test()).__init(this.bb_pos + 8, this.bb!); +} + +c(obj?:Ability):Ability|null { + return (obj || new Ability()).__init(this.bb_pos + 12, this.bb!); +} + +static sizeOf():number { + return 20; +} + +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 { + 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(); +} + +} + +export class MyGame_Example_StructOfStructsOfStructs { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_StructOfStructsOfStructs { + this.bb_pos = i; + this.bb = bb; + return this; +} + +a(obj?:StructOfStructs):StructOfStructs|null { + return (obj || new StructOfStructs()).__init(this.bb_pos, this.bb!); +} + +static sizeOf():number { + return 20; +} + +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 { + 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(); +} + +} + +export class MyGame_Example_Stat { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_Stat { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsStat(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_Stat):MyGame_Example_Stat { + return (obj || new MyGame_Example_Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsStat(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_Stat):MyGame_Example_Stat { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_Example_Stat()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +id():string|null +id(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +id(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; +} + +val():bigint { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); +} + +count():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; +} + +static startStat(builder:flatbuffers.Builder) { + builder.startObject(3); +} + +static addId(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset) { + builder.addFieldOffset(0, idOffset, 0); +} + +static addVal(builder:flatbuffers.Builder, val:bigint) { + builder.addFieldInt64(1, val, BigInt('0')); +} + +static addCount(builder:flatbuffers.Builder, count:number) { + builder.addFieldInt16(2, count, 0); +} + +static endStat(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createStat(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset, val:bigint, count:number):flatbuffers.Offset { + MyGame_Example_Stat.startStat(builder); + MyGame_Example_Stat.addId(builder, idOffset); + MyGame_Example_Stat.addVal(builder, val); + MyGame_Example_Stat.addCount(builder, count); + return MyGame_Example_Stat.endStat(builder); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):Stat { + return Stat.getRootAsStat(new flatbuffers.ByteBuffer(buffer)) +} +} + +export class MyGame_Example_Referrable { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_Referrable { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsReferrable(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_Referrable):MyGame_Example_Referrable { + return (obj || new MyGame_Example_Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsReferrable(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_Referrable):MyGame_Example_Referrable { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_Example_Referrable()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +id():bigint { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +static startReferrable(builder:flatbuffers.Builder) { + builder.startObject(1); +} + +static addId(builder:flatbuffers.Builder, id:bigint) { + builder.addFieldInt64(0, id, BigInt('0')); +} + +static endReferrable(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return offset; +} + +static createReferrable(builder:flatbuffers.Builder, id:bigint):flatbuffers.Offset { + MyGame_Example_Referrable.startReferrable(builder); + MyGame_Example_Referrable.addId(builder, id); + return MyGame_Example_Referrable.endReferrable(builder); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):Referrable { + return Referrable.getRootAsReferrable(new flatbuffers.ByteBuffer(buffer)) +} +} + +/** + * an example documentation comment: "monster object" + */ +export class MyGame_Example_Monster { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_Monster { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_Monster):MyGame_Example_Monster { + return (obj || new MyGame_Example_Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_Monster):MyGame_Example_Monster { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_Example_Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static bufferHasIdentifier(bb:flatbuffers.ByteBuffer):boolean { + return bb.__has_identifier('MONS'); +} + +pos(obj?:Vec3):Vec3|null { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? (obj || new Vec3()).__init(this.bb_pos + offset, this.bb!) : null; +} + +mana():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : 150; +} + +hp():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : 100; +} + +name():string|null +name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null +name(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; +} + +inventory(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0; +} + +inventoryLength():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +inventoryArray():Uint8Array|null { + 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():Color { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : Color.Blue; +} + +testType():Any { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : Any.NONE; +} + +test(obj:any):any|null { + const offset = this.bb!.__offset(this.bb_pos, 20); + return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null; +} + +test4(index: number, obj?:Test):Test|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 22); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +testarrayofstring(index: number):string +testarrayofstring(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +testarrayofstring(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; +} + +testarrayofstringLength():number { + 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: number, obj?:Monster):Monster|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 26); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +enemy(obj?:Monster):Monster|null { + 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: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 30); + return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0; +} + +testnestedflatbufferLength():number { + const offset = this.bb!.__offset(this.bb_pos, 30); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +testnestedflatbufferArray():Uint8Array|null { + 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?:Stat):Stat|null { + 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():boolean { + const offset = this.bb!.__offset(this.bb_pos, 34); + return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false; +} + +testhashs32Fnv1():number { + const offset = this.bb!.__offset(this.bb_pos, 36); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +testhashu32Fnv1():number { + const offset = this.bb!.__offset(this.bb_pos, 38); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; +} + +testhashs64Fnv1():bigint { + const offset = this.bb!.__offset(this.bb_pos, 40); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); +} + +testhashu64Fnv1():bigint { + const offset = this.bb!.__offset(this.bb_pos, 42); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +testhashs32Fnv1a():number { + const offset = this.bb!.__offset(this.bb_pos, 44); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +testhashu32Fnv1a():number { + const offset = this.bb!.__offset(this.bb_pos, 46); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; +} + +testhashs64Fnv1a():bigint { + const offset = this.bb!.__offset(this.bb_pos, 48); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); +} + +testhashu64Fnv1a():bigint { + const offset = this.bb!.__offset(this.bb_pos, 50); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +testarrayofbools(index: number):boolean|null { + const offset = this.bb!.__offset(this.bb_pos, 52); + return offset ? !!this.bb!.readInt8(this.bb!.__vector(this.bb_pos + offset) + index) : false; +} + +testarrayofboolsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 52); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +testarrayofboolsArray():Int8Array|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 54); + return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 3.14159; +} + +testf2():number { + const offset = this.bb!.__offset(this.bb_pos, 56); + return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 3.0; +} + +testf3():number { + const offset = this.bb!.__offset(this.bb_pos, 58); + return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0; +} + +testarrayofstring2(index: number):string +testarrayofstring2(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +testarrayofstring2(index: number,optionalEncoding?:any):string|Uint8Array|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 60); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +testarrayofsortedstruct(index: number, obj?:Ability):Ability|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 62); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +flex(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 64); + return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0; +} + +flexLength():number { + const offset = this.bb!.__offset(this.bb_pos, 64); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +flexArray():Uint8Array|null { + 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: number, obj?:Test):Test|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 66); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +vectorOfLongs(index: number):bigint|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 68); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +vectorOfDoubles(index: number):number|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 70); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +vectorOfDoublesArray():Float64Array|null { + 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?:InParentNamespace):InParentNamespace|null { + 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: number, obj?:Referrable):Referrable|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 74); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +singleWeakReference():bigint { + const offset = this.bb!.__offset(this.bb_pos, 76); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +vectorOfWeakReferences(index: number):bigint|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 78); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +vectorOfStrongReferrables(index: number, obj?:Referrable):Referrable|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 80); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +coOwningReference():bigint { + const offset = this.bb!.__offset(this.bb_pos, 82); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +vectorOfCoOwningReferences(index: number):bigint|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 84); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +nonOwningReference():bigint { + const offset = this.bb!.__offset(this.bb_pos, 86); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +vectorOfNonOwningReferences(index: number):bigint|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 88); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +anyUniqueType():AnyUniqueAliases { + const offset = this.bb!.__offset(this.bb_pos, 90); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : AnyUniqueAliases.NONE; +} + +anyUnique(obj:any):any|null { + const offset = this.bb!.__offset(this.bb_pos, 92); + return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null; +} + +anyAmbiguousType():AnyAmbiguousAliases { + const offset = this.bb!.__offset(this.bb_pos, 94); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : AnyAmbiguousAliases.NONE; +} + +anyAmbiguous(obj:any):any|null { + const offset = this.bb!.__offset(this.bb_pos, 96); + return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null; +} + +vectorOfEnums(index: number):Color|null { + const offset = this.bb!.__offset(this.bb_pos, 98); + return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0; +} + +vectorOfEnumsLength():number { + const offset = this.bb!.__offset(this.bb_pos, 98); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +vectorOfEnumsArray():Uint8Array|null { + 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():Race { + const offset = this.bb!.__offset(this.bb_pos, 100); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : Race.None; +} + +testrequirednestedflatbuffer(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 102); + return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0; +} + +testrequirednestedflatbufferLength():number { + const offset = this.bb!.__offset(this.bb_pos, 102); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +testrequirednestedflatbufferArray():Uint8Array|null { + 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: number, obj?:Stat):Stat|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 104); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +nativeInline(obj?:Test):Test|null { + const offset = this.bb!.__offset(this.bb_pos, 106); + return offset ? (obj || new Test()).__init(this.bb_pos + offset, this.bb!) : null; +} + +longEnumNonEnumDefault():bigint { + const offset = this.bb!.__offset(this.bb_pos, 108); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +longEnumNormalDefault():bigint { + const offset = this.bb!.__offset(this.bb_pos, 110); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('2'); +} + +static startMonster(builder:flatbuffers.Builder) { + builder.startObject(54); +} + +static addPos(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset) { + builder.addFieldStruct(0, posOffset, 0); +} + +static addMana(builder:flatbuffers.Builder, mana:number) { + builder.addFieldInt16(1, mana, 150); +} + +static addHp(builder:flatbuffers.Builder, hp:number) { + builder.addFieldInt16(2, hp, 100); +} + +static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) { + builder.addFieldOffset(3, nameOffset, 0); +} + +static addInventory(builder:flatbuffers.Builder, inventoryOffset:flatbuffers.Offset) { + builder.addFieldOffset(5, inventoryOffset, 0); +} + +static createInventoryVector(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 startInventoryVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(1, numElems, 1); +} + +static addColor(builder:flatbuffers.Builder, color:Color) { + builder.addFieldInt8(6, color, Color.Blue); +} + +static addTestType(builder:flatbuffers.Builder, testType:Any) { + builder.addFieldInt8(7, testType, Any.NONE); +} + +static addTest(builder:flatbuffers.Builder, testOffset:flatbuffers.Offset) { + builder.addFieldOffset(8, testOffset, 0); +} + +static addTest4(builder:flatbuffers.Builder, test4Offset:flatbuffers.Offset) { + builder.addFieldOffset(9, test4Offset, 0); +} + +static startTest4Vector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 2); +} + +static addTestarrayofstring(builder:flatbuffers.Builder, testarrayofstringOffset:flatbuffers.Offset) { + builder.addFieldOffset(10, testarrayofstringOffset, 0); +} + +static createTestarrayofstringVector(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 startTestarrayofstringVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 4); +} + +static addTestarrayoftables(builder:flatbuffers.Builder, testarrayoftablesOffset:flatbuffers.Offset) { + builder.addFieldOffset(11, testarrayoftablesOffset, 0); +} + +static createTestarrayoftablesVector(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 startTestarrayoftablesVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 4); +} + +static addEnemy(builder:flatbuffers.Builder, enemyOffset:flatbuffers.Offset) { + builder.addFieldOffset(12, enemyOffset, 0); +} + +static addTestnestedflatbuffer(builder:flatbuffers.Builder, testnestedflatbufferOffset:flatbuffers.Offset) { + builder.addFieldOffset(13, testnestedflatbufferOffset, 0); +} + +static createTestnestedflatbufferVector(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 startTestnestedflatbufferVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(1, numElems, 1); +} + +static addTestempty(builder:flatbuffers.Builder, testemptyOffset:flatbuffers.Offset) { + builder.addFieldOffset(14, testemptyOffset, 0); +} + +static addTestbool(builder:flatbuffers.Builder, testbool:boolean) { + builder.addFieldInt8(15, +testbool, +false); +} + +static addTesthashs32Fnv1(builder:flatbuffers.Builder, testhashs32Fnv1:number) { + builder.addFieldInt32(16, testhashs32Fnv1, 0); +} + +static addTesthashu32Fnv1(builder:flatbuffers.Builder, testhashu32Fnv1:number) { + builder.addFieldInt32(17, testhashu32Fnv1, 0); +} + +static addTesthashs64Fnv1(builder:flatbuffers.Builder, testhashs64Fnv1:bigint) { + builder.addFieldInt64(18, testhashs64Fnv1, BigInt('0')); +} + +static addTesthashu64Fnv1(builder:flatbuffers.Builder, testhashu64Fnv1:bigint) { + builder.addFieldInt64(19, testhashu64Fnv1, BigInt('0')); +} + +static addTesthashs32Fnv1a(builder:flatbuffers.Builder, testhashs32Fnv1a:number) { + builder.addFieldInt32(20, testhashs32Fnv1a, 0); +} + +static addTesthashu32Fnv1a(builder:flatbuffers.Builder, testhashu32Fnv1a:number) { + builder.addFieldInt32(21, testhashu32Fnv1a, 0); +} + +static addTesthashs64Fnv1a(builder:flatbuffers.Builder, testhashs64Fnv1a:bigint) { + builder.addFieldInt64(22, testhashs64Fnv1a, BigInt('0')); +} + +static addTesthashu64Fnv1a(builder:flatbuffers.Builder, testhashu64Fnv1a:bigint) { + builder.addFieldInt64(23, testhashu64Fnv1a, BigInt('0')); +} + +static addTestarrayofbools(builder:flatbuffers.Builder, testarrayofboolsOffset:flatbuffers.Offset) { + builder.addFieldOffset(24, testarrayofboolsOffset, 0); +} + +static createTestarrayofboolsVector(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 startTestarrayofboolsVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(1, numElems, 1); +} + +static addTestf(builder:flatbuffers.Builder, testf:number) { + builder.addFieldFloat32(25, testf, 3.14159); +} + +static addTestf2(builder:flatbuffers.Builder, testf2:number) { + builder.addFieldFloat32(26, testf2, 3.0); +} + +static addTestf3(builder:flatbuffers.Builder, testf3:number) { + builder.addFieldFloat32(27, testf3, 0.0); +} + +static addTestarrayofstring2(builder:flatbuffers.Builder, testarrayofstring2Offset:flatbuffers.Offset) { + builder.addFieldOffset(28, testarrayofstring2Offset, 0); +} + +static createTestarrayofstring2Vector(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 startTestarrayofstring2Vector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 4); +} + +static addTestarrayofsortedstruct(builder:flatbuffers.Builder, testarrayofsortedstructOffset:flatbuffers.Offset) { + builder.addFieldOffset(29, testarrayofsortedstructOffset, 0); +} + +static startTestarrayofsortedstructVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(8, numElems, 4); +} + +static addFlex(builder:flatbuffers.Builder, flexOffset:flatbuffers.Offset) { + builder.addFieldOffset(30, flexOffset, 0); +} + +static createFlexVector(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 startFlexVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(1, numElems, 1); +} + +static addTest5(builder:flatbuffers.Builder, test5Offset:flatbuffers.Offset) { + builder.addFieldOffset(31, test5Offset, 0); +} + +static startTest5Vector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 2); +} + +static addVectorOfLongs(builder:flatbuffers.Builder, vectorOfLongsOffset:flatbuffers.Offset) { + builder.addFieldOffset(32, vectorOfLongsOffset, 0); +} + +static createVectorOfLongsVector(builder:flatbuffers.Builder, data:bigint[]):flatbuffers.Offset { + 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:flatbuffers.Builder, numElems:number) { + builder.startVector(8, numElems, 8); +} + +static addVectorOfDoubles(builder:flatbuffers.Builder, vectorOfDoublesOffset:flatbuffers.Offset) { + builder.addFieldOffset(33, vectorOfDoublesOffset, 0); +} + +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 createVectorOfDoublesVector(builder:flatbuffers.Builder, data:number[]|Float64Array|Uint8Array):flatbuffers.Offset { + 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:flatbuffers.Builder, numElems:number) { + builder.startVector(8, numElems, 8); +} + +static addParentNamespaceTest(builder:flatbuffers.Builder, parentNamespaceTestOffset:flatbuffers.Offset) { + builder.addFieldOffset(34, parentNamespaceTestOffset, 0); +} + +static addVectorOfReferrables(builder:flatbuffers.Builder, vectorOfReferrablesOffset:flatbuffers.Offset) { + builder.addFieldOffset(35, vectorOfReferrablesOffset, 0); +} + +static createVectorOfReferrablesVector(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 startVectorOfReferrablesVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 4); +} + +static addSingleWeakReference(builder:flatbuffers.Builder, singleWeakReference:bigint) { + builder.addFieldInt64(36, singleWeakReference, BigInt('0')); +} + +static addVectorOfWeakReferences(builder:flatbuffers.Builder, vectorOfWeakReferencesOffset:flatbuffers.Offset) { + builder.addFieldOffset(37, vectorOfWeakReferencesOffset, 0); +} + +static createVectorOfWeakReferencesVector(builder:flatbuffers.Builder, data:bigint[]):flatbuffers.Offset { + 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:flatbuffers.Builder, numElems:number) { + builder.startVector(8, numElems, 8); +} + +static addVectorOfStrongReferrables(builder:flatbuffers.Builder, vectorOfStrongReferrablesOffset:flatbuffers.Offset) { + builder.addFieldOffset(38, vectorOfStrongReferrablesOffset, 0); +} + +static createVectorOfStrongReferrablesVector(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 startVectorOfStrongReferrablesVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 4); +} + +static addCoOwningReference(builder:flatbuffers.Builder, coOwningReference:bigint) { + builder.addFieldInt64(39, coOwningReference, BigInt('0')); +} + +static addVectorOfCoOwningReferences(builder:flatbuffers.Builder, vectorOfCoOwningReferencesOffset:flatbuffers.Offset) { + builder.addFieldOffset(40, vectorOfCoOwningReferencesOffset, 0); +} + +static createVectorOfCoOwningReferencesVector(builder:flatbuffers.Builder, data:bigint[]):flatbuffers.Offset { + 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:flatbuffers.Builder, numElems:number) { + builder.startVector(8, numElems, 8); +} + +static addNonOwningReference(builder:flatbuffers.Builder, nonOwningReference:bigint) { + builder.addFieldInt64(41, nonOwningReference, BigInt('0')); +} + +static addVectorOfNonOwningReferences(builder:flatbuffers.Builder, vectorOfNonOwningReferencesOffset:flatbuffers.Offset) { + builder.addFieldOffset(42, vectorOfNonOwningReferencesOffset, 0); +} + +static createVectorOfNonOwningReferencesVector(builder:flatbuffers.Builder, data:bigint[]):flatbuffers.Offset { + 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:flatbuffers.Builder, numElems:number) { + builder.startVector(8, numElems, 8); +} + +static addAnyUniqueType(builder:flatbuffers.Builder, anyUniqueType:AnyUniqueAliases) { + builder.addFieldInt8(43, anyUniqueType, AnyUniqueAliases.NONE); +} + +static addAnyUnique(builder:flatbuffers.Builder, anyUniqueOffset:flatbuffers.Offset) { + builder.addFieldOffset(44, anyUniqueOffset, 0); +} + +static addAnyAmbiguousType(builder:flatbuffers.Builder, anyAmbiguousType:AnyAmbiguousAliases) { + builder.addFieldInt8(45, anyAmbiguousType, AnyAmbiguousAliases.NONE); +} + +static addAnyAmbiguous(builder:flatbuffers.Builder, anyAmbiguousOffset:flatbuffers.Offset) { + builder.addFieldOffset(46, anyAmbiguousOffset, 0); +} + +static addVectorOfEnums(builder:flatbuffers.Builder, vectorOfEnumsOffset:flatbuffers.Offset) { + builder.addFieldOffset(47, vectorOfEnumsOffset, 0); +} + +static createVectorOfEnumsVector(builder:flatbuffers.Builder, data:Color[]):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 startVectorOfEnumsVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(1, numElems, 1); +} + +static addSignedEnum(builder:flatbuffers.Builder, signedEnum:Race) { + builder.addFieldInt8(48, signedEnum, Race.None); +} + +static addTestrequirednestedflatbuffer(builder:flatbuffers.Builder, testrequirednestedflatbufferOffset:flatbuffers.Offset) { + builder.addFieldOffset(49, testrequirednestedflatbufferOffset, 0); +} + +static createTestrequirednestedflatbufferVector(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 startTestrequirednestedflatbufferVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(1, numElems, 1); +} + +static addScalarKeySortedTables(builder:flatbuffers.Builder, scalarKeySortedTablesOffset:flatbuffers.Offset) { + builder.addFieldOffset(50, scalarKeySortedTablesOffset, 0); +} + +static createScalarKeySortedTablesVector(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 startScalarKeySortedTablesVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 4); +} + +static addNativeInline(builder:flatbuffers.Builder, nativeInlineOffset:flatbuffers.Offset) { + builder.addFieldStruct(51, nativeInlineOffset, 0); +} + +static addLongEnumNonEnumDefault(builder:flatbuffers.Builder, longEnumNonEnumDefault:bigint) { + builder.addFieldInt64(52, longEnumNonEnumDefault, BigInt('0')); +} + +static addLongEnumNormalDefault(builder:flatbuffers.Builder, longEnumNormalDefault:bigint) { + builder.addFieldInt64(53, longEnumNormalDefault, BigInt('2')); +} + +static endMonster(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + builder.requiredField(offset, 10) // name + return offset; +} + +static finishMonsterBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { + builder.finish(offset, 'MONS'); +} + +static finishSizePrefixedMonsterBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) { + builder.finish(offset, 'MONS', true); +} + + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):Monster { + return Monster.getRootAsMonster(new flatbuffers.ByteBuffer(buffer)) +} +} + +export class MyGame_Example_TypeAliases { + bb: flatbuffers.ByteBuffer|null = null; + bb_pos = 0; + __init(i:number, bb:flatbuffers.ByteBuffer):MyGame_Example_TypeAliases { + this.bb_pos = i; + this.bb = bb; + return this; +} + +static getRootAsTypeAliases(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_TypeAliases):MyGame_Example_TypeAliases { + return (obj || new MyGame_Example_TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +static getSizePrefixedRootAsTypeAliases(bb:flatbuffers.ByteBuffer, obj?:MyGame_Example_TypeAliases):MyGame_Example_TypeAliases { + bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); + return (obj || new MyGame_Example_TypeAliases()).__init(bb.readInt32(bb.position()) + bb.position(), bb); +} + +i8():number { + const offset = this.bb!.__offset(this.bb_pos, 4); + return offset ? this.bb!.readInt8(this.bb_pos + offset) : 0; +} + +u8():number { + const offset = this.bb!.__offset(this.bb_pos, 6); + return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0; +} + +i16():number { + const offset = this.bb!.__offset(this.bb_pos, 8); + return offset ? this.bb!.readInt16(this.bb_pos + offset) : 0; +} + +u16():number { + const offset = this.bb!.__offset(this.bb_pos, 10); + return offset ? this.bb!.readUint16(this.bb_pos + offset) : 0; +} + +i32():number { + const offset = this.bb!.__offset(this.bb_pos, 12); + return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0; +} + +u32():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0; +} + +i64():bigint { + const offset = this.bb!.__offset(this.bb_pos, 16); + return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0'); +} + +u64():bigint { + const offset = this.bb!.__offset(this.bb_pos, 18); + return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0'); +} + +f32():number { + const offset = this.bb!.__offset(this.bb_pos, 20); + return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0; +} + +f64():number { + const offset = this.bb!.__offset(this.bb_pos, 22); + return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0; +} + +v8(index: number):number|null { + const offset = this.bb!.__offset(this.bb_pos, 24); + return offset ? this.bb!.readInt8(this.bb!.__vector(this.bb_pos + offset) + index) : 0; +} + +v8Length():number { + const offset = this.bb!.__offset(this.bb_pos, 24); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +v8Array():Int8Array|null { + 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: number):number|null { + 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():number { + const offset = this.bb!.__offset(this.bb_pos, 26); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + +vf64Array():Float64Array|null { + 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 startTypeAliases(builder:flatbuffers.Builder) { + builder.startObject(12); +} + +static addI8(builder:flatbuffers.Builder, i8:number) { + builder.addFieldInt8(0, i8, 0); +} + +static addU8(builder:flatbuffers.Builder, u8:number) { + builder.addFieldInt8(1, u8, 0); +} + +static addI16(builder:flatbuffers.Builder, i16:number) { + builder.addFieldInt16(2, i16, 0); +} + +static addU16(builder:flatbuffers.Builder, u16:number) { + builder.addFieldInt16(3, u16, 0); +} + +static addI32(builder:flatbuffers.Builder, i32:number) { + builder.addFieldInt32(4, i32, 0); +} + +static addU32(builder:flatbuffers.Builder, u32:number) { + builder.addFieldInt32(5, u32, 0); +} + +static addI64(builder:flatbuffers.Builder, i64:bigint) { + builder.addFieldInt64(6, i64, BigInt('0')); +} + +static addU64(builder:flatbuffers.Builder, u64:bigint) { + builder.addFieldInt64(7, u64, BigInt('0')); +} + +static addF32(builder:flatbuffers.Builder, f32:number) { + builder.addFieldFloat32(8, f32, 0.0); +} + +static addF64(builder:flatbuffers.Builder, f64:number) { + builder.addFieldFloat64(9, f64, 0.0); +} + +static addV8(builder:flatbuffers.Builder, v8Offset:flatbuffers.Offset) { + builder.addFieldOffset(10, v8Offset, 0); +} + +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 createV8Vector(builder:flatbuffers.Builder, data:number[]|Int8Array|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 startV8Vector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(1, numElems, 1); +} + +static addVf64(builder:flatbuffers.Builder, vf64Offset:flatbuffers.Offset) { + builder.addFieldOffset(11, vf64Offset, 0); +} + +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 createVf64Vector(builder:flatbuffers.Builder, data:number[]|Float64Array|Uint8Array):flatbuffers.Offset { + 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:flatbuffers.Builder, numElems:number) { + builder.startVector(8, numElems, 8); +} + +static endTypeAliases(builder:flatbuffers.Builder):flatbuffers.Offset { + const offset = builder.endObject(); + return 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 { + MyGame_Example_TypeAliases.startTypeAliases(builder); + MyGame_Example_TypeAliases.addI8(builder, i8); + MyGame_Example_TypeAliases.addU8(builder, u8); + MyGame_Example_TypeAliases.addI16(builder, i16); + MyGame_Example_TypeAliases.addU16(builder, u16); + MyGame_Example_TypeAliases.addI32(builder, i32); + MyGame_Example_TypeAliases.addU32(builder, u32); + MyGame_Example_TypeAliases.addI64(builder, i64); + MyGame_Example_TypeAliases.addU64(builder, u64); + MyGame_Example_TypeAliases.addF32(builder, f32); + MyGame_Example_TypeAliases.addF64(builder, f64); + MyGame_Example_TypeAliases.addV8(builder, v8Offset); + MyGame_Example_TypeAliases.addVf64(builder, vf64Offset); + return MyGame_Example_TypeAliases.endTypeAliases(builder); +} + +serialize():Uint8Array { + return this.bb!.bytes(); +} + +static deserialize(buffer: Uint8Array):TypeAliases { + return TypeAliases.getRootAsTypeAliases(new flatbuffers.ByteBuffer(buffer)) +} +} + diff --git a/tests/union_vector/character.ts b/tests/union_vector/character.ts index 57c658bd5..d8ffbc2a1 100644 --- a/tests/union_vector/character.ts +++ b/tests/union_vector/character.ts @@ -47,4 +47,3 @@ export function unionListToCharacter( default: return null; } } - diff --git a/tests/union_vector/gadget.ts b/tests/union_vector/gadget.ts index 12a766610..328071ebb 100644 --- a/tests/union_vector/gadget.ts +++ b/tests/union_vector/gadget.ts @@ -34,4 +34,3 @@ export function unionListToGadget( default: return null; } } -