public SerializedRequest Serialize() { _request = _serializer.Serialize(new Mock { Id = 1337, Email = "*****@*****.**", FirstName = "Adelina", LastName = "Mavin", Gender = "Female", IpAddress = "42.241.120.161", Data = "[email protected]: Adelina Mavin (Female) from 42.241.120.161" }); _arrayPool.Return(_request.RentedArray); return(_request); }
public async Task SerializeDeserializeSpeedTest() { var pool = ArrayPool <byte> .Create(); var serializer = new TcpSerializer <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > >(_bitConverterHelper, i => pool.Rent(i)); var deserializer = new TcpDeserializer <long, RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > >(_bitConverterHelper); var mock = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <int> > > .Create( RecursiveMock <RecursiveMock <int> > .Create( RecursiveMock <int> .Create(int.MaxValue ) ) ) ) ); var sw = Stopwatch.StartNew(); SerializedRequest serialize = null; for (var i = 0; i < 10000; i++) { serialize = serializer.Serialize(mock); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 1000); TestContext.WriteLine($"Serialize: {sw.Elapsed.ToString()}"); sw.Reset(); for (var i = 0; i < 10000; i++) { var pipe = PipeReader.Create(new MemoryStream(serialize.Request.ToArray())); sw.Start(); var(id, data) = await deserializer.DeserializeAsync(pipe, CancellationToken.None); sw.Stop(); Assert.NotNull(id); Assert.NotNull(data); } Assert.Less(sw.ElapsedMilliseconds, 1000); TestContext.WriteLine($"Deserialize: {sw.Elapsed.ToString()}"); }
/// <summary> /// To make serialization easier just ovveride ToString so we don't have to bother with casting objects /// in our custom serializer. /// </summary> /// <returns></returns> public override string ToString() { Serialize(); return(SerializedRequest.ToString()); }