Esempio n. 1
0
        private static void WriteValueImpl(Stream stream, decimal value, byte[] bytes)
        {
            var data = decimal.GetBits(value);

            Int32Serializer.WriteValueImpl(stream, data[0], bytes);
            Int32Serializer.WriteValueImpl(stream, data[1], bytes);
            Int32Serializer.WriteValueImpl(stream, data[2], bytes);
            Int32Serializer.WriteValueImpl(stream, data[3], bytes);
        }
Esempio n. 2
0
        public override void WriteValue(Stream stream, object value, SerializerSession session)
        {
            var bytes = session.GetBuffer(Int32Serializer.Size);

            var data = decimal.GetBits((decimal)value);

            Int32Serializer.WriteValueImpl(stream, data[0], bytes);
            Int32Serializer.WriteValueImpl(stream, data[1], bytes);
            Int32Serializer.WriteValueImpl(stream, data[2], bytes);
            Int32Serializer.WriteValueImpl(stream, data[3], bytes);
        }
Esempio n. 3
0
        private static decimal ReadValueImpl(Stream stream, byte[] bytes)
        {
            var parts = new[]
            {
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes)
            };
            var sign = (parts[3] & 0x80000000) != 0;

            var scale    = (byte)((parts[3] >> 16) & 0x7F);
            var newValue = new decimal(parts[0], parts[1], parts[2], sign, scale);

            return(newValue);
        }
Esempio n. 4
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var bytes = session.GetBuffer(Int32Serializer.Size);

            var parts = new[]
            {
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes)
            };
            var sign = (parts[3] & 0x80000000) != 0;

            var scale    = (byte)((parts[3] >> 16) & 0x7F);
            var newValue = new decimal(parts[0], parts[1], parts[2], sign, scale);

            return(newValue);
        }
Esempio n. 5
0
 private static void WriteValues <T>(T[] array, Stream stream, ValueSerializer elementSerializer, SerializerSession session)
 {
     Int32Serializer.WriteValueImpl(stream, array.Length, session);
     if (typeof(T).IsFixedSizeType())
     {
         var size   = typeof(T).GetTypeSize();
         var result = new byte[array.Length * size];
         Buffer.BlockCopy(array, 0, result, 0, result.Length);
         stream.Write(result);
     }
     else
     {
         foreach (var value in array)
         {
             elementSerializer.WriteValue(stream, value, session);
         }
     }
 }
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     Int32Serializer.WriteValueImpl(stream, (int)value, session);
 }