CalculateSize() public method

public CalculateSize ( Document doc ) : int
doc Document
return int
Beispiel #1
0
 protected override int CalculateBodySize(BsonWriter writer)
 {
     int size = 8; //first int32, second int32
     size += writer.CalculateSize(this.FullCollectionName,false);
     size += writer.CalculateSize(Selector);
     return size;
 }
 protected override int CalculateBodySize(BsonWriter writer)
 {
     int size = 4; //first int32
     size += writer.CalculateSize(this.FullCollectionName,false);
     size += 4; //flags
     size += writer.CalculateSize(this.Selector);
     size += writer.CalculateSize(this.Document);
     return size;
 }
 /// <summary>
 /// The base size that all chunks will have.
 /// </summary>
 protected int CalculateBaseSize(BsonWriter writer)
 {
     int size = 4; //first int32
     size += writer.CalculateSize(this.FullCollectionName,false);
     size += Header.MessageLength;
     return size;
 }
 protected override int CalculateBodySize(BsonWriter writer)
 {
     int size = 4; //first int32
     size += writer.CalculateSize(this.FullCollectionName,false);
     size += 12; //number to return + cursorid
     return size;
 }
        public void TestCalculateSizeOfEmptyDoc()
        {
            Document doc = new Document();
            MemoryStream ms = new MemoryStream();
            BsonWriter writer = new BsonWriter(ms);

            Assert.AreEqual(5,writer.CalculateSize(doc));
        }
Beispiel #6
0
        public void TestCalculateSizeOfEmptyDoc()
        {
            Document     doc    = new Document();
            MemoryStream ms     = new MemoryStream();
            BsonWriter   writer = new BsonWriter(ms);

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

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

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

            Assert.AreEqual(51,writer.CalculateSize(doc));
        }
Beispiel #9
0
        public void TestCalculateSizeOfComplexDoc()
        {
            Document doc = new Document();

            doc.Append("a", "a");
            doc.Append("b", 1);
            Document sub = new Document().Append("c_1", 1).Append("c_2", DateTime.Now);

            doc.Append("c", sub);
            MemoryStream ms     = new MemoryStream();
            BsonWriter   writer = new BsonWriter(ms);

            Assert.AreEqual(51, writer.CalculateSize(doc));
        }
Beispiel #10
0
        public void TestCalculateSizeOfSimpleDoc()
        {
            Document doc = new Document();

            doc.Append("a", "a");
            doc.Append("b", 1);

            MemoryStream ms     = new MemoryStream();
            BsonWriter   writer = new BsonWriter(ms);

            //BsonDocument bdoc = BsonConvert.From(doc);

            Assert.AreEqual(21, writer.CalculateSize(doc));
        }
        /// <summary>
        /// Breaks down an insert message that may be too large into managable sizes.  
        /// When inserting only one document there will be only one chunk.  However chances
        /// are that when inserting thousands of documents at once there will be many.
        /// </summary>
        protected void ChunkMessage(BsonWriter writer)
        {
            int baseSize = CalculateBaseSize(writer);

            MessageChunk chunk = new MessageChunk(){Size = baseSize, Documents = new List<Document>()};
            foreach(Document doc in this.Documents){
                int docSize = writer.CalculateSize(doc);
                if(docSize + baseSize >= MessageBase.MaximumMessageSize) throw new MongoException("Document is too big to fit in a message.");

                if(docSize + chunk.Size > MessageBase.MaximumMessageSize){
                    chunks.Add(chunk);
                    chunk = new MessageChunk(){Size = baseSize, Documents = new List<Document>()};
                }
                chunk.Documents.Add(doc);
                chunk.Size += docSize;
            }
            chunks.Add(chunk);
        }
Beispiel #12
0
 protected override int CalculateBodySize(BsonWriter writer)
 {
     int size = 12; //options, numbertoskip, numbertoreturn
     size += writer.CalculateSize(this.FullCollectionName,false);
     size += writer.CalculateSize(this.Query);
     if(this.ReturnFieldSelector != null){
         size += writer.CalculateSize(this.ReturnFieldSelector);
     }
     return size;
 }
Beispiel #13
0
 protected override int CalculateBodySize(BsonWriter writer)
 {
     return writer.CalculateSize(this.Message,false);
 }
 private string WriteAndReadLenString(string val)
 {
     MemoryStream ms = new MemoryStream();
     BsonWriter bs = new BsonWriter(ms);
     BinaryWriter w = new BinaryWriter(ms);
     int byteCount = bs.CalculateSize(val,false);
     w.Write(byteCount);
     bs.WriteString(val);
     ms.Seek(0,SeekOrigin.Begin);
     BsonReader reader = new BsonReader(ms);
     return reader.ReadLenString();
 }