internal ByteArrayObjectDataOutput(int size, ISerializationService service, ByteOrder byteOrder)
 {
     _initialSize = size;
     Buffer = new byte[size];
     _service = service;
     _isBigEndian = byteOrder == ByteOrder.BigEndian;
 }
        public virtual void TestInputOutputWithPortableReader(ByteOrder byteOrder)
        {
            var portable = KitchenSinkPortable.Generate();

            var config = new SerializationConfig();
            config.AddPortableFactoryClass(KitchenSinkPortableFactory.FactoryId, typeof (KitchenSinkPortableFactory));

            var ss = new SerializationServiceBuilder().SetConfig(config).
                SetUseNativeByteOrder(false).SetByteOrder(byteOrder).Build();

            var data = ss.ToData(portable);
            var reader = ss.CreatePortableReader(data);

            var actual = new KitchenSinkPortable();
            actual.ReadPortable(reader);

            Assert.AreEqual(portable, actual);

            ss.Destroy();
        }
        public virtual void TestDataInputOutputWithPortable(ByteOrder byteOrder)
        {
            var portable = KitchenSinkPortable.Generate();

            var config = new SerializationConfig();
            config.AddPortableFactoryClass(KitchenSinkPortableFactory.FactoryId, typeof (KitchenSinkPortableFactory));

            var ss = new SerializationServiceBuilder().SetConfig(config).
                SetUseNativeByteOrder(false).SetByteOrder(byteOrder).Build();

            IObjectDataOutput output = ss.CreateObjectDataOutput(1024);
            output.WriteObject(portable);
            var data = output.ToByteArray();

            IObjectDataInput input = ss.CreateObjectDataInput(data);
            var readObject = input.ReadObject<IPortable>();

            Assert.AreEqual(portable, readObject);

            ss.Destroy();
        }
        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 ISerializationServiceBuilder SetByteOrder(ByteOrder byteOrder)
 {
     this._byteOrder = byteOrder;
     return this;
 }
 public void WriteLong(int position, long v, ByteOrder byteOrder)
 {
     Bits.WriteLong(buffer, position, v, isBigEndian);
 }
 internal static ISerializationService CreateSerializationService(int version, ByteOrder order)
 {
     return new SerializationServiceBuilder()
         .SetUseNativeByteOrder(false).SetByteOrder(order).SetPortableVersion(version)
         .AddPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new TestPortableFactory())
         .AddDataSerializableFactory(TestSerializationConstants.DATA_SERIALIZABLE_FACTORY_ID,
             GetDataSerializableFactory())
         .Build();
 }
        public virtual void TestReadWrite(ByteOrder byteOrder)
        {
            var obj = KitchenSinkDataSerializable.Generate();
            obj.Serializable = KitchenSinkDataSerializable.Generate();

            var ss = new SerializationServiceBuilder()
                .AddDataSerializableFactory(1, new ArrayDataSerializableFactory(new Func<IIdentifiedDataSerializable>[]
                {
                    () => new KitchenSinkDataSerializable(),
                }))
                .SetUseNativeByteOrder(false).SetByteOrder(byteOrder).Build();

            IObjectDataOutput output = ss.CreateObjectDataOutput(1024);
            output.WriteObject(obj);

            IObjectDataInput input = ss.CreateObjectDataInput(output.ToByteArray());
            var readObj = input.ReadObject<object>();
            Assert.AreEqual(obj, readObj);

            ss.Destroy();
        }
 public void WriteFloat(int position, float v, ByteOrder byteOrder)
 {
     WriteInt(position, BitConverter.ToInt32(BitConverter.GetBytes(v), 0), byteOrder);
 }
 public void WriteFloat(float v, ByteOrder byteOrder)
 {
     WriteInt(BitConverter.ToInt32(BitConverter.GetBytes(v), 0), byteOrder);
 }
 public void WriteDouble(int position, double v, ByteOrder byteOrder)
 {
     WriteLong(position, BitConverter.DoubleToInt64Bits(v), byteOrder);
 }
 public void WriteDouble(double v, ByteOrder byteOrder)
 {
     WriteLong(BitConverter.DoubleToInt64Bits(v), byteOrder);
 }
 public void WriteInt(int position, int v, ByteOrder byteOrder)
 {
     Bits.WriteInt(buffer, position, v, byteOrder == ByteOrder.BigEndian);
 }
 public void WriteInt(int v, ByteOrder byteOrder)
 {
     EnsureAvailable(Bits.IntSizeInBytes);
     Bits.WriteInt(buffer, pos, v, byteOrder == ByteOrder.BigEndian);
     pos += Bits.IntSizeInBytes;
 }
 public ISerializationServiceBuilder SetConfig(SerializationConfig config)
 {
     this._config = config;
     if (_portableVersion < 0)
     {
         _portableVersion = config.GetPortableVersion();
     }
     _checkClassDefErrors = config.IsCheckClassDefErrors();
     _useNativeByteOrder = config.IsUseNativeByteOrder();
     _byteOrder = config.GetByteOrder();
     _enableCompression = config.IsEnableCompression();
     _enableSharedObject = config.IsEnableSharedObject();
     return this;
 }
 private IInputOutputFactory CreateInputOutputFactory()
 {
     if (_byteOrder == null)
     {
         _byteOrder = ByteOrder.BigEndian;
     }
     if (_useNativeByteOrder || _byteOrder == ByteOrder.NativeOrder())
     {
         _byteOrder = ByteOrder.NativeOrder();
     }
     return new ByteArrayInputOutputFactory(_byteOrder);
 }
 public void WriteLong(long v, ByteOrder byteOrder)
 {
     EnsureAvailable(Bits.LongSizeInBytes);
     Bits.WriteLong(Buffer, Pos, v, byteOrder == ByteOrder.BigEndian);
     Pos += Bits.LongSizeInBytes;
 }
 public void WriteLong(int position, long v, ByteOrder byteOrder)
 {
     Bits.WriteLong(Buffer, position, v, byteOrder == ByteOrder.BigEndian);
 }
 public void WriteShort(int v, ByteOrder byteOrder)
 {
     EnsureAvailable(Bits.ShortSizeInBytes);
     Bits.WriteShort(Buffer, Pos, (short) v, byteOrder == ByteOrder.BigEndian);
     Pos += Bits.ShortSizeInBytes;
 }
 public ByteArrayInputOutputFactory(ByteOrder byteOrder)
 {
     _byteOrder = byteOrder;
 }
 public void WriteShort(int position, int v, ByteOrder byteOrder)
 {
     Bits.WriteShort(Buffer, position, (short) v, byteOrder == ByteOrder.BigEndian);
 }
 public virtual SerializationConfig SetByteOrder(ByteOrder byteOrder)
 {
     this.byteOrder = byteOrder;
     return this;
 }
 public void WriteLong(long v, ByteOrder byteOrder)
 {
     EnsureAvailable(Bits.LongSizeInBytes);
     Bits.WriteLong(buffer, pos, v, isBigEndian);
     pos += Bits.LongSizeInBytes;
 }