示例#1
0
        public CollectionPage(PageBuffer buffer)
            : base(buffer)
        {
            ENSURE(this.PageType == PageType.Collection, "page type must be collection page");

            if (this.PageType != PageType.Collection)
            {
                LiteException.InvalidPageType(PageType.Collection, this);
            }

            // create new buffer area to store BsonDocument indexes
            var area = _buffer.Slice(PAGE_HEADER_SIZE, PAGE_SIZE - PAGE_HEADER_SIZE);

            using (var r = new BufferReader(new[] { area }, false))
            {
                // read position for FreeDataPage and FreeIndexPage
                for (var i = 0; i < PAGE_FREE_LIST_SLOTS; i++)
                {
                    this.FreeDataPageList[i] = r.ReadUInt32();
                }

                // skip reserved area
                r.Skip(P_INDEXES - PAGE_HEADER_SIZE - r.Position);

                // read indexes count (max 255 indexes per collection)
                var count = r.ReadByte(); // 1 byte

                for (var i = 0; i < count; i++)
                {
                    var index = new CollectionIndex(r);

                    _indexes[index.Name] = index;
                }
            }
        }
示例#2
0
文件: DataPage.cs 项目: zamis/LiteDB
        /// <summary>
        /// Read existing DataPage in buffer
        /// </summary>
        public DataPage(PageBuffer buffer)
            : base(buffer)
        {
            ENSURE(this.PageType == PageType.Data, "page type must be data page");

            if (this.PageType != PageType.Data)
            {
                throw LiteException.InvalidPageType(PageType.Data, this);
            }
        }
示例#3
0
        /// <summary>
        /// Read existing IndexPage in buffer
        /// </summary>
        public IndexPage(PageBuffer buffer)
            : base(buffer)
        {
            ENSURE(this.PageType == PageType.Index, "page type must be index page");

            if (this.PageType != PageType.Index)
            {
                throw LiteException.InvalidPageType(PageType.Index, this);
            }
        }