ThrowMissingItem() public static method

This is intended to MsgPack for CLI internal use. Do not use this type from application directly. Throws a exception to notify that item is not found on the unpacking stream.
Always thrown.
public static ThrowMissingItem ( int index, Unpacker unpacker ) : void
index int The index to be unpacking.
unpacker Unpacker The unpacker for pretty message.
return void
Beispiel #1
0
        public static void UnpackArrayTo <T>(Unpacker unpacker, MessagePackSerializer <T> serializer, T[] array)
        {
            if (unpacker == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

            if (serializer == null)
            {
                SerializationExceptions.ThrowArgumentNullException("serializer");
            }

            if (array == null)
            {
                SerializationExceptions.ThrowArgumentNullException("array");
            }

#if ASSERT
            Contract.Assert(unpacker != null);
            Contract.Assert(serializer != null);
            Contract.Assert(array != null);
#endif // ASSERT

            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowIsNotArrayHeader(unpacker);
            }

#if ASSERT
            Contract.EndContractBlock();
#endif // ASSERT

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

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

                array[i] = item;
            }
        }
Beispiel #2
0
        public static void UnpackCollectionTo <TDiscarded>(Unpacker unpacker, IEnumerable collection, Func <object, TDiscarded> addition)
        {
            if (unpacker == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

            if (collection == null)
            {
                SerializationExceptions.ThrowArgumentNullException("collection");
            }

            if (addition == null)
            {
                SerializationExceptions.ThrowArgumentNullException("addition");
            }

#if ASSERT
            Contract.Assert(unpacker != null);
            Contract.Assert(collection != null);
            Contract.Assert(addition != null);
#endif // ASSERT

            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowIsNotArrayHeader(unpacker);
            }

#if ASSERT
            Contract.EndContractBlock();
#endif // ASSERT

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

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

                addition(item);
            }
        }
Beispiel #3
0
        public static void UnpackMapTo(Unpacker unpacker, IDictionary dictionary)
        {
            if (unpacker == null)
            {
                SerializationExceptions.ThrowArgumentNullException("unpacker");
            }

            if (dictionary == null)
            {
                SerializationExceptions.ThrowArgumentNullException("dictionary");
            }

#if ASSERT
            Contract.Assert(unpacker != null);
            Contract.Assert(dictionary != null);
#endif // ASSERT

            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

#if ASSERT
            Contract.EndContractBlock();
#endif // ASSERT

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

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


                if (!unpacker.Read())
                {
                    SerializationExceptions.ThrowMissingItem(i, unpacker);
                }

                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);
            }
        }