diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 1f4501629..25706e84f 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -347,6 +347,7 @@ struct IDLOptions { bool generate_name_strings; bool escape_proto_identifiers; bool generate_object_based_api; + bool union_value_namespacing; // Possible options for the more general generator below. enum Language { kJava, kCSharp, kGo, kMAX }; @@ -368,6 +369,7 @@ struct IDLOptions { generate_name_strings(false), escape_proto_identifiers(false), generate_object_based_api(false), + union_value_namespacing(true), lang(IDLOptions::kJava) {} }; diff --git a/src/flatc.cpp b/src/flatc.cpp index a568bbb24..b174cbd43 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -195,6 +195,8 @@ int main(int argc, const char *argv[]) { } else if(arg == "--scoped-enums") { opts.prefixed_enums = false; opts.scoped_enums = true; + } else if (arg == "--no-union-value-namespacing") { + opts.union_value_namespacing = false; } else if(arg == "--gen-mutable") { opts.mutable_buffer = true; } else if(arg == "--gen-name-strings") { diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index fc2136757..b03655c92 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1216,10 +1216,12 @@ CheckedError Parser::ParseEnum(bool is_union, EnumDef **dest) { EXPECT(kTokenIdentifier); if (is_union) { ECHECK(ParseNamespacing(&full_name, &value_name)); - // Since we can't namespace the actual enum identifiers, turn - // namespace parts into part of the identifier. - value_name = full_name; - std::replace(value_name.begin(), value_name.end(), '.', '_'); + if (opts.union_value_namespacing) { + // Since we can't namespace the actual enum identifiers, turn + // namespace parts into part of the identifier. + value_name = full_name; + std::replace(value_name.begin(), value_name.end(), '.', '_'); + } } auto prevsize = enum_def.vals.vec.size(); auto value = enum_def.vals.vec.size()