public void LocationStruct()
    {
        var builder    = new FlatBuffers.FlatBufferBuilder(1024);
        var fakeString = builder.CreateString("foobar");

        Oracle.LocationHolder.StartLocationVectorVector(builder, 3);
        Oracle.Location.CreateLocation(builder, 7f, 8f, 9f);
        Oracle.Location.CreateLocation(builder, 4f, 5f, 6f);
        Oracle.Location.CreateLocation(builder, 1f, 2f, 3f);
        var vectorOffset = builder.EndVector();

        Oracle.LocationHolder.StartLocationHolder(builder);
        Oracle.LocationHolder.AddFake(builder, fakeString);
        Oracle.LocationHolder.AddSingleLocation(builder, Oracle.Location.CreateLocation(builder, 0.1f, 0.2f, 0.3f));
        Oracle.LocationHolder.AddLocationVector(builder, vectorOffset);
        var testData = Oracle.LocationHolder.EndLocationHolder(builder);

        builder.Finish(testData.Value);

        byte[] realBuffer = builder.SizedByteArray();
        var    parsed     = FlatBufferSerializer.Default.Parse <LocationHolder>(realBuffer);

        Assert.Equal("foobar", parsed.Fake);
        Assert.Equal(0.1f, parsed.Location.X);
        Assert.Equal(0.2f, parsed.Location.Y);
        Assert.Equal(0.3f, parsed.Location.Z);
        Assert.Equal(3, parsed.LocationVector.Count);

        for (int i = 0; i < 3; ++i)
        {
            Assert.Equal((float)(3 * i + 1), parsed.LocationVector[i].X);
            Assert.Equal((float)(3 * i + 2), parsed.LocationVector[i].Y);
            Assert.Equal((float)(3 * i + 3), parsed.LocationVector[i].Z);
        }
    }
    public void FiveByteStructVector()
    {
        var builder = new FlatBuffers.FlatBufferBuilder(1024);

        Oracle.FiveByteStructTable.StartVectorVector(builder, 3);
        Oracle.FiveByteStruct.CreateFiveByteStruct(builder, 3, 3);
        Oracle.FiveByteStruct.CreateFiveByteStruct(builder, 2, 2);
        Oracle.FiveByteStruct.CreateFiveByteStruct(builder, 1, 1);
        var vectorOffset = builder.EndVector();

        Oracle.FiveByteStructTable.StartFiveByteStructTable(builder);
        Oracle.FiveByteStructTable.AddVector(builder, vectorOffset);
        var testData = Oracle.FiveByteStructTable.EndFiveByteStructTable(builder);

        builder.Finish(testData.Value);

        byte[] realBuffer = builder.SizedByteArray();
        var    parsed     = FlatBufferSerializer.Default.Parse <FiveByteStructTable>(realBuffer);

        Assert.Equal(3, parsed.Vector.Length);

        Assert.Equal(1, parsed.Vector[0].Int);
        Assert.Equal(2, parsed.Vector[1].Int);
        Assert.Equal(3, parsed.Vector[2].Int);

        Assert.Equal((byte)1, parsed.Vector[0].Byte);
        Assert.Equal((byte)2, parsed.Vector[1].Byte);
        Assert.Equal((byte)3, parsed.Vector[2].Byte);
    }
Пример #3
0
 public static VectorOffset CreateUnitLevelsVector(FlatBufferBuilder builder, Offset<TypeLevel>[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector();
 }
Пример #4
0
 public static VectorOffset CreateTechnologiesVector(FlatBufferBuilder builder, StringOffset[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector();
 }
Пример #5
0
 public static VectorOffset CreateSectorsVector(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();
 }
Пример #6
0
 public static VectorOffset CreatePlayerResourcesVector(FlatBufferBuilder builder, Offset<TypeAmount>[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector();
 }
Пример #7
0
 public static VectorOffset CreateCurrentQuestsVector(FlatBufferBuilder builder, Offset<CurrentQuest>[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector();
 }
Пример #8
0
 public static VectorOffset CreateItemsVector(FlatBufferBuilder builder, Offset<uvSwapItemData>[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector();
 }
 public static VectorOffset CreateMeshesVector(FlatBufferBuilder builder, Offset<animationMesh>[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector();
 }
Пример #10
0
 public static VectorOffset CreateStartPtVector(FlatBufferBuilder builder, float[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddFloat(data[i]); return builder.EndVector();
 }
    VectorOffset TypeLevelVector(FlatBufferBuilder fbb, System.Collections.Generic.Dictionary<string, int> items)
    {
        var quantities = metaPool.unitLevels.values;
        int count = quantities.Count;

        Offset<TypeLevel>[] resources = new Offset<TypeLevel>[count];

        int index = 0;
        foreach (var type in quantities.Keys) {
            StringOffset typeStringOffset = fbb.CreateString(type);
            resources[index] = TypeLevel.CreateTypeLevel(fbb,typeStringOffset, (sbyte)quantities[type]);
            index++;
        }
        fbb.StartVector(4, resources.Length, 4);
        for (int i = resources.Length - 1; i >= 0; i--) fbb.AddOffset(resources[i].Value);
        return fbb.EndVector();
    }
    VectorOffset TypeAmountVector(FlatBufferBuilder fbb, System.Collections.Generic.Dictionary<string, int> items)
    {
        if(items == null || items.Count == 0){
            return default(VectorOffset);
        }
        int count = items.Count;

        Offset<TypeAmount>[] resources = new Offset<TypeAmount>[count];
        int index = 0;
        foreach (var type in items.Keys) {
            StringOffset typeStringOffset = fbb.CreateString(type);
            resources[index] = TypeAmount.CreateTypeAmount(fbb,typeStringOffset, items[type]);
            index++;
        }

        fbb.StartVector(4, resources.Length, 4);
        for (int i = resources.Length - 1; i >= 0; i--) fbb.AddOffset(resources[i].Value);
        return fbb.EndVector();
    }
Пример #13
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();
 }
Пример #14
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();
 }
Пример #15
0
 public static VectorOffset CreateWeightsVector(FlatBufferBuilder builder, Offset<meshRegionBone>[] data)
 {
     builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector();
 }