protected override void ParseStream(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
/* Message Format (Excluding Header)
* Flag (int32) - normally zero, non-zero on query failure
* CursorId (int64) - id of the cursor created for this query response
* StartingFrom (int32) - indicates where in this content is starting from
* TotalReturned (int32) - number of documents in the reply
* Documents (BSON array) - The documents (parsed separately)
*/
//get the flag first
this.Flag = reader.ReadInt32();
//second is the cursor value
this.CursorId = reader.ReadInt64();
//and the skipped and returned counts
this.StartingFrom = reader.ReadInt32();
this.TotalReturned = reader.ReadInt32();
//next, read and parse the records
this.Documents = new List<MongoDocument>();
for (int i = 0; i < this.TotalReturned; i++) {
//convert to a MongoDocument
BsonDocument parsed = BsonDocument.FromStream(stream);
MongoDocument document = new MongoDocument();
document.Merge(parsed);
//and add it to the list
this.Documents.Add(document);
}
//check for server exceptions
this.CheckForExceptions();
}