Beispiel #1
0
 public void BinDeserialize(BinaryReader reader)
 {
     BaseBinDeserialize(reader);
     if (MemberPresent == reader.ReadByte())
     {
         Values = VariableValue_Serializer.Deserialize(reader);
     }
 }
Beispiel #2
0
        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();

                VariableValue_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 <VariableValue> listB;
                listB = VariableValue_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));
        }
Beispiel #3
0
        public void BinDeserialize(BinaryReader reader)
        {
            BaseBinDeserialize(reader);
            if (MemberPresent == reader.ReadByte())
            {
                Values = VariableValue_Serializer.Deserialize(reader);
            }
            byte timeOutState = reader.ReadByte();

            if (MemberPresent == timeOutState)
            {
                Timeout = Duration.FromMilliseconds(reader.ReadInt64());
            }
            else if (MemberNull == timeOutState)
            {
                Timeout = null;
            }
        }