public void BinDeserialize(BinaryReader reader) { BaseBinDeserialize(reader); if (MemberPresent == reader.ReadByte()) { Variables = VariableRef_Serializer.Deserialize(reader); } }
public void Test() { const int len = 10000; const int repeat = 100; var stream = new MemoryStream(750 * 1024); long totalTicksSeri = 0; long totalTicksDeseri = 0; for (int i = 0; i < repeat; ++i) { stream.Seek(0, SeekOrigin.Begin); var listA = MakeTestData(len); var sw = Stopwatch.StartNew(); VariableRef_Serializer.Serialize(stream, listA, Common.CurrentBinaryVersion); //StdJson.ObjectToStream(listA, stream); sw.Stop(); totalTicksSeri += sw.ElapsedTicks; //Console.WriteLine($"{i} Dauer 1: {sw.ElapsedMilliseconds} ms {stream.Position} {listA.Count}"); Console.WriteLine($"{stream.Position / (double)listA.Count} {listA.Count}"); stream.Seek(0, SeekOrigin.Begin); sw.Restart(); List <VariableRef> listB; listB = VariableRef_Serializer.Deserialize(stream); //using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8, leaveOpen: true)) { // listB = StdJson.ObjectFromReader<List<VariableValue>>(reader); //} sw.Stop(); totalTicksDeseri += sw.ElapsedTicks; bool ok = listA.Count == listB.Count && Enumerable.Range(0, listA.Count).All(x => listA[x] == listB[x]); if (!ok) { throw new Exception("Test failed!"); } //Console.WriteLine($"{i} Dauer 2: {sw.ElapsedMilliseconds} ms {ok}\n"); if (i == 0) { totalTicksSeri = 0; totalTicksDeseri = 0; } } console.WriteLine(Util.FormatDuration("Serial", totalTicksSeri, repeat)); console.WriteLine(Util.FormatDuration("Deseri", totalTicksDeseri, repeat)); }
public void BinSerialize(BinaryWriter writer, byte binaryVersion) { BaseBinSerialize(writer, binaryVersion); writer.Write(MemberPresent); VariableRef_Serializer.Serialize(writer, Variables, binaryVersion); writer.Write(Timeout.HasValue ? MemberPresent : MemberNull); if (Timeout.HasValue) { writer.Write((long)Timeout.Value.TotalMilliseconds); } }
public void BinDeserialize(BinaryReader reader) { BaseBinDeserialize(reader); if (MemberPresent == reader.ReadByte()) { Variables = VariableRef_Serializer.Deserialize(reader); } byte timeOutState = reader.ReadByte(); if (MemberPresent == timeOutState) { Timeout = Duration.FromMilliseconds(reader.ReadInt64()); } else if (MemberNull == timeOutState) { Timeout = null; } }
public void BinSerialize(BinaryWriter writer, byte binaryVersion) { BaseBinSerialize(writer, binaryVersion); writer.Write(MemberPresent); VariableRef_Serializer.Serialize(writer, Variables, binaryVersion); }