MongoDB.Bson.IO.MultiChunkBuffer.WriteBackingBytes C# (CSharp) Method

WriteBackingBytes() public method

Write directly to the backing bytes. The returned ArraySegment points directly to the backing bytes for the current position and you can write the bytes directly to 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 WriteBytes instead. When WriteBackingBytes returns the position has not been advanced. After you have written up to count bytes directly to the backing bytes advance the position by the number of bytes actually written.
MultiChunkBuffer
public WriteBackingBytes ( int count ) : ArraySegment
count int The count.
return ArraySegment
        public ArraySegment<byte> WriteBackingBytes(int count)
        {
            ThrowIfDisposed();
            EnsureSpaceAvailable(count);
            var chunkIndex = (_sliceOffset + _position) / _chunkSize;
            var chunkOffset = (_sliceOffset + _position) % _chunkSize;
            var chunkRemaining = _chunkSize - chunkOffset;
            if (count <= chunkRemaining)
            {
                return new ArraySegment<byte>(_chunks[chunkIndex].Bytes, chunkOffset, count);
            }
            else
            {
                return new ArraySegment<byte>();
            }
        }