Esempio n. 1
0
        private byte[] RemoveLastDocument(Stream stream)
        {
            var streamReader       = new BsonStreamReader(stream, WriterSettings.Encoding);
            var lastDocumentLength = (int)streamReader.Position - _lastDocumentStartPosition;

            streamReader.Position = _lastDocumentStartPosition;
            var lastDocument = streamReader.ReadBytes(lastDocumentLength);

            streamReader.Position = _lastDocumentStartPosition;
            streamReader.BaseStream.SetLength(_lastDocumentStartPosition);

            _batchCount -= 1;
            _batchLength = (int)streamReader.Position - _batchStartPosition;

            return(lastDocument);
        }
            private IByteBuffer RemoveOverflow(Stream stream)
            {
                var streamReader      = new BsonStreamReader(stream, Utf8Helper.StrictUtf8Encoding);
                var lastRequestLength = (int)stream.Position - _lastRequestPosition;

                stream.Position = _lastRequestPosition;
                var lastArrayItem = streamReader.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);

                stream.Position = _lastRequestPosition;
                stream.SetLength(_lastRequestPosition);

                _batchCount--;
                _batchLength = (int)stream.Position - _batchStartPosition;

                return(overflow);
            }