public BsonJsonReader( BsonJsonBuffer buffer ) { this.buffer = buffer; this.context = new BsonJsonReaderContext(null, ContextType.TopLevel); }
internal BsonJsonReaderBookmark( BsonReadState state, BsonType currentBsonType, string currentName, BsonJsonReaderContext context, JsonToken currentToken, BsonValue currentValue, JsonToken pushedToken, int position ) : base(state, currentBsonType, currentName) { this.context = context.Clone(); this.currentToken = currentToken; this.currentValue = currentValue; this.pushedToken = pushedToken; this.position = position; }
public override void ReturnToBookmark( BsonReaderBookmark bookmark ) { var jsonReaderBookmark = (BsonJsonReaderBookmark) bookmark; state = jsonReaderBookmark.State; currentBsonType = jsonReaderBookmark.CurrentBsonType; currentName = jsonReaderBookmark.CurrentName; context = jsonReaderBookmark.Context; currentToken = jsonReaderBookmark.CurrentToken; currentValue = jsonReaderBookmark.CurrentValue; pushedToken = jsonReaderBookmark.PushedToken; buffer.Position = jsonReaderBookmark.Position; }
public override void ReadStartDocument() { if (disposed) { ThrowObjectDisposedException(); } VerifyBsonType("ReadStartDocument", BsonType.Document); context = new BsonJsonReaderContext(context, ContextType.Document); state = BsonReadState.Type; }
public override string ReadJavaScriptWithScope() { if (disposed) { ThrowObjectDisposedException(); } VerifyBsonType("ReadJavaScriptWithScope", BsonType.JavaScriptWithScope); context = new BsonJsonReaderContext(context, ContextType.JavaScriptWithScope); state = BsonReadState.ScopeDocument; return currentValue.AsString; }
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) { ReadBsonType(); // will set state to EndOfDocument if at end of document } if (state != BsonReadState.EndOfDocument) { var message = string.Format("ReadEndDocument cannot be called when ReadState is: {0}", state); throw new InvalidOperationException(message); } context = context.PopContext(); if (context != null && context.ContextType == ContextType.JavaScriptWithScope) { context = context.PopContext(); // JavaScriptWithScope VerifyToken("}"); // outermost closing bracket for JavaScriptWithScope } switch (context.ContextType) { case ContextType.Array: state = BsonReadState.Type; break; case ContextType.Document: state = BsonReadState.Type; break; case ContextType.TopLevel: state = BsonReadState.Done; break; default: throw new BsonInternalException("Unexpected ContextType"); } }
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) { ReadBsonType(); // will set state to EndOfArray if at end of array } if (state != BsonReadState.EndOfArray) { var message = string.Format("ReadEndArray cannot be called when ReadState is: {0}", state); throw new InvalidOperationException(message); } context = context.PopContext(); switch (context.ContextType) { case ContextType.Array: state = BsonReadState.Type; break; case ContextType.Document: state = BsonReadState.Type; break; case ContextType.TopLevel: state = BsonReadState.Done; break; default: throw new BsonInternalException("Unexpected ContextType"); } }