public void SerializeDeserialize() { var factories = new List <Func <ByteBuffer, IFlatbufferObject> > { (data) => Data_8b.GetRootAsData_8b(data) }; var serializer = new FlatBufferSerializer(factories); Data_8b original; { var builder = new FlatBufferBuilder(8); var offset = Data_8b.CreateData_8b(builder); builder.Finish(offset.Value); original = Data_8b.GetRootAsData_8b(builder.DataBuffer); } var b = serializer.Serialize(original); var deserialized = serializer.Deserialize <Data_8b>(b); Assert.Equal(original.Val1, deserialized.Val1); Assert.Equal(original.Val2, deserialized.Val2); }
static Benchmarks() { { var builder = new FlatBufferBuilder(8); var offset = Data_8b.CreateData_8b(builder); builder.Finish(offset.Value); InputData.Add(Data_8b.GetRootAsData_8b(builder.DataBuffer)); } { var builder = new FlatBufferBuilder(128); List <Offset <Data_8b> > inner8b = new List <Offset <Data_8b> >(); for (var i = 0; i < 16; i++) { inner8b.Add(Data_8b.CreateData_8b(builder)); } var innerOffset = Data_128b.CreateInnerVector(builder, inner8b.ToArray()); var offset = Data_128b.CreateData_128b(builder, innerOffset); builder.Finish(offset.Value); InputData.Add(Data_128b.GetRootAsData_128b(builder.DataBuffer)); } { var builder = new FlatBufferBuilder(128); List <Offset <Data_128b> > inner128b = new List <Offset <Data_128b> >(); for (var i = 0; i < 8; i++) { List <Offset <Data_8b> > inner8b = new List <Offset <Data_8b> >(); for (var j = 0; j < 16; j++) { inner8b.Add(Data_8b.CreateData_8b(builder)); } var inner8bOffset = Data_128b.CreateInnerVector(builder, inner8b.ToArray()); inner128b.Add(Data_128b.CreateData_128b(builder, inner8bOffset)); } var innerOffset = Data_1KB.CreateInnerVector(builder, inner128b.ToArray()); var offset = Data_1KB.CreateData_1KB(builder, innerOffset); builder.Finish(offset.Value); InputData.Add(Data_1KB.GetRootAsData_1KB(builder.DataBuffer)); } { var builder = new FlatBufferBuilder(128); List <Offset <Data_1KB> > inner1kb = new List <Offset <Data_1KB> >(); for (var i = 0; i < 1024; i++) { List <Offset <Data_128b> > inner128b = new List <Offset <Data_128b> >(); for (var j = 0; j < 8; j++) { List <Offset <Data_8b> > inner8b = new List <Offset <Data_8b> >(); for (var k = 0; k < 16; k++) { inner8b.Add(Data_8b.CreateData_8b(builder)); } var inner8bOffset = Data_128b.CreateInnerVector(builder, inner8b.ToArray()); inner128b.Add(Data_128b.CreateData_128b(builder, inner8bOffset)); } var inner128bOffset = Data_1KB.CreateInnerVector(builder, inner128b.ToArray()); inner1kb.Add(Data_1KB.CreateData_1KB(builder, inner128bOffset)); } var innerOffset = Data_1MB.CreateInnerVector(builder, inner1kb.ToArray()); var offset = Data_1MB.CreateData_1MB(builder, innerOffset); builder.Finish(offset.Value); InputData.Add(Data_1MB.GetRootAsData_1MB(builder.DataBuffer)); } }