コード例 #1
0
        private IASValue ReadMixedArray()
        {
            int length = input.ReadInt();

            if (length < 0)
            {
                throw new AMFException(ExceptionPrefix + "Encountered negative MixedArray length.");
            }

            // Important: Add the array to the cache before deserializing its properties!
            ASArray result = ASArray.CreateUninitializedInstance();

            AddObjectToCache(result);

            IASValue[] indexedValues = length == 0 ? EmptyArray <IASValue> .Instance : new IASValue[length];
            IDictionary <string, IASValue> mixedValues = null;

            for (;;)
            {
                string key = input.ReadShortString();
                if (key.Length == 0)
                {
                    break;
                }

                IASValue value = input.ReadObject();

                // If the string looks like a valid index, then stuff it into the array.
                int index;
                if (int.TryParse(key, NumberStyles.None, CultureInfo.InvariantCulture, out index) && index >= 0 && index < length)
                {
                    indexedValues[index] = value;
                }
                else
                {
                    // Otherwise add it as a mixed value.
                    if (mixedValues == null)
                    {
                        mixedValues = new Dictionary <string, IASValue>();
                    }

                    mixedValues.Add(key, value);
                }
            }

            if (mixedValues == null)
            {
                mixedValues = EmptyDictionary <string, IASValue> .Instance;
            }

            ConsumeEndOfObject();

            result.SetProperties(indexedValues, mixedValues);
            return(result);
        }
コード例 #2
0
ファイル: ASArrayTest.cs プロジェクト: mgagne-atman/Projects
 public void SetPropertiesWithInitializedInstanceThrows()
 {
     ASArray array = new ASArray(1);
     array.SetProperties(EmptyArray<IASValue>.Instance, EmptyDictionary<string, IASValue>.Instance);
 }
コード例 #3
0
        public void SetPropertiesWithInitializedInstanceThrows()
        {
            ASArray array = new ASArray(1);

            array.SetProperties(EmptyArray <IASValue> .Instance, EmptyDictionary <string, IASValue> .Instance);
        }
コード例 #4
0
        private IASValue ReadArray()
        {
            int bits = input.ReadVWInt29();
            int lengthOrReferenceId = bits >> 1;

            // Handle cached objects.
            if ((bits & 1) == 0)
            {
                return(GetObjectFromCache(AMF3ObjectTypeCode.Array, lengthOrReferenceId));
            }

            // Read out the whole array.
            if (lengthOrReferenceId < 0)
            {
                throw new AMFException(String.Format(CultureInfo.CurrentCulture,
                                                     ExceptionPrefix + "Encountered Array token with invalid length '{0}'.", lengthOrReferenceId));
            }

            // Important: Add the array to the cache before deserializing its properties!
            ASArray result = ASArray.CreateUninitializedInstance();

            AddObjectToCache(AMF3ObjectTypeCode.Array, result);

            // Read mixed values if any.
            IDictionary <string, IASValue> mixedValues;

            string key = ReadStringData();

            if (key.Length != 0)
            {
                mixedValues = new Dictionary <string, IASValue>();

                for (; ;)
                {
                    IASValue value = ReadObject();
                    mixedValues.Add(key, value);

                    key = ReadStringData();
                    if (key.Length == 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                mixedValues = EmptyDictionary <string, IASValue> .Instance;
            }

            // Read indexed values if any.
            IASValue[] indexedValues;

            if (lengthOrReferenceId != 0)
            {
                indexedValues = new IASValue[lengthOrReferenceId];

                for (int i = 0; i < lengthOrReferenceId; i++)
                {
                    indexedValues[i] = ReadObject();
                }
            }
            else
            {
                indexedValues = EmptyArray <IASValue> .Instance;
            }

            result.SetProperties(indexedValues, mixedValues);
            return(result);
        }