Пример #1
0
        protected internal override async Task <T> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var buffer = new KeyValuePair <TKey, TValue> [UnpackHelpers.GetItemsCount(unpacker)];

            using (var subTreeUnpacker = unpacker.ReadSubtree())
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (!await subTreeUnpacker.ReadAsync(cancellationToken).ConfigureAwait(false))
                    {
                        SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
                    }

                    var key = await this._keySerializer.UnpackFromAsync(unpacker, cancellationToken).ConfigureAwait(false);

                    if (!await subTreeUnpacker.ReadAsync(cancellationToken).ConfigureAwait(false))
                    {
                        SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
                    }

                    var value = await this._valueSerializer.UnpackFromAsync(unpacker, cancellationToken).ConfigureAwait(false);

                    buffer[i] = new KeyValuePair <TKey, TValue>(key, value);
                }
            }

            return(this._factory(buffer));
        }
Пример #2
0
        protected internal override T UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var buffer = new KeyValuePair <TKey, TValue> [UnpackHelpers.GetItemsCount(unpacker)];

            using (var subTreeUnpacker = unpacker.ReadSubtree())
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (!subTreeUnpacker.Read())
                    {
                        SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
                    }

                    var key = this._keySerializer.UnpackFrom(unpacker);

                    if (!subTreeUnpacker.Read())
                    {
                        SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
                    }

                    var value = this._valueSerializer.UnpackFrom(unpacker);

                    buffer[i] = new KeyValuePair <TKey, TValue>(key, value);
                }
            }

            return(this._factory(buffer));
        }
Пример #3
0
        protected internal override void UnpackToCore(Unpacker unpacker, Dictionary <TKey, TValue> collection)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            this.UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker));
        }
Пример #4
0
        protected internal override Task UnpackToAsyncCore(Unpacker unpacker, Dictionary <TKey, TValue> collection, CancellationToken cancellationToken)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            return(this.UnpackToAsyncCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker), cancellationToken));
        }
Пример #5
0
        protected internal override void UnpackToCore(Unpacker unpacker, NameValueCollection collection)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker));
        }
Пример #6
0
        protected internal override Dictionary <TKey, TValue> UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var count      = UnpackHelpers.GetItemsCount(unpacker);
            var collection = new Dictionary <TKey, TValue>(count);

            this.UnpackToCore(unpacker, collection, count);
            return(collection);
        }
Пример #7
0
        protected internal override NameValueCollection UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var count      = UnpackHelpers.GetItemsCount(unpacker);
            var collection = new NameValueCollection(count);

            UnpackToCore(unpacker, collection, count);
            return(collection);
        }
Пример #8
0
        protected internal override MessagePackObjectDictionary UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var count  = UnpackHelpers.GetItemsCount(unpacker);
            var result = new MessagePackObjectDictionary(count);

            UnpackToCore(unpacker, count, result);
            return(result);
        }
Пример #9
0
        protected internal override async Task <Dictionary <TKey, TValue> > UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var count      = UnpackHelpers.GetItemsCount(unpacker);
            var collection = new Dictionary <TKey, TValue>(count);

            await this.UnpackToAsyncCore(unpacker, collection, count, cancellationToken).ConfigureAwait(false);

            return(collection);
        }
Пример #10
0
        protected internal override async Task <MessagePackObjectDictionary> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsMapHeader)
            {
                SerializationExceptions.ThrowIsNotMapHeader(unpacker);
            }

            var count  = UnpackHelpers.GetItemsCount(unpacker);
            var result = new MessagePackObjectDictionary(count);

            await UnpackToAsyncCore(unpacker, count, result, cancellationToken).ConfigureAwait(false);

            return(result);
        }