static FlatBuffersObject.Person SerializeSingleFlatBuffers() { Console.WriteLine("FlatBuffers"); FlatBuffersObject.Person copy = default(FlatBuffersObject.Person); byte[] bytes = null; using (new Measure("Serialize")) { for (int i = 0; i < Iteration; i++) { var builder = new FlatBuffers.FlatBufferBuilder(1); var person = FlatBuffersObject.Person.CreatePerson(builder, 99999, builder.CreateString("Windows"), builder.CreateString("Server"), FlatBuffersObject.Sex.Male); builder.Finish(person.Value); bytes = builder.SizedByteArray(); } } using (new Measure("Deserialize")) { for (int i = 0; i < Iteration; i++) { copy = FlatBuffersObject.Person.GetRootAsPerson(new FlatBuffers.ByteBuffer(bytes)); } } if (!dryRun) { Console.WriteLine(string.Format("{0,15} {1}", "Binary Size", ToHumanReadableSize(bytes.Length))); } return(copy); }
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"); } } }