本文整理汇总了C#中MongoDB.Bson.IO.BsonBuffer类的典型用法代码示例。如果您正苦于以下问题:C# BsonBuffer类的具体用法?C# BsonBuffer怎么用?C# BsonBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonBuffer类属于MongoDB.Bson.IO命名空间,在下文中一共展示了BsonBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteBodyTo
// internal methods
internal override void WriteBodyTo(BsonBuffer buffer)
{
var processedRequests = new List<InsertRequest>();
var continuationBatch = _batch as ContinuationBatch<InsertRequest, byte[]>;
if (continuationBatch != null)
{
AddOverflow(buffer, continuationBatch.PendingState);
processedRequests.Add(continuationBatch.PendingItem);
continuationBatch.ClearPending(); // so pending objects can be garbage collected sooner
}
// always go one document too far so that we can set IsDone as early as possible
var enumerator = _batch.Enumerator;
while (enumerator.MoveNext())
{
var request = enumerator.Current;
AddRequest(buffer, request);
if ((_batchCount > _maxBatchCount || _batchLength > _maxBatchLength) && _batchCount > 1)
{
var serializedDocument = RemoveLastDocument(buffer);
var nextBatch = new ContinuationBatch<InsertRequest, byte[]>(enumerator, request, serializedDocument);
_batchProgress = new BatchProgress<InsertRequest>(_batchCount, _batchLength, processedRequests, nextBatch);
return;
}
processedRequests.Add(request);
}
_batchProgress = new BatchProgress<InsertRequest>(_batchCount, _batchLength, processedRequests, null);
}
示例2: Execute
// public methods
public WriteConcernResult Execute(MongoConnection connection)
{
var serverInstance = connection.ServerInstance;
if (serverInstance.Supports(FeatureId.WriteCommands) && _args.WriteConcern.Enabled)
{
var emulator = new UpdateOpcodeOperationEmulator(_args);
return emulator.Execute(connection);
}
SendMessageWithWriteConcernResult sendMessageResult;
using (var buffer = new BsonBuffer(new MultiChunkBuffer(BsonChunkPool.Default), true))
{
var requests = _args.Requests.ToList();
if (requests.Count != 1)
{
throw new NotSupportedException("Update opcode only supports a single update request.");
}
var updateRequest = (UpdateRequest)requests[0];
var flags = UpdateFlags.None;
if (updateRequest.IsMultiUpdate ?? false) { flags |= UpdateFlags.Multi; }
if (updateRequest.IsUpsert ?? false) { flags |= UpdateFlags.Upsert; }
var maxDocumentSize = connection.ServerInstance.MaxDocumentSize;
var query = updateRequest.Query ?? new QueryDocument();
var message = new MongoUpdateMessage(WriterSettings, CollectionFullName, _args.CheckElementNames, flags, maxDocumentSize, query, updateRequest.Update);
message.WriteTo(buffer);
sendMessageResult = SendMessageWithWriteConcern(connection, buffer, message.RequestId, ReaderSettings, WriterSettings, WriteConcern);
}
return WriteConcern.Enabled ? ReadWriteConcernResult(connection, sendMessageResult) : null;
}
示例3: WriteHeaderTo
internal virtual void WriteHeaderTo(BsonBuffer buffer)
{
buffer.WriteInt32(0); // messageLength will be backpatched later
buffer.WriteInt32(_requestId);
buffer.WriteInt32(0); // responseTo not used in requests sent by client
buffer.WriteInt32((int)_opcode);
}
示例4: Create
public static BsonWriter Create(
BsonBuffer buffer,
BsonBinaryWriterSettings settings
)
{
return new BsonBinaryWriter(null, buffer, settings);
}
示例5: WriteBody
// protected methods
protected override void WriteBody(BsonBuffer buffer)
{
buffer.WriteInt32(0); // reserved
buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName);
buffer.WriteInt32(_numberToReturn);
buffer.WriteInt64(_cursorId);
}
示例6: WriteBody
// protected methods
protected override void WriteBody(BsonBuffer buffer)
{
buffer.WriteInt32((int)_flags);
buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName);
_firstDocumentStartPosition = buffer.Position;
// documents to be added later by calling AddDocument
}
示例7: ResetBatch
internal void ResetBatch(BsonBuffer buffer, byte[] lastDocument)
{
buffer.Position = _firstDocumentStartPosition;
buffer.Length = _firstDocumentStartPosition;
buffer.WriteBytes(lastDocument);
BackpatchMessageLength(buffer);
}
示例8: Create
public static BsonReader Create(
BsonBuffer buffer,
BsonBinaryReaderSettings settings
)
{
return new BsonBinaryReader(buffer, settings);
}
示例9: WriteHeaderTo
internal override void WriteHeaderTo(BsonBuffer buffer)
{
base.WriteHeaderTo(buffer);
buffer.WriteInt32(0); // reserved
buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName);
buffer.WriteInt32(_numberToReturn);
}
示例10: Test20KDocument
public void Test20KDocument()
{
// manufacture an approximately 20K document using 200 strings each 100 characters long
// it's enough to cause the document to straddle a chunk boundary
var document = new BsonDocument();
var value = new string('x', 100);
for (int i = 0; i < 200; i++)
{
var name = i.ToString();
document.Add(name, value);
}
// round trip tests
var bson = document.ToBson();
var rehydrated = BsonSerializer.Deserialize<BsonDocument>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
// test failure mode when 20 bytes are truncated from the buffer
using (var buffer = new BsonBuffer())
{
buffer.LoadFrom(new MemoryStream(bson));
buffer.Length -= 20;
using (var bsonReader = BsonReader.Create(buffer))
{
Assert.Throws<EndOfStreamException>(() => BsonSerializer.Deserialize<BsonDocument>(bsonReader));
}
}
}
示例11: WriteMessageHeaderTo
protected void WriteMessageHeaderTo(
BsonBuffer buffer
) {
buffer.WriteInt32(0); // messageLength will be backpatched later
buffer.WriteInt32(requestId);
buffer.WriteInt32(0); // responseTo not used in requests sent by client
buffer.WriteInt32((int) opcode);
}
示例12: WriteBodyTo
// internal methods
internal override void WriteBodyTo(BsonBuffer buffer)
{
buffer.WriteInt32(_cursorIds.Length);
foreach (long cursorId in _cursorIds)
{
buffer.WriteInt64(cursorId);
}
}
示例13: BsonBinaryReader
public BsonBinaryReader(
BsonBuffer buffer,
BsonBinaryReaderSettings settings
) {
this.buffer = buffer ?? new BsonBuffer();
this.disposeBuffer = buffer == null; // only call Dispose if we allocated the buffer
this.settings = settings;
context = null;
}
示例14: WriteBody
// protected methods
protected override void WriteBody(BsonBuffer buffer)
{
buffer.WriteInt32(0); // reserved
buffer.WriteInt32(_cursorIds.Length);
foreach (long cursorId in _cursorIds)
{
buffer.WriteInt64(cursorId);
}
}
示例15: RemoveLastDocument
internal byte[] RemoveLastDocument(BsonBuffer buffer)
{
var lastDocumentLength = buffer.Position - _lastDocumentStartPosition;
buffer.Position = _lastDocumentStartPosition;
var lastDocument = buffer.ReadBytes(lastDocumentLength);
buffer.Length = _lastDocumentStartPosition;
BackpatchMessageLength(buffer);
return lastDocument;
}