internal byte[] RemoveLastDocument(BsonBuffer buffer) { var lastDocumentLength = buffer.Position - _lastDocumentStartPosition; buffer.Position = _lastDocumentStartPosition; var lastDocument = buffer.ReadBytes(lastDocumentLength); buffer.Position = _lastDocumentStartPosition; buffer.Length = _lastDocumentStartPosition; BackpatchMessageLength(buffer); return(lastDocument); }
private byte[] RemoveLastDocument(BsonBuffer buffer) { var lastDocumentLength = buffer.Position - _lastDocumentStartPosition; buffer.Position = _lastDocumentStartPosition; var lastDocument = buffer.ReadBytes(lastDocumentLength); buffer.Position = _lastDocumentStartPosition; buffer.Length = _lastDocumentStartPosition; _batchCount -= 1; _batchLength = buffer.Position - _batchStartPosition; return(lastDocument); }
private IByteBuffer RemoveOverflow(BsonBuffer buffer) { var lastRequestLength = buffer.Position - _lastRequestPosition; buffer.Position = _lastRequestPosition; var lastArrayItem = buffer.ReadBytes(lastRequestLength); if ((BsonType)lastArrayItem[0] != BsonType.Document) { throw new MongoInternalException("Expected overflow item to be a BsonDocument."); } var sliceOffset = Array.IndexOf <byte>(lastArrayItem, 0) + 1; // skip over type and array index var overflow = new ByteArrayBuffer(lastArrayItem, sliceOffset, lastArrayItem.Length - sliceOffset, true); buffer.Position = _lastRequestPosition; buffer.Length = _lastRequestPosition; _batchCount--; _batchLength = buffer.Position - _batchStartPosition; return(overflow); }