コード例 #1
0
 // constructors
 internal BsonBinaryReaderContext(BsonBinaryReaderContext parentContext, ContextType contextType, int startPosition, int size)
 {
     this.parentContext = parentContext;
     this.contextType = contextType;
     this.startPosition = startPosition;
     this.size = size;
 }
コード例 #2
0
ファイル: BsonBinaryReader.cs プロジェクト: LJM74520/nice
        /// <summary>
        /// Reads a raw BSON document.
        /// </summary>
        /// <returns>
        /// The raw BSON document.
        /// </returns>
        public override IByteBuffer ReadRawBsonDocument()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadRawBsonDocument", BsonType.Document);

            var slice = _bsonStream.ReadSlice();

            if (_context.ContextType == ContextType.JavaScriptWithScope)
            {
                _context = _context.PopContext(_bsonStream.Position); // JavaScriptWithScope
            }
            switch (_context.ContextType)
            {
            case ContextType.Array: State = BsonReaderState.Type; break;

            case ContextType.Document: State = BsonReaderState.Type; break;

            case ContextType.TopLevel: State = BsonReaderState.Initial; break;

            default: throw new BsonInternalException("Unexpected ContextType.");
            }

            return(slice);
        }
コード例 #3
0
 // constructors
 internal BsonBinaryReaderContext(BsonBinaryReaderContext parentContext, ContextType contextType, int startPosition, int size)
 {
     this.parentContext = parentContext;
     this.contextType   = contextType;
     this.startPosition = startPosition;
     this.size          = size;
 }
コード例 #4
0
        /// <summary>
        /// Reads the end of a BSON array from the reader.
        /// </summary>
        public override void ReadEndArray()
        {
            if (disposed)
            {
                ThrowObjectDisposedException();
            }
            if (context.ContextType != ContextType.Array)
            {
                var message = string.Format("ReadEndArray cannot be called when ContextType is: {0}", context.ContextType);
                throw new InvalidOperationException(message);
            }
            if (state == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfArray if at end of array
            }
            if (state != BsonReaderState.EndOfArray)
            {
                var message = string.Format("ReadEndArray cannot be called when State is: {0}", state);
                throw new InvalidOperationException(message);
            }

            context = context.PopContext(buffer.Position);
            switch (context.ContextType)
            {
            case ContextType.Array: state = BsonReaderState.Type; break;

            case ContextType.Document: state = BsonReaderState.Type; break;

            case ContextType.TopLevel: state = BsonReaderState.Done; break;

            default: throw new BsonInternalException("Unexpected ContextType");
            }
        }
コード例 #5
0
ファイル: BsonBinaryReader.cs プロジェクト: LJM74520/nice
        /// <summary>
        /// Reads the end of a BSON array from the reader.
        /// </summary>
        public override void ReadEndArray()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            if (_context.ContextType != ContextType.Array)
            {
                ThrowInvalidContextType("ReadEndArray", _context.ContextType, ContextType.Array);
            }
            if (State == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfArray if at end of array
            }
            if (State != BsonReaderState.EndOfArray)
            {
                ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray);
            }

            _context = _context.PopContext(_bsonStream.Position);
            switch (_context.ContextType)
            {
            case ContextType.Array: State = BsonReaderState.Type; break;

            case ContextType.Document: State = BsonReaderState.Type; break;

            case ContextType.TopLevel: State = BsonReaderState.Initial; break;

            default: throw new BsonInternalException("Unexpected ContextType.");
            }
        }
コード例 #6
0
        /// <summary>
        /// Reads the end of a BSON document from the reader.
        /// </summary>
        public override void ReadEndDocument()
        {
            if (disposed)
            {
                ThrowObjectDisposedException();
            }
            if (context.ContextType != ContextType.Document && context.ContextType != ContextType.ScopeDocument)
            {
                ThrowInvalidContextType("ReadEndDocument", context.ContextType, ContextType.Document, ContextType.ScopeDocument);
            }
            if (state == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfDocument if at end of document
            }
            if (state != BsonReaderState.EndOfDocument)
            {
                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
            }

            context = context.PopContext(buffer.Position);
            if (context != null && context.ContextType == ContextType.JavaScriptWithScope)
            {
                context = context.PopContext(buffer.Position); // JavaScriptWithScope
            }
            switch (context.ContextType)
            {
            case ContextType.Array: state = BsonReaderState.Type; break;

            case ContextType.Document: state = BsonReaderState.Type; break;

            case ContextType.TopLevel: state = BsonReaderState.Done; break;

            default: throw new BsonInternalException("Unexpected ContextType.");
            }
        }
コード例 #7
0
ファイル: BsonBinaryReader.cs プロジェクト: LJM74520/nice
        /// <summary>
        /// Reads the end of a BSON document from the reader.
        /// </summary>
        public override void ReadEndDocument()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
            {
                ThrowInvalidContextType("ReadEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
            }
            if (State == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfDocument if at end of document
            }
            if (State != BsonReaderState.EndOfDocument)
            {
                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
            }

            _context = _context.PopContext(_bsonStream.Position);
            if (_context.ContextType == ContextType.JavaScriptWithScope)
            {
                _context = _context.PopContext(_bsonStream.Position); // JavaScriptWithScope
            }
            switch (_context.ContextType)
            {
            case ContextType.Array: State = BsonReaderState.Type; break;

            case ContextType.Document: State = BsonReaderState.Type; break;

            case ContextType.TopLevel: State = BsonReaderState.Initial; break;

            default: throw new BsonInternalException("Unexpected ContextType.");
            }
        }
コード例 #8
0
 /// <summary>
 /// Returns the reader to previously bookmarked position and state.
 /// </summary>
 /// <param name="bookmark">The bookmark.</param>
 public override void ReturnToBookmark(BsonReaderBookmark bookmark)
 {
     var binaryReaderBookmark = (BsonBinaryReaderBookmark)bookmark;
     State = binaryReaderBookmark.State;
     CurrentBsonType = binaryReaderBookmark.CurrentBsonType;
     CurrentName = binaryReaderBookmark.CurrentName;
     _context = binaryReaderBookmark.CloneContext();
     _bsonStream.Position = binaryReaderBookmark.Position;
 }
コード例 #9
0
 public BsonBinaryReader(
     BsonBuffer buffer,
     BsonBinaryReaderSettings settings
 ) {
     this.buffer = buffer ?? new BsonBuffer();
     this.disposeBuffer = buffer == null; // only call Dispose if we allocated the buffer
     this.settings = settings;
     context = null;
 }
コード例 #10
0
        /// <summary>
        /// Returns the reader to previously bookmarked position and state.
        /// </summary>
        /// <param name="bookmark">The bookmark.</param>
        public override void ReturnToBookmark(BsonReaderBookmark bookmark)
        {
            var binaryReaderBookmark = (BsonBinaryReaderBookmark)bookmark;

            state           = binaryReaderBookmark.State;
            currentBsonType = binaryReaderBookmark.CurrentBsonType;
            currentName     = binaryReaderBookmark.CurrentName;
            context         = binaryReaderBookmark.CloneContext();
            buffer.Position = binaryReaderBookmark.Position;
        }
コード例 #11
0
        /// <summary>
        /// Reads the start of a BSON array.
        /// </summary>
        public override void ReadStartArray()
        {
            if (Disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadStartArray", BsonType.Array);

            var startPosition = _bsonStream.Position; // position of size field
            var size = ReadSize();
            _context = new BsonBinaryReaderContext(_context, ContextType.Array, startPosition, size);
            State = BsonReaderState.Type;
        }
コード例 #12
0
 // constructors
 internal BsonBinaryReaderBookmark(
     BsonReaderState state,
     BsonType currentBsonType,
     string currentName,
     BsonBinaryReaderContext context,
     int position)
     : base(state, currentBsonType, currentName)
 {
     _context  = context.Clone();
     _position = position;
 }
コード例 #13
0
 // constructors
 internal BsonBinaryReaderBookmark(
     BsonReaderState state,
     BsonType currentBsonType,
     string currentName,
     BsonBinaryReaderContext context,
     int position)
     : base(state, currentBsonType, currentName)
 {
     _context = context.Clone();
     _position = position;
 }
コード例 #14
0
 public BsonBinaryReader(
     BsonBuffer buffer,
     BsonBinaryReaderSettings settings
 ) {
     this.buffer = buffer ?? new BsonBuffer();
     this.disposeBuffer = buffer == null; // only call Dispose if we allocated the buffer
     this.settings = settings;
     context = null;
     state = BsonReadState.Initial;
     currentBsonType = BsonType.Document;
 }
コード例 #15
0
        /// <summary>
        /// Reads the start of a BSON document.
        /// </summary>
        public override void ReadStartDocument()
        {
            if (Disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadStartDocument", BsonType.Document);

            var contextType = (State == BsonReaderState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
            var startPosition = _bsonStream.Position; // position of size field
            var size = ReadSize();
            _context = new BsonBinaryReaderContext(_context, contextType, startPosition, size);
            State = BsonReaderState.Type;
        }
コード例 #16
0
 // constructors
 internal BsonBinaryReaderContext(
     BsonBinaryReaderContext parentContext,
     ContextType contextType,
     int startPosition, 
     int size)
 {
     _parentContext = parentContext;
     _contextType = contextType;
     _startPosition = startPosition;
     _size = size;
 }
コード例 #17
0
 // constructors
 internal BsonBinaryReaderContext(
     BsonBinaryReaderContext parentContext,
     ContextType contextType,
     int startPosition,
     int size)
 {
     _parentContext = parentContext;
     _contextType   = contextType;
     _startPosition = startPosition;
     _size          = size;
 }
コード例 #18
0
 internal BsonBinaryReaderBookmark(
     BsonBinaryReaderContext context,
     BsonReadState state,
     BsonType currentBsonType,
     int position
 )
 {
     this.context = context;
     this.state = state;
     this.currentBsonType = currentBsonType;
     this.position = position;
 }
コード例 #19
0
        /// <summary>
        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
        /// </summary>
        /// <returns>A string.</returns>
        public override string ReadJavaScriptWithScope()
        {
            if (Disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);

            var startPosition = _bsonStream.Position; // position of size field
            var size = ReadSize();
            _context = new BsonBinaryReaderContext(_context, ContextType.JavaScriptWithScope, startPosition, size);
            var code = _bsonStream.ReadString(_settings.Encoding);

            State = BsonReaderState.ScopeDocument;
            return code;
        }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the BsonBinaryReader class.
 /// <param name="buffer">A BsonBuffer.</param>
 /// <param name="settings">A BsonBinaryReaderSettings.</param>
 /// </summary>
 public BsonBinaryReader(
     BsonBuffer buffer,
     BsonBinaryReaderSettings settings
 ) {
     if (buffer == null) {
         this.buffer = new BsonBuffer();
         this.disposeBuffer = true; // only call Dispose if we allocated the buffer
     } else {
         this.buffer = buffer;
         this.disposeBuffer = false;
     }
     this.settings = settings.Freeze();
     context = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
 }
コード例 #21
0
        /// <summary>
        /// Initializes a new instance of the BsonBinaryReader class.
        /// </summary>
        /// <param name="buffer">A BsonBuffer.</param>
        /// <param name="disposeBuffer">if set to <c>true</c> this BsonBinaryReader will own the buffer and when Dispose is called the buffer will be Disposed also.</param>
        /// <param name="settings">A BsonBinaryReaderSettings.</param>
        /// <exception cref="System.ArgumentNullException">
        /// buffer
        /// or
        /// settings
        /// </exception>
        public BsonBinaryReader(BsonBuffer buffer, bool disposeBuffer, BsonBinaryReaderSettings settings)
            : base(settings)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            _buffer               = buffer;
            _disposeBuffer        = disposeBuffer;
            _binaryReaderSettings = settings; // already frozen by base class

            _context = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
        }
コード例 #22
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the BsonBinaryReader class.
 /// </summary>
 /// <param name="buffer">A BsonBuffer.</param>
 /// <param name="settings">A BsonBinaryReaderSettings.</param>
 public BsonBinaryReader(BsonBuffer buffer, BsonBinaryReaderSettings settings)
     : base(settings)
 {
     if (buffer == null)
     {
         this.buffer        = new BsonBuffer();
         this.disposeBuffer = true; // only call Dispose if we allocated the buffer
     }
     else
     {
         this.buffer        = buffer;
         this.disposeBuffer = false;
     }
     this.settings = settings; // already frozen by base class
     context       = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
 }
コード例 #23
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the BsonBinaryReader class.
 /// </summary>
 /// <param name="buffer">A BsonBuffer.</param>
 /// <param name="settings">A BsonBinaryReaderSettings.</param>
 public BsonBinaryReader(BsonBuffer buffer, BsonBinaryReaderSettings settings)
     : base(settings)
 {
     if (buffer == null)
     {
         _buffer = new BsonBuffer();
         _disposeBuffer = true; // only call Dispose if we allocated the buffer
     }
     else
     {
         _buffer = buffer;
         _disposeBuffer = false;
     }
     _binaryReaderSettings = settings; // already frozen by base class
     _context = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
 }
コード例 #24
0
        /// <summary>
        /// Initializes a new instance of the BsonBinaryReader class.
        /// </summary>
        /// <param name="stream">A stream (BsonBinary does not own the stream and will not Dispose it).</param>
        /// <param name="settings">A BsonBinaryReaderSettings.</param>
        public BsonBinaryReader(Stream stream, BsonBinaryReaderSettings settings)
            : base(settings)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must be capable of seeking.", "stream");
            }

            _streamReader = new BsonStreamReader(stream, settings.Encoding);
            _settings     = settings; // already frozen by base class

            _context = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
        }
コード例 #25
0
        /// <summary>
        /// Initializes a new instance of the BsonBinaryReader class.
        /// </summary>
        /// <param name="stream">A stream (BsonBinary does not own the stream and will not Dispose it).</param>
        /// <param name="settings">A BsonBinaryReaderSettings.</param>
        public BsonBinaryReader(Stream stream, BsonBinaryReaderSettings settings)
            : base(settings)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must be capable of seeking.", "stream");
            }

            _baseStream = stream;
            _bsonStream = (stream as BsonStream) ?? new BsonStreamAdapter(stream);

            _context = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
        }
コード例 #26
0
        /// <summary>
        /// Initializes a new instance of the BsonBinaryReader class.
        /// </summary>
        /// <param name="stream">A stream (BsonBinary does not own the stream and will not Dispose it).</param>
        /// <param name="settings">A BsonBinaryReaderSettings.</param>
        public BsonBinaryReader(Stream stream, BsonBinaryReaderSettings settings)
            : base(settings)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must be capable of seeking.", "stream");
            }

            _streamReader = new BsonStreamReader(stream, settings.Encoding);
            _settings = settings; // already frozen by base class

            _context = new BsonBinaryReaderContext(null, ContextType.TopLevel, 0, 0);
        }
コード例 #27
0
        /// <summary>
        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
        /// </summary>
        /// <returns>A string.</returns>
        public override string ReadJavaScriptWithScope()
        {
            if (disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);

            var startPosition = buffer.Position; // position of size field
            var size          = ReadSize();

            context = new BsonBinaryReaderContext(context, ContextType.JavaScriptWithScope, startPosition, size);
            var code = buffer.ReadString();

            state = BsonReaderState.ScopeDocument;
            return(code);
        }
コード例 #28
0
ファイル: BsonBinaryReader.cs プロジェクト: LJM74520/nice
 private string GenerateDottedElementName(BsonBinaryReaderContext context, string elementName)
 {
     if (context.ContextType == ContextType.Document)
     {
         return(GenerateDottedElementName(context.ParentContext, (context.CurrentElementName ?? "?") + "." + elementName));
     }
     else if (context.ContextType == ContextType.Array)
     {
         var indexElementName = context.CurrentArrayIndex.ToString(NumberFormatInfo.InvariantInfo);
         return(GenerateDottedElementName(context.ParentContext, indexElementName + "." + elementName));
     }
     else if (context.ParentContext != null)
     {
         return(GenerateDottedElementName(context.ParentContext, "?." + elementName));
     }
     else
     {
         return(elementName);
     }
 }
コード例 #29
0
 public override void ReturnToBookmark(
     BsonBinaryReaderBookmark bookmark
 ) {
     context = bookmark.Context;
     state = bookmark.State;
     currentBsonType = bookmark.CurrentBsonType;
     buffer.Position = bookmark.Position;
 }
コード例 #30
0
 private string GenerateDottedElementName(BsonBinaryReaderContext context, string elementName)
 {
     if (context.ContextType == ContextType.Document)
     {
         return GenerateDottedElementName(context.ParentContext, (context.CurrentElementName ?? "?") + "." + elementName);
     }
     else if (context.ContextType == ContextType.Array)
     {
         var indexElementName = context.CurrentArrayIndex.ToString(NumberFormatInfo.InvariantInfo);
         return GenerateDottedElementName(context.ParentContext, indexElementName + "." + elementName);
     }
     else if (context.ParentContext != null)
     {
         return GenerateDottedElementName(context.ParentContext, "?." + elementName);
     }
     else
     {
         return elementName;
     }
 }
コード例 #31
0
        /// <summary>
        /// Reads the end of a BSON document from the reader.
        /// </summary>
        public override void ReadEndDocument() {
            if (disposed) { ThrowObjectDisposedException(); }
            if (
                context.ContextType != ContextType.Document &&
                context.ContextType != ContextType.ScopeDocument
            ) {
                var message = string.Format("ReadEndDocument cannot be called when ContextType is: {0}", context.ContextType);
                throw new InvalidOperationException(message);
            }
            if (state == BsonReaderState.Type) {
                ReadBsonType(); // will set state to EndOfDocument if at end of document
            }
            if (state != BsonReaderState.EndOfDocument) {
                var message = string.Format("ReadEndDocument cannot be called when State is: {0}", state);
                throw new InvalidOperationException(message);
            }

            context = context.PopContext(buffer.Position);
            if (context != null && context.ContextType == ContextType.JavaScriptWithScope) {
                context = context.PopContext(buffer.Position); // JavaScriptWithScope
            }
            switch (context.ContextType) {
                case ContextType.Array: state = BsonReaderState.Type; break;
                case ContextType.Document: state = BsonReaderState.Type; break;
                case ContextType.TopLevel: state = BsonReaderState.Done; break;
                default: throw new BsonInternalException("Unexpected ContextType");
            }
        }
コード例 #32
0
        /// <summary>
        /// Reads the end of a BSON document from the reader.
        /// </summary>
        public override void ReadEndDocument()
        {
            if (Disposed) { ThrowObjectDisposedException(); }
            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
            {
                ThrowInvalidContextType("ReadEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
            }
            if (State == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfDocument if at end of document
            }
            if (State != BsonReaderState.EndOfDocument)
            {
                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
            }

            _context = _context.PopContext(_bsonStream.Position);
            if (_context.ContextType == ContextType.JavaScriptWithScope)
            {
                _context = _context.PopContext(_bsonStream.Position); // JavaScriptWithScope
            }
            switch (_context.ContextType)
            {
                case ContextType.Array: State = BsonReaderState.Type; break;
                case ContextType.Document: State = BsonReaderState.Type; break;
                case ContextType.TopLevel: State = BsonReaderState.Initial; break;
                default: throw new BsonInternalException("Unexpected ContextType.");
            }
        }
コード例 #33
0
        /// <summary>
        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
        /// </summary>
        /// <returns>A string.</returns>
        public override string ReadJavaScriptWithScope()
        {
            if (Disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);

            var startPosition = _bsonStream.Position; // position of size field
            var size = ReadSize();
            _context = new BsonBinaryReaderContext(_context, ContextType.JavaScriptWithScope, startPosition, size);
            var code = _bsonStream.ReadString(_settings.Encoding);

            State = BsonReaderState.ScopeDocument;
            return code;
        }
コード例 #34
0
 /// <summary>
 /// Returns the reader to previously bookmarked position and state.
 /// </summary>
 /// <param name="bookmark">The bookmark.</param>
 public override void ReturnToBookmark(BsonReaderBookmark bookmark)
 {
     var binaryReaderBookmark = (BsonBinaryReaderBookmark)bookmark;
     State = binaryReaderBookmark.State;
     CurrentBsonType = binaryReaderBookmark.CurrentBsonType;
     CurrentName = binaryReaderBookmark.CurrentName;
     _context = binaryReaderBookmark.CloneContext();
     _bsonStream.Position = binaryReaderBookmark.Position;
 }
コード例 #35
0
        /// <summary>
        /// Reads the end of a BSON array from the reader.
        /// </summary>
        public override void ReadEndArray() {
            if (disposed) { ThrowObjectDisposedException(); }
            if (context.ContextType != ContextType.Array) {
                ThrowInvalidContextType("ReadEndArray", context.ContextType, ContextType.Array);
            }
            if (state == BsonReaderState.Type) {
                ReadBsonType(); // will set state to EndOfArray if at end of array
            }
            if (state != BsonReaderState.EndOfArray) {
                ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray);
            }

            context = context.PopContext(buffer.Position);
            switch (context.ContextType) {
                case ContextType.Array: state = BsonReaderState.Type; break;
                case ContextType.Document: state = BsonReaderState.Type; break;
                case ContextType.TopLevel: state = BsonReaderState.Done; break;
                default: throw new BsonInternalException("Unexpected ContextType.");
            }
        }
コード例 #36
0
        /// <summary>
        /// Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).
        /// </summary>
        /// <returns>A string.</returns>
        public override string ReadJavaScriptWithScope() {
            if (disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);

            var startPosition = buffer.Position; // position of size field
            var size = ReadSize();
            context = new BsonBinaryReaderContext(context, ContextType.JavaScriptWithScope, startPosition, size);
            var code = buffer.ReadString();

            state = BsonReaderState.ScopeDocument;
            return code;
        }
コード例 #37
0
        /// <summary>
        /// Reads the start of a BSON document.
        /// </summary>
        public override void ReadStartDocument() {
            if (disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadStartDocument", BsonType.Document);

            var contextType = (state == BsonReaderState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
            var startPosition = buffer.Position; // position of size field
            var size = ReadSize();
            context = new BsonBinaryReaderContext(context, contextType, startPosition, size);
            state = BsonReaderState.Type;
        }
コード例 #38
0
        public override void ReadStartDocument() {
            if (disposed) { ThrowObjectDisposedException(); }
            if (
                state != BsonReadState.Initial &&
                state != BsonReadState.Done &&
                state != BsonReadState.ScopeDocument &&
                (state != BsonReadState.Value || currentBsonType != BsonType.Document)
            ) {
                string message = string.Format("ReadStartDocument cannot be called when ReadState is: {0} and BsonType is: {1}", state, currentBsonType);
                throw new InvalidOperationException(message);
            }

            var contextType = (state == BsonReadState.ScopeDocument) ? ContextType.ScopeDocument : ContextType.Document;
            var startPosition = buffer.Position; // position of size field
            var size = ReadSize();
            context = new BsonBinaryReaderContext(context, contextType, startPosition, size);
            state = BsonReadState.Type;
        }
コード例 #39
0
        /// <summary>
        /// Reads a raw BSON document.
        /// </summary>
        /// <returns>
        /// The raw BSON document.
        /// </returns>
        public override IByteBuffer ReadRawBsonDocument()
        {
            if (Disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadRawBsonDocument", BsonType.Document);

            var slice = ReadSlice();

            if (_context.ContextType == ContextType.JavaScriptWithScope)
            {
                _context = _context.PopContext(_streamReader.Position); // JavaScriptWithScope
            }
            switch (_context.ContextType)
            {
                case ContextType.Array: State = BsonReaderState.Type; break;
                case ContextType.Document: State = BsonReaderState.Type; break;
                case ContextType.TopLevel: State = BsonReaderState.Done; break;
                default: throw new BsonInternalException("Unexpected ContextType.");
            }

            return slice;
        }
コード例 #40
0
        public override void ReadEndArray() {
            if (disposed) { ThrowObjectDisposedException(); }
            if (context.ContextType != ContextType.Array) {
                var message = string.Format("ReadEndArray cannot be called when ContextType is: {0}", context.ContextType);
                throw new InvalidOperationException(message);
            }
            if (state == BsonReadState.Type && buffer.PeekByte() == 0) {
                buffer.Skip(1); // automatically advance to EndOfDocument state
                state = BsonReadState.EndOfDocument;
            }
            if (state != BsonReadState.EndOfDocument) {
                var message = string.Format("ReadEndArray cannot be called when ReadState is: {0}", state);
                throw new InvalidOperationException(message);
            }

            context = context.PopContext(buffer.Position);
            state = BsonReadState.Type;
        }
コード例 #41
0
        /// <summary>
        /// Reads the end of a BSON document from the reader.
        /// </summary>
        public override void ReadEndDocument() {
            if (disposed) { ThrowObjectDisposedException(); }
            if (
                context.ContextType != ContextType.Document &&
                context.ContextType != ContextType.ScopeDocument
            ) {
                ThrowInvalidContextType("ReadEndDocument", context.ContextType, ContextType.Document, ContextType.ScopeDocument);
            }
            if (state == BsonReaderState.Type) {
                ReadBsonType(); // will set state to EndOfDocument if at end of document
            }
            if (state != BsonReaderState.EndOfDocument) {
                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
            }

            context = context.PopContext(buffer.Position);
            if (context != null && context.ContextType == ContextType.JavaScriptWithScope) {
                context = context.PopContext(buffer.Position); // JavaScriptWithScope
            }
            switch (context.ContextType) {
                case ContextType.Array: state = BsonReaderState.Type; break;
                case ContextType.Document: state = BsonReaderState.Type; break;
                case ContextType.TopLevel: state = BsonReaderState.Done; break;
                default: throw new BsonInternalException("Unexpected ContextType.");
            }
        }
コード例 #42
0
        public override void ReadEndDocument() {
            if (disposed) { ThrowObjectDisposedException(); }
            if (
                context.ContextType != ContextType.Document &&
                context.ContextType != ContextType.ScopeDocument
            ) {
                var message = string.Format("ReadEndDocument cannot be called when ContextType is: {0}", context.ContextType);
                throw new InvalidOperationException(message);
            }
            if (state == BsonReadState.Type && buffer.PeekByte() == 0) {
                buffer.Skip(1); // automatically advance to EndOfDocument state
                state = BsonReadState.EndOfDocument;
            }
            if (state != BsonReadState.EndOfDocument) {
                var message = string.Format("ReadEndDocument cannot be called when ReadState is: {0}", state);
                throw new InvalidOperationException(message);
            }

            context = context.PopContext(buffer.Position);
            if (context != null && context.ContextType == ContextType.JavaScriptWithScope) {
                context = context.PopContext(buffer.Position); // JavaScriptWithScope
            }
            state = (context == null) ? BsonReadState.Done : BsonReadState.Type;
        }
コード例 #43
0
        /// <summary>
        /// Reads the start of a BSON array.
        /// </summary>
        public override void ReadStartArray() {
            if (disposed) { ThrowObjectDisposedException(); }
            VerifyBsonType("ReadStartArray", BsonType.Array);

            var startPosition = buffer.Position; // position of size field
            var size = ReadSize();
            context = new BsonBinaryReaderContext(context, ContextType.Array, startPosition, size);
            state = BsonReaderState.Type;
        }
コード例 #44
0
        public override void ReadStartArray() {
            if (disposed) { ThrowObjectDisposedException(); }
            if (state != BsonReadState.Value || currentBsonType != BsonType.Array) {
                string message = string.Format("ReadStartArray cannot be called when ReadState is: {0} and BsonType is: {1}", state, currentBsonType);
                throw new InvalidOperationException(message);
            }

            var startPosition = buffer.Position; // position of size field
            var size = ReadSize();
            context = new BsonBinaryReaderContext(context, ContextType.Array, startPosition, size);
            state = BsonReadState.Type;
        }
コード例 #45
0
 /// <summary>
 /// Returns the reader to previously bookmarked position and state.
 /// </summary>
 /// <param name="bookmark">The bookmark.</param>
 public override void ReturnToBookmark(
     BsonReaderBookmark bookmark
 ) {
     var binaryReaderBookmark = (BsonBinaryReaderBookmark) bookmark;
     state = binaryReaderBookmark.State;
     currentBsonType = binaryReaderBookmark.CurrentBsonType;
     currentName = binaryReaderBookmark.CurrentName;
     context = binaryReaderBookmark.CloneContext();
     buffer.Position = binaryReaderBookmark.Position;
 }
コード例 #46
0
 public BsonBinaryReaderContext Clone()
 {
     var clone = new BsonBinaryReaderContext();
     clone.parentContext = this.parentContext;
     clone.contextType = this.contextType;
     clone.startPosition = this.startPosition;
     clone.size = this.size;
     return clone;
 }