Compare commits

..

10 Commits

Author SHA1 Message Date
derekbailey
166f25f82b MODULE.bazel: Upgrade rules_swift version 2026-01-21 00:53:45 +00:00
razvanalex
d74e2945f7 [C++] Check for case insensitive keywords (#8420)
* chore(idl): Check for case insensitive keywords

Most languages are not affected by this change. In PHP, some names such
as Bool cannot be used because it is a reserved keyword for to the bool
data type. The field `keywords_casing` in the configs enables checking
all characters in lowercase against every keyword. This should be safe
as flatbuffers does not allow non-ASCII characters in its grammar.

* chore: Fix formatting to follow google's coding style for enums

* chore: Extract convert case to lower when CaseInsensitive

---------

Co-authored-by: Justin Davis <jtdavis777@gmail.com>
Co-authored-by: Derek Bailey <derekbailey@google.com>
2026-01-20 16:06:07 -08:00
Nicolas Ulrich
8914d06ab7 Remove invalid dependency on FLATBUFFERS_GENERATE_HEADERS_SCHEMAS (#8834)
* Remove invalid dependency on FLATBUFFERS_GENERATE_HEADERS_SCHEMAS

add_dependencies() is for targets.

CMake 4.2.0 fails because of this (it shouldn't crash though, but that's another topic). See https://gitlab.kitware.com/cmake/cmake/-/issues/27415

* Use FLATC_TARGET

---------

Co-authored-by: Justin Davis <jtdavis777@gmail.com>
2025-12-22 02:25:14 +00:00
Derek Bailey
522f2379a6 Update CODEOWNERS 2025-12-21 16:10:34 -08:00
Justin Davis
7cb0bcb212 C++ Feature: Mutable union getters (#8852)
* generate mutable union accessors

* add test

* Revert "add test"

This reverts commit 45e352b18f.

* update file

* formatter got in the way

* merge conflicts

* updated genned code

* manually fix code gen bc I can't figure out why this file won't code gen

---------

Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
2025-12-21 17:36:47 -05:00
Justin Davis
b1e7868db6 add verification that type_vec.size == vec.size() (#8853)
Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
2025-12-21 21:55:54 +00:00
Justin Davis
68e3c839c3 update provenance (#8873) 2025-12-21 21:50:57 +00:00
mustiikhalil
0723245085 [Swift] Fixes bazel.build file allowing it to find Vectors folder in 8.5.0 (#8875) 2025-12-21 21:22:49 +00:00
Ville Vesilehto
9d64b9c0c0 fix(go): add bounds checking to ByteVector (#8776)
Add missing bounds checking to ByteVector before slice
operations in the Go FlatBuffers implementation. Relative offset and
vector length are now checked against the buffer size. Instead of
panicking, the code now returns nil. Regression test added.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Co-authored-by: Justin Davis <jtdavis777@gmail.com>
2025-12-21 20:25:30 +00:00
Justin Davis
d01f20f2fb Fix python generation with nested flatbuffers (#8854)
* implement fix from issue

* implement actual fix
2025-12-21 11:18:05 -08:00
32 changed files with 488 additions and 20 deletions

2
.github/CODEOWNERS vendored
View File

@@ -1,5 +1,5 @@
# Default owner
* @aardappel @dbaileychess derekbailey@google.com
* @dbaileychess derekbailey@google.com
# Prevent modification of this file
.github/CODEOWNERS @dbaileychess derekbailey@google.com

View File

@@ -592,11 +592,16 @@ jobs:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
# Explicitly use 8.5.1 until we can update or https://github.com/actions/runner-images/issues/13564 is fixed.
- name: Set env
run: >
echo "USE_BAZEL_VERSION=8.5.1" >> $GITHUB_ENV
- name: bazel build
run: >
bazel build
//:flatc
//:flatbuffers
//tests:flatbuffers_test
- name: bazel test
run: >
bazel test
@@ -633,8 +638,7 @@ jobs:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.1
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
with:
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
upload-assets: true # Optional: Upload to a new release
compile-generator: true # Workaround for https://github.com/slsa-framework/slsa-github-generator/issues/1163

View File

@@ -305,8 +305,7 @@ function(flatbuffers_generate_headers)
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
add_dependencies(
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
${FLATC}
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
${FLATC_TARGET})
target_include_directories(
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
INTERFACE ${generated_target_dir})

View File

@@ -7,7 +7,7 @@ module(
bazel_dep(
name = "aspect_bazel_lib",
version = "2.11.0",
version = "2.14.0",
)
bazel_dep(
name = "aspect_rules_esbuild",
@@ -28,11 +28,11 @@ bazel_dep(
)
bazel_dep(
name = "platforms",
version = "0.0.10",
version = "0.0.11",
)
bazel_dep(
name = "rules_cc",
version = "0.0.16",
version = "0.1.1",
)
bazel_dep(
name = "rules_go",

View File

@@ -31,10 +31,25 @@ func (t *Table) String(off UOffsetT) string {
}
// ByteVector gets a byte slice from data stored inside the flatbuffer.
// If the offset is invalid or out of bounds, returns nil to prevent crashes.
func (t *Table) ByteVector(off UOffsetT) []byte {
n := UOffsetT(len(t.Bytes))
// Need at least SizeUOffsetT bytes to read the relative vector offset.
u := UOffsetT(SizeUOffsetT)
if n < u || off > n-u {
return nil
}
off += GetUOffsetT(t.Bytes[off:])
// Need at least SizeUOffsetT bytes to read the vector length.
if n < u || off > n-u {
return nil
}
start := off + UOffsetT(SizeUOffsetT)
length := GetUOffsetT(t.Bytes[off:])
// Avoid overflow by checking the length against the remaining buffer space.
if length > n-start {
return nil
}
return t.Bytes[start : start+length]
}

View File

@@ -91,6 +91,14 @@ class Namer {
std::string keyword_prefix;
// Suffix used to escape keywords. It is usually "_".
std::string keyword_suffix;
// The casing used for keywords when escaping. For most languages, keywords
// are case sensitive. PHP is an instance where some keywords are case
// insensitive.
enum class KeywordsCasing {
CaseSensitive,
CaseInsensitive,
};
KeywordsCasing keywords_casing;
// Files.
@@ -204,8 +212,16 @@ class Namer {
return result;
}
virtual std::string NormalizeKeywordCase(const std::string& name) const {
if (config_.keywords_casing == Config::KeywordsCasing::CaseInsensitive) {
return ConvertCase(name, Case::kAllLower);
} else {
return name;
}
}
virtual std::string EscapeKeyword(const std::string& name) const {
if (keywords_.find(name) == keywords_.end()) {
if (keywords_.find(NormalizeKeywordCase(name)) == keywords_.end()) {
return name;
} else {
return config_.keyword_prefix + name + config_.keyword_suffix;

View File

@@ -26,6 +26,7 @@ static const Namer::Config kConfig = {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",
@@ -49,6 +50,7 @@ static const Namer::Config kStubConfig = {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -328,6 +328,10 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Sample::Weapon *equipped_as_Weapon() const {
return equipped_type() == MyGame::Sample::Equipment_Weapon ? static_cast<const MyGame::Sample::Weapon *>(equipped()) : nullptr;
}
template<typename T> T *mutable_equipped_as();
MyGame::Sample::Weapon *mutable_equipped_as_Weapon() {
return equipped_type() == MyGame::Sample::Equipment_Weapon ? static_cast<MyGame::Sample::Weapon *>(mutable_equipped()) : nullptr;
}
void *mutable_equipped() {
return GetPointer<void *>(VT_EQUIPPED);
}
@@ -367,6 +371,10 @@ template<> inline const MyGame::Sample::Weapon *Monster::equipped_as<MyGame::Sam
return equipped_as_Weapon();
}
template<> inline MyGame::Sample::Weapon *Monster::mutable_equipped_as<MyGame::Sample::Weapon>() {
return mutable_equipped_as_Weapon();
}
struct MonsterBuilder {
typedef Monster Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -61,6 +61,7 @@ Namer::Config LuaDefaultConfig() {
/*object_suffix=*/"",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -70,6 +70,7 @@ Namer::Config NimDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -2685,14 +2685,18 @@ class CppGenerator : public BaseGenerator {
code_ += " }";
}
void GenTableUnionAsGetters(const FieldDef& field) {
void GenTableUnionAsGetters(const FieldDef& field, bool is_mutable) {
const auto& type = field.value.type;
auto u = type.enum_def;
code_.SetValue("MUTABLE_EXT", is_mutable ? "" : " const");
code_.SetValue("MUTABLE", is_mutable ? "mutable_" : "");
if (!type.enum_def->uses_multiple_type_instances)
code_ +=
" template<typename T> "
"const T *{{NULLABLE_EXT}}{{FIELD_NAME}}_as() const;";
" template<typename T>"
"{{MUTABLE_EXT}} T *{{MUTABLE}}{{NULLABLE_EXT}}{{FIELD_NAME}}_as()"
"{{MUTABLE_EXT}};";
for (auto u_it = u->Vals().begin(); u_it != u->Vals().end(); ++u_it) {
auto& ev = **u_it;
@@ -2706,15 +2710,19 @@ class CppGenerator : public BaseGenerator {
EscapeKeyword(Name(field) + UnionTypeFieldSuffix()));
code_.SetValue("U_ELEMENT_TYPE", WrapInNameSpace(u->defined_namespace,
GetEnumValUse(*u, ev)));
code_.SetValue("U_FIELD_TYPE", "const " + full_struct_name + " *");
code_.SetValue("U_FIELD_TYPE",
(is_mutable ? "" : "const ") + full_struct_name + " *");
code_.SetValue("U_FIELD_NAME", Name(field) + "_as_" + Name(ev));
code_.SetValue("U_NULLABLE", NullableExtension());
// `const Type *union_name_asType() const` accessor.
code_ += " {{U_FIELD_TYPE}}{{U_NULLABLE}}{{U_FIELD_NAME}}() const {";
// and `Type *mutable_union_name_asType()` accessor.
code_ +=
" {{U_FIELD_TYPE}}{{U_NULLABLE}}{{MUTABLE}}{{U_FIELD_NAME}}()"
"{{MUTABLE_EXT}} {";
code_ +=
" return {{U_GET_TYPE}}() == {{U_ELEMENT_TYPE}} ? "
"static_cast<{{U_FIELD_TYPE}}>({{FIELD_NAME}}()) "
"static_cast<{{U_FIELD_TYPE}}>({{MUTABLE}}{{FIELD_NAME}}()) "
": nullptr;";
code_ += " }";
}
@@ -2755,7 +2763,7 @@ class CppGenerator : public BaseGenerator {
code_.SetValue("FIELD_VALUE", GenUnderlyingCast(field, true, call));
code_.SetValue("NULLABLE_EXT", NullableExtension());
code_ += " {{FIELD_TYPE}}{{FIELD_NAME}}() const {";
if (IsVector(type) && field.value.constant == "[]") {
if (IsVector(type) && field.value.constant == "[]") {
const auto& vec_type = type.VectorType();
const std::string vtype_wire = GenTypeWire(
vec_type, "", VectorElementUserFacing(vec_type), field.offset64);
@@ -2799,7 +2807,7 @@ class CppGenerator : public BaseGenerator {
}
if (type.base_type == BASE_TYPE_UNION) {
GenTableUnionAsGetters(field);
GenTableUnionAsGetters(field, false);
}
}
@@ -2974,6 +2982,11 @@ class CppGenerator : public BaseGenerator {
auto wire_type = GenTypeGet(type, " ", "", postptr.c_str(), true);
code_.SetValue("FIELD_TYPE", wire_type);
// mutable union accessors
if (type.base_type == BASE_TYPE_UNION) {
GenTableUnionAsGetters(field, true);
}
if (IsVector(type) && field.value.constant == "[]") {
const auto& vec_type = type.VectorType();
const std::string vtype_wire = GenTypeWire(
@@ -3185,6 +3198,7 @@ class CppGenerator : public BaseGenerator {
code_.SetValue("U_FIELD_NAME", Name(*field) + "_as_" + Name(ev));
// `template<> const T *union_name_as<T>() const` accessor.
// and `template<> T *mutable_union_name_as<T>()` accessor.
code_ +=
"template<> "
"inline {{U_FIELD_TYPE}}{{STRUCT_NAME}}::{{FIELD_NAME}}_as"
@@ -3192,6 +3206,20 @@ class CppGenerator : public BaseGenerator {
code_ += " return {{U_FIELD_NAME}}();";
code_ += "}";
code_ += "";
if (opts_.mutable_buffer) {
code_.SetValue("U_FIELD_TYPE", full_struct_name + " *");
code_.SetValue("U_FIELD_NAME",
"mutable_" + Name(*field) + "_as_" + Name(ev));
code_ +=
"template<> "
"inline {{U_FIELD_TYPE}}"
"{{STRUCT_NAME}}::mutable_{{FIELD_NAME}}_as"
"<{{U_ELEMENT_NAME}}>() {";
code_ += " return {{U_FIELD_NAME}}();";
code_ += "}";
code_ += "";
}
}
}

View File

@@ -48,6 +48,7 @@ static Namer::Config DartDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"$",
/*keyword_suffix=*/"",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -75,6 +75,7 @@ static Namer::Config GoDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -46,6 +46,7 @@ static Namer::Config JavaDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -64,6 +64,7 @@ static Namer::Config KotlinDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -62,6 +62,7 @@ static Namer::Config KotlinDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"E",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kUpperCamel,
/*directories=*/Case::kLowerCamel,
/*output_path=*/"",

View File

@@ -1201,12 +1201,15 @@ class PythonGenerator : public BaseGenerator {
return;
} // There is no nested flatbuffer.
const std::string unqualified_name = nested->constant;
std::string unqualified_name = nested->constant;
std::string qualified_name = NestedFlatbufferType(unqualified_name);
if (qualified_name.empty()) {
qualified_name = nested->constant;
}
// name may be partially qualified -- need to get the true unqualified name
unqualified_name = namer_.Denamespace(qualified_name);
const ImportMapEntry import_entry = {qualified_name, unqualified_name};
auto& code = *code_ptr;

View File

@@ -49,6 +49,7 @@ static Namer::Config RustDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kSnake,
/*directories=*/Case::kSnake,
/*output_path=*/"",

View File

@@ -47,6 +47,7 @@ static Namer::Config SwiftDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",

View File

@@ -67,6 +67,7 @@ Namer::Config TypeScriptDefaultConfig() {
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
/*filenames=*/Case::kDasher,
/*directories=*/Case::kDasher,
/*output_path=*/"",

View File

@@ -156,6 +156,7 @@ static bool VerifyVector(flatbuffers::Verifier& v,
auto type_vec = table.GetPointer<Vector<uint8_t>*>(vec_field.offset() -
sizeof(voffset_t));
if (!v.VerifyVector(type_vec)) return false;
if (type_vec->size() != vec->size()) return false;
for (uoffset_t j = 0; j < vec->size(); j++) {
// get union type from the prev field
auto utype = type_vec->Get(j);

View File

@@ -14,7 +14,8 @@ swift_library(
name = "swift",
srcs = glob([
"Sources/FlatBuffers/*.swift",
"Sources/Common/*.swift",
"Sources/FlatBuffers/Vectors/*.swift",
"Sources/Common/*.swift"
]),
module_name = "FlatBuffers",
visibility = ["//visibility:public"],

View File

@@ -1481,6 +1481,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *test_as_MyGame_Example2_Monster() const {
return test_type() == MyGame::Example::Any::MyGame_Example2_Monster ? static_cast<const MyGame::Example2::Monster *>(test()) : nullptr;
}
template<typename T> T *mutable_test_as();
MyGame::Example::Monster *mutable_test_as_Monster() {
return test_type() == MyGame::Example::Any::Monster ? static_cast<MyGame::Example::Monster *>(mutable_test()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_test_as_TestSimpleTableWithEnum() {
return test_type() == MyGame::Example::Any::TestSimpleTableWithEnum ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_test()) : nullptr;
}
MyGame::Example2::Monster *mutable_test_as_MyGame_Example2_Monster() {
return test_type() == MyGame::Example::Any::MyGame_Example2_Monster ? static_cast<MyGame::Example2::Monster *>(mutable_test()) : nullptr;
}
void *mutable_test() {
return GetPointer<void *>(VT_TEST);
}
@@ -1716,6 +1726,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *any_unique_as_M2() const {
return any_unique_type() == MyGame::Example::AnyUniqueAliases::M2 ? static_cast<const MyGame::Example2::Monster *>(any_unique()) : nullptr;
}
template<typename T> T *mutable_any_unique_as();
MyGame::Example::Monster *mutable_any_unique_as_M() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases::M ? static_cast<MyGame::Example::Monster *>(mutable_any_unique()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_any_unique_as_TS() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases::TS ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_any_unique()) : nullptr;
}
MyGame::Example2::Monster *mutable_any_unique_as_M2() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases::M2 ? static_cast<MyGame::Example2::Monster *>(mutable_any_unique()) : nullptr;
}
void *mutable_any_unique() {
return GetPointer<void *>(VT_ANY_UNIQUE);
}
@@ -1734,6 +1754,15 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example::Monster *any_ambiguous_as_M3() const {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases::M3 ? static_cast<const MyGame::Example::Monster *>(any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M1() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases::M1 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M2() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases::M2 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M3() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases::M3 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
void *mutable_any_ambiguous() {
return GetPointer<void *>(VT_ANY_AMBIGUOUS);
}
@@ -2008,26 +2037,50 @@ template<> inline const MyGame::Example::Monster *Monster::test_as<MyGame::Examp
return test_as_Monster();
}
template<> inline MyGame::Example::Monster *Monster::mutable_test_as<MyGame::Example::Monster>() {
return mutable_test_as_Monster();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::test_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return test_as_TestSimpleTableWithEnum();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_test_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_test_as_TestSimpleTableWithEnum();
}
template<> inline const MyGame::Example2::Monster *Monster::test_as<MyGame::Example2::Monster>() const {
return test_as_MyGame_Example2_Monster();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_test_as<MyGame::Example2::Monster>() {
return mutable_test_as_MyGame_Example2_Monster();
}
template<> inline const MyGame::Example::Monster *Monster::any_unique_as<MyGame::Example::Monster>() const {
return any_unique_as_M();
}
template<> inline MyGame::Example::Monster *Monster::mutable_any_unique_as<MyGame::Example::Monster>() {
return mutable_any_unique_as_M();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return any_unique_as_TS();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_any_unique_as_TS();
}
template<> inline const MyGame::Example2::Monster *Monster::any_unique_as<MyGame::Example2::Monster>() const {
return any_unique_as_M2();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_any_unique_as<MyGame::Example2::Monster>() {
return mutable_any_unique_as_M2();
}
struct MonsterBuilder {
typedef Monster Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -595,6 +595,24 @@ struct Movie FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const ::flatbuffers::String *main_character_as_Unused() const {
return main_character_type() == Character::Unused ? static_cast<const ::flatbuffers::String *>(main_character()) : nullptr;
}
Attacker *mutable_main_character_as_MuLan() {
return main_character_type() == Character::MuLan ? static_cast<Attacker *>(mutable_main_character()) : nullptr;
}
Rapunzel *mutable_main_character_as_Rapunzel() {
return main_character_type() == Character::Rapunzel ? static_cast<Rapunzel *>(mutable_main_character()) : nullptr;
}
BookReader *mutable_main_character_as_Belle() {
return main_character_type() == Character::Belle ? static_cast<BookReader *>(mutable_main_character()) : nullptr;
}
BookReader *mutable_main_character_as_BookFan() {
return main_character_type() == Character::BookFan ? static_cast<BookReader *>(mutable_main_character()) : nullptr;
}
::flatbuffers::String *mutable_main_character_as_Other() {
return main_character_type() == Character::Other ? static_cast<::flatbuffers::String *>(mutable_main_character()) : nullptr;
}
::flatbuffers::String *mutable_main_character_as_Unused() {
return main_character_type() == Character::Unused ? static_cast<::flatbuffers::String *>(mutable_main_character()) : nullptr;
}
void *mutable_main_character() {
return GetPointer<void *>(VT_MAIN_CHARACTER);
}

View File

@@ -22,8 +22,8 @@ import (
pizza "Pizza"
"encoding/json"
optional_scalars "optional_scalars" // refers to generated code
required_strings "required_strings" // refers to generated code
order "order"
required_strings "required_strings" // refers to generated code
"bytes"
"flag"
@@ -132,6 +132,10 @@ func TestAll(t *testing.T) {
CheckByteStringIsNestedError(t.Fatalf)
CheckStructIsNotInlineError(t.Fatalf)
CheckFinishedBytesError(t.Fatalf)
// Verify bounds checking
CheckByteVectorBoundsChecking(t.Fatalf)
CheckSharedStrings(t.Fatalf)
CheckEmptiedBuilder(t.Fatalf)
@@ -2471,6 +2475,52 @@ func CheckByKey(fail func(string, ...interface{})) {
expectEq("Mana Count", mpStat.Count(), uint16(0))
}
// CheckByteVectorBoundsChecking ensures ByteVector handles malformed input safely.
func CheckByteVectorBoundsChecking(fail func(string, ...interface{})) {
// Test case 1: Offset beyond buffer size
table := &flatbuffers.Table{
Bytes: []byte{0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, // Small buffer
Pos: 0,
}
result := table.ByteVector(100) // Offset way beyond buffer
if result != nil {
fail("ByteVector should return nil for offset beyond buffer")
}
// Test case 2: Malicious length field
// Construct: [relative offset: 4] [vector length: 0xFFFFFFFF] [data...]
maliciousBytes := make([]byte, 20)
// At position 0, set relative offset to point to position 4
maliciousBytes[0] = 4
maliciousBytes[1] = 0
maliciousBytes[2] = 0
maliciousBytes[3] = 0
// At position 4, set malicious vector length
maliciousBytes[4] = 0xFF
maliciousBytes[5] = 0xFF
maliciousBytes[6] = 0xFF
maliciousBytes[7] = 0xFF
table = &flatbuffers.Table{Bytes: maliciousBytes, Pos: 0}
result = table.ByteVector(0)
if result != nil {
fail("ByteVector should return nil for malicious length field")
}
// Test case 3: Valid case should still work
// Construct: [relative offset: 4] [vector length: 3] [data: 'a', 'b', 'c']
validBytes := []byte{
4, 0, 0, 0, // relative offset to vector data (at position 4)
3, 0, 0, 0, // vector length (3 bytes)
'a', 'b', 'c', // actual vector data
}
table = &flatbuffers.Table{Bytes: validBytes, Pos: 0}
result = table.ByteVector(0)
if result == nil || !bytes.Equal(result, []byte("abc")) {
fail("ByteVector should work correctly for valid data")
}
}
// BenchmarkVtableDeduplication measures the speed of vtable deduplication
// by creating prePop vtables, then populating b.N objects with a
// different single vtable.

View File

@@ -1497,6 +1497,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *test_as_MyGame_Example2_Monster() const {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<const MyGame::Example2::Monster *>(test()) : nullptr;
}
template<typename T> T *mutable_test_as();
MyGame::Example::Monster *mutable_test_as_Monster() {
return test_type() == MyGame::Example::Any_Monster ? static_cast<MyGame::Example::Monster *>(mutable_test()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_test_as_TestSimpleTableWithEnum() {
return test_type() == MyGame::Example::Any_TestSimpleTableWithEnum ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_test()) : nullptr;
}
MyGame::Example2::Monster *mutable_test_as_MyGame_Example2_Monster() {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<MyGame::Example2::Monster *>(mutable_test()) : nullptr;
}
void *mutable_test() {
return GetPointer<void *>(VT_TEST);
}
@@ -1732,6 +1742,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *any_unique_as_M2() const {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<const MyGame::Example2::Monster *>(any_unique()) : nullptr;
}
template<typename T> T *mutable_any_unique_as();
MyGame::Example::Monster *mutable_any_unique_as_M() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M ? static_cast<MyGame::Example::Monster *>(mutable_any_unique()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_any_unique_as_TS() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_TS ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_any_unique()) : nullptr;
}
MyGame::Example2::Monster *mutable_any_unique_as_M2() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<MyGame::Example2::Monster *>(mutable_any_unique()) : nullptr;
}
void *mutable_any_unique() {
return GetPointer<void *>(VT_ANY_UNIQUE);
}
@@ -1750,6 +1770,15 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example::Monster *any_ambiguous_as_M3() const {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<const MyGame::Example::Monster *>(any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M1() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M1 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M2() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M2 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M3() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
void *mutable_any_ambiguous() {
return GetPointer<void *>(VT_ANY_AMBIGUOUS);
}
@@ -1959,26 +1988,50 @@ template<> inline const MyGame::Example::Monster *Monster::test_as<MyGame::Examp
return test_as_Monster();
}
template<> inline MyGame::Example::Monster *Monster::mutable_test_as<MyGame::Example::Monster>() {
return mutable_test_as_Monster();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::test_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return test_as_TestSimpleTableWithEnum();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_test_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_test_as_TestSimpleTableWithEnum();
}
template<> inline const MyGame::Example2::Monster *Monster::test_as<MyGame::Example2::Monster>() const {
return test_as_MyGame_Example2_Monster();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_test_as<MyGame::Example2::Monster>() {
return mutable_test_as_MyGame_Example2_Monster();
}
template<> inline const MyGame::Example::Monster *Monster::any_unique_as<MyGame::Example::Monster>() const {
return any_unique_as_M();
}
template<> inline MyGame::Example::Monster *Monster::mutable_any_unique_as<MyGame::Example::Monster>() {
return mutable_any_unique_as_M();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return any_unique_as_TS();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_any_unique_as_TS();
}
template<> inline const MyGame::Example2::Monster *Monster::any_unique_as<MyGame::Example2::Monster>() const {
return any_unique_as_M2();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_any_unique_as<MyGame::Example2::Monster>() {
return mutable_any_unique_as_M2();
}
struct MonsterBuilder {
typedef Monster Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -1488,6 +1488,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *test_as_MyGame_Example2_Monster() const {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<const MyGame::Example2::Monster *>(test()) : nullptr;
}
template<typename T> T *mutable_test_as();
MyGame::Example::Monster *mutable_test_as_Monster() {
return test_type() == MyGame::Example::Any_Monster ? static_cast<MyGame::Example::Monster *>(mutable_test()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_test_as_TestSimpleTableWithEnum() {
return test_type() == MyGame::Example::Any_TestSimpleTableWithEnum ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_test()) : nullptr;
}
MyGame::Example2::Monster *mutable_test_as_MyGame_Example2_Monster() {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<MyGame::Example2::Monster *>(mutable_test()) : nullptr;
}
void *mutable_test() {
return GetPointer<void *>(VT_TEST);
}
@@ -1723,6 +1733,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *any_unique_as_M2() const {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<const MyGame::Example2::Monster *>(any_unique()) : nullptr;
}
template<typename T> T *mutable_any_unique_as();
MyGame::Example::Monster *mutable_any_unique_as_M() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M ? static_cast<MyGame::Example::Monster *>(mutable_any_unique()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_any_unique_as_TS() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_TS ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_any_unique()) : nullptr;
}
MyGame::Example2::Monster *mutable_any_unique_as_M2() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<MyGame::Example2::Monster *>(mutable_any_unique()) : nullptr;
}
void *mutable_any_unique() {
return GetPointer<void *>(VT_ANY_UNIQUE);
}
@@ -1741,6 +1761,15 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example::Monster *any_ambiguous_as_M3() const {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<const MyGame::Example::Monster *>(any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M1() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M1 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M2() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M2 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M3() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
void *mutable_any_ambiguous() {
return GetPointer<void *>(VT_ANY_AMBIGUOUS);
}
@@ -1950,26 +1979,50 @@ template<> inline const MyGame::Example::Monster *Monster::test_as<MyGame::Examp
return test_as_Monster();
}
template<> inline MyGame::Example::Monster *Monster::mutable_test_as<MyGame::Example::Monster>() {
return mutable_test_as_Monster();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::test_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return test_as_TestSimpleTableWithEnum();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_test_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_test_as_TestSimpleTableWithEnum();
}
template<> inline const MyGame::Example2::Monster *Monster::test_as<MyGame::Example2::Monster>() const {
return test_as_MyGame_Example2_Monster();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_test_as<MyGame::Example2::Monster>() {
return mutable_test_as_MyGame_Example2_Monster();
}
template<> inline const MyGame::Example::Monster *Monster::any_unique_as<MyGame::Example::Monster>() const {
return any_unique_as_M();
}
template<> inline MyGame::Example::Monster *Monster::mutable_any_unique_as<MyGame::Example::Monster>() {
return mutable_any_unique_as_M();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return any_unique_as_TS();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_any_unique_as_TS();
}
template<> inline const MyGame::Example2::Monster *Monster::any_unique_as<MyGame::Example2::Monster>() const {
return any_unique_as_M2();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_any_unique_as<MyGame::Example2::Monster>() {
return mutable_any_unique_as_M2();
}
struct MonsterBuilder {
typedef Monster Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -1488,6 +1488,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *test_as_MyGame_Example2_Monster() const {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<const MyGame::Example2::Monster *>(test()) : nullptr;
}
template<typename T> T *mutable_test_as();
MyGame::Example::Monster *mutable_test_as_Monster() {
return test_type() == MyGame::Example::Any_Monster ? static_cast<MyGame::Example::Monster *>(mutable_test()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_test_as_TestSimpleTableWithEnum() {
return test_type() == MyGame::Example::Any_TestSimpleTableWithEnum ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_test()) : nullptr;
}
MyGame::Example2::Monster *mutable_test_as_MyGame_Example2_Monster() {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<MyGame::Example2::Monster *>(mutable_test()) : nullptr;
}
void *mutable_test() {
return GetPointer<void *>(VT_TEST);
}
@@ -1723,6 +1733,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *any_unique_as_M2() const {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<const MyGame::Example2::Monster *>(any_unique()) : nullptr;
}
template<typename T> T *mutable_any_unique_as();
MyGame::Example::Monster *mutable_any_unique_as_M() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M ? static_cast<MyGame::Example::Monster *>(mutable_any_unique()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_any_unique_as_TS() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_TS ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_any_unique()) : nullptr;
}
MyGame::Example2::Monster *mutable_any_unique_as_M2() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<MyGame::Example2::Monster *>(mutable_any_unique()) : nullptr;
}
void *mutable_any_unique() {
return GetPointer<void *>(VT_ANY_UNIQUE);
}
@@ -1741,6 +1761,15 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example::Monster *any_ambiguous_as_M3() const {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<const MyGame::Example::Monster *>(any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M1() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M1 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M2() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M2 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M3() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
void *mutable_any_ambiguous() {
return GetPointer<void *>(VT_ANY_AMBIGUOUS);
}
@@ -1950,26 +1979,50 @@ template<> inline const MyGame::Example::Monster *Monster::test_as<MyGame::Examp
return test_as_Monster();
}
template<> inline MyGame::Example::Monster *Monster::mutable_test_as<MyGame::Example::Monster>() {
return mutable_test_as_Monster();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::test_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return test_as_TestSimpleTableWithEnum();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_test_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_test_as_TestSimpleTableWithEnum();
}
template<> inline const MyGame::Example2::Monster *Monster::test_as<MyGame::Example2::Monster>() const {
return test_as_MyGame_Example2_Monster();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_test_as<MyGame::Example2::Monster>() {
return mutable_test_as_MyGame_Example2_Monster();
}
template<> inline const MyGame::Example::Monster *Monster::any_unique_as<MyGame::Example::Monster>() const {
return any_unique_as_M();
}
template<> inline MyGame::Example::Monster *Monster::mutable_any_unique_as<MyGame::Example::Monster>() {
return mutable_any_unique_as_M();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return any_unique_as_TS();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_any_unique_as_TS();
}
template<> inline const MyGame::Example2::Monster *Monster::any_unique_as<MyGame::Example2::Monster>() const {
return any_unique_as_M2();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_any_unique_as<MyGame::Example2::Monster>() {
return mutable_any_unique_as_M2();
}
struct MonsterBuilder {
typedef Monster Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -1488,6 +1488,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *test_as_MyGame_Example2_Monster() const {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<const MyGame::Example2::Monster *>(test()) : nullptr;
}
template<typename T> T *mutable_test_as();
MyGame::Example::Monster *mutable_test_as_Monster() {
return test_type() == MyGame::Example::Any_Monster ? static_cast<MyGame::Example::Monster *>(mutable_test()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_test_as_TestSimpleTableWithEnum() {
return test_type() == MyGame::Example::Any_TestSimpleTableWithEnum ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_test()) : nullptr;
}
MyGame::Example2::Monster *mutable_test_as_MyGame_Example2_Monster() {
return test_type() == MyGame::Example::Any_MyGame_Example2_Monster ? static_cast<MyGame::Example2::Monster *>(mutable_test()) : nullptr;
}
void *mutable_test() {
return GetPointer<void *>(VT_TEST);
}
@@ -1723,6 +1733,16 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example2::Monster *any_unique_as_M2() const {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<const MyGame::Example2::Monster *>(any_unique()) : nullptr;
}
template<typename T> T *mutable_any_unique_as();
MyGame::Example::Monster *mutable_any_unique_as_M() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M ? static_cast<MyGame::Example::Monster *>(mutable_any_unique()) : nullptr;
}
MyGame::Example::TestSimpleTableWithEnum *mutable_any_unique_as_TS() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_TS ? static_cast<MyGame::Example::TestSimpleTableWithEnum *>(mutable_any_unique()) : nullptr;
}
MyGame::Example2::Monster *mutable_any_unique_as_M2() {
return any_unique_type() == MyGame::Example::AnyUniqueAliases_M2 ? static_cast<MyGame::Example2::Monster *>(mutable_any_unique()) : nullptr;
}
void *mutable_any_unique() {
return GetPointer<void *>(VT_ANY_UNIQUE);
}
@@ -1741,6 +1761,15 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const MyGame::Example::Monster *any_ambiguous_as_M3() const {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<const MyGame::Example::Monster *>(any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M1() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M1 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M2() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M2 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
MyGame::Example::Monster *mutable_any_ambiguous_as_M3() {
return any_ambiguous_type() == MyGame::Example::AnyAmbiguousAliases_M3 ? static_cast<MyGame::Example::Monster *>(mutable_any_ambiguous()) : nullptr;
}
void *mutable_any_ambiguous() {
return GetPointer<void *>(VT_ANY_AMBIGUOUS);
}
@@ -1950,26 +1979,50 @@ template<> inline const MyGame::Example::Monster *Monster::test_as<MyGame::Examp
return test_as_Monster();
}
template<> inline MyGame::Example::Monster *Monster::mutable_test_as<MyGame::Example::Monster>() {
return mutable_test_as_Monster();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::test_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return test_as_TestSimpleTableWithEnum();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_test_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_test_as_TestSimpleTableWithEnum();
}
template<> inline const MyGame::Example2::Monster *Monster::test_as<MyGame::Example2::Monster>() const {
return test_as_MyGame_Example2_Monster();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_test_as<MyGame::Example2::Monster>() {
return mutable_test_as_MyGame_Example2_Monster();
}
template<> inline const MyGame::Example::Monster *Monster::any_unique_as<MyGame::Example::Monster>() const {
return any_unique_as_M();
}
template<> inline MyGame::Example::Monster *Monster::mutable_any_unique_as<MyGame::Example::Monster>() {
return mutable_any_unique_as_M();
}
template<> inline const MyGame::Example::TestSimpleTableWithEnum *Monster::any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() const {
return any_unique_as_TS();
}
template<> inline MyGame::Example::TestSimpleTableWithEnum *Monster::mutable_any_unique_as<MyGame::Example::TestSimpleTableWithEnum>() {
return mutable_any_unique_as_TS();
}
template<> inline const MyGame::Example2::Monster *Monster::any_unique_as<MyGame::Example2::Monster>() const {
return any_unique_as_M2();
}
template<> inline MyGame::Example2::Monster *Monster::mutable_any_unique_as<MyGame::Example2::Monster>() {
return mutable_any_unique_as_M2();
}
struct MonsterBuilder {
typedef Monster Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -117,6 +117,10 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const NamespaceA::NamespaceB::TableInNestedNS *foo_union_as_TableInNestedNS() const {
return foo_union_type() == NamespaceA::NamespaceB::UnionInNestedNS_TableInNestedNS ? static_cast<const NamespaceA::NamespaceB::TableInNestedNS *>(foo_union()) : nullptr;
}
template<typename T> T *mutable_foo_union_as();
NamespaceA::NamespaceB::TableInNestedNS *mutable_foo_union_as_TableInNestedNS() {
return foo_union_type() == NamespaceA::NamespaceB::UnionInNestedNS_TableInNestedNS ? static_cast<NamespaceA::NamespaceB::TableInNestedNS *>(mutable_foo_union()) : nullptr;
}
void *mutable_foo_union() {
return GetPointer<void *>(VT_FOO_UNION);
}
@@ -147,6 +151,10 @@ template<> inline const NamespaceA::NamespaceB::TableInNestedNS *TableInFirstNS:
return foo_union_as_TableInNestedNS();
}
template<> inline NamespaceA::NamespaceB::TableInNestedNS *TableInFirstNS::mutable_foo_union_as<NamespaceA::NamespaceB::TableInNestedNS>() {
return mutable_foo_union_as_TableInNestedNS();
}
struct TableInFirstNSBuilder {
typedef TableInFirstNS Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -420,6 +420,16 @@ struct D FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const UnionUnderlyingType::C *test_union_as_C() const {
return test_union_type() == UnionUnderlyingType::ABC::C ? static_cast<const UnionUnderlyingType::C *>(test_union()) : nullptr;
}
template<typename T> T *mutable_test_union_as();
UnionUnderlyingType::A *mutable_test_union_as_A() {
return test_union_type() == UnionUnderlyingType::ABC::A ? static_cast<UnionUnderlyingType::A *>(mutable_test_union()) : nullptr;
}
UnionUnderlyingType::B *mutable_test_union_as_B() {
return test_union_type() == UnionUnderlyingType::ABC::B ? static_cast<UnionUnderlyingType::B *>(mutable_test_union()) : nullptr;
}
UnionUnderlyingType::C *mutable_test_union_as_C() {
return test_union_type() == UnionUnderlyingType::ABC::C ? static_cast<UnionUnderlyingType::C *>(mutable_test_union()) : nullptr;
}
void *mutable_test_union() {
return GetPointer<void *>(VT_TEST_UNION);
}
@@ -457,14 +467,26 @@ template<> inline const UnionUnderlyingType::A *D::test_union_as<UnionUnderlying
return test_union_as_A();
}
template<> inline UnionUnderlyingType::A *D::mutable_test_union_as<UnionUnderlyingType::A>() {
return mutable_test_union_as_A();
}
template<> inline const UnionUnderlyingType::B *D::test_union_as<UnionUnderlyingType::B>() const {
return test_union_as_B();
}
template<> inline UnionUnderlyingType::B *D::mutable_test_union_as<UnionUnderlyingType::B>() {
return mutable_test_union_as_B();
}
template<> inline const UnionUnderlyingType::C *D::test_union_as<UnionUnderlyingType::C>() const {
return test_union_as_C();
}
template<> inline UnionUnderlyingType::C *D::mutable_test_union_as<UnionUnderlyingType::C>() {
return mutable_test_union_as_C();
}
struct DBuilder {
typedef D Table;
::flatbuffers::FlatBufferBuilder &fbb_;

View File

@@ -623,6 +623,24 @@ struct Movie FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const ::flatbuffers::String *main_character_as_Unused() const {
return main_character_type() == Character_Unused ? static_cast<const ::flatbuffers::String *>(main_character()) : nullptr;
}
Attacker *mutable_main_character_as_MuLan() {
return main_character_type() == Character_MuLan ? static_cast<Attacker *>(mutable_main_character()) : nullptr;
}
Rapunzel *mutable_main_character_as_Rapunzel() {
return main_character_type() == Character_Rapunzel ? static_cast<Rapunzel *>(mutable_main_character()) : nullptr;
}
BookReader *mutable_main_character_as_Belle() {
return main_character_type() == Character_Belle ? static_cast<BookReader *>(mutable_main_character()) : nullptr;
}
BookReader *mutable_main_character_as_BookFan() {
return main_character_type() == Character_BookFan ? static_cast<BookReader *>(mutable_main_character()) : nullptr;
}
::flatbuffers::String *mutable_main_character_as_Other() {
return main_character_type() == Character_Other ? static_cast<::flatbuffers::String *>(mutable_main_character()) : nullptr;
}
::flatbuffers::String *mutable_main_character_as_Unused() {
return main_character_type() == Character_Unused ? static_cast<::flatbuffers::String *>(mutable_main_character()) : nullptr;
}
void *mutable_main_character() {
return GetPointer<void *>(VT_MAIN_CHARACTER);
}