コード例 #1
0
 internal BsonBinaryReaderContext(
     BsonBinaryReaderContext parentContext,
     BsonReadState readState
 )
 {
     this.parentContext = parentContext;
     this.readState = readState;
 }
コード例 #2
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 = new BsonBinaryReaderContext(null, BsonReadState.Initial);
 }
コード例 #3
0
 public override void Close() {
     // Close can be called on Disposed objects
     if (context.ReadState != BsonReadState.Closed) {
         context = new BsonBinaryReaderContext(null, BsonReadState.Closed);
     }
 }
コード例 #4
0
 public override void ReadStartDocument() {
     if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); }
     if (context.ReadState == BsonReadState.StartDocument) {
         context = context.ParentContext;
     } else  if (context.ReadState == BsonReadState.Initial || context.ReadState == BsonReadState.Done) {
         context = new BsonBinaryReaderContext(context, BsonReadState.Document);
     } else {
         string message = string.Format("ReadStartDocument cannot be called when ReadState is: {0}", context.ReadState);
         throw new InvalidOperationException(message);
     }
     context.StartPosition = buffer.Position;
     context.Size = ReadSize();
 }
コード例 #5
0
 public override string ReadJavaScriptWithScope(
     out string name
 ) {
     if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); }
     VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope);
     name = buffer.ReadCString();
     context = new BsonBinaryReaderContext(context, BsonReadState.JavaScriptWithScope);
     context.StartPosition = buffer.Position;
     context.Size = ReadSize();
     var code = buffer.ReadString();
     context = new BsonBinaryReaderContext(context, BsonReadState.ScopeDocument);
     context = new BsonBinaryReaderContext(context, BsonReadState.StartDocument);
     return code;
 }
コード例 #6
0
        public override void ReadEndDocument() {
            if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); }
            VerifyBsonType("ReadEndDocument", BsonType.EndOfDocument);
            if (context.Size != buffer.Position - context.StartPosition) {
                throw new FileFormatException("Document size was incorrect");
            }
            context = context.ParentContext;

            if (context.ReadState == BsonReadState.JavaScriptWithScope) {
                if (context.Size != buffer.Position - context.StartPosition) {
                    throw new FileFormatException("JavaScriptWithScope size was incorrect");
                }
                context = context.ParentContext;
            }

            if (context.ReadState == BsonReadState.Initial) {
                context = new BsonBinaryReaderContext(null, BsonReadState.Done);
            }
        }
コード例 #7
0
 public override void ReadDocumentName(
     out string name
 ) {
     if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); }
     VerifyBsonType("ReadDocumentName", BsonType.Document);
     name = buffer.ReadCString();
     context = new BsonBinaryReaderContext(context, BsonReadState.EmbeddedDocument);
     context = new BsonBinaryReaderContext(context, BsonReadState.StartDocument);
 }