internal BsonBinaryReaderContext( BsonBinaryReaderContext parentContext, BsonReadState readState ) { this.parentContext = parentContext; this.readState = readState; }
protected BsonReaderBookmark( BsonReadState state, BsonType currentBsonType, string currentName ) { this.state = state; this.currentBsonType = currentBsonType; this.currentName = currentName; }
internal BsonDocumentReaderBookmark( BsonDocumentReaderContext context, BsonReadState state, BsonType currentBsonType ) { this.context = context.Clone(); this.state = state; this.currentBsonType = currentBsonType; }
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; }
internal BsonBinaryReaderBookmark( BsonBinaryReaderContext context, BsonReadState state, BsonType currentBsonType, int position ) { this.context = context; this.state = state; this.currentBsonType = currentBsonType; this.position = position; }
internal BsonDocumentReaderBookmark( BsonReadState state, BsonType currentBsonType, string currentName, BsonDocumentReaderContext context, BsonValue currentValue ) : base(state, currentBsonType, currentName) { this.context = context.Clone(); this.currentValue = currentValue; }
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 SkipName() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } if (state != BsonReadState.Name) { var message = string.Format("SkipName cannot be called when ReadState is: {0}", state); throw new InvalidOperationException(message); } buffer.SkipCString(); state = BsonReadState.Value; }
public override void SkipValue() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } if (state != BsonReadState.Value) { var message = string.Format("SkipValue cannot be called when ReadState is: {0}", state); throw new InvalidOperationException(message); } int skip; switch (currentBsonType) { case BsonType.Array: skip = ReadSize() - 4; break; case BsonType.Binary: skip = ReadSize() + 1; break; case BsonType.Boolean: skip = 1; break; case BsonType.DateTime: skip = 8; break; case BsonType.Document: skip = ReadSize() - 4; break; case BsonType.Double: skip = 8; break; case BsonType.Int32: skip = 4; break; case BsonType.Int64: skip = 8; break; case BsonType.JavaScript: skip = ReadSize(); break; case BsonType.JavaScriptWithScope: skip = ReadSize() - 4; break; case BsonType.MaxKey: skip = 0; break; case BsonType.MinKey: skip = 0; break; case BsonType.Null: skip = 0; break; case BsonType.ObjectId: skip = 12; break; case BsonType.RegularExpression: buffer.SkipCString(); buffer.SkipCString(); skip = 0; break; case BsonType.String: skip = ReadSize(); break; case BsonType.Symbol: skip = ReadSize(); break; case BsonType.Timestamp: skip = 8; break; default: throw new BsonInternalException("Unexpected BsonType"); } buffer.Skip(skip); state = BsonReadState.Type; }
public override long ReadTimestamp() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadTimestamp", BsonType.Timestamp); state = BsonReadState.Type; return buffer.ReadInt64(); }
public override void ReturnToBookmark( BsonBinaryReaderBookmark bookmark ) { context = bookmark.Context; state = bookmark.State; currentBsonType = bookmark.CurrentBsonType; buffer.Position = bookmark.Position; }
public override bool ReadBoolean() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadBoolean", BsonType.Boolean); state = BsonReadState.Type; return buffer.ReadBoolean(); }
public override void ReadEndDocument() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } 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); } if (context.ContextType == ContextType.Document) { context = context.PopContext(buffer.Position); // Document } else if (context.ContextType == ContextType.ScopeDocument) { context = context.PopContext(buffer.Position); // ScopeDocument context = context.PopContext(buffer.Position); // JavaScriptWithScope } else { var message = string.Format("ReadEndDocument cannot be called when ContextType is: {0}", context.ContextType); throw new InvalidOperationException(message); } state = (context == null) ? BsonReadState.Done : BsonReadState.Type; }
public override DateTime ReadDateTime() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadDateTime", BsonType.DateTime); state = BsonReadState.Type; long milliseconds = buffer.ReadInt64(); if (milliseconds == 253402300800000) { // special case to avoid ArgumentOutOfRangeException in AddMilliseconds return DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc); } else { return BsonConstants.UnixEpoch.AddMilliseconds(milliseconds); // Kind = DateTimeKind.Utc } }
protected void VerifyBsonType( string methodName, BsonType requiredBsonType ) { if (state == BsonReadState.Initial || state == BsonReadState.ScopeDocument || state == BsonReadState.Type) { ReadBsonType(); } if (state == BsonReadState.Name) { // ignore name state = BsonReadState.Value; } if (state != BsonReadState.Value) { var message = string.Format("{0} cannot be called when ReadState is: {1}", methodName, state); throw new InvalidOperationException(message); } if (currentBsonType != requiredBsonType) { var message = string.Format("{0} cannot be called when BsonType is: {1}", methodName, currentBsonType); throw new InvalidOperationException(message); } }
public override void ReadNull() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadNull", BsonType.Null); state = BsonReadState.Type; }
public override void ReadObjectId( out int timestamp, out int machine, out short pid, out int increment ) { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadObjectId", BsonType.ObjectId); buffer.ReadObjectId(out timestamp, out machine, out pid, out increment); state = BsonReadState.Type; }
public override double ReadDouble() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadDouble", BsonType.Double); state = BsonReadState.Type; return buffer.ReadDouble(); }
public override string ReadJavaScriptWithScope() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } 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 = BsonReadState.ScopeDocument; return code; }
public override int ReadInt32() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadInt32", BsonType.Int32); state = BsonReadState.Type; return buffer.ReadInt32(); }
public override void Close() { // Close can be called on Disposed objects if (state != BsonReadState.Closed) { state = BsonReadState.Closed; } }
public override BsonType ReadBsonType() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } if (state != BsonReadState.Type) { var message = string.Format("ReadBsonType cannot be called when ReadState is: {0}", state); throw new InvalidOperationException(message); } currentBsonType = buffer.ReadBsonType(); // set currentBsonType before state state = (currentBsonType == BsonType.EndOfDocument) ? BsonReadState.EndOfDocument : BsonReadState.Name; return currentBsonType; }
public override string ReadName() { if (disposed) { ThrowObjectDisposedException(); } if (state == BsonReadState.Type) { ReadBsonType(); } if (state != BsonReadState.Name) { var message = string.Format("ReadName cannot be called when ReadState is: {0}", state); throw new InvalidOperationException(message); } state = BsonReadState.Value; return currentName; }
public override void ReadStartDocument() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } 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; }
protected BsonBaseReader() { state = BsonReadState.Initial; }
public override string ReadSymbol() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadSymbol", BsonType.Symbol); state = BsonReadState.Type; return buffer.ReadString(); }
public override void ReadRegularExpression( out string pattern, out string options ) { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } VerifyBsonType("ReadRegularExpression", BsonType.RegularExpression); pattern = buffer.ReadCString(); options = buffer.ReadCString(); state = BsonReadState.Type; }
public override void ReadEndArray() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } 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); } if (context.ContextType != ContextType.Array) { var message = string.Format("ReadEndArray cannot be called when ContextType is: {0}", context.ContextType); throw new InvalidOperationException(message); } context = context.PopContext(buffer.Position); state = BsonReadState.Type; }
protected BsonBaseReader() { state = BsonReadState.Initial; currentBsonType = BsonType.Document; }
public override void ReadStartArray() { if (disposed) { throw new ObjectDisposedException("BsonBinaryReader"); } 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; }