Merge "added reuse option for root objects" into ub-games-master
This commit is contained in:
commit
42bfe240e0
|
@ -322,13 +322,18 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
|
|||
if (!struct_def.fixed) {
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
// of a FlatBuffer
|
||||
code += " public static " + struct_def.name + " ";
|
||||
code += FunctionStart(lang, 'G') + "etRootAs" + struct_def.name;
|
||||
code += "(ByteBuffer _bb) { ";
|
||||
std::string method_name = FunctionStart(lang, 'G') + "etRootAs" + struct_def.name;
|
||||
std::string method_signature = " public static " + struct_def.name + " " + method_name;
|
||||
|
||||
// create convenience method that doesn't require an existing object
|
||||
code += method_signature + "(ByteBuffer _bb) ";
|
||||
code += "{ return " + method_name + "(_bb, new " + struct_def.name+ "()); }\n";
|
||||
|
||||
// create method that allows object reuse
|
||||
code += method_signature + "(ByteBuffer _bb, " + struct_def.name + " obj) { ";
|
||||
code += lang.set_bb_byteorder;
|
||||
code += "return (new " + struct_def.name;
|
||||
code += "()).__init(_bb." + FunctionStart(lang, 'G');
|
||||
code += "etInt(_bb.position()) + _bb.position(), _bb); }\n";
|
||||
code += "return (obj.__init(_bb." + FunctionStart(lang, 'G');
|
||||
code += "etInt(_bb.position()) + _bb.position(), _bb)); }\n";
|
||||
if (parser.root_struct_def == &struct_def) {
|
||||
if (parser.file_identifier_.length()) {
|
||||
// Check if a buffer has the identifier.
|
||||
|
|
|
@ -6,7 +6,8 @@ namespace MyGame.Example
|
|||
using FlatBuffers;
|
||||
|
||||
public class Monster : Table {
|
||||
public static Monster GetRootAsMonster(ByteBuffer _bb) { return (new Monster()).__init(_bb.GetInt(_bb.position()) + _bb.position(), _bb); }
|
||||
public static Monster GetRootAsMonster(ByteBuffer _bb) { return GetRootAsMonster(_bb, new Monster()); }
|
||||
public static Monster GetRootAsMonster(ByteBuffer _bb, Monster obj) { return (obj.__init(_bb.GetInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public static bool MonsterBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "MONS"); }
|
||||
public Monster __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ import java.util.*;
|
|||
import com.google.flatbuffers.*;
|
||||
|
||||
public class Monster extends Table {
|
||||
public static Monster getRootAsMonster(ByteBuffer _bb) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (new Monster()).__init(_bb.getInt(_bb.position()) + _bb.position(), _bb); }
|
||||
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
|
||||
public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public static boolean MonsterBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "MONS"); }
|
||||
public Monster __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ namespace MyGame.Example
|
|||
using FlatBuffers;
|
||||
|
||||
public class Stat : Table {
|
||||
public static Stat GetRootAsStat(ByteBuffer _bb) { return (new Stat()).__init(_bb.GetInt(_bb.position()) + _bb.position(), _bb); }
|
||||
public static Stat GetRootAsStat(ByteBuffer _bb) { return GetRootAsStat(_bb, new Stat()); }
|
||||
public static Stat GetRootAsStat(ByteBuffer _bb, Stat obj) { return (obj.__init(_bb.GetInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public Stat __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
public string Id() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
|
|
|
@ -8,7 +8,8 @@ import java.util.*;
|
|||
import com.google.flatbuffers.*;
|
||||
|
||||
public class Stat extends Table {
|
||||
public static Stat getRootAsStat(ByteBuffer _bb) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (new Stat()).__init(_bb.getInt(_bb.position()) + _bb.position(), _bb); }
|
||||
public static Stat getRootAsStat(ByteBuffer _bb) { return getRootAsStat(_bb, new Stat()); }
|
||||
public static Stat getRootAsStat(ByteBuffer _bb, Stat obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public Stat __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
public String id() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
|
|
Loading…
Reference in New Issue