mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 12:54:12 +00:00
Made sure GetRootAs..() functions are generated for all Java tables.
Previously they were only generated for the root_type, making it impossible to use the other types in the file as the root of a buffer. Bug: 17206174 Change-Id: Ie71bed42ac3b22dcceae6385cbd5846c37e5f1b8 Tested: on Linux
This commit is contained in:
@@ -154,9 +154,7 @@ static void GenStructBody(const StructDef &struct_def, std::string *code_ptr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GenStruct(StructDef &struct_def,
|
static void GenStruct(StructDef &struct_def, std::string *code_ptr) {
|
||||||
std::string *code_ptr,
|
|
||||||
StructDef *root_struct_def) {
|
|
||||||
if (struct_def.generated) return;
|
if (struct_def.generated) return;
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
|
|
||||||
@@ -170,9 +168,9 @@ static void GenStruct(StructDef &struct_def,
|
|||||||
code += "public class " + struct_def.name + " extends ";
|
code += "public class " + struct_def.name + " extends ";
|
||||||
code += struct_def.fixed ? "Struct" : "Table";
|
code += struct_def.fixed ? "Struct" : "Table";
|
||||||
code += " {\n";
|
code += " {\n";
|
||||||
if (&struct_def == root_struct_def) {
|
if (!struct_def.fixed) {
|
||||||
// Generate a special accessor for the table that has been declared as
|
// Generate a special accessor for the table that when used as the root
|
||||||
// the root type.
|
// of a FlatBuffer
|
||||||
code += " public static " + struct_def.name + " getRootAs";
|
code += " public static " + struct_def.name + " getRootAs";
|
||||||
code += struct_def.name;
|
code += struct_def.name;
|
||||||
code += "(ByteBuffer _bb, int offset) { ";
|
code += "(ByteBuffer _bb, int offset) { ";
|
||||||
@@ -377,7 +375,7 @@ bool GenerateJava(const Parser &parser,
|
|||||||
for (auto it = parser.structs_.vec.begin();
|
for (auto it = parser.structs_.vec.begin();
|
||||||
it != parser.structs_.vec.end(); ++it) {
|
it != parser.structs_.vec.end(); ++it) {
|
||||||
std::string declcode;
|
std::string declcode;
|
||||||
GenStruct(**it, &declcode, parser.root_struct_def);
|
GenStruct(**it, &declcode);
|
||||||
if (!SaveClass(parser, **it, declcode, path, true))
|
if (!SaveClass(parser, **it, declcode, path, true))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user