public static IByteBuffer Create(BsonChunkPool chunkPool, int fixedCapacity)
{
if (chunkPool == null)
{
throw new ArgumentNullException("pool");
}
if (fixedCapacity <= 0)
{
throw new ArgumentOutOfRangeException("capacity");
}
if (fixedCapacity < chunkPool.ChunkSize)
{
var chunk = chunkPool.AcquireChunk();
return new SingleChunkBuffer(chunk, 0, 0, false);
}
else
{
var chunksNeeded = ((fixedCapacity - 1) / chunkPool.ChunkSize) + 1;
var chunks = new List<BsonChunk>(chunksNeeded);
for (int i = 0; i < chunksNeeded; i++)
{
chunks.Add(chunkPool.AcquireChunk());
}
return new MultiChunkBuffer(chunks, 0, 0, false);
}
}