diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2014-09-25 15:53:56 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2014-09-25 15:53:56 -0700 |
commit | 18cf19f87629b54e961e2b81542aaca5bf956ada (patch) | |
tree | d07d44b8714a1dcc2c564f74a027b295caf63baf /tests/MyGame/Example | |
parent | 730c0cadde2302efa1487d672a1e2f53680ce2ea (diff) | |
download | flatbuffers-18cf19f87629b54e961e2b81542aaca5bf956ada.tar.gz flatbuffers-18cf19f87629b54e961e2b81542aaca5bf956ada.tar.bz2 flatbuffers-18cf19f87629b54e961e2b81542aaca5bf956ada.zip |
Fixed bug in convenient constructors for Java/C#
Also fixed Go unit tests not being up to date with recent schema
changes.
Change-Id: I42e619f9c5ea05f6f937c68a5c8a92462c46bce3
Tested: on Linux and Windows.
Diffstat (limited to 'tests/MyGame/Example')
-rw-r--r-- | tests/MyGame/Example/Monster.cs | 4 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.go | 7 | ||||
-rw-r--r-- | tests/MyGame/Example/Monster.java | 4 | ||||
-rw-r--r-- | tests/MyGame/Example/Stat.cs | 34 | ||||
-rw-r--r-- | tests/MyGame/Example/Stat.go | 36 | ||||
-rw-r--r-- | tests/MyGame/Example/Stat.java | 35 |
6 files changed, 112 insertions, 8 deletions
diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs index a389cb82..2b36eed3 100644 --- a/tests/MyGame/Example/Monster.cs +++ b/tests/MyGame/Example/Monster.cs @@ -34,8 +34,8 @@ public class Monster : Table { 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 Stat Testempty() { return Testempty(new Stat()); } + public Stat Testempty(Stat 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); } diff --git a/tests/MyGame/Example/Monster.go b/tests/MyGame/Example/Monster.go index 74bf7b5a..ed0f6061 100644 --- a/tests/MyGame/Example/Monster.go +++ b/tests/MyGame/Example/Monster.go @@ -139,8 +139,7 @@ func (rcv *Monster) TestarrayofstringLength() int { return 0 } -/// an example documentation comment: this will end up in the generated code -/// multiline too +/// an example documentation comment: this will end up in the generated code multiline too func (rcv *Monster) Testarrayoftables(obj *Monster, j int) bool { o := flatbuffers.UOffsetT(rcv._tab.Offset(26)) if o != 0 { @@ -194,12 +193,12 @@ func (rcv *Monster) TestnestedflatbufferLength() int { return 0 } -func (rcv *Monster) Testempty(obj *Monster) *Monster { +func (rcv *Monster) Testempty(obj *Stat) *Stat { o := flatbuffers.UOffsetT(rcv._tab.Offset(32)) if o != 0 { x := rcv._tab.Indirect(o + rcv._tab.Pos) if obj == nil { - obj = new(Monster) + obj = new(Stat) } obj.Init(rcv._tab.Bytes, x) return obj diff --git a/tests/MyGame/Example/Monster.java b/tests/MyGame/Example/Monster.java index 5f8da24b..f7411d9d 100644 --- a/tests/MyGame/Example/Monster.java +++ b/tests/MyGame/Example/Monster.java @@ -42,8 +42,8 @@ public class Monster extends Table { public byte testnestedflatbuffer(int j) { int o = __offset(30); return o != 0 ? bb.get(__vector(o) + j * 1) : 0; } public int testnestedflatbufferLength() { int o = __offset(30); return o != 0 ? __vector_len(o) : 0; } public ByteBuffer testnestedflatbufferAsByteBuffer() { return __vector_as_bytebuffer(30, 1); } - 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 Stat testempty() { return testempty(new Stat()); } + public Stat testempty(Stat 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); } diff --git a/tests/MyGame/Example/Stat.cs b/tests/MyGame/Example/Stat.cs new file mode 100644 index 00000000..1a554f29 --- /dev/null +++ b/tests/MyGame/Example/Stat.cs @@ -0,0 +1,34 @@ +// automatically generated, do not modify + +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 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; } + public long Val() { int o = __offset(6); return o != 0 ? bb.GetLong(o + bb_pos) : (long)0; } + + public static int CreateStat(FlatBufferBuilder builder, + int id = 0, + long val = 0) { + builder.StartObject(2); + Stat.AddVal(builder, val); + Stat.AddId(builder, id); + return Stat.EndStat(builder); + } + + public static void StartStat(FlatBufferBuilder builder) { builder.StartObject(2); } + public static void AddId(FlatBufferBuilder builder, int idOffset) { builder.AddOffset(0, idOffset, 0); } + public static void AddVal(FlatBufferBuilder builder, long val) { builder.AddLong(1, val, 0); } + public static int EndStat(FlatBufferBuilder builder) { + int o = builder.EndObject(); + return o; + } +}; + + +} diff --git a/tests/MyGame/Example/Stat.go b/tests/MyGame/Example/Stat.go new file mode 100644 index 00000000..4c07f56b --- /dev/null +++ b/tests/MyGame/Example/Stat.go @@ -0,0 +1,36 @@ +// automatically generated, do not modify + +package Example + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) +type Stat struct { + _tab flatbuffers.Table +} + +func (rcv *Stat) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *Stat) Id() string { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.String(o + rcv._tab.Pos) + } + return "" +} + +func (rcv *Stat) Val() int64 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) + if o != 0 { + return rcv._tab.GetInt64(o + rcv._tab.Pos) + } + return 0 +} + +func StatStart(builder *flatbuffers.Builder) { builder.StartObject(2) } +func StatAddId(builder *flatbuffers.Builder, id flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(id), 0) } +func StatAddVal(builder *flatbuffers.Builder, val int64) { builder.PrependInt64Slot(1, val, 0) } +func StatEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } diff --git a/tests/MyGame/Example/Stat.java b/tests/MyGame/Example/Stat.java new file mode 100644 index 00000000..66be12f1 --- /dev/null +++ b/tests/MyGame/Example/Stat.java @@ -0,0 +1,35 @@ +// automatically generated, do not modify + +package MyGame.Example; + +import java.nio.*; +import java.lang.*; +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 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; } + public ByteBuffer idAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } + public long val() { int o = __offset(6); return o != 0 ? bb.getLong(o + bb_pos) : 0; } + + public static int createStat(FlatBufferBuilder builder, + int id, + long val) { + builder.startObject(2); + Stat.addVal(builder, val); + Stat.addId(builder, id); + return Stat.endStat(builder); + } + + public static void startStat(FlatBufferBuilder builder) { builder.startObject(2); } + public static void addId(FlatBufferBuilder builder, int idOffset) { builder.addOffset(0, idOffset, 0); } + public static void addVal(FlatBufferBuilder builder, long val) { builder.addLong(1, val, 0); } + public static int endStat(FlatBufferBuilder builder) { + int o = builder.endObject(); + return o; + } +}; + |