Example #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();
        }
        protected override void ReadContent(ByteReader reader)
        {
            this.CollectionName = reader.ReadString();
            this.DocumentCount  = reader.ReadInt64();
            this.FreeDataPageID = reader.ReadUInt32();

            foreach (var index in this.Indexes)
            {
                var field = reader.ReadString();
                var eq    = field.IndexOf('=');

                // Use same string to avoid change file defition
                if (eq > 0)
                {
                    index.Field      = field.Substring(0, eq);
                    index.Expression = field.Substring(eq + 1);
                }
                else
                {
                    index.Field      = field;
                    index.Expression = "$." + field;
                }

                index.Unique          = reader.ReadBoolean();
                index.HeadNode        = reader.ReadPageAddress();
                index.TailNode        = reader.ReadPageAddress();
                index.FreeIndexPageID = reader.ReadUInt32();
            }

            // position on page-footer (avoid file structure change)
            reader.Position = BasePage.PAGE_SIZE - 8;
            this.Sequence   = reader.ReadInt64();
        }
Example #3
0
        protected override void ReadContent(ByteReader reader)
        {
            this.CollectionName = reader.ReadString();
            this.FreeDataPageID = reader.ReadUInt32();
            this.DocumentCount  = reader.ReadUInt32();

            foreach (var index in this.Indexes)
            {
                index.Field                     = reader.ReadString();
                index.HeadNode                  = reader.ReadPageAddress();
                index.TailNode                  = reader.ReadPageAddress();
                index.FreeIndexPageID           = reader.ReadUInt32();
                index.Options.Unique            = reader.ReadBoolean();
                index.Options.IgnoreCase        = reader.ReadBoolean();
                index.Options.TrimWhitespace    = reader.ReadBoolean();
                index.Options.EmptyStringToNull = reader.ReadBoolean();
                index.Options.RemoveAccents     = reader.ReadBoolean();
            }
        }
        protected override void ReadContent(ByteReader reader)
        {
            this.CollectionName = reader.ReadString();
            this.FreeDataPageID = reader.ReadUInt32();
            this.DocumentCount = reader.ReadUInt32();

            foreach (var index in this.Indexes)
            {
                index.Field = reader.ReadString();
                index.HeadNode = reader.ReadPageAddress();
                index.TailNode = reader.ReadPageAddress();
                index.FreeIndexPageID = reader.ReadUInt32();
                index.Options.Unique = reader.ReadBoolean();
                index.Options.IgnoreCase = reader.ReadBoolean();
                index.Options.TrimWhitespace = reader.ReadBoolean();
                index.Options.EmptyStringToNull = reader.ReadBoolean();
                index.Options.RemoveAccents = reader.ReadBoolean();
            }
        }
Example #5
0
        protected override void ReadContent(ByteReader reader)
        {
            this.CollectionName = reader.ReadString();
            this.FreeDataPageID = reader.ReadUInt32();
            var uintCount = reader.ReadUInt32(); // read as uint (4 bytes)

            foreach (var index in this.Indexes)
            {
                index.Field                     = reader.ReadString();
                index.HeadNode                  = reader.ReadPageAddress();
                index.TailNode                  = reader.ReadPageAddress();
                index.FreeIndexPageID           = reader.ReadUInt32();
                index.Options.Unique            = reader.ReadBoolean();
                index.Options.IgnoreCase        = reader.ReadBoolean();
                index.Options.TrimWhitespace    = reader.ReadBoolean();
                index.Options.EmptyStringToNull = reader.ReadBoolean();
                index.Options.RemoveAccents     = reader.ReadBoolean();
            }

            // be compatible with v2_beta
            var longCount = reader.ReadInt64();

            this.DocumentCount = Math.Max(uintCount, longCount);
        }
Example #6
0
        protected override void ReadContent(ByteReader reader)
        {
            this.CollectionName = reader.ReadString();
            this.DocumentCount  = reader.ReadInt64();
            this.FreeDataPageID = reader.ReadUInt32();

            foreach (var index in this.Indexes)
            {
                index.Field           = reader.ReadString();
                index.Unique          = reader.ReadBoolean();
                index.HeadNode        = reader.ReadPageAddress();
                index.TailNode        = reader.ReadPageAddress();
                index.FreeIndexPageID = reader.ReadUInt32();
            }
        }
Example #7
0
        protected override void ReadContent(ByteReader reader)
        {
            this.CollectionName = reader.ReadString();
            this.FreeDataPageID = reader.ReadUInt32();
            var uintCount = reader.ReadUInt32(); // read as uint (4 bytes)

            foreach (var index in this.Indexes)
            {
                index.Field = reader.ReadString();
                index.HeadNode = reader.ReadPageAddress();
                index.TailNode = reader.ReadPageAddress();
                index.FreeIndexPageID = reader.ReadUInt32();
                index.Options.Unique = reader.ReadBoolean();
                index.Options.IgnoreCase = reader.ReadBoolean();
                index.Options.TrimWhitespace = reader.ReadBoolean();
                index.Options.EmptyStringToNull = reader.ReadBoolean();
                index.Options.RemoveAccents = reader.ReadBoolean();
            }

            // be compatible with v2_beta
            var longCount = reader.ReadInt64();
            this.DocumentCount = Math.Max(uintCount, longCount);

        }
Example #8
0
        /// <summary>
        /// Reads an element (key-value) from an reader
        /// </summary>
        private BsonValue ReadElement(ByteReader reader, out string name)
        {
            var type = reader.ReadByte();

            name = this.ReadCString(reader);

            if (type == 0x01) // Double
            {
                return(reader.ReadDouble());
            }
            else if (type == 0x02) // String
            {
                return(this.ReadString(reader));
            }
            else if (type == 0x03) // Document
            {
                return(this.ReadDocument(reader));
            }
            else if (type == 0x04) // Array
            {
                return(this.ReadArray(reader));
            }
            else if (type == 0x05) // Binary
            {
                var length  = reader.ReadInt32();
                var subType = reader.ReadByte();
                var bytes   = reader.ReadBytes(length);

                switch (subType)
                {
                case 0x00: return(bytes);

                case 0x04: return(new Guid(bytes));
                }
            }
            else if (type == 0x07) // ObjectId
            {
                return(new ObjectId(reader.ReadBytes(12)));
            }
            else if (type == 0x08) // Boolean
            {
                return(reader.ReadBoolean());
            }
            else if (type == 0x09) // DateTime
            {
                var ts = reader.ReadInt64();

                // catch specific values for MaxValue / MinValue #19
                if (ts == 253402300800000)
                {
                    return(DateTime.MaxValue);
                }
                if (ts == -62135596800000)
                {
                    return(DateTime.MinValue);
                }

                return(BsonValue.UnixEpoch.AddMilliseconds(ts).ToLocalTime());
            }
            else if (type == 0x0A) // Null
            {
                return(BsonValue.Null);
            }
            else if (type == 0x10) // Int32
            {
                return(reader.ReadInt32());
            }
            else if (type == 0x12) // Int64
            {
                return(reader.ReadInt64());
            }
            else if (type == 0xFF) // MinKey
            {
                return(BsonValue.MinValue);
            }
            else if (type == 0x7F) // MaxKey
            {
                return(BsonValue.MaxValue);
            }

            throw new NotSupportedException("BSON type not supported");
        }
Example #9
0
        /// <summary>
        /// Reads an element (key-value) from an reader
        /// </summary>
        private BsonValue ReadElement(ByteReader reader, out string name)
        {
            var type = reader.ReadByte();
            name = this.ReadCString(reader);

            if (type == 0x01) // Double
            {
                return reader.ReadDouble();
            }
            else if (type == 0x02) // String
            {
                return this.ReadString(reader);
            }
            else if (type == 0x03) // Document
            {
                return this.ReadDocument(reader);
            }
            else if (type == 0x04) // Array
            {
                return this.ReadArray(reader);
            }
            else if (type == 0x05) // Binary
            {
                var length = reader.ReadInt32();
                var subType = reader.ReadByte();
                var bytes = reader.ReadBytes(length);

                switch (subType)
                {
                    case 0x00: return bytes;
                    case 0x04: return new Guid(bytes);
                }
            }
            else if (type == 0x07) // ObjectId
            {
                return new ObjectId(reader.ReadBytes(12));
            }
            else if (type == 0x08) // Boolean
            {
                return reader.ReadBoolean();
            }
            else if (type == 0x09) // DateTime
            {
                var ts = reader.ReadInt64();

                // catch specific values for MaxValue / MinValue #19
                if (ts == 253402300800000) return DateTime.MaxValue;
                if (ts == -62135596800000) return DateTime.MinValue;

                return BsonValue.UnixEpoch.AddMilliseconds(ts).ToLocalTime();
            }
            else if (type == 0x0A) // Null
            {
                return BsonValue.Null;
            }
            else if (type == 0x10) // Int32
            {
                return reader.ReadInt32();
            }
            else if (type == 0x12) // Int64
            {
                return reader.ReadInt64();
            }
            else if (type == 0xFF) // MinKey
            {
                return BsonValue.MinValue;
            }
            else if (type == 0x7F) // MaxKey
            {
                return BsonValue.MaxValue;
            }

            throw new NotSupportedException("BSON type not supported");
        }
Example #10
0
        protected override void ReadContent(ByteReader reader)
        {
            this.CollectionName = reader.ReadString();
            this.DocumentCount = reader.ReadInt64();
            this.FreeDataPageID = reader.ReadUInt32();

            foreach (var index in this.Indexes)
            {
                index.Field = reader.ReadString();
                index.Unique = reader.ReadBoolean();
                index.HeadNode = reader.ReadPageAddress();
                index.TailNode = reader.ReadPageAddress();
                index.FreeIndexPageID = reader.ReadUInt32();
            }
        }