mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Allow unions of table types with the same name but from different namespaces.
Also fixed most codegenerators using the wrong namespace when multiple namespace were used in a file, with some files not being generated. Change-Id: Ib42969221239d7244e431cbd667ef69200fc415f Tested: on Linux. Bug: 29338474
This commit is contained in:
@@ -24,11 +24,12 @@ class BaseGenerator {
|
||||
virtual bool generate() = 0;
|
||||
|
||||
static const std::string NamespaceDir(const Parser &parser,
|
||||
const std::string &path) {
|
||||
const std::string &path,
|
||||
const Namespace &ns) {
|
||||
EnsureDirExists(path.c_str());
|
||||
if (parser.opts.one_file) return path;
|
||||
std::string namespace_dir = path; // Either empty or ends in separator.
|
||||
auto &namespaces = parser.namespaces_.back()->components;
|
||||
auto &namespaces = ns.components;
|
||||
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||
namespace_dir += *it + kPathSeparator;
|
||||
EnsureDirExists(namespace_dir.c_str());
|
||||
@@ -41,14 +42,17 @@ class BaseGenerator {
|
||||
const std::string &file_name)
|
||||
: parser_(parser),
|
||||
path_(path),
|
||||
file_name_(file_name),
|
||||
namespace_dir_(BaseGenerator::NamespaceDir(parser, path)){};
|
||||
virtual ~BaseGenerator(){};
|
||||
file_name_(file_name) {};
|
||||
virtual ~BaseGenerator() {};
|
||||
|
||||
// No copy/assign.
|
||||
BaseGenerator &operator=(const BaseGenerator &);
|
||||
BaseGenerator(const BaseGenerator &);
|
||||
|
||||
const std::string NamespaceDir(const Namespace &ns) {
|
||||
return BaseGenerator::NamespaceDir(parser_, path_, ns);
|
||||
}
|
||||
|
||||
const char *FlatBuffersGeneratedWarning() {
|
||||
return "automatically generated by the FlatBuffers compiler,"
|
||||
" do not modify\n\n";
|
||||
@@ -66,9 +70,9 @@ class BaseGenerator {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string FullNamespace(const char *separator) {
|
||||
std::string FullNamespace(const char *separator, const Namespace &ns) {
|
||||
std::string namespace_name;
|
||||
auto &namespaces = parser_.namespaces_.back()->components;
|
||||
auto &namespaces = ns.components;
|
||||
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||
if (namespace_name.length()) namespace_name += separator;
|
||||
namespace_name += *it;
|
||||
@@ -76,15 +80,14 @@ class BaseGenerator {
|
||||
return namespace_name;
|
||||
}
|
||||
|
||||
const std::string LastNamespacePart() {
|
||||
auto &namespaces = parser_.namespaces_.back()->components;
|
||||
const std::string LastNamespacePart(const Namespace &ns) {
|
||||
auto &namespaces = ns.components;
|
||||
if (namespaces.size()) return *(namespaces.end() - 1); else return std::string("");
|
||||
}
|
||||
|
||||
const Parser &parser_;
|
||||
const std::string &path_;
|
||||
const std::string &file_name_;
|
||||
const std::string namespace_dir_;
|
||||
};
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -1129,27 +1129,32 @@ class GeneralGenerator : public BaseGenerator {
|
||||
for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
|
||||
++it) {
|
||||
std::string enumcode;
|
||||
GenEnum(lang, parser_, **it, &enumcode);
|
||||
auto &enum_def = **it;
|
||||
GenEnum(lang, parser_, enum_def, &enumcode);
|
||||
if (parser_.opts.one_file) {
|
||||
one_file_code += enumcode;
|
||||
} else {
|
||||
if (!SaveType(lang, (**it).name, enumcode, false)) return false;
|
||||
if (!SaveType(lang, enum_def.name, *enum_def.defined_namespace,
|
||||
enumcode, false)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = parser_.structs_.vec.begin();
|
||||
it != parser_.structs_.vec.end(); ++it) {
|
||||
std::string declcode;
|
||||
GenStruct(lang, parser_, **it, &declcode);
|
||||
auto &struct_def = **it;
|
||||
GenStruct(lang, parser_, struct_def, &declcode);
|
||||
if (parser_.opts.one_file) {
|
||||
one_file_code += declcode;
|
||||
} else {
|
||||
if (!SaveType(lang, (**it).name, declcode, true)) return false;
|
||||
if (!SaveType(lang, struct_def.name, *struct_def.defined_namespace,
|
||||
declcode, true)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (parser_.opts.one_file) {
|
||||
return SaveType(lang, file_name_, one_file_code, true);
|
||||
return SaveType(lang, file_name_, *parser_.namespaces_.back(),
|
||||
one_file_code, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1157,12 +1162,13 @@ class GeneralGenerator : public BaseGenerator {
|
||||
// Save out the generated code for a single class while adding
|
||||
// declaration boilerplate.
|
||||
bool SaveType(const LanguageParameters &lang, const std::string &defname,
|
||||
const std::string &classcode, bool needs_includes) {
|
||||
const Namespace &ns, const std::string &classcode,
|
||||
bool needs_includes) {
|
||||
if (!classcode.length()) return true;
|
||||
|
||||
std::string code;
|
||||
code = code + "// " + FlatBuffersGeneratedWarning();
|
||||
std::string namespace_name = FullNamespace(".");
|
||||
std::string namespace_name = FullNamespace(".", ns);
|
||||
if (!namespace_name.empty()) {
|
||||
code += lang.namespace_ident + namespace_name + lang.namespace_begin;
|
||||
code += "\n\n";
|
||||
@@ -1170,7 +1176,7 @@ class GeneralGenerator : public BaseGenerator {
|
||||
if (needs_includes) code += lang.includes;
|
||||
code += classcode;
|
||||
if (!namespace_name.empty()) code += lang.namespace_end;
|
||||
auto filename = namespace_dir_ + defname + lang.file_extension;
|
||||
auto filename = NamespaceDir(ns) + defname + lang.file_extension;
|
||||
return SaveFile(filename.c_str(), code, false);
|
||||
}
|
||||
};
|
||||
@@ -1188,19 +1194,25 @@ std::string GeneralMakeRule(const Parser &parser, const std::string &path,
|
||||
auto lang = language_parameters[parser.opts.lang];
|
||||
|
||||
std::string make_rule;
|
||||
std::string directory =
|
||||
BaseGenerator::NamespaceDir(parser, path) + kPathSeparator;
|
||||
|
||||
for (auto it = parser.enums_.vec.begin(); it != parser.enums_.vec.end();
|
||||
++it) {
|
||||
auto &enum_def = **it;
|
||||
if (make_rule != "") make_rule += " ";
|
||||
make_rule += directory + (**it).name + lang.file_extension;
|
||||
std::string directory =
|
||||
BaseGenerator::NamespaceDir(parser, path, *enum_def.defined_namespace) +
|
||||
kPathSeparator;
|
||||
make_rule += directory + enum_def.name + lang.file_extension;
|
||||
}
|
||||
|
||||
for (auto it = parser.structs_.vec.begin(); it != parser.structs_.vec.end();
|
||||
++it) {
|
||||
auto &struct_def = **it;
|
||||
if (make_rule != "") make_rule += " ";
|
||||
make_rule += directory + (**it).name + lang.file_extension;
|
||||
std::string directory =
|
||||
BaseGenerator::NamespaceDir(parser, path, *struct_def.defined_namespace) +
|
||||
kPathSeparator;
|
||||
make_rule += directory + struct_def.name + lang.file_extension;
|
||||
}
|
||||
|
||||
make_rule += ": ";
|
||||
|
||||
@@ -664,9 +664,10 @@ class GoGenerator : public BaseGenerator {
|
||||
if (!classcode.length()) return true;
|
||||
|
||||
std::string code = "";
|
||||
BeginFile(LastNamespacePart(), needs_imports, &code);
|
||||
BeginFile(LastNamespacePart(*def.defined_namespace), needs_imports, &code);
|
||||
code += classcode;
|
||||
std::string filename = namespace_dir_ + def.name + ".go";
|
||||
std::string filename =
|
||||
NamespaceDir(*def.defined_namespace) + def.name + ".go";
|
||||
return SaveFile(filename.c_str(), code, false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -985,11 +985,12 @@ namespace php {
|
||||
if (!classcode.length()) return true;
|
||||
|
||||
std::string code = "";
|
||||
BeginFile(FullNamespace("\\"), needs_imports, &code);
|
||||
BeginFile(FullNamespace("\\", *def.defined_namespace),
|
||||
needs_imports, &code);
|
||||
code += classcode;
|
||||
|
||||
std::string filename =
|
||||
namespace_dir_ + kPathSeparator + def.name + ".php";
|
||||
std::string filename = NamespaceDir(*def.defined_namespace) +
|
||||
kPathSeparator + def.name + ".php";
|
||||
return SaveFile(filename.c_str(), code, false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -652,9 +652,10 @@ class PythonGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
std::string code = "";
|
||||
BeginFile(LastNamespacePart(), needs_imports, &code);
|
||||
BeginFile(LastNamespacePart(*def.defined_namespace), needs_imports, &code);
|
||||
code += classcode;
|
||||
std::string filename = namespace_dir_ + kPathSeparator + def.name + ".py";
|
||||
std::string filename = NamespaceDir(*def.defined_namespace) +
|
||||
kPathSeparator + def.name + ".py";
|
||||
return SaveFile(filename.c_str(), code, false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1180,7 +1180,13 @@ CheckedError Parser::ParseEnum(bool is_union, EnumDef **dest) {
|
||||
auto full_name = value_name;
|
||||
std::vector<std::string> value_comment = doc_comment_;
|
||||
EXPECT(kTokenIdentifier);
|
||||
if (is_union) ECHECK(ParseNamespacing(&full_name, &value_name));
|
||||
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(), '.', '_');
|
||||
}
|
||||
auto prevsize = enum_def.vals.vec.size();
|
||||
auto value = enum_def.vals.vec.size()
|
||||
? enum_def.vals.vec.back()->value + 1
|
||||
|
||||
@@ -8,6 +8,7 @@ public enum Any : byte
|
||||
NONE = 0,
|
||||
Monster = 1,
|
||||
TestSimpleTableWithEnum = 2,
|
||||
MyGame_Example2_Monster = 3,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -6,4 +6,5 @@ const (
|
||||
AnyNONE = 0
|
||||
AnyMonster = 1
|
||||
AnyTestSimpleTableWithEnum = 2
|
||||
AnyMyGame_Example2_Monster = 3
|
||||
)
|
||||
|
||||
@@ -7,8 +7,9 @@ public final class Any {
|
||||
public static final byte NONE = 0;
|
||||
public static final byte Monster = 1;
|
||||
public static final byte TestSimpleTableWithEnum = 2;
|
||||
public static final byte MyGame_Example2_Monster = 3;
|
||||
|
||||
private static final String[] names = { "NONE", "Monster", "TestSimpleTableWithEnum", };
|
||||
private static final String[] names = { "NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@ class Any
|
||||
const NONE = 0;
|
||||
const Monster = 1;
|
||||
const TestSimpleTableWithEnum = 2;
|
||||
const MyGame_Example2_Monster = 3;
|
||||
|
||||
private static $names = array(
|
||||
"NONE",
|
||||
"Monster",
|
||||
"TestSimpleTableWithEnum",
|
||||
"MyGame_Example2_Monster",
|
||||
);
|
||||
|
||||
public static function Name($e)
|
||||
|
||||
@@ -6,4 +6,5 @@ class Any(object):
|
||||
NONE = 0
|
||||
Monster = 1
|
||||
TestSimpleTableWithEnum = 2
|
||||
MyGame_Example2_Monster = 3
|
||||
|
||||
|
||||
23
tests/MyGame/Example2/Monster.cs
Normal file
23
tests/MyGame/Example2/Monster.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace MyGame.Example2
|
||||
{
|
||||
|
||||
using System;
|
||||
using FlatBuffers;
|
||||
|
||||
public sealed class Monster : Table {
|
||||
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 Monster __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
|
||||
public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(0); }
|
||||
public static Offset<MyGame.Example2.Monster> EndMonster(FlatBufferBuilder builder) {
|
||||
int o = builder.EndObject();
|
||||
return new Offset<MyGame.Example2.Monster>(o);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
18
tests/MyGame/Example2/Monster.go
Normal file
18
tests/MyGame/Example2/Monster.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package Example2
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
)
|
||||
type Monster struct {
|
||||
_tab flatbuffers.Table
|
||||
}
|
||||
|
||||
func (rcv *Monster) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||
rcv._tab.Bytes = buf
|
||||
rcv._tab.Pos = i
|
||||
}
|
||||
|
||||
func MonsterStart(builder *flatbuffers.Builder) { builder.StartObject(0) }
|
||||
func MonsterEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() }
|
||||
23
tests/MyGame/Example2/Monster.java
Normal file
23
tests/MyGame/Example2/Monster.java
Normal file
@@ -0,0 +1,23 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example2;
|
||||
|
||||
import java.nio.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
import com.google.flatbuffers.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Monster extends Table {
|
||||
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 Monster __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
|
||||
public static void startMonster(FlatBufferBuilder builder) { builder.startObject(0); }
|
||||
public static int endMonster(FlatBufferBuilder builder) {
|
||||
int o = builder.endObject();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
79
tests/MyGame/Example2/Monster.php
Normal file
79
tests/MyGame/Example2/Monster.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace MyGame\Example2;
|
||||
|
||||
use \Google\FlatBuffers\Struct;
|
||||
use \Google\FlatBuffers\Table;
|
||||
use \Google\FlatBuffers\ByteBuffer;
|
||||
use \Google\FlatBuffers\FlatBufferBuilder;
|
||||
|
||||
class Monster extends Table
|
||||
{
|
||||
/**
|
||||
* @param ByteBuffer $bb
|
||||
* @return Monster
|
||||
*/
|
||||
public static function getRootAsMonster(ByteBuffer $bb)
|
||||
{
|
||||
$obj = new Monster();
|
||||
return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
|
||||
}
|
||||
|
||||
public static function MonsterIdentifier()
|
||||
{
|
||||
return "MONS";
|
||||
}
|
||||
|
||||
public static function MonsterBufferHasIdentifier(ByteBuffer $buf)
|
||||
{
|
||||
return self::__has_identifier($buf, self::MonsterIdentifier());
|
||||
}
|
||||
|
||||
public static function MonsterExtension()
|
||||
{
|
||||
return "mon";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $_i offset
|
||||
* @param ByteBuffer $_bb
|
||||
* @return Monster
|
||||
**/
|
||||
public function init($_i, ByteBuffer $_bb)
|
||||
{
|
||||
$this->bb_pos = $_i;
|
||||
$this->bb = $_bb;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return void
|
||||
*/
|
||||
public static function startMonster(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return Monster
|
||||
*/
|
||||
public static function createMonster(FlatBufferBuilder $builder, )
|
||||
{
|
||||
$builder->startObject(0);
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return int table offset
|
||||
*/
|
||||
public static function endMonster(FlatBufferBuilder $builder)
|
||||
{
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
15
tests/MyGame/Example2/Monster.py
Normal file
15
tests/MyGame/Example2/Monster.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example2
|
||||
|
||||
import flatbuffers
|
||||
|
||||
class Monster(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
# Monster
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
def MonsterStart(builder): builder.StartObject(0)
|
||||
def MonsterEnd(builder): return builder.EndObject()
|
||||
Binary file not shown.
@@ -2,13 +2,17 @@
|
||||
|
||||
include "include_test1.fbs";
|
||||
|
||||
namespace MyGame.Example2;
|
||||
|
||||
table Monster {} // Test having same name as below, but in different namespace.
|
||||
|
||||
namespace MyGame.Example;
|
||||
|
||||
attribute "priority";
|
||||
|
||||
enum Color:byte (bit_flags) { Red = 0, Green, Blue = 3, }
|
||||
|
||||
union Any { Monster, TestSimpleTableWithEnum } // TODO: add more elements
|
||||
union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster }
|
||||
|
||||
struct Test { a:short; b:byte; }
|
||||
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
namespace MyGame {
|
||||
namespace Example2 {
|
||||
|
||||
struct Monster;
|
||||
|
||||
} // namespace Example2
|
||||
|
||||
namespace Example {
|
||||
|
||||
struct Test;
|
||||
@@ -37,12 +43,13 @@ enum Any {
|
||||
Any_NONE = 0,
|
||||
Any_Monster = 1,
|
||||
Any_TestSimpleTableWithEnum = 2,
|
||||
Any_MyGame_Example2_Monster = 3,
|
||||
Any_MIN = Any_NONE,
|
||||
Any_MAX = Any_TestSimpleTableWithEnum
|
||||
Any_MAX = Any_MyGame_Example2_Monster
|
||||
};
|
||||
|
||||
inline const char **EnumNamesAny() {
|
||||
static const char *names[] = { "NONE", "Monster", "TestSimpleTableWithEnum", nullptr };
|
||||
static const char *names[] = { "NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster", nullptr };
|
||||
return names;
|
||||
}
|
||||
|
||||
@@ -98,6 +105,37 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||
};
|
||||
STRUCT_END(Vec3, 32);
|
||||
|
||||
} // namespace Example
|
||||
|
||||
namespace Example2 {
|
||||
|
||||
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct MonsterBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
MonsterBuilder &operator=(const MonsterBuilder &);
|
||||
flatbuffers::Offset<Monster> Finish() {
|
||||
auto o = flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 0));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb) {
|
||||
MonsterBuilder builder_(_fbb);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
} // namespace Example2
|
||||
|
||||
namespace Example {
|
||||
|
||||
struct TestSimpleTableWithEnum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
enum {
|
||||
VT_COLOR = 4
|
||||
@@ -424,6 +462,7 @@ inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, An
|
||||
case Any_NONE: return true;
|
||||
case Any_Monster: return verifier.VerifyTable(reinterpret_cast<const Monster *>(union_obj));
|
||||
case Any_TestSimpleTableWithEnum: return verifier.VerifyTable(reinterpret_cast<const TestSimpleTableWithEnum *>(union_obj));
|
||||
case Any_MyGame_Example2_Monster: return verifier.VerifyTable(reinterpret_cast<const MyGame::Example2::Monster *>(union_obj));
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,11 @@ var MyGame = MyGame || {};
|
||||
*/
|
||||
MyGame.Example = MyGame.Example || {};
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
MyGame.Example2 = MyGame.Example2 || {};
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
@@ -30,7 +35,59 @@ MyGame.Example.Color = {
|
||||
MyGame.Example.Any = {
|
||||
NONE: 0,
|
||||
Monster: 1,
|
||||
TestSimpleTableWithEnum: 2
|
||||
TestSimpleTableWithEnum: 2,
|
||||
MyGame_Example2_Monster: 3
|
||||
};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
MyGame.Example2.Monster = function() {
|
||||
/**
|
||||
* @type {flatbuffers.ByteBuffer}
|
||||
*/
|
||||
this.bb = null;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.bb_pos = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} i
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @returns {MyGame.Example2.Monster}
|
||||
*/
|
||||
MyGame.Example2.Monster.prototype.__init = function(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @param {MyGame.Example2.Monster=} obj
|
||||
* @returns {MyGame.Example2.Monster}
|
||||
*/
|
||||
MyGame.Example2.Monster.getRootAsMonster = function(bb, obj) {
|
||||
return (obj || new MyGame.Example2.Monster).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
*/
|
||||
MyGame.Example2.Monster.startMonster = function(builder) {
|
||||
builder.startObject(0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Example2.Monster.endMonster = function(builder) {
|
||||
var offset = builder.endObject();
|
||||
return offset;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
38
tests/namespace_test/NamespaceC/TableInC.cs
Normal file
38
tests/namespace_test/NamespaceC/TableInC.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace NamespaceC
|
||||
{
|
||||
|
||||
using System;
|
||||
using FlatBuffers;
|
||||
|
||||
public sealed class TableInC : Table {
|
||||
public static TableInC GetRootAsTableInC(ByteBuffer _bb) { return GetRootAsTableInC(_bb, new TableInC()); }
|
||||
public static TableInC GetRootAsTableInC(ByteBuffer _bb, TableInC obj) { return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public TableInC __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
public NamespaceA.TableInFirstNS ReferToA1 { get { return GetReferToA1(new NamespaceA.TableInFirstNS()); } }
|
||||
public NamespaceA.TableInFirstNS GetReferToA1(NamespaceA.TableInFirstNS obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
|
||||
public SecondTableInA ReferToA2 { get { return GetReferToA2(new SecondTableInA()); } }
|
||||
public SecondTableInA GetReferToA2(SecondTableInA obj) { int o = __offset(6); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
|
||||
|
||||
public static Offset<NamespaceC.TableInC> CreateTableInC(FlatBufferBuilder builder,
|
||||
Offset<NamespaceA.TableInFirstNS> refer_to_a1Offset = default(Offset<NamespaceA.TableInFirstNS>),
|
||||
Offset<SecondTableInA> refer_to_a2Offset = default(Offset<SecondTableInA>)) {
|
||||
builder.StartObject(2);
|
||||
TableInC.AddReferToA2(builder, refer_to_a2Offset);
|
||||
TableInC.AddReferToA1(builder, refer_to_a1Offset);
|
||||
return TableInC.EndTableInC(builder);
|
||||
}
|
||||
|
||||
public static void StartTableInC(FlatBufferBuilder builder) { builder.StartObject(2); }
|
||||
public static void AddReferToA1(FlatBufferBuilder builder, Offset<NamespaceA.TableInFirstNS> referToA1Offset) { builder.AddOffset(0, referToA1Offset.Value, 0); }
|
||||
public static void AddReferToA2(FlatBufferBuilder builder, Offset<SecondTableInA> referToA2Offset) { builder.AddOffset(1, referToA2Offset.Value, 0); }
|
||||
public static Offset<NamespaceC.TableInC> EndTableInC(FlatBufferBuilder builder) {
|
||||
int o = builder.EndObject();
|
||||
return new Offset<NamespaceC.TableInC>(o);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
46
tests/namespace_test/NamespaceC/TableInC.go
Normal file
46
tests/namespace_test/NamespaceC/TableInC.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package NamespaceC
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
)
|
||||
type TableInC struct {
|
||||
_tab flatbuffers.Table
|
||||
}
|
||||
|
||||
func (rcv *TableInC) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||
rcv._tab.Bytes = buf
|
||||
rcv._tab.Pos = i
|
||||
}
|
||||
|
||||
func (rcv *TableInC) ReferToA1(obj *TableInFirstNS) *TableInFirstNS {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
|
||||
if o != 0 {
|
||||
x := rcv._tab.Indirect(o + rcv._tab.Pos)
|
||||
if obj == nil {
|
||||
obj = new(TableInFirstNS)
|
||||
}
|
||||
obj.Init(rcv._tab.Bytes, x)
|
||||
return obj
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcv *TableInC) ReferToA2(obj *SecondTableInA) *SecondTableInA {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
|
||||
if o != 0 {
|
||||
x := rcv._tab.Indirect(o + rcv._tab.Pos)
|
||||
if obj == nil {
|
||||
obj = new(SecondTableInA)
|
||||
}
|
||||
obj.Init(rcv._tab.Bytes, x)
|
||||
return obj
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TableInCStart(builder *flatbuffers.Builder) { builder.StartObject(2) }
|
||||
func TableInCAddReferToA1(builder *flatbuffers.Builder, referToA1 flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(referToA1), 0) }
|
||||
func TableInCAddReferToA2(builder *flatbuffers.Builder, referToA2 flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(referToA2), 0) }
|
||||
func TableInCEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() }
|
||||
38
tests/namespace_test/NamespaceC/TableInC.java
Normal file
38
tests/namespace_test/NamespaceC/TableInC.java
Normal file
@@ -0,0 +1,38 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package NamespaceC;
|
||||
|
||||
import java.nio.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
import com.google.flatbuffers.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class TableInC extends Table {
|
||||
public static TableInC getRootAsTableInC(ByteBuffer _bb) { return getRootAsTableInC(_bb, new TableInC()); }
|
||||
public static TableInC getRootAsTableInC(ByteBuffer _bb, TableInC obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public TableInC __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
|
||||
|
||||
public NamespaceA.TableInFirstNS referToA1() { return referToA1(new NamespaceA.TableInFirstNS()); }
|
||||
public NamespaceA.TableInFirstNS referToA1(NamespaceA.TableInFirstNS obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
|
||||
public SecondTableInA referToA2() { return referToA2(new SecondTableInA()); }
|
||||
public SecondTableInA referToA2(SecondTableInA obj) { int o = __offset(6); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
|
||||
|
||||
public static int createTableInC(FlatBufferBuilder builder,
|
||||
int refer_to_a1Offset,
|
||||
int refer_to_a2Offset) {
|
||||
builder.startObject(2);
|
||||
TableInC.addReferToA2(builder, refer_to_a2Offset);
|
||||
TableInC.addReferToA1(builder, refer_to_a1Offset);
|
||||
return TableInC.endTableInC(builder);
|
||||
}
|
||||
|
||||
public static void startTableInC(FlatBufferBuilder builder) { builder.startObject(2); }
|
||||
public static void addReferToA1(FlatBufferBuilder builder, int referToA1Offset) { builder.addOffset(0, referToA1Offset, 0); }
|
||||
public static void addReferToA2(FlatBufferBuilder builder, int referToA2Offset) { builder.addOffset(1, referToA2Offset, 0); }
|
||||
public static int endTableInC(FlatBufferBuilder builder) {
|
||||
int o = builder.endObject();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
100
tests/namespace_test/NamespaceC/TableInC.php
Normal file
100
tests/namespace_test/NamespaceC/TableInC.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace NamespaceC;
|
||||
|
||||
use \Google\FlatBuffers\Struct;
|
||||
use \Google\FlatBuffers\Table;
|
||||
use \Google\FlatBuffers\ByteBuffer;
|
||||
use \Google\FlatBuffers\FlatBufferBuilder;
|
||||
|
||||
class TableInC extends Table
|
||||
{
|
||||
/**
|
||||
* @param ByteBuffer $bb
|
||||
* @return TableInC
|
||||
*/
|
||||
public static function getRootAsTableInC(ByteBuffer $bb)
|
||||
{
|
||||
$obj = new TableInC();
|
||||
return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $_i offset
|
||||
* @param ByteBuffer $_bb
|
||||
* @return TableInC
|
||||
**/
|
||||
public function init($_i, ByteBuffer $_bb)
|
||||
{
|
||||
$this->bb_pos = $_i;
|
||||
$this->bb = $_bb;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReferToA1()
|
||||
{
|
||||
$obj = new TableInFirstNS();
|
||||
$o = $this->__offset(4);
|
||||
return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0;
|
||||
}
|
||||
|
||||
public function getReferToA2()
|
||||
{
|
||||
$obj = new SecondTableInA();
|
||||
$o = $this->__offset(6);
|
||||
return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return void
|
||||
*/
|
||||
public static function startTableInC(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return TableInC
|
||||
*/
|
||||
public static function createTableInC(FlatBufferBuilder $builder, $refer_to_a1, $refer_to_a2)
|
||||
{
|
||||
$builder->startObject(2);
|
||||
self::addReferToA1($builder, $refer_to_a1);
|
||||
self::addReferToA2($builder, $refer_to_a2);
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param int
|
||||
* @return void
|
||||
*/
|
||||
public static function addReferToA1(FlatBufferBuilder $builder, $referToA1)
|
||||
{
|
||||
$builder->addOffsetX(0, $referToA1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param int
|
||||
* @return void
|
||||
*/
|
||||
public static function addReferToA2(FlatBufferBuilder $builder, $referToA2)
|
||||
{
|
||||
$builder->addOffsetX(1, $referToA2, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return int table offset
|
||||
*/
|
||||
public static function endTableInC(FlatBufferBuilder $builder)
|
||||
{
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
39
tests/namespace_test/NamespaceC/TableInC.py
Normal file
39
tests/namespace_test/NamespaceC/TableInC.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: NamespaceC
|
||||
|
||||
import flatbuffers
|
||||
|
||||
class TableInC(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
# TableInC
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# TableInC
|
||||
def ReferToA1(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
|
||||
if o != 0:
|
||||
x = self._tab.Indirect(o + self._tab.Pos)
|
||||
from .TableInFirstNS import TableInFirstNS
|
||||
obj = TableInFirstNS()
|
||||
obj.Init(self._tab.Bytes, x)
|
||||
return obj
|
||||
return None
|
||||
|
||||
# TableInC
|
||||
def ReferToA2(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
||||
if o != 0:
|
||||
x = self._tab.Indirect(o + self._tab.Pos)
|
||||
from .SecondTableInA import SecondTableInA
|
||||
obj = SecondTableInA()
|
||||
obj.Init(self._tab.Bytes, x)
|
||||
return obj
|
||||
return None
|
||||
|
||||
def TableInCStart(builder): builder.StartObject(2)
|
||||
def TableInCAddReferToA1(builder, referToA1): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(referToA1), 0)
|
||||
def TableInCAddReferToA2(builder, referToA2): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(referToA2), 0)
|
||||
def TableInCEnd(builder): return builder.EndObject()
|
||||
Reference in New Issue
Block a user