Ejemplo n.º 1
0
        // Token: 0x0600036C RID: 876 RVA: 0x00009AEC File Offset: 0x00008AEC
        private int ReadField(Context context, Integer field, out object fieldValue)
        {
            fieldValue = null;
            byte[] buffer = context.Buffer;
            int    num    = field.LengthSpecified ? field.Length : 4;
            bool   flag   = field.Signed;

            if (field.GetType() == typeof(Int8))
            {
                num  = 1;
                flag = true;
            }
            else if (field.GetType() == typeof(Int16))
            {
                num  = 2;
                flag = true;
            }
            else if (field.GetType() == typeof(Int32))
            {
                num  = 4;
                flag = true;
            }
            else if (field.GetType() == typeof(Int64))
            {
                num  = 8;
                flag = true;
            }
            else if (field.GetType() == typeof(UInt8))
            {
                num  = 1;
                flag = false;
            }
            else if (field.GetType() == typeof(UInt16))
            {
                num  = 2;
                flag = false;
            }
            else if (field.GetType() == typeof(UInt32))
            {
                num  = 4;
                flag = false;
            }
            else if (field.GetType() == typeof(UInt64))
            {
                num  = 8;
                flag = false;
            }
            if (buffer.Length - context.Index < num)
            {
                throw new InvalidDataInBufferException("Unexpected end of buffer.");
            }
            byte[] array = new byte[num];
            for (int i = 0; i < num; i++)
            {
                array[i] = buffer[context.Index + i];
            }
            if (context.BigEndian)
            {
                base.SwapBytes(array, 0, num);
            }
            if (flag)
            {
                int num2 = num;
                switch (num2)
                {
                case 1:
                    if (array[0] < 128)
                    {
                        fieldValue = (sbyte)array[0];
                        return(num);
                    }
                    fieldValue = (sbyte)(-(sbyte)array[0]);
                    return(num);

                case 2:
                    fieldValue = BitConverter.ToInt16(array, 0);
                    return(num);

                case 3:
                    break;

                case 4:
                    fieldValue = BitConverter.ToInt32(array, 0);
                    return(num);

                default:
                    if (num2 == 8)
                    {
                        fieldValue = BitConverter.ToInt64(array, 0);
                        return(num);
                    }
                    break;
                }
                fieldValue = array;
            }
            else
            {
                int num3 = num;
                switch (num3)
                {
                case 1:
                    fieldValue = array[0];
                    return(num);

                case 2:
                    fieldValue = BitConverter.ToUInt16(array, 0);
                    return(num);

                case 3:
                    break;

                case 4:
                    fieldValue = BitConverter.ToUInt32(array, 0);
                    return(num);

                default:
                    if (num3 == 8)
                    {
                        fieldValue = BitConverter.ToUInt64(array, 0);
                        return(num);
                    }
                    break;
                }
                fieldValue = array;
            }
            return(num);
        }