コード例 #1
0
        public bool VariantEncode(object obj)
        {
            int         num1 = 0;
            bool        flag = false;
            VariantType variantType;

            if (obj is Array && !(obj is byte[]))
            {
                Type type = obj.GetType();
                flag = true;
                num1 = type.GetArrayRank();
                Type elementType = type.GetElementType();
                if (num1 > 1)
                {
                    throw new Exception("TODO");
                }

                variantType = MemoryBuffer.GetVariantTypeFromType(elementType);
            }
            else
            {
                variantType = MemoryBuffer.GetVariantTypeFromInstance(obj);
            }

            byte num2 = (byte)variantType;

            if (num1 > 1)
            {
                num2 |= 64;
            }

            if (flag)
            {
                byte num3 = (byte)(num2 | 128U);
                if (!this.Encode(num3) || !this.Encode(((Array)obj).Length))
                {
                    return(false);
                }

                Array array = (Array)obj;
                for (int index = 0; index < array.Length; ++index)
                {
                    if (!this.VariantEncode(array.GetValue(index), num3))
                    {
                        return(false);
                    }
                }
            }
            else if (!this.Encode(num2) || !this.VariantEncode(obj, num2))
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public int VariantCodingSize(object obj)
        {
            int         num1 = 0;
            bool        flag = false;
            VariantType variantType;

            if (obj is Array && !(obj is byte[]))
            {
                Type type = obj.GetType();
                flag = true;
                num1 = type.GetArrayRank();
                Type elementType = type.GetElementType();
                if (num1 > 1)
                {
                    throw new Exception("TODO");
                }

                variantType = MemoryBuffer.GetVariantTypeFromType(elementType);
            }
            else
            {
                variantType = MemoryBuffer.GetVariantTypeFromInstance(obj);
            }

            int  num2  = 0;
            byte mask1 = (byte)variantType;
            int  num3  = num2 + 1;

            if (num1 > 1)
            {
                mask1 |= 64;
            }

            int num4;

            if (flag)
            {
                byte mask2 = (byte)(mask1 | 128U);
                num4 = num3 + this.CodingSize(((Array)obj).Length);
                Array array = (Array)obj;
                for (int index = 0; index < array.Length; ++index)
                {
                    num4 += this.VariantCodingSize(array.GetValue(index), mask2);
                }
            }
            else
            {
                num4 = num3 + this.VariantCodingSize(obj, mask1);
            }

            return(num4);
        }