Esempio n. 1
0
 public static Offset <PersonVector> CreatePersonVector(FlatBufferBuilder builder,
                                                        VectorOffset listOffset = default(VectorOffset))
 {
     builder.StartObject(1);
     PersonVector.AddList(builder, listOffset);
     return(PersonVector.EndPersonVector(builder));
 }
Esempio n. 2
0
    static FlatBuffersObject.PersonVector SerializeArrayFlatBuffers()
    {
        Console.WriteLine("FlatBuffers");

        FlatBuffersObject.PersonVector copy = default(FlatBuffersObject.PersonVector);
        byte[] bytes = null;

        Func <FlatBuffers.FlatBufferBuilder, FlatBuffers.Offset <FlatBuffersObject.Person>[]> makeVector = b =>
        {
            var array = new FlatBuffers.Offset <FlatBuffersObject.Person> [1000];
            var count = 0;
            for (int j = 1000; j < 2000; j++)
            {
                var person = FlatBuffersObject.Person.CreatePerson(b, j, b.CreateString("Windows"), b.CreateString("Server"), FlatBuffersObject.Sex.Female);
                array[count++] = person;
            }
            return(array);
        };

        using (new Measure("Serialize"))
        {
            for (int i = 0; i < Iteration; i++)
            {
                var builder = new FlatBuffers.FlatBufferBuilder(1);

                var personVector = FlatBuffersObject.PersonVector.CreatePersonVector(builder, FlatBuffersObject.PersonVector.CreateListVector(builder, makeVector(builder)));
                builder.Finish(personVector.Value);

                bytes = builder.SizedByteArray();
            }
        }

        using (new Measure("Deserialize"))
        {
            for (int i = 0; i < Iteration; i++)
            {
                copy = FlatBuffersObject.PersonVector.GetRootAsPersonVector(new FlatBuffers.ByteBuffer(bytes));
            }
        }

        using (new Measure("ReSerialize"))
        {
            for (int i = 0; i < Iteration; i++)
            {
                var bb       = copy.ByteBuffer;
                var newbytes = new byte[bb.Length];
                Buffer.BlockCopy(bb.Data, 0, newbytes, 0, bb.Length);
            }
        }

        if (!dryRun)
        {
            Console.WriteLine(string.Format("{0,15}   {1}", "Binary Size", ToHumanReadableSize(bytes.Length)));
        }

        return(copy);
    }
Esempio n. 3
0
    static void ValidateFlatBuffers(Person original, IList <Person> list, FlatBuffersObject.Person p, FlatBuffersObject.PersonVector l)
    {
        if (!(p.Age == original.Age && p.FirstName == original.FirstName && p.LastName == original.LastName && (sbyte)p.Sex == (sbyte)original.Sex))
        {
            throw new Exception("Validation failed");
        }

        for (int i = 0; i < list.Count; i++)
        {
            if (!(l.GetList(i).Age == list[i].Age && l.GetList(i).FirstName == list[i].FirstName && l.GetList(i).LastName == list[i].LastName && (sbyte)l.GetList(i).Sex == (sbyte)list[i].Sex))
            {
                throw new Exception("Validation failed");
            }
        }
    }
Esempio n. 4
0
 public static PersonVector GetRootAsPersonVector(ByteBuffer _bb, PersonVector obj)
 {
     return(obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }