summaryrefslogtreecommitdiff
path: root/tests/MyGame
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2014-09-16 17:37:17 -0700
committerWouter van Oortmerssen <wvo@google.com>2014-09-18 12:29:31 -0700
commit557c88c0396220e79e9a43c07f8393a5c68b739d (patch)
tree1e837db4c944197b63dd7a6547ae5eb0adc166d4 /tests/MyGame
parentd01b30cdd688166caa93df67546191543892453a (diff)
downloadflatbuffers-557c88c0396220e79e9a43c07f8393a5c68b739d.tar.gz
flatbuffers-557c88c0396220e79e9a43c07f8393a5c68b739d.tar.bz2
flatbuffers-557c88c0396220e79e9a43c07f8393a5c68b739d.zip
Refactored the Java and C# code generators into one.
Also made the C# implementation support unsigned types, and made it more like the Java version. Bug: 17359988 Change-Id: If5305c08cd5c97f35426639516ce05e53bbec36c Tested: on Linux and Windows.
Diffstat (limited to 'tests/MyGame')
-rw-r--r--tests/MyGame/Example/Any.cs2
-rw-r--r--tests/MyGame/Example/Color.cs8
-rw-r--r--tests/MyGame/Example/Monster.cs132
-rw-r--r--tests/MyGame/Example/Test.cs8
-rw-r--r--tests/MyGame/Example/Vec3.cs10
5 files changed, 80 insertions, 80 deletions
diff --git a/tests/MyGame/Example/Any.cs b/tests/MyGame/Example/Any.cs
index 73a22487..8f88a9d4 100644
--- a/tests/MyGame/Example/Any.cs
+++ b/tests/MyGame/Example/Any.cs
@@ -3,8 +3,6 @@
namespace MyGame.Example
{
-using FlatBuffers;
-
public class Any
{
public static byte NONE = 0;
diff --git a/tests/MyGame/Example/Color.cs b/tests/MyGame/Example/Color.cs
index 34abc641..7d9df7b6 100644
--- a/tests/MyGame/Example/Color.cs
+++ b/tests/MyGame/Example/Color.cs
@@ -3,13 +3,11 @@
namespace MyGame.Example
{
-using FlatBuffers;
-
public class Color
{
- public static byte Red = 1;
- public static byte Green = 2;
- public static byte Blue = 8;
+ public static sbyte Red = 1;
+ public static sbyte Green = 2;
+ public static sbyte Blue = 8;
};
diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs
index 0e02416b..2910aa6b 100644
--- a/tests/MyGame/Example/Monster.cs
+++ b/tests/MyGame/Example/Monster.cs
@@ -1,64 +1,68 @@
-// automatically generated, do not modify
-
-namespace MyGame.Example
-{
-
-using FlatBuffers;
-
-public class Monster : Table {
- public static Monster GetRootAsMonster(ByteBuffer _bb, int offset) { return (new Monster()).__init(_bb.GetInt(offset) + offset, _bb); }
- public static bool MonsterBufferHasIdentifier(ByteBuffer _bb, int offset) { return __has_identifier(_bb, offset, "MONS"); }
- public Monster __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
-
- public Vec3 Pos() { return Pos(new Vec3()); }
- public Vec3 Pos(Vec3 obj) { int o = __offset(4); return o != 0 ? obj.__init(o + bb_pos, bb) : null; }
- public short Mana() { int o = __offset(6); return o != 0 ? bb.GetShort(o + bb_pos) : (short)150; }
- public short Hp() { int o = __offset(8); return o != 0 ? bb.GetShort(o + bb_pos) : (short)100; }
- public string Name() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; }
- public byte Inventory(int j) { int o = __offset(14); return o != 0 ? bb.Get(__vector(o) + j * 1) : (byte)0; }
- public int InventoryLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
- public byte Color() { int o = __offset(16); return o != 0 ? bb.Get(o + bb_pos) : (byte)8; }
- public byte TestType() { int o = __offset(18); return o != 0 ? bb.Get(o + bb_pos) : (byte)0; }
- public Table Test(Table obj) { int o = __offset(20); return o != 0 ? __union(obj, o) : null; }
- public Test Test4(int j) { return Test4(new Test(), j); }
- public Test Test4(Test obj, int j) { int o = __offset(22); return o != 0 ? obj.__init(__vector(o) + j * 4, bb) : null; }
- public int Test4Length() { int o = __offset(22); return o != 0 ? __vector_len(o) : 0; }
- public string Testarrayofstring(int j) { int o = __offset(24); return o != 0 ? __string(__vector(o) + j * 4) : null; }
- public int TestarrayofstringLength() { int o = __offset(24); return o != 0 ? __vector_len(o) : 0; }
- /* an example documentation comment: this will end up in the generated code multiline too */
- public Monster Testarrayoftables(int j) { return Testarrayoftables(new Monster(), j); }
- public Monster Testarrayoftables(Monster obj, int j) { int o = __offset(26); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; }
- public int TestarrayoftablesLength() { int o = __offset(26); return o != 0 ? __vector_len(o) : 0; }
- public Monster Enemy() { return Enemy(new Monster()); }
- public Monster Enemy(Monster obj) { int o = __offset(28); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
- public byte Testnestedflatbuffer(int j) { int o = __offset(30); return o != 0 ? bb.Get(__vector(o) + j * 1) : (byte)0; }
- public int TestnestedflatbufferLength() { int o = __offset(30); return o != 0 ? __vector_len(o) : 0; }
- public Monster Testempty() { return Testempty(new Monster()); }
- public Monster Testempty(Monster obj) { int o = __offset(32); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
-
- public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(15); }
- 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); }
- public static void AddName(FlatBufferBuilder builder, int nameOffset) { builder.AddOffset(3, nameOffset, 0); }
- public static void AddInventory(FlatBufferBuilder builder, int inventoryOffset) { builder.AddOffset(5, inventoryOffset, 0); }
- public static void StartInventoryVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
- public static void AddColor(FlatBufferBuilder builder, byte color) { builder.AddByte(6, color, 8); }
- public static void AddTestType(FlatBufferBuilder builder, byte testType) { builder.AddByte(7, testType, 0); }
- public static void AddTest(FlatBufferBuilder builder, int testOffset) { builder.AddOffset(8, testOffset, 0); }
- public static void AddTest4(FlatBufferBuilder builder, int test4Offset) { builder.AddOffset(9, test4Offset, 0); }
- public static void StartTest4Vector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 2); }
- public static void AddTestarrayofstring(FlatBufferBuilder builder, int testarrayofstringOffset) { builder.AddOffset(10, testarrayofstringOffset, 0); }
- public static void StartTestarrayofstringVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 4); }
- public static void AddTestarrayoftables(FlatBufferBuilder builder, int testarrayoftablesOffset) { builder.AddOffset(11, testarrayoftablesOffset, 0); }
- public static void StartTestarrayoftablesVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 4); }
- public static void AddEnemy(FlatBufferBuilder builder, int enemyOffset) { builder.AddOffset(12, enemyOffset, 0); }
- public static void AddTestnestedflatbuffer(FlatBufferBuilder builder, int testnestedflatbufferOffset) { builder.AddOffset(13, testnestedflatbufferOffset, 0); }
- public static void StartTestnestedflatbufferVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
- public static void AddTestempty(FlatBufferBuilder builder, int testemptyOffset) { builder.AddOffset(14, testemptyOffset, 0); }
- public static int EndMonster(FlatBufferBuilder builder) { return builder.EndObject(); }
- public static void FinishMonsterBuffer(FlatBufferBuilder builder, int offset) { builder.Finish(offset, "MONS"); }
-};
-
-
-}
+// automatically generated, do not modify
+
+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 bool MonsterBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "MONS"); }
+ public Monster __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
+
+ public Vec3 Pos() { return Pos(new Vec3()); }
+ public Vec3 Pos(Vec3 obj) { int o = __offset(4); return o != 0 ? obj.__init(o + bb_pos, bb) : null; }
+ public short Mana() { int o = __offset(6); return o != 0 ? bb.GetShort(o + bb_pos) : (short)150; }
+ public short Hp() { int o = __offset(8); return o != 0 ? bb.GetShort(o + bb_pos) : (short)100; }
+ public string Name() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; }
+ public byte Inventory(int j) { int o = __offset(14); return o != 0 ? bb.Get(__vector(o) + j * 1) : (byte)0; }
+ public int InventoryLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
+ public sbyte Color() { int o = __offset(16); return o != 0 ? bb.GetSbyte(o + bb_pos) : (sbyte)8; }
+ public byte TestType() { int o = __offset(18); return o != 0 ? bb.Get(o + bb_pos) : (byte)0; }
+ public Table Test(Table obj) { int o = __offset(20); return o != 0 ? __union(obj, o) : null; }
+ public Test Test4(int j) { return Test4(new Test(), j); }
+ public Test Test4(Test obj, int j) { int o = __offset(22); return o != 0 ? obj.__init(__vector(o) + j * 4, bb) : null; }
+ public int Test4Length() { int o = __offset(22); return o != 0 ? __vector_len(o) : 0; }
+ public string Testarrayofstring(int j) { int o = __offset(24); return o != 0 ? __string(__vector(o) + j * 4) : null; }
+ public int TestarrayofstringLength() { int o = __offset(24); return o != 0 ? __vector_len(o) : 0; }
+ /// an example documentation comment: this will end up in the generated code multiline too
+ public Monster Testarrayoftables(int j) { return Testarrayoftables(new Monster(), j); }
+ public Monster Testarrayoftables(Monster obj, int j) { int o = __offset(26); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; }
+ public int TestarrayoftablesLength() { int o = __offset(26); return o != 0 ? __vector_len(o) : 0; }
+ public Monster Enemy() { return Enemy(new Monster()); }
+ public Monster Enemy(Monster obj) { int o = __offset(28); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
+ public byte Testnestedflatbuffer(int j) { int o = __offset(30); return o != 0 ? bb.Get(__vector(o) + j * 1) : (byte)0; }
+ public int TestnestedflatbufferLength() { int o = __offset(30); return o != 0 ? __vector_len(o) : 0; }
+ public Monster Testempty() { return Testempty(new Monster()); }
+ public Monster Testempty(Monster obj) { int o = __offset(32); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; }
+
+ public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(15); }
+ 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); }
+ public static void AddName(FlatBufferBuilder builder, int nameOffset) { builder.AddOffset(3, nameOffset, 0); }
+ public static void AddInventory(FlatBufferBuilder builder, int inventoryOffset) { builder.AddOffset(5, inventoryOffset, 0); }
+ public static int CreateInventoryVector(FlatBufferBuilder builder, byte[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddByte(data[i]); return builder.EndVector(); }
+ public static void StartInventoryVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
+ public static void AddColor(FlatBufferBuilder builder, sbyte color) { builder.AddSbyte(6, color, 8); }
+ public static void AddTestType(FlatBufferBuilder builder, byte testType) { builder.AddByte(7, testType, 0); }
+ public static void AddTest(FlatBufferBuilder builder, int testOffset) { builder.AddOffset(8, testOffset, 0); }
+ public static void AddTest4(FlatBufferBuilder builder, int test4Offset) { builder.AddOffset(9, test4Offset, 0); }
+ public static void StartTest4Vector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 2); }
+ public static void AddTestarrayofstring(FlatBufferBuilder builder, int testarrayofstringOffset) { builder.AddOffset(10, testarrayofstringOffset, 0); }
+ public static int CreateTestarrayofstringVector(FlatBufferBuilder builder, int[] data) { builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i]); return builder.EndVector(); }
+ public static void StartTestarrayofstringVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 4); }
+ public static void AddTestarrayoftables(FlatBufferBuilder builder, int testarrayoftablesOffset) { builder.AddOffset(11, testarrayoftablesOffset, 0); }
+ public static int CreateTestarrayoftablesVector(FlatBufferBuilder builder, int[] data) { builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i]); return builder.EndVector(); }
+ public static void StartTestarrayoftablesVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 4); }
+ public static void AddEnemy(FlatBufferBuilder builder, int enemyOffset) { builder.AddOffset(12, enemyOffset, 0); }
+ public static void AddTestnestedflatbuffer(FlatBufferBuilder builder, int testnestedflatbufferOffset) { builder.AddOffset(13, testnestedflatbufferOffset, 0); }
+ public static int CreateTestnestedflatbufferVector(FlatBufferBuilder builder, byte[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddByte(data[i]); return builder.EndVector(); }
+ public static void StartTestnestedflatbufferVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
+ public static void AddTestempty(FlatBufferBuilder builder, int testemptyOffset) { builder.AddOffset(14, testemptyOffset, 0); }
+ public static int EndMonster(FlatBufferBuilder builder) { return builder.EndObject(); }
+ public static void FinishMonsterBuffer(FlatBufferBuilder builder, int offset) { builder.Finish(offset, "MONS"); }
+};
+
+
+}
diff --git a/tests/MyGame/Example/Test.cs b/tests/MyGame/Example/Test.cs
index 20d8fe6f..1603582b 100644
--- a/tests/MyGame/Example/Test.cs
+++ b/tests/MyGame/Example/Test.cs
@@ -9,14 +9,14 @@ public class Test : Struct {
public Test __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public short A() { return bb.GetShort(bb_pos + 0); }
- public byte B() { return bb.Get(bb_pos + 2); }
+ public sbyte B() { return bb.GetSbyte(bb_pos + 2); }
- public static int CreateTest(FlatBufferBuilder builder, short A, byte B) {
+ public static int CreateTest(FlatBufferBuilder builder, short A, sbyte B) {
builder.Prep(2, 4);
builder.Pad(1);
- builder.PutByte(B);
+ builder.PutSbyte(B);
builder.PutShort(A);
- return builder.Offset;
+ return builder.Offset();
}
};
diff --git a/tests/MyGame/Example/Vec3.cs b/tests/MyGame/Example/Vec3.cs
index 169a9443..4284aba4 100644
--- a/tests/MyGame/Example/Vec3.cs
+++ b/tests/MyGame/Example/Vec3.cs
@@ -12,25 +12,25 @@ public class Vec3 : Struct {
public float Y() { return bb.GetFloat(bb_pos + 4); }
public float Z() { return bb.GetFloat(bb_pos + 8); }
public double Test1() { return bb.GetDouble(bb_pos + 16); }
- public byte Test2() { return bb.Get(bb_pos + 24); }
+ public sbyte Test2() { return bb.GetSbyte(bb_pos + 24); }
public Test Test3() { return Test3(new Test()); }
public Test Test3(Test obj) { return obj.__init(bb_pos + 26, bb); }
- public static int CreateVec3(FlatBufferBuilder builder, float X, float Y, float Z, double Test1, byte Test2, short Test_A, byte Test_B) {
+ public static int CreateVec3(FlatBufferBuilder builder, float X, float Y, float Z, double Test1, sbyte Test2, short Test_A, sbyte Test_B) {
builder.Prep(16, 32);
builder.Pad(2);
builder.Prep(2, 4);
builder.Pad(1);
- builder.PutByte(Test_B);
+ builder.PutSbyte(Test_B);
builder.PutShort(Test_A);
builder.Pad(1);
- builder.PutByte(Test2);
+ builder.PutSbyte(Test2);
builder.PutDouble(Test1);
builder.Pad(4);
builder.PutFloat(Z);
builder.PutFloat(Y);
builder.PutFloat(X);
- return builder.Offset;
+ return builder.Offset();
}
};