Esempio n. 1
0
        /// <exception cref="System.IO.IOException" />
        internal static void TestDifferentClassVersionsUsingDataWriteAndRead(ISerializationService serializationService,
                                                                             ISerializationService serializationService2)
        {
            var p1   = new NamedPortable("portable-v1", 111);
            var data = serializationService.ToData(p1);
            // emulate socket write by writing data to stream
            var @out = serializationService.CreateObjectDataOutput(1024);

            @out.WriteData(data);
            var bytes = @out.ToByteArray();
            // emulate socket read by reading data from stream
            var @in = serializationService2.CreateObjectDataInput(bytes);

            data = @in.ReadData();
            // read data
            var object1 = serializationService2.ToObject <object>(data);
            // serialize new portable version
            var p2    = new NamedPortableV2("portable-v2", 123);
            var data2 = serializationService2.ToData(p2);
            // de-serialize back using old version
            var object2 = serializationService.ToObject <object>(data2);

            Assert.IsNotNull(object1, "object1 should not be null!");
            Assert.IsNotNull(object2, "object2 should not be null!");
            Assert.IsInstanceOf <NamedPortableV2>(object1, "Should be instance of NamedPortableV2: " + object1.GetType());
            Assert.IsInstanceOf <NamedPortable>(object2, "Should be instance of NamedPortable: " + object2.GetType());
        }
        /// <exception cref="System.IO.IOException" />
        internal static void TestDifferentClassVersionsUsingDataWriteAndRead(ISerializationService serializationService,
                                                                             ISerializationService serializationService2)
        {
            NamedPortable portableV1 = new NamedPortable("portable-v1", 111);
            IData         dataV1     = serializationService.ToData(portableV1);


            // emulate socket write by writing data to stream
            var @out = serializationService.CreateObjectDataOutput(1024);

            @out.WriteData(dataV1);
            var bytes = @out.ToByteArray();
            // emulate socket read by reading data from stream
            var @in = serializationService2.CreateObjectDataInput(bytes);

            dataV1 = @in.ReadData();

            // serialize new portable version
            var portableV2 = new NamedPortableV2("portable-v2", 123, 500);
            var dataV2     = serializationService2.ToData(portableV2);

            NamedPortable v1FromV2 = serializationService.ToObject <NamedPortable>(dataV2);

            Assert.AreEqual(portableV2.name, v1FromV2.name);
            Assert.AreEqual(portableV2.k, v1FromV2.k);

            NamedPortableV2 v2FromV1 = serializationService2.ToObject <NamedPortableV2>(dataV1);

            Assert.AreEqual(portableV1.name, v2FromV1.name);
            Assert.AreEqual(portableV1.k, v2FromV1.k);

            Assert.AreEqual(v2FromV1.v, 0);
        }
 public RawDataPortable(long l, char[] c, NamedPortable p, int k, string s, ByteArrayDataSerializable sds)
 {
     this.l = l;
     this.c = c;
     this.p = p;
     this.k = k;
     this.s = s;
     this.sds = sds;
 }
Esempio n. 4
0
 public RawDataPortable(long l, char[] c, NamedPortable p, int k, string s, ByteArrayDataSerializable sds)
 {
     this.l   = l;
     this.c   = c;
     this.p   = p;
     this.k   = k;
     this.s   = s;
     this.sds = sds;
 }
Esempio n. 5
0
        public virtual void ReadPortable(IPortableReader reader)
        {
            l = reader.ReadLong("l");
            c = reader.ReadCharArray("c");
            p = reader.ReadPortable <NamedPortable>("p");
            var input = reader.GetRawDataInput();

            k   = input.ReadInt();
            s   = input.ReadUTF();
            sds = input.ReadObject <ByteArrayDataSerializable>();
        }
 public InnerPortable(byte[] bb, char[] cc, short[] ss, int[] ii, long[] ll, float[] ff, double[] dd,
     NamedPortable[] nn)
 {
     this.bb = bb;
     this.cc = cc;
     this.ss = ss;
     this.ii = ii;
     this.ll = ll;
     this.ff = ff;
     this.dd = dd;
     this.nn = nn;
 }
Esempio n. 7
0
        internal static void TestDifferentClassVersions(ISerializationService serializationService,
                                                        ISerializationService serializationService2)
        {
            var p1    = new NamedPortable("named-portable", 123);
            var data  = serializationService.ToData(p1);
            var p2    = new NamedPortableV2("named-portable", 123);
            var data2 = serializationService2.ToData(p2);
            var o1    = serializationService2.ToObject <NamedPortableV2>(data);
            var o2    = serializationService.ToObject <NamedPortable>(data2);

            Assert.AreEqual(o1.name, o2.name);
        }
Esempio n. 8
0
        public virtual void TestPreDefinedDifferentVersionsWithInnerPortable()
        {
            var serializationService = PortableSerializationTest.CreateSerializationService(1);

            serializationService.GetPortableContext().RegisterClassDefinition(CreateInnerPortableClassDefinition());
            var serializationService2 = PortableSerializationTest.CreateSerializationService(2);

            serializationService2.GetPortableContext().RegisterClassDefinition(CreateInnerPortableClassDefinition());
            var nn = new NamedPortable[1];

            nn[0] = new NamedPortable("name", 123);
            var inner = new InnerPortable(new byte[] { 0, 1, 2 }, new[] { 'c', 'h', 'a', 'r' }, new short[] { 3, 4, 5 },
                                          new[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 }, new[] { 0.6543f, -3.56f, 45.67f }, new[]
            {
                456.456
                , 789.789, 321.321
            }, nn);
            var mainWithInner = new MainPortable(unchecked (113), true, 'x', -500, 56789, -50992225L, 900.5678f,
                                                 -897543.3678909d, "this is main portable object created for testing!", inner);

            TestPreDefinedDifferentVersions(serializationService, serializationService2, mainWithInner);
        }
        internal static void TestDifferentClassVersions(ISerializationService serializationService,
                                                        ISerializationService serializationService2)
        {
            NamedPortable portableV1 = new NamedPortable("named-portable", 123);
            IData         dataV1     = serializationService.ToData(portableV1);

            NamedPortableV2 portableV2 = new NamedPortableV2("named-portable", 123, 500);
            IData           dataV2     = serializationService2.ToData(portableV2);

            NamedPortable v1FromV2 = serializationService.ToObject <NamedPortable>(dataV2);

            Assert.AreEqual(portableV2.name, v1FromV2.name);
            Assert.AreEqual(portableV2.k, v1FromV2.k);

            NamedPortableV2 v2FromV1 = serializationService2.ToObject <NamedPortableV2>(dataV1);

            Assert.AreEqual(portableV1.name, v2FromV1.name);
            Assert.AreEqual(portableV1.k, v2FromV1.k);

            Assert.AreEqual(v2FromV1.v, 0);
            //Assert.IsNull(v2FromV1.v);
        }
        public void TestBasics(ByteOrder byteOrder)
        {
            var ss = CreateSerializationService(1, byteOrder);
            var ss2 = CreateSerializationService(2, byteOrder);

            var nn = new NamedPortable[5];
            for (var i = 0; i < nn.Length; i++)
            {
                nn[i] = new NamedPortable("named-portable-" + i, i);
            }

            var inner = new InnerPortable(new byte[] {0, 1, 2}, new[] {'c', 'h', 'a', 'r'},
                new short[] {3, 4, 5}, new[] {9, 8, 7, 6}, new long[] {0, 1, 5, 7, 9, 11},
                new[] {0.6543f, -3.56f, 45.67f}, new[] {456.456, 789.789, 321.321}, nn);

            var main = new MainPortable(113, true, 'x', -500, 56789, -50992225L, 900.5678f, -897543.3678909d,
                "this is main portable object created for testing!", inner);

            var data = ss.ToData(main);

            Assert.AreEqual(main, ss.ToObject<MainPortable>(data));
            Assert.AreEqual(main, ss2.ToObject<MainPortable>(data));
        }
        public void TestBasics(ByteOrder byteOrder)
        {
            var ss  = CreateSerializationService(1, byteOrder);
            var ss2 = CreateSerializationService(2, byteOrder);

            var nn = new NamedPortable[5];

            for (var i = 0; i < nn.Length; i++)
            {
                nn[i] = new NamedPortable("named-portable-" + i, i);
            }

            var inner = new InnerPortable(new byte[] { 0, 1, 2 }, new[] { 'c', 'h', 'a', 'r' },
                                          new short[] { 3, 4, 5 }, new[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 },
                                          new[] { 0.6543f, -3.56f, 45.67f }, new[] { 456.456, 789.789, 321.321 }, nn);

            var main = new MainPortable(113, true, 'x', -500, 56789, -50992225L, 900.5678f, -897543.3678909d,
                                        "this is main portable object created for testing!", inner);

            var data = ss.ToData(main);

            Assert.AreEqual(main, ss.ToObject <MainPortable>(data));
            Assert.AreEqual(main, ss2.ToObject <MainPortable>(data));
        }
 public virtual void TestPreDefinedDifferentVersionsWithInnerPortable()
 {
     var serializationService = PortableSerializationTest.CreateSerializationService(1);
     serializationService.GetPortableContext().RegisterClassDefinition(CreateInnerPortableClassDefinition());
     var serializationService2 = PortableSerializationTest.CreateSerializationService(2);
     serializationService2.GetPortableContext().RegisterClassDefinition(CreateInnerPortableClassDefinition());
     var nn = new NamedPortable[1];
     nn[0] = new NamedPortable("name", 123);
     var inner = new InnerPortable(new byte[] {0, 1, 2}, new[] {'c', 'h', 'a', 'r'}, new short[] {3, 4, 5},
         new[] {9, 8, 7, 6}, new long[] {0, 1, 5, 7, 9, 11}, new[] {0.6543f, -3.56f, 45.67f}, new[]
         {
             456.456
             , 789.789, 321.321
         }, nn);
     var mainWithInner = new MainPortable(unchecked(113), true, 'x', -500, 56789, -50992225L, 900.5678f,
         -897543.3678909d, "this is main portable object created for testing!", inner);
     TestPreDefinedDifferentVersions(serializationService, serializationService2, mainWithInner);
 }
 /// <exception cref="System.IO.IOException" />
 internal static void TestDifferentClassVersionsUsingDataWriteAndRead(ISerializationService serializationService,
     ISerializationService serializationService2)
 {
     var p1 = new NamedPortable("portable-v1", 111);
     var data = serializationService.ToData(p1);
     // emulate socket write by writing data to stream
     var @out = serializationService.CreateObjectDataOutput(1024);
     @out.WriteData(data);
     var bytes = @out.ToByteArray();
     // emulate socket read by reading data from stream
     var @in = serializationService2.CreateObjectDataInput(bytes);
     data = @in.ReadData();
     // read data
     var object1 = serializationService2.ToObject<object>(data);
     // serialize new portable version
     var p2 = new NamedPortableV2("portable-v2", 123);
     var data2 = serializationService2.ToData(p2);
     // de-serialize back using old version
     var object2 = serializationService.ToObject<object>(data2);
     Assert.IsNotNull(object1, "object1 should not be null!");
     Assert.IsNotNull(object2, "object2 should not be null!");
     Assert.IsInstanceOf<NamedPortableV2>(object1, "Should be instance of NamedPortableV2: " + object1.GetType());
     Assert.IsInstanceOf<NamedPortable>(object2, "Should be instance of NamedPortable: " + object2.GetType());
 }
 internal static void TestDifferentClassVersions(ISerializationService serializationService,
     ISerializationService serializationService2)
 {
     var p1 = new NamedPortable("named-portable", 123);
     var data = serializationService.ToData(p1);
     var p2 = new NamedPortableV2("named-portable", 123);
     var data2 = serializationService2.ToData(p2);
     var o1 = serializationService2.ToObject<NamedPortableV2>(data);
     var o2 = serializationService.ToObject<NamedPortable>(data2);
     Assert.AreEqual(o1.name, o2.name);
 }
 public InvalidRawDataPortable(long l, char[] c, NamedPortable p, int k, string s, ByteArrayDataSerializable sds)
     : base(l, c, p, k, s, sds)
 {
 }
 public virtual void ReadPortable(IPortableReader reader)
 {
     l = reader.ReadLong("l");
     c = reader.ReadCharArray("c");
     p = reader.ReadPortable<NamedPortable>("p");
     var input = reader.GetRawDataInput();
     k = input.ReadInt();
     s = input.ReadUTF();
     sds = input.ReadObject<ByteArrayDataSerializable>();
 }
 protected bool Equals(NamedPortable other)
 {
     return string.Equals(name, other.name) && k == other.k;
 }
Esempio n. 18
0
 protected bool Equals(NamedPortable other)
 {
     return(string.Equals(name, other.name) && k == other.k);
 }
 public InvalidRawDataPortable(long l, char[] c, NamedPortable p, int k, string s, ByteArrayDataSerializable sds)
     :
     base(l, c, p, k, s, sds)
 {
 }