Пример #1
0
 /// <summary>
 /// Calculates the size of the body.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <returns></returns>
 protected override int CalculateBodySize(BsonWriter writer){
     var size = 4; //first int32
     size += writer.CalculateSize(FullCollectionName, false);
     size += 4; //flags
     size += writer.CalculateSizeObject(Selector);
     size += writer.CalculateSizeObject(Document);
     return size;
 }
        public void TestCalculateSizeOfEmptyDoc()
        {
            var doc = new Document();
            var ms = new MemoryStream();
            var writer = new BsonWriter(ms, new BsonDocumentDescriptor());

            Assert.AreEqual(5, writer.CalculateSizeObject(doc));
        }
        public void TestCalculateSizeOfSimpleDoc()
        {
            var doc = new Document {{"a", "a"}, {"b", 1}};

            var ms = new MemoryStream();
            var writer = new BsonWriter(ms, new BsonDocumentDescriptor());
            //BsonDocument bdoc = BsonConvert.From(doc);

            Assert.AreEqual(21, writer.CalculateSizeObject(doc));
        }
        public void TestCalculateSizeOfComplexDoc()
        {
            var doc = new Document();
            doc.Add("a", "a");
            doc.Add("b", 1);
            var sub = new Document().Add("c_1", 1).Add("c_2", DateTime.Now);
            doc.Add("c", sub);
            var ms = new MemoryStream();
            var writer = new BsonWriter(ms, new BsonDocumentDescriptor());

            Assert.AreEqual(51, writer.CalculateSizeObject(doc));
        }
Пример #5
0
 /// <summary>
 /// Calculates the size of the body.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <returns></returns>
 protected override int CalculateBodySize(BsonWriter writer){
     var size = 12; //options, numbertoskip, numbertoreturn
     size += writer.CalculateSize(FullCollectionName, false);
     size += writer.CalculateSizeObject(Query);
     if(ReturnFieldSelector != null)
         size += writer.CalculateSizeObject(ReturnFieldSelector);
     return size;
 }