public static List <TDocument> DeserializeBatch <TDocument>(RawBsonArray batch, IBsonSerializer <TDocument> documentSerializer, MessageEncoderSettings messageEncoderSettings) { var documents = new List <TDocument>(); var readerSettings = new BsonBinaryReaderSettings(); if (messageEncoderSettings != null) { readerSettings.Encoding = messageEncoderSettings.GetOrDefault(MessageEncoderSettingsName.ReadEncoding, Utf8Encodings.Strict); readerSettings.GuidRepresentation = messageEncoderSettings.GetOrDefault(MessageEncoderSettingsName.GuidRepresentation, GuidRepresentation.CSharpLegacy); } ; using (var stream = new ByteBufferStream(batch.Slice, ownsBuffer: false)) using (var reader = new BsonBinaryReader(stream, readerSettings)) { // BSON requires that the top level object be a document, but an array looks close enough to a document that we can pretend it is one reader.ReadStartDocument(); while (reader.ReadBsonType() != 0) { reader.SkipName(); // skip over the index pseudo names var context = BsonDeserializationContext.CreateRoot(reader); var document = documentSerializer.Deserialize <TDocument>(context); documents.Add(document); } reader.ReadEndDocument(); } return(documents); }
public void Dispose() { if (A != null) { A.Dispose(); A = null; } }
public void Dispose() { if (A != null) { A.Dispose(); A = null; } }