internal BsonBinaryReaderContext( BsonBinaryReaderContext parentContext, BsonReadState readState ) { this.parentContext = parentContext; this.readState = readState; }
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); }
public override void Close() { // Close can be called on Disposed objects if (context.ReadState != BsonReadState.Closed) { context = new BsonBinaryReaderContext(null, BsonReadState.Closed); } }
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(); }
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; }
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); } }
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); }