Пример #1
0
        private object DeserializeCustom(StreamBuffer din, byte customTypeCode)
        {
            short      num        = this.DeserializeShort(din);
            CustomType customType = default(CustomType);

            if (Protocol.CodeDict.TryGetValue(customTypeCode, out customType))
            {
                if (customType.DeserializeStreamFunction == null)
                {
                    byte[] array = new byte[num];
                    din.Read(array, 0, num);
                    return(customType.DeserializeFunction(array));
                }
                int    position = din.Position;
                object result   = customType.DeserializeStreamFunction(din, num);
                int    num2     = din.Position - position;
                if (num2 != num)
                {
                    din.Position = position + num;
                }
                return(result);
            }
            byte[] array2 = new byte[num];
            din.Read(array2, 0, num);
            return(array2);
        }
Пример #2
0
 private double DeserializeDouble(StreamBuffer din)
 {
     byte[] obj = this.memDouble;
     lock (obj)
     {
         byte[] array = this.memDouble;
         din.Read(array, 0, 8);
         if (BitConverter.IsLittleEndian)
         {
             byte b  = array[0];
             byte b2 = array[1];
             byte b3 = array[2];
             byte b4 = array[3];
             array[0] = array[7];
             array[1] = array[6];
             array[2] = array[5];
             array[3] = array[4];
             array[4] = b4;
             array[5] = b3;
             array[6] = b2;
             array[7] = b;
         }
         return(BitConverter.ToDouble(array, 0));
     }
 }
Пример #3
0
 private int DeserializeInteger(StreamBuffer din)
 {
     byte[] obj = this.memInteger;
     lock (obj)
     {
         byte[] array = this.memInteger;
         din.Read(array, 0, 4);
         return(array[0] << 24 | array[1] << 16 | array[2] << 8 | array[3]);
     }
 }
Пример #4
0
 public override short DeserializeShort(StreamBuffer din)
 {
     byte[] obj = this.memShort;
     lock (obj)
     {
         byte[] array = this.memShort;
         din.Read(array, 0, 2);
         return((short)(array[0] << 8 | array[1]));
     }
 }
Пример #5
0
 private byte[] DeserializeByteArray(StreamBuffer din, int size = -1)
 {
     if (size == -1)
     {
         size = this.DeserializeInteger(din);
     }
     byte[] array = new byte[size];
     din.Read(array, 0, size);
     return(array);
 }
Пример #6
0
 private long DeserializeLong(StreamBuffer din)
 {
     byte[] obj = this.memLong;
     lock (obj)
     {
         byte[] array = this.memLong;
         din.Read(array, 0, 8);
         if (BitConverter.IsLittleEndian)
         {
             return((long)((ulong)array[0] << 56 | (ulong)array[1] << 48 | (ulong)array[2] << 40 | (ulong)array[3] << 32 | (ulong)array[4] << 24 | (ulong)array[5] << 16 | (ulong)array[6] << 8 | array[7]));
         }
         return(BitConverter.ToInt64(array, 0));
     }
 }
Пример #7
0
        private string DeserializeString(StreamBuffer din)
        {
            short num = this.DeserializeShort(din);

            if (num == 0)
            {
                return(string.Empty);
            }
            if (this.memString == null || this.memString.Length < num)
            {
                this.memString = new byte[num];
            }
            din.Read(this.memString, 0, num);
            return(Encoding.UTF8.GetString(this.memString, 0, num));
        }
Пример #8
0
 private float DeserializeFloat(StreamBuffer din)
 {
     lock (memFloat)
     {
         byte[] array = this.memFloat;
         din.Read(array, 0, 4);
         if (BitConverter.IsLittleEndian)
         {
             byte b  = array[0];
             byte b2 = array[1];
             array[0] = array[3];
             array[1] = array[2];
             array[2] = b2;
             array[3] = b;
         }
         return(BitConverter.ToSingle(array, 0));
     }
 }
Пример #9
0
        private Array DeserializeArray(StreamBuffer din)
        {
            short num   = this.DeserializeShort(din);
            byte  b     = din.ReadByte();
            Array array = null;

            switch (b)
            {
            case 121:
            {
                Array array3 = this.DeserializeArray(din);
                Type  type   = array3.GetType();
                array = Array.CreateInstance(type, num);
                array.SetValue(array3, 0);
                for (short num4 = 1; num4 < num; num4 = (short)(num4 + 1))
                {
                    array3 = this.DeserializeArray(din);
                    array.SetValue(array3, num4);
                }
                goto IL_0226;
            }

            case 120:
                array = Array.CreateInstance(typeof(byte[]), num);
                for (short num5 = 0; num5 < num; num5 = (short)(num5 + 1))
                {
                    Array value = this.DeserializeByteArray(din, -1);
                    array.SetValue(value, num5);
                }
                goto IL_0226;

            case 98:
                array = this.DeserializeByteArray(din, num);
                goto IL_0226;

            case 105:
                array = this.DeserializeIntArray(din, num);
                goto IL_0226;

            case 99:
            {
                byte       b2         = din.ReadByte();
                CustomType customType = default(CustomType);
                if (Protocol.CodeDict.TryGetValue(b2, out customType))
                {
                    array = Array.CreateInstance(customType.Type, num);
                    for (int i = 0; i < num; i++)
                    {
                        short num3 = this.DeserializeShort(din);
                        if (customType.DeserializeStreamFunction == null)
                        {
                            byte[] array2 = new byte[num3];
                            din.Read(array2, 0, num3);
                            array.SetValue(customType.DeserializeFunction(array2), i);
                        }
                        else
                        {
                            array.SetValue(customType.DeserializeStreamFunction(din, num3), i);
                        }
                    }
                    goto IL_0226;
                }
                throw new Exception("Cannot find deserializer for custom type: " + b2);
            }

            case 68:
            {
                Array result = null;
                this.DeserializeDictionaryArray(din, num, out result);
                return(result);
            }

            default:
            {
                array = this.CreateArrayByType(b, num);
                for (short num2 = 0; num2 < num; num2 = (short)(num2 + 1))
                {
                    array.SetValue(this.Deserialize(din, b), num2);
                }
                goto IL_0226;
            }
IL_0226:
                return(array);
            }
        }