Changes to support binary schema file loading and parsing (flatc) (#6823)

* Changes to support binary schema file loading and parsing (flatc)
- parser.reset() is also called if binary schema file is given
- code flow changed to not try to load a binary schema as textual schema

* Removed unneeded braces
This commit is contained in:
Herr Frei
2021-09-08 22:19:00 +02:00
committed by GitHub
parent 156a30c753
commit 338331b55b

View File

@@ -482,16 +482,17 @@ int FlatCompiler::Compile(int argc, const char **argv) {
contents.length() != strlen(contents.c_str())) {
Error("input file appears to be binary: " + filename, true);
}
if (is_schema) {
if (is_schema || is_binary_schema) {
// If we're processing multiple schemas, make sure to start each
// one from scratch. If it depends on previous schemas it must do
// so explicitly using an include.
parser.reset(new flatbuffers::Parser(opts));
}
// Try to parse the file contents (binary schema/flexbuffer/textual
// schema)
if (is_binary_schema) {
LoadBinarySchema(*parser.get(), filename, contents);
}
if (opts.use_flexbuffers) {
} else if (opts.use_flexbuffers) {
if (opts.lang_to_generate == IDLOptions::kJson) {
parser->flex_root_ = flexbuffers::GetRoot(
reinterpret_cast<const uint8_t *>(contents.c_str()),