summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMaxim Zaks <maxim.zaks@gmail.com>2015-08-16 09:34:56 +0200
committerWouter van Oortmerssen <wvo@google.com>2015-08-19 14:39:06 -0700
commitac10873e26f99b3d054d1cb89c00bad239ace691 (patch)
tree0e3bd1beaa2491a69a14e902d091b685c6b536d0 /tests
parent9689d38befbb7640d8d7439431fa2dce7265ac50 (diff)
downloadflatbuffers-ac10873e26f99b3d054d1cb89c00bad239ace691.tar.gz
flatbuffers-ac10873e26f99b3d054d1cb89c00bad239ace691.tar.bz2
flatbuffers-ac10873e26f99b3d054d1cb89c00bad239ace691.zip
fixed code generator for array of bools
Change-Id: I3cdd801b641bf180222203a37634598350d340e3
Diffstat (limited to 'tests')
-rw-r--r--tests/MyGame/Example/Monster.cs8
-rw-r--r--tests/MyGame/Example/Monster.go22
-rw-r--r--tests/MyGame/Example/Monster.java9
-rw-r--r--tests/MyGame/Example/Monster.py19
-rw-r--r--tests/MyGame/Example/TestSimpleTableWithEnum.cs1
-rw-r--r--tests/MyGame/Example/TestSimpleTableWithEnum.java1
-rw-r--r--tests/monster_test.bfbsbin2496 -> 2744 bytes
-rwxr-xr-xtests/monster_test.fbs1
-rw-r--r--tests/monster_test_generated.h11
-rw-r--r--tests/monsterdata_python_wire.monbin288 -> 288 bytes
-rwxr-xr-xtests/monsterdata_test.json3
-rw-r--r--tests/monsterdata_test.monbin336 -> 352 bytes
12 files changed, 69 insertions, 6 deletions
diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs
index 975e4d08..0076595a 100644
--- a/tests/MyGame/Example/Monster.cs
+++ b/tests/MyGame/Example/Monster.cs
@@ -61,8 +61,11 @@ public sealed class Monster : Table {
public bool MutateTesthashs64Fnv1a(long testhashs64_fnv1a) { int o = __offset(48); if (o != 0) { bb.PutLong(o + bb_pos, testhashs64_fnv1a); return true; } else { return false; } }
public ulong Testhashu64Fnv1a { get { int o = __offset(50); return o != 0 ? bb.GetUlong(o + bb_pos) : (ulong)0; } }
public bool MutateTesthashu64Fnv1a(ulong testhashu64_fnv1a) { int o = __offset(50); if (o != 0) { bb.PutUlong(o + bb_pos, testhashu64_fnv1a); return true; } else { return false; } }
+ public bool GetTestarrayofbools(int j) { int o = __offset(52); return o != 0 ? 0!=bb.Get(__vector(o) + j * 1) : false; }
+ public int TestarrayofboolsLength { get { int o = __offset(52); return o != 0 ? __vector_len(o) : 0; } }
+ public bool MutateTestarrayofbools(int j, bool testarrayofbools) { int o = __offset(52); if (o != 0) { bb.Put(__vector(o) + j * 1, (byte)(testarrayofbools ? 1 : 0)); return true; } else { return false; } }
- public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(24); }
+ public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(25); }
public static void AddPos(FlatBufferBuilder builder, Offset<Vec3> posOffset) { builder.AddStruct(0, posOffset.Value, 0); }
public static void AddMana(FlatBufferBuilder builder, short mana) { builder.AddShort(1, mana, 150); }
public static void AddHp(FlatBufferBuilder builder, short hp) { builder.AddShort(2, hp, 100); }
@@ -95,6 +98,9 @@ public sealed class Monster : Table {
public static void AddTesthashu32Fnv1a(FlatBufferBuilder builder, uint testhashu32Fnv1a) { builder.AddUint(21, testhashu32Fnv1a, 0); }
public static void AddTesthashs64Fnv1a(FlatBufferBuilder builder, long testhashs64Fnv1a) { builder.AddLong(22, testhashs64Fnv1a, 0); }
public static void AddTesthashu64Fnv1a(FlatBufferBuilder builder, ulong testhashu64Fnv1a) { builder.AddUlong(23, testhashu64Fnv1a, 0); }
+ public static void AddTestarrayofbools(FlatBufferBuilder builder, VectorOffset testarrayofboolsOffset) { builder.AddOffset(24, testarrayofboolsOffset.Value, 0); }
+ public static VectorOffset CreateTestarrayofboolsVector(FlatBufferBuilder builder, bool[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddBool(data[i]); return builder.EndVector(); }
+ public static void StartTestarrayofboolsVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
public static Offset<Monster> EndMonster(FlatBufferBuilder builder) {
int o = builder.EndObject();
builder.Required(o, 10); // name
diff --git a/tests/MyGame/Example/Monster.go b/tests/MyGame/Example/Monster.go
index a51e4296..6c0c3659 100644
--- a/tests/MyGame/Example/Monster.go
+++ b/tests/MyGame/Example/Monster.go
@@ -295,7 +295,24 @@ func (rcv *Monster) Testhashu64Fnv1a() uint64 {
return 0
}
-func MonsterStart(builder *flatbuffers.Builder) { builder.StartObject(24) }
+func (rcv *Monster) Testarrayofbools(j int) byte {
+ o := flatbuffers.UOffsetT(rcv._tab.Offset(52))
+ if o != 0 {
+ a := rcv._tab.Vector(o)
+ return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j * 1))
+ }
+ return 0
+}
+
+func (rcv *Monster) TestarrayofboolsLength() int {
+ o := flatbuffers.UOffsetT(rcv._tab.Offset(52))
+ if o != 0 {
+ return rcv._tab.VectorLen(o)
+ }
+ return 0
+}
+
+func MonsterStart(builder *flatbuffers.Builder) { builder.StartObject(25) }
func MonsterAddPos(builder *flatbuffers.Builder, pos flatbuffers.UOffsetT) { builder.PrependStructSlot(0, flatbuffers.UOffsetT(pos), 0) }
func MonsterAddMana(builder *flatbuffers.Builder, mana int16) { builder.PrependInt16Slot(1, mana, 150) }
func MonsterAddHp(builder *flatbuffers.Builder, hp int16) { builder.PrependInt16Slot(2, hp, 100) }
@@ -329,4 +346,7 @@ func MonsterAddTesthashs32Fnv1a(builder *flatbuffers.Builder, testhashs32Fnv1a i
func MonsterAddTesthashu32Fnv1a(builder *flatbuffers.Builder, testhashu32Fnv1a uint32) { builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) }
func MonsterAddTesthashs64Fnv1a(builder *flatbuffers.Builder, testhashs64Fnv1a int64) { builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) }
func MonsterAddTesthashu64Fnv1a(builder *flatbuffers.Builder, testhashu64Fnv1a uint64) { builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) }
+func MonsterAddTestarrayofbools(builder *flatbuffers.Builder, testarrayofbools flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(24, flatbuffers.UOffsetT(testarrayofbools), 0) }
+func MonsterStartTestarrayofboolsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems, 1)
+}
func MonsterEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() }
diff --git a/tests/MyGame/Example/Monster.java b/tests/MyGame/Example/Monster.java
index 0a5f7dde..19b356de 100644
--- a/tests/MyGame/Example/Monster.java
+++ b/tests/MyGame/Example/Monster.java
@@ -68,8 +68,12 @@ public final class Monster extends Table {
public boolean mutateTesthashs64Fnv1a(long testhashs64_fnv1a) { int o = __offset(48); if (o != 0) { bb.putLong(o + bb_pos, testhashs64_fnv1a); return true; } else { return false; } }
public long testhashu64Fnv1a() { int o = __offset(50); return o != 0 ? bb.getLong(o + bb_pos) : 0; }
public boolean mutateTesthashu64Fnv1a(long testhashu64_fnv1a) { int o = __offset(50); if (o != 0) { bb.putLong(o + bb_pos, testhashu64_fnv1a); return true; } else { return false; } }
+ public boolean testarrayofbools(int j) { int o = __offset(52); return o != 0 ? 0!=bb.get(__vector(o) + j * 1) : false; }
+ public int testarrayofboolsLength() { int o = __offset(52); return o != 0 ? __vector_len(o) : 0; }
+ public ByteBuffer testarrayofboolsAsByteBuffer() { return __vector_as_bytebuffer(52, 1); }
+ public boolean mutateTestarrayofbools(int j, boolean testarrayofbools) { int o = __offset(52); if (o != 0) { bb.put(__vector(o) + j * 1, (byte)(testarrayofbools ? 1 : 0)); return true; } else { return false; } }
- public static void startMonster(FlatBufferBuilder builder) { builder.startObject(24); }
+ public static void startMonster(FlatBufferBuilder builder) { builder.startObject(25); }
public static void addPos(FlatBufferBuilder builder, int posOffset) { builder.addStruct(0, posOffset, 0); }
public static void addMana(FlatBufferBuilder builder, short mana) { builder.addShort(1, mana, 150); }
public static void addHp(FlatBufferBuilder builder, short hp) { builder.addShort(2, hp, 100); }
@@ -102,6 +106,9 @@ public final class Monster extends Table {
public static void addTesthashu32Fnv1a(FlatBufferBuilder builder, long testhashu32Fnv1a) { builder.addInt(21, (int)(testhashu32Fnv1a & 0xFFFFFFFFL), 0); }
public static void addTesthashs64Fnv1a(FlatBufferBuilder builder, long testhashs64Fnv1a) { builder.addLong(22, testhashs64Fnv1a, 0); }
public static void addTesthashu64Fnv1a(FlatBufferBuilder builder, long testhashu64Fnv1a) { builder.addLong(23, testhashu64Fnv1a, 0); }
+ public static void addTestarrayofbools(FlatBufferBuilder builder, int testarrayofboolsOffset) { builder.addOffset(24, testarrayofboolsOffset, 0); }
+ public static int createTestarrayofboolsVector(FlatBufferBuilder builder, boolean[] data) { builder.startVector(1, data.length, 1); for (int i = data.length - 1; i >= 0; i--) builder.addBoolean(data[i]); return builder.endVector(); }
+ public static void startTestarrayofboolsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(1, numElems, 1); }
public static int endMonster(FlatBufferBuilder builder) {
int o = builder.endObject();
builder.required(o, 10); // name
diff --git a/tests/MyGame/Example/Monster.py b/tests/MyGame/Example/Monster.py
index 2f0dc35e..6122de59 100644
--- a/tests/MyGame/Example/Monster.py
+++ b/tests/MyGame/Example/Monster.py
@@ -246,7 +246,22 @@ class Monster(object):
return self._tab.Get(flatbuffers.number_types.Uint64Flags, o + self._tab.Pos)
return 0
-def MonsterStart(builder): builder.StartObject(24)
+ # Monster
+ def Testarrayofbools(self, j):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(52))
+ if o != 0:
+ a = self._tab.Vector(o)
+ return self._tab.Get(flatbuffers.number_types.BoolFlags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1))
+ return 0
+
+ # Monster
+ def TestarrayofboolsLength(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(52))
+ if o != 0:
+ return self._tab.VectorLen(o)
+ return 0
+
+def MonsterStart(builder): builder.StartObject(25)
def MonsterAddPos(builder, pos): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0)
def MonsterAddMana(builder, mana): builder.PrependInt16Slot(1, mana, 150)
def MonsterAddHp(builder, hp): builder.PrependInt16Slot(2, hp, 100)
@@ -275,4 +290,6 @@ def MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a): builder.PrependInt32S
def MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a): builder.PrependUint32Slot(21, testhashu32Fnv1a, 0)
def MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a): builder.PrependInt64Slot(22, testhashs64Fnv1a, 0)
def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): builder.PrependUint64Slot(23, testhashu64Fnv1a, 0)
+def MonsterAddTestarrayofbools(builder, testarrayofbools): builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0)
+def MonsterStartTestarrayofboolsVector(builder, numElems): return builder.StartVector(1, numElems, 1)
def MonsterEnd(builder): return builder.EndObject()
diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.cs b/tests/MyGame/Example/TestSimpleTableWithEnum.cs
index d2e75b52..9b436ffd 100644
--- a/tests/MyGame/Example/TestSimpleTableWithEnum.cs
+++ b/tests/MyGame/Example/TestSimpleTableWithEnum.cs
@@ -11,6 +11,7 @@ public sealed class TestSimpleTableWithEnum : Table {
public TestSimpleTableWithEnum __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public Color Color { get { int o = __offset(4); return o != 0 ? (Color)bb.GetSbyte(o + bb_pos) : (Color)2; } }
+ public bool MutateColor(Color color) { int o = __offset(4); if (o != 0) { bb.PutSbyte(o + bb_pos, (sbyte)color); return true; } else { return false; } }
public static Offset<TestSimpleTableWithEnum> CreateTestSimpleTableWithEnum(FlatBufferBuilder builder,
Color color = (Color)2) {
diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.java b/tests/MyGame/Example/TestSimpleTableWithEnum.java
index af9d7dbf..d5d63de7 100644
--- a/tests/MyGame/Example/TestSimpleTableWithEnum.java
+++ b/tests/MyGame/Example/TestSimpleTableWithEnum.java
@@ -13,6 +13,7 @@ public final class TestSimpleTableWithEnum extends Table {
public TestSimpleTableWithEnum __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public byte color() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) : 2; }
+ public boolean mutateColor(byte color) { int o = __offset(4); if (o != 0) { bb.put(o + bb_pos, color); return true; } else { return false; } }
public static int createTestSimpleTableWithEnum(FlatBufferBuilder builder,
byte color) {
diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs
index fcf8d9ce..e5f51fac 100644
--- a/tests/monster_test.bfbs
+++ b/tests/monster_test.bfbs
Binary files differ
diff --git a/tests/monster_test.fbs b/tests/monster_test.fbs
index 6a205b05..b2b99bb8 100755
--- a/tests/monster_test.fbs
+++ b/tests/monster_test.fbs
@@ -43,6 +43,7 @@ table Monster {
/// multiline too
testarrayoftables:[Monster] (id: 11);
testarrayofstring:[string] (id: 10);
+ testarrayofbools:[bool] (id: 24);
enemy:MyGame.Example.Monster (id:12); // Test referring by full namespace.
test:Any (id: 8);
test4:[Test] (id: 9);
diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h
index 93262ddd..c468b108 100644
--- a/tests/monster_test_generated.h
+++ b/tests/monster_test_generated.h
@@ -219,6 +219,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool mutate_testhashs64_fnv1a(int64_t testhashs64_fnv1a) { return SetField(48, testhashs64_fnv1a); }
uint64_t testhashu64_fnv1a() const { return GetField<uint64_t>(50, 0); }
bool mutate_testhashu64_fnv1a(uint64_t testhashu64_fnv1a) { return SetField(50, testhashu64_fnv1a); }
+ const flatbuffers::Vector<uint8_t> *testarrayofbools() const { return GetPointer<const flatbuffers::Vector<uint8_t> *>(52); }
+ flatbuffers::Vector<uint8_t> *mutable_testarrayofbools() { return GetPointer<flatbuffers::Vector<uint8_t> *>(52); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<Vec3>(verifier, 4 /* pos */) &&
@@ -255,6 +257,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VerifyField<uint32_t>(verifier, 46 /* testhashu32_fnv1a */) &&
VerifyField<int64_t>(verifier, 48 /* testhashs64_fnv1a */) &&
VerifyField<uint64_t>(verifier, 50 /* testhashu64_fnv1a */) &&
+ VerifyField<flatbuffers::uoffset_t>(verifier, 52 /* testarrayofbools */) &&
+ verifier.Verify(testarrayofbools()) &&
verifier.EndTable();
}
};
@@ -285,10 +289,11 @@ struct MonsterBuilder {
void add_testhashu32_fnv1a(uint32_t testhashu32_fnv1a) { fbb_.AddElement<uint32_t>(46, testhashu32_fnv1a, 0); }
void add_testhashs64_fnv1a(int64_t testhashs64_fnv1a) { fbb_.AddElement<int64_t>(48, testhashs64_fnv1a, 0); }
void add_testhashu64_fnv1a(uint64_t testhashu64_fnv1a) { fbb_.AddElement<uint64_t>(50, testhashu64_fnv1a, 0); }
+ void add_testarrayofbools(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> testarrayofbools) { fbb_.AddOffset(52, testarrayofbools); }
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_, 24));
+ auto o = flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 25));
fbb_.Required(o, 10); // name
return o;
}
@@ -317,12 +322,14 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
int32_t testhashs32_fnv1a = 0,
uint32_t testhashu32_fnv1a = 0,
int64_t testhashs64_fnv1a = 0,
- uint64_t testhashu64_fnv1a = 0) {
+ uint64_t testhashu64_fnv1a = 0,
+ flatbuffers::Offset<flatbuffers::Vector<uint8_t>> testarrayofbools = 0) {
MonsterBuilder builder_(_fbb);
builder_.add_testhashu64_fnv1a(testhashu64_fnv1a);
builder_.add_testhashs64_fnv1a(testhashs64_fnv1a);
builder_.add_testhashu64_fnv1(testhashu64_fnv1);
builder_.add_testhashs64_fnv1(testhashs64_fnv1);
+ builder_.add_testarrayofbools(testarrayofbools);
builder_.add_testhashu32_fnv1a(testhashu32_fnv1a);
builder_.add_testhashs32_fnv1a(testhashs32_fnv1a);
builder_.add_testhashu32_fnv1(testhashu32_fnv1);
diff --git a/tests/monsterdata_python_wire.mon b/tests/monsterdata_python_wire.mon
index ae24c6bd..c6c39784 100644
--- a/tests/monsterdata_python_wire.mon
+++ b/tests/monsterdata_python_wire.mon
Binary files differ
diff --git a/tests/monsterdata_test.json b/tests/monsterdata_test.json
index 6525d545..a718efa0 100755
--- a/tests/monsterdata_test.json
+++ b/tests/monsterdata_test.json
@@ -37,6 +37,9 @@
"test1",
"test2"
],
+ testarrayofbools:[
+ true, false, true
+ ],
testhashs32_fnv1: "This string is being hashed!",
testhashu32_fnv1: "This string is being hashed!",
testhashs64_fnv1: "This string is being hashed!",
diff --git a/tests/monsterdata_test.mon b/tests/monsterdata_test.mon
index feb29e83..0505aeeb 100644
--- a/tests/monsterdata_test.mon
+++ b/tests/monsterdata_test.mon
Binary files differ