/// <summary>
            /// Loads the stack from storage.
            /// </summary>
            /// <param name="reader">The reader to load the stack from.</param>
            protected override void LoadCore(IStateReader reader)
            {
                //
                // Deserialize metadata/count as an integer.
                //

                using (var countStream = reader.GetItemReader(MetadataCategory, CountKey))
                {
                    _count = GetDeserializer <int>().Deserialize(countStream);
                }

                //
                // Prepare an array of eventual objects and fill with the elements obtained from the reader at items/i with indexes in range [0..count).
                //

                _data = new EventualObject[_count];

                for (var i = 0; i < _count; i++)
                {
                    var key = GetKeyForIndex(i);

                    using var itemStream = reader.GetItemReader(ItemsCategory, key);

                    _data[i] = EventualObject.FromState(itemStream);
                }
            }
            /// <summary>
            /// Loads the queue from storage.
            /// </summary>
            /// <param name="reader">The reader to load the queue from.</param>
            protected override void LoadCore(IStateReader reader)
            {
                //
                // Deserialize metadata/head and metadata/tail as integers.
                //

                using (var headStream = reader.GetItemReader(MetadataCategory, HeadKey))
                {
                    _head = GetDeserializer <long>().Deserialize(headStream);
                }

                using (var tailStream = reader.GetItemReader(MetadataCategory, TailKey))
                {
                    _tail = GetDeserializer <long>().Deserialize(tailStream);
                }

                //
                // Prepare an array of eventual objects and fill with the elements obtained from the reader at items/i with indexes in range [head..tail).
                //
                // NB: Tail is an exclusive index.
                //

                var length = _tail - _head;

                _data = new EventualObject[length];

                for (var i = 0; i < length; i++)
                {
                    var key = GetKeyForIndex(_head + i);

                    using var itemStream = reader.GetItemReader(ItemsCategory, key);

                    _data[i] = EventualObject.FromState(itemStream);
                }
            }
            /// <summary>
            /// Loads the value from storage.
            /// </summary>
            /// <param name="reader">The reader to load the value from.</param>
            protected override void LoadCore(IStateReader reader)
            {
                //
                // Create an eventual object for data/value which gets deserialized upon first use by Restore<T>.
                //

                using var stream = reader.GetItemReader(DataCategory, ValueKey);

                _data = EventualObject.FromState(stream);
            }
Exemple #4
0
            /// <summary>
            /// Loads the heap item with the specified <paramref name="key"/> from storage.
            /// </summary>
            /// <param name="reader">The reader to load the item from.</param>
            /// <param name="key">The key of the item to load.</param>
            /// <param name="keyValue">The numeric representation of <paramref name="key"/>.</param>
            protected override void LoadItemCore(IStateReader reader, string key, long keyValue)
            {
                //
                // Create an entry in _data containing the key and the eventual object for deferred deserialization in Restore<T>.
                //

                using var itemStream = reader.GetItemReader(ItemsCategory, key);

                var obj = EventualObject.FromState(itemStream);

                _data.Add((keyValue, obj));
            }
            /// <summary>
            /// Loads the array from storage.
            /// </summary>
            /// <param name="reader">The reader to load the array from.</param>
            protected override void LoadCore(IStateReader reader)
            {
                //
                // Deserialize metadata/length as an integer.
                //

                using (var lengthStream = reader.GetItemReader(MetadataCategory, LengthKey))
                {
                    _length = GetDeserializer <int>().Deserialize(lengthStream);
                }

                //
                // Prepare an array of eventual objects and fill with the elements obtained from the reader at items/i with indexes in range [0..length).
                //

                _data = new EventualObject[_length];

                for (var i = 0; i < _length; i++)
                {
                    using var itemStream = reader.GetItemReader(ItemsCategory, GetKeyForIndex(i));

                    _data[i] = EventualObject.FromState(itemStream);
                }
            }