本文整理汇总了C#中MongoDB.Bson.IO.BsonStreamAdapter.WriteSlice方法的典型用法代码示例。如果您正苦于以下问题:C# BsonStreamAdapter.WriteSlice方法的具体用法?C# BsonStreamAdapter.WriteSlice怎么用?C# BsonStreamAdapter.WriteSlice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonStreamAdapter
的用法示例。
在下文中一共展示了BsonStreamAdapter.WriteSlice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteSlice_should_have_expected_effect
public void WriteSlice_should_have_expected_effect(
[Values(0, 1, 2, 16)]
int length,
[Values(1, 2, 3)]
int numberOfChunks)
{
numberOfChunks = length == 0 ? 1 : length < numberOfChunks ? length : numberOfChunks;
using (var memoryStream = new MemoryStream())
using (var stream = new BsonStreamAdapter(memoryStream))
{
IByteBuffer slice;
var bytes = Enumerable.Range(0, length).Select(n => (byte)n).ToArray();
if (numberOfChunks == 1)
{
slice = new ByteArrayBuffer(bytes, isReadOnly: true);
}
else
{
var chunkSize = length / numberOfChunks;
var chunks = Enumerable.Range(0, numberOfChunks)
.Select(i => bytes.Skip(i * chunkSize).Take(i < numberOfChunks - 1 ? chunkSize : int.MaxValue).ToArray())
.Select(b => new ByteArrayChunk(b));
slice = new MultiChunkBuffer(chunks);
}
stream.WriteSlice(slice);
memoryStream.ToArray().Should().Equal(bytes);
}
}
示例2: WriteSlice_should_have_expected_effect
public void WriteSlice_should_have_expected_effect(
[Values(0, 1, 2, 16)]
int length)
{
using (var memoryStream = new MemoryStream())
using (var stream = new BsonStreamAdapter(memoryStream))
{
var bytes = Enumerable.Range(0, length).Select(n => (byte)n).ToArray();
var slice = new ByteArrayBuffer(bytes, isReadOnly: true);
stream.WriteSlice(slice);
memoryStream.ToArray().Should().Equal(bytes);
}
}