NewMissingItem() private method

private NewMissingItem ( int index ) : Exception
index int
return System.Exception
Esempio n. 1
0
        public static void UnpackCollectionTo <T>(Unpacker unpacker, MessagePackSerializer <T> serializer, IEnumerable <T> collection, Action <T> addition)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }


            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }


            if (addition == null)
            {
                throw new ArgumentNullException("addition");
            }

            if (!unpacker.IsArrayHeader)
            {
                throw SerializationExceptions.NewIsNotArrayHeader();
            }

#if !UNITY
            Contract.EndContractBlock();
#endif // !UNITY

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                T item;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    item = serializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        item = serializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                addition(item);
            }
        }
Esempio n. 2
0
        public static void UnpackMapTo <TKey, TValue>(Unpacker unpacker, MessagePackSerializer <TKey> keySerializer, MessagePackSerializer <TValue> valueSerializer, IDictionary <TKey, TValue> dictionary)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }
            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }
            int itemsCount = GetItemsCount(unpacker);

            for (int i = 0; i < itemsCount; i++)
            {
                TKey     local;
                Unpacker unpacker2;
                TValue   local2;
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }
                if (!(unpacker.IsArrayHeader || unpacker.IsMapHeader))
                {
                    local = keySerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (unpacker2 = unpacker.ReadSubtree())
                    {
                        local = keySerializer.UnpackFrom(unpacker2);
                    }
                }
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }
                if (!(unpacker.IsArrayHeader || unpacker.IsMapHeader))
                {
                    local2 = valueSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (unpacker2 = unpacker.ReadSubtree())
                    {
                        local2 = valueSerializer.UnpackFrom(unpacker2);
                    }
                }
                dictionary.Add(local, local2);
            }
        }
Esempio n. 3
0
        public static void UnpackMapTo(Unpacker unpacker, IDictionary dictionary)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }
            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }
            int itemsCount = GetItemsCount(unpacker);

            for (int i = 0; i < itemsCount; i++)
            {
                MessagePackObject obj2;
                Unpacker          unpacker2;
                MessagePackObject obj3;
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }
                if (!(unpacker.IsArrayHeader || unpacker.IsMapHeader))
                {
                    obj2 = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (unpacker2 = unpacker.ReadSubtree())
                    {
                        obj2 = _messagePackObjectSerializer.UnpackFrom(unpacker2);
                    }
                }
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }
                if (!(unpacker.IsArrayHeader || unpacker.IsMapHeader))
                {
                    obj3 = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (unpacker2 = unpacker.ReadSubtree())
                    {
                        obj3 = _messagePackObjectSerializer.UnpackFrom(unpacker2);
                    }
                }
                dictionary.Add(obj2, obj3);
            }
        }
Esempio n. 4
0
        public static void UnpackArrayTo <T>(Unpacker unpacker, MessagePackSerializer <T> serializer, T[] array)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (!unpacker.IsArrayHeader)
            {
                throw SerializationExceptions.NewIsNotArrayHeader();
            }

#if !UNITY
            Contract.EndContractBlock();
#endif // !UNITY

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                T item;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    item = serializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        item = serializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                array[i] = item;
            }
        }
Esempio n. 5
0
        public static void UnpackCollectionTo <TDiscarded>(Unpacker unpacker, IEnumerable collection, Func <object, TDiscarded> addition)
        {
#if DEBUG
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            if (!unpacker.IsArrayHeader)
            {
                throw SerializationExceptions.NewIsNotArrayHeader();
            }

            Contract.EndContractBlock();
#endif

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                MessagePackObject item;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    item = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        item = _messagePackObjectSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                addition(item);
            }
        }
Esempio n. 6
0
        public static void UnpackArrayTo <T>(Unpacker unpacker, MessagePackSerializer <T> serializer, T[] array)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (!unpacker.IsArrayHeader)
            {
                throw SerializationExceptions.NewIsNotArrayHeader();
            }
            int itemsCount = GetItemsCount(unpacker);

            for (int i = 0; i < itemsCount; i++)
            {
                T local;
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }
                if (!(unpacker.IsArrayHeader || unpacker.IsMapHeader))
                {
                    local = serializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker unpacker2 = unpacker.ReadSubtree())
                    {
                        local = serializer.UnpackFrom(unpacker2);
                    }
                }
                array[i] = local;
            }
        }
Esempio n. 7
0
        public static void UnpackCollectionTo <T, TDiscarded>(Unpacker unpacker, MessagePackSerializer <T> serializer, IEnumerable <T> collection, Func <T, TDiscarded> addition)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (!unpacker.IsArrayHeader)
            {
                throw SerializationExceptions.NewIsNotArrayHeader();
            }
            int itemsCount = GetItemsCount(unpacker);

            for (int i = 0; i < itemsCount; i++)
            {
                T local;
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }
                if (!(unpacker.IsArrayHeader || unpacker.IsMapHeader))
                {
                    local = serializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker unpacker2 = unpacker.ReadSubtree())
                    {
                        local = serializer.UnpackFrom(unpacker2);
                    }
                }
                addition(local);
            }
        }
Esempio n. 8
0
        public static void UnpackCollectionTo(Unpacker unpacker, IEnumerable collection, Action <object> addition)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (!unpacker.IsArrayHeader)
            {
                throw SerializationExceptions.NewIsNotArrayHeader();
            }
            int itemsCount = GetItemsCount(unpacker);

            for (int i = 0; i < itemsCount; i++)
            {
                MessagePackObject obj2;
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }
                if (!(unpacker.IsArrayHeader || unpacker.IsMapHeader))
                {
                    obj2 = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker unpacker2 = unpacker.ReadSubtree())
                    {
                        obj2 = _messagePackObjectSerializer.UnpackFrom(unpacker2);
                    }
                }
                addition(obj2);
            }
        }
Esempio n. 9
0
        public static void UnpackMapTo(Unpacker unpacker, IDictionary dictionary)
        {
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            Contract.EndContractBlock();

            int count = GetItemsCount(unpacker);

            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                MessagePackObject key;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    key = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        key = _messagePackObjectSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }


                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                MessagePackObject value;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    value = _messagePackObjectSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        value = _messagePackObjectSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                dictionary.Add(key, value);
            }
        }
Esempio n. 10
0
        public static void UnpackMapTo <TKey, TValue>(Unpacker unpacker, MessagePackSerializer keySerializer, MessagePackSerializer valueSerializer, Dictionary <TKey, TValue> dictionary)

        {
#if DEBUG
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            Contract.EndContractBlock();
#endif

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                TKey key;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    key = (TKey)keySerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        key = (TKey)keySerializer.UnpackFrom(subtreeUnpacker);
                    }
                }


                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                TValue value;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    value = (TValue)valueSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        value = (TValue)valueSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                dictionary.Add(key, value);
            }
        }
Esempio n. 11
0
        public static void UnpackMapToDictionary(Unpacker unpacker, MessagePackSerializer keySerializer, MessagePackSerializer valueSerializer, object dictionary)
        {
#if DEBUG
            if (unpacker == null)
            {
                throw new ArgumentNullException("unpacker");
            }

            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            Contract.EndContractBlock();
#endif

            int count = GetItemsCount(unpacker);
            for (int i = 0; i < count; i++)
            {
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                object key;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    key = keySerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        key = keySerializer.UnpackFrom(subtreeUnpacker);
                    }
                }


                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewMissingItem(i);
                }

                object value;
                if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader)
                {
                    value = valueSerializer.UnpackFrom(unpacker);
                }
                else
                {
                    using (Unpacker subtreeUnpacker = unpacker.ReadSubtree())
                    {
                        value = valueSerializer.UnpackFrom(subtreeUnpacker);
                    }
                }

                var addMethod = dictionary.GetType().GetMethod("Add", new[] { keySerializer.TargetType, valueSerializer.TargetType });

                addMethod.Invoke(dictionary, new[] { key, value });
            }
        }