/// <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 BufferPool(ISerializationService serializationService) { _inputPool = new ObjectPool <IBufferObjectDataInput>(MaxPooledItems, () => serializationService.CreateObjectDataInput((byte[])null), item => item.Clear()); _outputPool = new ObjectPool <IBufferObjectDataOutput>(MaxPooledItems, () => serializationService.CreateObjectDataOutput(), item => item.Clear()); }
public IBufferObjectDataInput TakeInputBuffer(IData data) { IBufferObjectDataInput input; try { input = inputQueue.Dequeue(); } catch (InvalidOperationException) { input = _serializationService.CreateObjectDataInput((byte[])null); } input.Init(data.ToByteArray(), HeapData.DataOffset); return(input); }
/// <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()); }