mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 19:52:01 +00:00
Merge pull request #3924 from TGIshib/master
Added --escape-proto-identifiers command-line option.
This commit is contained in:
@@ -337,6 +337,7 @@ struct IDLOptions {
|
|||||||
bool generate_all;
|
bool generate_all;
|
||||||
bool skip_unexpected_fields_in_json;
|
bool skip_unexpected_fields_in_json;
|
||||||
bool generate_name_strings;
|
bool generate_name_strings;
|
||||||
|
bool escape_proto_identifiers;
|
||||||
|
|
||||||
// Possible options for the more general generator below.
|
// Possible options for the more general generator below.
|
||||||
enum Language { kJava, kCSharp, kGo, kMAX };
|
enum Language { kJava, kCSharp, kGo, kMAX };
|
||||||
@@ -356,6 +357,7 @@ struct IDLOptions {
|
|||||||
generate_all(false),
|
generate_all(false),
|
||||||
skip_unexpected_fields_in_json(false),
|
skip_unexpected_fields_in_json(false),
|
||||||
generate_name_strings(false),
|
generate_name_strings(false),
|
||||||
|
escape_proto_identifiers(false),
|
||||||
lang(IDLOptions::kJava) {}
|
lang(IDLOptions::kJava) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -120,8 +120,9 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) {
|
|||||||
" --no-includes Don\'t generate include statements for included\n"
|
" --no-includes Don\'t generate include statements for included\n"
|
||||||
" schemas the generated file depends on (C++).\n"
|
" schemas the generated file depends on (C++).\n"
|
||||||
" --gen-mutable Generate accessors that can mutate buffers in-place.\n"
|
" --gen-mutable Generate accessors that can mutate buffers in-place.\n"
|
||||||
" --gen-onefile Generate single output file for C#\n"
|
" --gen-onefile Generate single output file for C#.\n"
|
||||||
" --gen-name-strings Generate type name functions for C++.\n"
|
" --gen-name-strings Generate type name functions for C++.\n"
|
||||||
|
" --escape-proto-ids Disable appending '_' in namespaces names.\n"
|
||||||
" --raw-binary Allow binaries without file_indentifier to be read.\n"
|
" --raw-binary Allow binaries without file_indentifier to be read.\n"
|
||||||
" This may crash flatc given a mismatched schema.\n"
|
" This may crash flatc given a mismatched schema.\n"
|
||||||
" --proto Input is a .proto, translate to .fbs.\n"
|
" --proto Input is a .proto, translate to .fbs.\n"
|
||||||
@@ -194,6 +195,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
binary_files_from = filenames.size();
|
binary_files_from = filenames.size();
|
||||||
} else if(arg == "--proto") {
|
} else if(arg == "--proto") {
|
||||||
opts.proto_mode = true;
|
opts.proto_mode = true;
|
||||||
|
} else if(arg == "--escape-proto-ids") {
|
||||||
|
opts.escape_proto_identifiers = true;
|
||||||
} else if(arg == "--schema") {
|
} else if(arg == "--schema") {
|
||||||
schema_binary = true;
|
schema_binary = true;
|
||||||
} else if(arg == "-M") {
|
} else if(arg == "-M") {
|
||||||
|
|||||||
@@ -53,12 +53,14 @@ static void GenNameSpace(const Namespace &name_space, std::string *_schema,
|
|||||||
|
|
||||||
// Generate a flatbuffer schema from the Parser's internal representation.
|
// Generate a flatbuffer schema from the Parser's internal representation.
|
||||||
std::string GenerateFBS(const Parser &parser, const std::string &file_name) {
|
std::string GenerateFBS(const Parser &parser, const std::string &file_name) {
|
||||||
// Proto namespaces may clash with table names, so we have to prefix all:
|
// Proto namespaces may clash with table names, so we have to prefix all:
|
||||||
for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end();
|
if (!parser.opts.escape_proto_identifiers) {
|
||||||
++it) {
|
for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end();
|
||||||
for (auto comp = (*it)->components.begin(); comp != (*it)->components.end();
|
++it) {
|
||||||
++comp) {
|
for (auto comp = (*it)->components.begin(); comp != (*it)->components.end();
|
||||||
(*comp) = "_" + (*comp);
|
++comp) {
|
||||||
|
(*comp) = "_" + (*comp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user