Exemplo n.º 1
0
        protected override void ReadContent(ByteReader reader)
        {
            var info = reader.ReadString(HEADER_INFO.Length);
            var ver  = reader.ReadByte();

            if (info != HEADER_INFO)
            {
                throw LiteException.InvalidDatabase();
            }
            if (ver != FILE_VERSION)
            {
                throw LiteException.InvalidDatabaseVersion(ver);
            }

            this.ChangeID        = reader.ReadUInt16();
            this.FreeEmptyPageID = reader.ReadUInt32();
            this.LastPageID      = reader.ReadUInt32();
            this.UserVersion     = reader.ReadUInt16();
            this.Password        = reader.ReadBytes(this.Password.Length);
            this.Salt            = reader.ReadBytes(this.Salt.Length);

            // read page collections references (position on end of page)
            var cols = reader.ReadByte();

            for (var i = 0; i < cols; i++)
            {
                this.CollectionPages.Add(reader.ReadString(), reader.ReadUInt32());
            }

            // use last page byte position for recovery mode only because i forgot to reserve area before collection names!
            // TODO: fix this in next change data structure
            reader.Position = BasePage.PAGE_SIZE - 1;
            this.Recovery   = reader.ReadBoolean();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read a page with correct instance page object. Checks for pageType
        /// </summary>
        public static BasePage ReadPage(byte[] buffer)
        {
            var reader = new ByteReader(buffer);

            var pageID   = reader.ReadUInt32();
            var pageType = (PageType)reader.ReadByte();

            if (pageID == 0 && (byte)pageType > 5)
            {
                throw LiteException.InvalidDatabase();
            }

            var page = CreateInstance(pageID, pageType);

            page.ReadHeader(reader);
            page.ReadContent(reader);

            page.DiskData = buffer;

            return(page);
        }