MongoDB.Bson.IO.MultiChunkBuffer.ReadBackingBytes C# (CSharp) Метод

ReadBackingBytes() публичный Метод

Read directly from the backing bytes. The returned ArraySegment points directly to the backing bytes for the current position and you can read the bytes directly from there. If the backing bytes happen to span a chunk boundary shortly after the current position there might not be enough bytes left in the current chunk in which case the returned ArraySegment will have a Count of zero and you should call ReadBytes instead. When ReadBackingBytes returns the position will have been advanced by count bytes *if and only if* there were count bytes left in the current chunk.
MultiChunkBuffer
public ReadBackingBytes ( int count ) : ArraySegment
count int The number of bytes you need to read.
Результат ArraySegment
        public ArraySegment<byte> ReadBackingBytes(int count)
        {
            ThrowIfDisposed();
            EnsureDataAvailable(count);
            var chunkIndex = (_sliceOffset + _position) / _chunkSize;
            var chunkOffset = (_sliceOffset + _position) % _chunkSize;
            var chunkRemaining = _chunkSize - chunkOffset;
            if (count <= chunkRemaining)
            {
                _position += count;
                return new ArraySegment<byte>(_chunks[chunkIndex].Bytes, chunkOffset, count);
            }
            else
            {
                return new ArraySegment<byte>();
            }
        }