Esempio n. 1
0
        private void button6_Click(object sender, EventArgs e)
        {
            var ms1 = new MemoryStream();
            var ms2 = new MemoryStream();

            var slim1 = new SlimSerializer(new TypeRegistry(new Type[] { typeof(Library), typeof(Book), typeof(Perzon), typeof(List <Book>), typeof(object[]), typeof(string[]) }, TypeRegistry.CommonCollectionTypes));

            slim1.TypeMode = TypeRegistryMode.Batch;
            slim1.Serialize(ms1, data);
            slim1.Serialize(ms2, data);
            slim1.ResetCallBatch();

            ms1.Position = 0;
            slim1.Deserialize(ms1);
            var w = Stopwatch.StartNew();

            for (var i = 0; i < CNT; i++)
            {
                ms2.Position = 0;
                slim1.Deserialize(ms2);
            }

            w.Stop();

            Text = string.Format("Slim deserialized {0:n2} in {1:n2} ms, {2:n2}/sec {3}bytes", CNT, w.ElapsedMilliseconds, (CNT / (double)w.ElapsedMilliseconds) * 1000, ms2.Length);
        }
Esempio n. 2
0
        public void T1_ResetCallBatch()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer
                {
                    TypeMode = TypeRegistryMode.Batch
                };

                Aver.IsTrue(TypeRegistryMode.Batch == s1.TypeMode);
                Aver.IsFalse(s1.IsThreadSafe);
                Aver.IsFalse(s1.BatchTypesAdded);

                var o1 = new A1 {
                    I1 = 12
                };

                s1.Serialize(ms, o1);

                Aver.IsTrue(s1.BatchTypesAdded);

                s1.ResetCallBatch();

                Aver.IsFalse(s1.BatchTypesAdded);
            }
        }
Esempio n. 3
0
        public override void BeforeSerializationIterationBatch(Test test)
        {
            if (m_Batching &&
                (test.SerIterations > 1 || test.DeserIterations > 1))
            {
                throw new SerbenchException("SlimSerializer test is not properly configured. If BATCHING=true, then test may have many runs, not many ser/deser iterations as batching retains the stream state and is not an idempotent operation");
            }

            if (m_Batching)
            {
                m_BatchSer.ResetCallBatch();
                m_BatchDeser.ResetCallBatch();
            }
        }
Esempio n. 4
0
        public void T7_CountMismatchResetBatch_WriteMany()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer
                {
                    TypeMode = TypeRegistryMode.Batch
                };
                var o1a = new A1 {
                    I1 = 12
                };
                var o1b = new A2 {
                    I2 = 13
                };
                var o1c = new A1 {
                    I1 = 14
                };
                var o1d = new A1 {
                    I1 = 15
                };
                var o1e = new A1 {
                    I1 = 16
                };

                s1.Serialize(ms, o1a); Aver.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1b); Aver.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1c); Aver.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1d); Aver.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1e); Aver.IsFalse(s1.BatchTypesAdded);
                ms.Seek(0, SeekOrigin.Begin);

                var buf = ms.GetBuffer();
                buf.ToDumpString(DumpFormat.Printable, 0, (int)ms.Length).See();

                var s2 = new SlimSerializer
                {
                    TypeMode = TypeRegistryMode.Batch
                };
                var o2a = (A1)s2.Deserialize(ms); Aver.IsTrue(s2.BatchTypesAdded);
                Aver.AreEqual(12, o2a.I1);

                s2.ResetCallBatch();
                var o2b = (A2)s2.Deserialize(ms); //Exception
            }
        }
Esempio n. 5
0
        private void ensureClient()
        {
            if (m_Client != null)
            {
                return;
            }

            var ep = SyncBinding.ToIPEndPoint(Node);

            m_Client = new TcpClient();
            m_Client.Connect(ep);

            m_Client.NoDelay             = true;
            m_Client.LingerState.Enabled = false;

            m_Client.ReceiveBufferSize = Binding.ClientReceiveBufferSize;
            m_Client.SendBufferSize    = Binding.ClientSendBufferSize;

            m_Client.ReceiveTimeout = Binding.ClientReceiveTimeout;
            m_Client.SendTimeout    = Binding.ClientSendTimeout;

            m_Serializer.ResetCallBatch();
        }