Exemplo n.º 1
0
        public void T08_PreserveReferenceToTheSameArray()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var bytes   = new byte[] { 0x07, 0x12 };
                var strings = new string[] { "Veingarten", "Vecherovskiy", "Zahar Gubar'" };
                var ints    = new int[] { -100, 2345, 19044, 888889 };
                var dIn     = new C11()
                {
                    FBytes = bytes,
                    FC11   = new C11_1()
                    {
                        FBytes_1 = bytes, FStrings_1 = strings, FInts_1 = ints
                    },
                    FC12 = new C11_2()
                    {
                        FBytes_2 = bytes, FStrings_2 = strings, FInts_2 = ints
                    }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (C11)s.Deserialize(ms);

                Assert.AreSame(dOut.FBytes, dOut.FC11.FBytes_1);
                Assert.AreSame(dOut.FBytes, dOut.FC12.FBytes_2);

                Assert.AreSame(dOut.FC11.FStrings_1, dOut.FC12.FStrings_2);
                Assert.AreSame(dOut.FC11.FInts_1, dOut.FC12.FInts_2);
            }
        }
Exemplo n.º 2
0
        public void T11_DictComparer()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new Dictionary <int, int>(new Comparer1());
                dIn[1]  = 100;
                dIn[11] = 200;
                dIn[2]  = 300;

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (Dictionary <int, int>)s.Deserialize(ms);

                Assert.AreEqual(2, dOut.Count);

                //foreach (var kvp in dOut)
                //{
                //  Console.WriteLine(kvp.Key + "=>" + kvp.Value);
                //}

                Assert.AreEqual(200, dOut[1]);
                Assert.AreEqual(300, dOut[2]);

                dOut[1] = 100;

                Assert.AreEqual(2, dOut.Count);
                Assert.AreEqual(100, dOut[1]);
            }
        }
Exemplo n.º 3
0
        public void ASCII8_Class()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new withASCII8
                {
                    Name = "Josh",
                    Int  = 9876500,
                    A1   = new Atom(123),
                    A2   = null,
                    A3   = Atom.Encode("abc"),
                    A4   = new [] { Atom.Encode("a"), Atom.Encode("b") },
                    A5   = new Atom?[] { null, Atom.Encode("b"), null, null, Atom.Encode("zzz") }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (withASCII8)s.Deserialize(ms);

                Aver.IsNotNull(dOut);

                Aver.AreEqual(dIn.Name, dOut.Name);
                Aver.AreEqual(dIn.Int, dOut.Int);

                Aver.IsFalse(dOut.A2.HasValue);
                Aver.AreEqual("abc", dOut.A3.Value.Value);
                Aver.AreArraysEquivalent(dIn.A4, dOut.A4);
                Aver.AreArraysEquivalent(dIn.A5, dOut.A5);
            }
        }
Exemplo n.º 4
0
        public void NLS_InClass()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new nlsCls {
                    Map = new NLSMap("eng{n='name' d='description'} rus{n='имя' d='описание'}".AsLaconicConfig())
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (nlsCls)s.Deserialize(ms);

                Aver.IsNotNull(dOut);

                Aver.AreEqual(2, dOut.Map.Count);
                Aver.AreEqual("name", dOut.Map.Get(NLSMap.GetParts.Name, "eng"));
                Aver.AreEqual("имя", dOut.Map.Get(NLSMap.GetParts.Name, "rus"));

                Aver.AreEqual("description", dOut.Map.Get(NLSMap.GetParts.Description, "eng"));
                Aver.AreEqual("описание", dOut.Map.Get(NLSMap.GetParts.Description, "rus"));
            }
        }
Exemplo n.º 5
0
        public void StringMap_Sensitive()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new StringMap
                {
                    { "a", "Alex" },
                    { "b", "Boris" }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (StringMap)s.Deserialize(ms);

                Aver.IsNotNull(dOut);

                Aver.IsTrue(dOut.CaseSensitive);
                Aver.AreEqual(2, dOut.Count);
                Aver.AreEqual("Alex", dOut["a"]);
                Aver.AreEqual(null, dOut["A"]);

                Aver.AreEqual("Boris", dOut["b"]);
                Aver.AreEqual(null, dOut["B"]);
            }
        }
Exemplo n.º 6
0
        public void StringMap_One_InClass()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new stringMapCls
                {
                    Map1 = new StringMap(false)
                    {
                        { "a", "Alex" },
                        { "b", "Boris" }
                    }
                };

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (stringMapCls)s.Deserialize(ms);

                Aver.IsNotNull(dOut);
                Aver.IsNotNull(dOut.Map1);
                Aver.IsNull(dOut.Map2);

                Aver.IsFalse(dOut.Map1.CaseSensitive);
                Aver.AreEqual(2, dOut.Map1.Count);
                Aver.AreEqual("Alex", dOut.Map1["a"]);
                Aver.AreEqual("Alex", dOut.Map1["A"]);

                Aver.AreEqual("Boris", dOut.Map1["b"]);
                Aver.AreEqual("Boris", dOut.Map1["B"]);
            }
        }
Exemplo n.º 7
0
        public void T1_TypeWasAdded()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer();
                Aver.IsTrue(TypeRegistryMode.PerCall == s1.TypeMode);
                Aver.IsTrue(s1.IsThreadSafe);
                Aver.IsFalse(s1.BatchTypesAdded);

                s1.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);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = new SlimSerializer();
                s2.TypeMode = TypeRegistryMode.Batch;
                var o2 = (A1)s2.Deserialize(ms);

                Aver.AreEqual(12, o2.I1);

                Aver.IsTrue(s1.BatchTypesAdded);
                Aver.IsTrue(s2.BatchTypesAdded);
            }
        }
Exemplo n.º 8
0
        public void T1_TypeWasNotAdded()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer(new Type[] { typeof(A1) });//put it in globals
                s1.TypeMode = TypeRegistryMode.Batch;
                Aver.IsFalse(s1.BatchTypesAdded);


                var o1 = new A1 {
                    I1 = 12
                };

                s1.Serialize(ms, o1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = new SlimSerializer(new Type[] { typeof(A1) });
                s2.TypeMode = TypeRegistryMode.Batch;
                var o2 = (A1)s2.Deserialize(ms);

                Aver.AreEqual(12, o2.I1);

                Aver.IsFalse(s1.BatchTypesAdded);
                Aver.IsFalse(s2.BatchTypesAdded);
            }
        }
Exemplo n.º 9
0
        public void T01()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer(SlimFormat.Instance);

                var root = new ObjectA()
                {
                    AField = -890
                };

                s.Serialize(ms, root);

                ms.Position = 0;


                var deser = s.Deserialize(ms) as ObjectA;

                Assert.IsNotNull(deser);
                Assert.IsTrue(deser.GetType() == typeof(ObjectA));

                Assert.AreEqual(-890, deser.AField);
                Assert.IsNull(deser.Another1);
                Assert.IsNull(deser.Another2);
                Assert.IsNull(deser.Another3);
                Assert.IsNull(deser.Another4);
                Assert.IsNull(deser.Another5);
                Assert.IsNull(deser.Another6);
                Assert.IsNull(deser.Another7);
                Assert.IsNull(deser.Another8);
                Assert.IsNull(deser.Another9);
                Assert.IsNull(deser.Another10);
            }
        }
Exemplo n.º 10
0
        public void ValidationBatchException_Serialization()
        {
            var error1 = new AzosException("error1");
            var error2 = new ArgumentException("error2");

            var got = ValidationBatchException.Concatenate(error1, error2);

            Aver.IsNotNull(got);
            var ser = new SlimSerializer();
            var ms  = new MemoryStream();

            ser.Serialize(ms, got);
            ms.Position = 0;

            var deser = ser.Deserialize(ms) as ValidationBatchException;

            Aver.IsNotNull(deser);
            Aver.AreNotSameRef(got, deser);
            Aver.IsNotNull(deser.Batch);
            Aver.AreEqual(2, deser.Batch.Count);

            Aver.IsTrue(deser.Batch[0] is AzosException);
            Aver.IsTrue(deser.Batch[1] is ArgumentException);

            Aver.AreEqual("error1", deser.Batch[0].Message);
            Aver.AreEqual("error2", deser.Batch[1].Message);
        }
Exemplo n.º 11
0
        public void T11_DictComparer()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new Dictionary <int, int>(new Comparer1());
                dIn[1]  = 100;
                dIn[11] = 200;
                dIn[2]  = 300;

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (Dictionary <int, int>)s.Deserialize(ms);

                Aver.AreEqual(2, dOut.Count);

                Aver.AreEqual(200, dOut[1]);
                Aver.AreEqual(300, dOut[2]);

                dOut[1] = 100;

                Aver.AreEqual(2, dOut.Count);
                Aver.AreEqual(100, dOut[1]);
            }
        }
Exemplo n.º 12
0
        public void T15_Struct3()
        {
            //MyStructWithReadonlyField z = new MyStructWithReadonlyField(1, 2, false);
            //object oz = z;
            //typeof(MyStructWithReadonlyField).GetField("F").SetValue(oz, true);
            //z = (MyStructWithReadonlyField)oz;
            //Console.WriteLine(z.F);
            //return;

            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var s1 = new MyStructWithReadonlyField(10, 15, true);

                s.Serialize(ms, s1);
                ms.Seek(0, SeekOrigin.Begin);

                var s2 = (MyStructWithReadonlyField)s.Deserialize(ms);

                Console.WriteLine(NFX.Serialization.JSON.JSONWriter.Write(s1));
                Console.WriteLine(NFX.Serialization.JSON.JSONWriter.Write(s2));

                Assert.AreEqual(s1.X, s2.X);
                Assert.AreEqual(s1.Y, s2.Y);
                Assert.AreEqual(s1.F, s2.F);
            }
        }
Exemplo n.º 13
0
        public void T2000_TypeRegistry()
        {
            using (var ms = new MemoryStream())
            {
                var s   = new SlimSerializer();
                var tr1 = new TypeRegistry();

                Assert.IsTrue(tr1.Add(typeof(List <S3>)));
                Assert.IsTrue(tr1.Add(typeof(S3[])));
                Assert.IsTrue(tr1.Add(typeof(Tuple <string, S3>)));


                s.Serialize(ms, tr1);

                ms.Position = 0;

                var tr2 = s.Deserialize(ms) as TypeRegistry;

                Assert.IsNotNull(tr2);

                Assert.AreEqual(7, tr2.Count);//including system types
                Assert.AreEqual(typeof(Tuple <string, S3>), tr2["$6"]);
                Assert.AreEqual(typeof(S3[]), tr2["$5"]);
                Assert.AreEqual(typeof(List <S3>), tr2["$4"]);
            }
        }
Exemplo n.º 14
0
        public void T3000_Dictionary_TYPE_Int_Root()
        {
            using (var ms = new MemoryStream())
            {
                var s  = new SlimSerializer();
                var d1 = new Dictionary <Type, int>();

                d1.Add(typeof(List <S3>), 1);
                d1.Add(typeof(S3[]), 20);
                d1.Add(typeof(Tuple <string, S3>), 90);


                s.Serialize(ms, d1);

                ms.Position = 0;

                var d2 = s.Deserialize(ms) as Dictionary <Type, int>;

                Assert.IsNotNull(d2);

                Assert.AreEqual(3, d2.Count);
                Assert.AreEqual(1, d2[typeof(List <S3>)]);
                Assert.AreEqual(20, d2[typeof(S3[])]);
                Assert.AreEqual(90, d2[typeof(Tuple <string, S3>)]);
            }
        }
Exemplo n.º 15
0
Arquivo: Slim5.cs Projeto: zhabis/nfx
        public void Circular1()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new cA
                {
                    A = 2190,
                    B = 23232
                };

                dIn.Child = new cA {
                    A = -100, B = -900, Child = dIn
                };                                             //circular reference!!!


                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (cA)s.Deserialize(ms);

                Aver.AreEqual(2190, dOut.A);
                Aver.AreEqual(23232, dOut.B);
                Aver.IsNotNull(dOut.Child);
                Aver.AreEqual(-100, dOut.Child.A);
                Aver.AreEqual(-900, dOut.Child.B);
                Aver.AreSameRef(dOut, dOut.Child.Child);
            }
        }
Exemplo n.º 16
0
        public void TypedRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));


            tbl.Insert(new Person {
                ID           = "POP1",
                FirstName    = "Oleg",
                LastName     = "Popov-1",
                DOB          = new DateTime(1953, 12, 10),
                YearsInSpace = 12
            });

            var ser = new SlimSerializer();

            using (var ms = new MemoryStream())
            {
                ser.Serialize(ms, tbl);

                ms.Position = 0;

                var tbl2 = ser.Deserialize(ms) as Table;

                Assert.IsNotNull(tbl2);
                Assert.IsFalse(object.ReferenceEquals(tbl, tbl2));

                Assert.IsFalse(object.ReferenceEquals(tbl.Schema, tbl2.Schema));


                Assert.IsTrue(tbl.Schema.IsEquivalentTo(tbl2.Schema));
            }
        }
Exemplo n.º 17
0
    public void T04()
    {
      using (var ms = new MemoryStream())
      {
        var s = new SlimSerializer();

        var dIn = new[]{
         new customClassA {  A = 1, B = 100},
         new customClassA {  A = 2, B = 200},
         new customClassA {  A = 3, B = 300},
        };

        //StackOverflow while using ISerializable
        dIn[0].Child = dIn[2];
        dIn[1].Child = dIn[0];
        dIn[2].Child = dIn[1];

        s.Serialize(ms, dIn);
        "Written {0} bytes".Args(ms.Length).See();
        ms.Seek(0, SeekOrigin.Begin);

        var dOut = (customClassB[])s.Deserialize(ms);

        Aver.AreEqual(3, dOut.Length);
        Aver.AreEqual(1, dOut[0].A);
        Aver.AreEqual(100, dOut[0].B);
      }
    }
Exemplo n.º 18
0
        private void putResponse(TcpClient client, MemoryStream ms, ResponseMsg response, SlimSerializer serializer)
        {
            var frameBegin = Consts.PACKET_DELIMITER_LENGTH;

            ms.Position = frameBegin;

            var frame = new WireFrame(WireFrame.SLIM_FORMAT, true, response.RequestID);

            // Write the frame
            var frameSize = frame.Serialize(ms);

            // Write the message
            serializer.Serialize(ms, response);

            var size = (int)ms.Position - frameBegin;

            var buffer = ms.GetBuffer(); //no stream expansion beyond this point

            buffer.WriteBEInt32(0, size);

            Binding.DumpMsg(true, response, buffer, 0, (int)ms.Position);

            if (size > Binding.MaxMsgSize)
            {
                Instrumentation.ServerSerializedOverMaxMsgSizeErrorEvent.Happened(Node);
                throw new MessageSizeException(size, Binding.MaxMsgSize, "putResponse()", serializer.BatchTypesAdded);
            }

            client.GetStream().Write(buffer, 0, (int)ms.Position);

            stat_MsgSent();
            stat_BytesSent(size);
        }
Exemplo n.º 19
0
        private void button1_Click(object sender, EventArgs e)
        {
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            var ms = new MemoryStream();

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

            slim.TypeMode = TypeRegistryMode.Batch;

            var w = Stopwatch.StartNew();

            for (var i = 0; i < CNT; i++)
            {
                ms.Position = 0;
                slim.Serialize(ms, data);
            }

            w.Stop();

            using (var fs = new FileStream("C:\\azos\\SerializerForm2.slim", FileMode.Create))
            {
                fs.Write(ms.GetBuffer(), 0, (int)ms.Length);
            }

            Text = string.Format("Slim serialized {0:n2} in {1:n2} ms, {2:n2}/sec {3}bytes", CNT, w.ElapsedMilliseconds, (CNT / (double)w.ElapsedMilliseconds) * 1000, ms.Length);

            //   MessageBox.Show( ms.GetBuffer().ToDumpString(DumpFormat.Hex,0, (int)ms.Length));
        }
Exemplo n.º 20
0
    public void T02()
    {
      using (var ms = new MemoryStream())
      {
        var s = new SlimSerializer();

        var dIn = new customClassA
        {
          A = 2190,
          B = 23232,
          Child = new customClassA { A = -100, B = -900 }
        };

        s.Serialize(ms, dIn);
        ms.Seek(0, SeekOrigin.Begin);

        var dOut = (customClassB)s.Deserialize(ms);

        Aver.AreEqual(2190, dOut.A);
        Aver.AreEqual(23232, dOut.B);
        Aver.IsNotNull(dOut.Child);
        Aver.AreEqual(-100, dOut.Child.A);
        Aver.AreEqual(-900, dOut.Child.B);
      }
    }
Exemplo n.º 21
0
        public void Slim_SerializeTable_DynamicRows()
        {
            var tbl = new Table(Schema.GetForTypedDoc(typeof(Person)));

            for (var i = 0; i < 1000; i++)
            {
                var row = new DynamicDoc(tbl.Schema);

                row["ID"]           = "POP{0}".Args(i);
                row["FirstName"]    = "Oleg";
                row["LastName"]     = "Popov-{0}".Args(i);
                row["DOB"]          = new DateTime(1953, 12, 10);
                row["YearsInSpace"] = 12;

                tbl.Insert(row);
            }

            var ser = new SlimSerializer();

            using (var ms = new MemoryStream())
            {
                ser.Serialize(ms, tbl);
                Console.WriteLine("{0} rows took {1} bytes".Args(tbl.Count, ms.Position));
                ms.Position = 0;

                var tbl2 = ser.Deserialize(ms) as Table;

                Aver.IsNotNull(tbl2);
                Aver.IsFalse(object.ReferenceEquals(tbl, tbl2));

                Aver.AreEqual(1000, tbl2.Count);
                Aver.IsTrue(tbl.SequenceEqual(tbl2));
            }
        }
Exemplo n.º 22
0
        public void Test_InjectionTarget_Serialization()
        {
            using (var app = new AzosApplication(null, BASE_CONF))
            {
                const string DATA = "lalala!";

                var target = new InjectionTarget_Root();
                target.Data = DATA;

                app.DependencyInjector.InjectInto(target);
                target.AssertInjectionCorrectness(app);

                using (var ms = new MemoryStream())
                {
                    var ser = new SlimSerializer();
                    ser.Serialize(ms, target);
                    ms.Position = 0;

                    var target2 = ser.Deserialize(ms) as InjectionTarget_Root;
                    Aver.IsNotNull(target2);           //we deserialized the instance

                    Aver.AreEqual(DATA, target2.Data); //the Data member got deserialized ok
                    Aver.AreNotSameRef(target.Data, target2.Data);
                    Aver.AreNotSameRef(DATA, target2.Data);

                    target2.AssertAllInjectionsNull();       //but all injections are transitive, hence are null
                    app.DependencyInjector.InjectInto(target2);
                    target2.AssertInjectionCorrectness(app); //and are re-hydrated again after InjectInto() call
                }
            }
        }
Exemplo n.º 23
0
        public void DynamicRows()
        {
            var tbl = new Table(Schema.GetForTypedDoc(typeof(Person)));

            var row = new DynamicDoc(tbl.Schema);

            row["ID"]           = "POP1";
            row["FirstName"]    = "Oleg";
            row["LastName"]     = "Popov-1";
            row["DOB"]          = new DateTime(1953, 12, 10);
            row["YearsInSpace"] = 12;

            tbl.Insert(row);

            var ser = new SlimSerializer();

            using (var ms = new MemoryStream())
            {
                ser.Serialize(ms, tbl);

                ms.Position = 0;

                var tbl2 = ser.Deserialize(ms) as Table;

                Aver.IsNotNull(tbl2);
                Aver.IsFalse(object.ReferenceEquals(tbl, tbl2));

                Aver.IsFalse(object.ReferenceEquals(tbl.Schema, tbl2.Schema));

                Aver.IsTrue(tbl.Schema.IsEquivalentTo(tbl2.Schema));
            }
        }
Exemplo n.º 24
0
        public void Slim_SerializeTable_TypedRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));

            for (var i = 0; i < 1000; i++)
            {
                tbl.Insert(new Person {
                    ID           = "POP{0}".Args(i),
                    FirstName    = "Oleg",
                    LastName     = "Popov-{0}".Args(i),
                    DOB          = new DateTime(1953, 12, 10),
                    YearsInSpace = 12
                });
            }

            var ser = new SlimSerializer();

            using (var ms = new MemoryStream())
            {
                ser.Serialize(ms, tbl);
                Console.WriteLine("{0} rows took {1} bytes".Args(tbl.Count, ms.Position));
                ms.Position = 0;

                var tbl2 = ser.Deserialize(ms) as Table;

                Assert.IsNotNull(tbl2);
                Assert.IsFalse(object.ReferenceEquals(tbl, tbl2));

                Assert.AreEqual(1000, tbl2.Count);

                Assert.IsTrue(tbl.SequenceEqual(tbl2));
            }
        }
Exemplo n.º 25
0
        public void Create_Seal_SerializeDeserialize_Read()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            parcel.Seal(FakeNOPBank.Instance);



            var ser = new SlimSerializer(Parcel.STANDARD_KNOWN_SERIALIZER_TYPES);

            var ms = new MemoryStream();

            ser.Serialize(ms, parcel);
            ms.Position = 0;
            var parcel2 = ser.Deserialize(ms) as PeopleNamesParcel;

            Assert.IsNotNull(parcel2);
            var payload2 = parcel2.Payload;

            Assert.IsNotNull(payload2);


            Assert.AreEqual(payload2.Count, names.Count);
            Assert.IsTrue(payload2.SequenceEqual(names));
        }
Exemplo n.º 26
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);
            }
        }
Exemplo n.º 27
0
        public void T4_Batch_WriteMany()
        {
            using (var ms = new MemoryStream())
            {
                var s1 = new SlimSerializer();
                s1.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);  Assert.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1b);  Assert.IsTrue(s1.BatchTypesAdded);
                s1.Serialize(ms, o1c);  Assert.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1d);  Assert.IsFalse(s1.BatchTypesAdded);
                s1.Serialize(ms, o1e);  Assert.IsFalse(s1.BatchTypesAdded);
                ms.Seek(0, SeekOrigin.Begin);

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

                var s2 = new SlimSerializer();
                s2.TypeMode = TypeRegistryMode.Batch;
                var o2a = (A1)s2.Deserialize(ms); Assert.IsTrue(s2.BatchTypesAdded);
                var o2b = (A2)s2.Deserialize(ms); Assert.IsTrue(s2.BatchTypesAdded);
                var o2c = (A1)s2.Deserialize(ms); Assert.IsFalse(s2.BatchTypesAdded);
                var o2d = (A1)s2.Deserialize(ms); Assert.IsFalse(s2.BatchTypesAdded);
                var o2e = (A1)s2.Deserialize(ms); Assert.IsFalse(s2.BatchTypesAdded);

                Assert.AreEqual(12, o2a.I1);
                Assert.AreEqual(13, o2b.I2);
                Assert.AreEqual(14, o2c.I1);
                Assert.AreEqual(15, o2d.I1);
                Assert.AreEqual(16, o2e.I1);
            }
        }
Exemplo n.º 28
0
            public void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                var ms = new MemoryStream();
                var s  = new SlimSerializer();

                s.Serialize(ms, Data);
                info.AddValue("d", ms.GetBuffer(), typeof(byte[]));
            }
Exemplo n.º 29
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
            }
        }
Exemplo n.º 30
0
        private void SerializeNFXSlim()
        {
            var s          = new MemoryStream();
            var serializer = new SlimSerializer(SlimFormat.Instance);

            serializer.Serialize(s, Value);
            var bytes = s.ToArray();

            RunTest("NFX Slim Serializer", () =>
            {
                var stream = new MemoryStream();
                serializer.Serialize(stream, Value);
            }, () =>
            {
                s.Position = 0;
                serializer.Deserialize(s);
            }, bytes.Length);
        }