public void Union_Pickup() { CreateMonsterFlatBufferTypes(); var builder = new FlatBufferBuilder(1); var builderWrapper = new FlatBufferBuilderWrapper(_typeBuilder, builder); var pickup_name = builderWrapper.CreateString("Pickup"); builderWrapper.StartTable("Pickup"); builderWrapper.AddString("name", pickup_name); var pickup = builderWrapper.EndTable(); var monster_name = builderWrapper.CreateString("Monster2"); builderWrapper.StartTable("Monster"); builderWrapper.AddByte("thingy_type", 2); // Pickup builderWrapper.AddTable("thingy", pickup); builderWrapper.AddString("name", monster_name); builderWrapper.Finish(builderWrapper.EndTable()); var beginData = builder.DataBuffer.Position; var countData = builder.DataBuffer.Length - beginData; var byteBuffer = new ByteBuffer(builder.DataBuffer.Data.Skip(beginData).Take(countData).ToArray()); var wrapper = new FlatBufferWrapper(_typeBuilder, "Monster", byteBuffer); Assert.AreEqual("Monster2", (string)wrapper["name"]); Assert.AreEqual(2, (byte)wrapper["thingy_type"]); var thingy_wrapper = (FlatBufferWrapper)wrapper["thingy"]; Assert.IsNotNull(thingy_wrapper); Assert.AreEqual("Pickup", (string)thingy_wrapper["name"]); }
internal FlatBufferWrapper GetMonsterWrapper(TypeBuilder typeBuilder) { var builder = new FlatBufferBuilder(1); var builderWrapper = new FlatBufferBuilderWrapper(typeBuilder, builder); var monsterName = builderWrapper.CreateString("Fred"); builderWrapper.StartVector("Monster", "inventory", 2); builderWrapper.AddByte(3); //idx 1 builderWrapper.AddByte(2); //idx 0 var monsterInventory = builderWrapper.EndVector(); var minion1_name = builderWrapper.CreateString("Banana"); var minion2_name = builderWrapper.CreateString("Ananab"); var main_minion_name = builderWrapper.CreateString("MainMinion"); builderWrapper.StartTable("Minion"); builderWrapper.AddString("name", minion1_name); var minion1 = builderWrapper.EndTable(); builderWrapper.StartTable("Minion"); builderWrapper.AddString("name", minion2_name); var minion2 = builderWrapper.EndTable(); builderWrapper.StartTable("Minion"); builderWrapper.AddString("name", main_minion_name); var mainMinion = builderWrapper.EndTable(); builderWrapper.StartVector("Monster", "minions", 2); builderWrapper.AddTable(minion2); //idx 1 builderWrapper.AddTable(minion1); //idx 0 var minions = builderWrapper.EndVector(); builderWrapper.StartTable("Monster"); builderWrapper.AddStruct("pos", new object[] { 1.0f, 2.0f, 3.0f }); // x, y, z builderWrapper.AddShort("mana", 42); builderWrapper.AddShort("hp", 17); builderWrapper.AddString("name", monsterName); builderWrapper.AddBool("friendly", true); builderWrapper.AddVector("inventory", monsterInventory); builderWrapper.AddByte("color", 2); // Blue builderWrapper.AddVector("minions", minions); builderWrapper.AddTable("mainMinion", mainMinion); builderWrapper.Finish(builderWrapper.EndTable()); var beginData = builder.DataBuffer.Position; var countData = builder.DataBuffer.Length - beginData; var byteBuffer = new ByteBuffer(builder.DataBuffer.Data.Skip(beginData).Take(countData).ToArray()); return(new FlatBufferWrapper(_typeBuilder, "Monster", byteBuffer)); }