public static BsonReader Create(
     BsonBuffer buffer,
     BsonBinaryReaderSettings settings
 )
 {
     return new BsonBinaryReader(buffer, settings);
 }
 public static BsonWriter Create(
     BsonBuffer buffer,
     BsonBinaryWriterSettings settings
 )
 {
     return new BsonBinaryWriter(null, buffer, settings);
 }
 public static BsonReader Create(
     Stream stream,
     BsonBinaryReaderSettings settings
 )
 {
     BsonBuffer buffer = new BsonBuffer();
     buffer.LoadFrom(stream);
     return new BsonBinaryReader(buffer, settings);
 }
 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 = new BsonBinaryReaderContext(null, BsonReadState.Initial);
 }
 public void Dispose()
 {
     if (!disposed) {
         if (disposeBuffer) {
             buffer.Dispose();
         }
         buffer = null;
         disposed = true;
     }
 }
 protected MongoRequestMessage(
     MessageOpcode opcode,
     BsonBuffer buffer // not null if piggybacking this message onto an existing buffer
 )
     : base(opcode)
 {
     this.buffer = buffer ?? new BsonBuffer();
     this.disposeBuffer = buffer == null; // only call Dispose if we allocated the buffer
     this.requestId = Interlocked.Increment(ref lastRequestId);
 }
 public override void Dispose() {
     if (!disposed) {
         Close();
         if (disposeBuffer) {
             buffer.Dispose();
             buffer = null;
         }
         disposed = true;
     }
 }
 protected void ReadMessageHeaderFrom(
     BsonBuffer buffer
 )
 {
     messageLength = buffer.ReadInt32();
     requestId = buffer.ReadInt32();
     responseTo = buffer.ReadInt32();
     if ((MessageOpcode) buffer.ReadInt32() != opcode) {
         throw new FileFormatException("Message header opcode is not the expected one");
     }
 }
 public BsonBinaryWriter(
     Stream stream,
     BsonBuffer buffer,
     BsonBinaryWriterSettings settings
 ) {
     this.stream = stream;
     this.buffer = buffer ?? new BsonBuffer();
     this.disposeBuffer = buffer == null; // only call Dispose if we allocated the buffer
     this.settings = settings;
     context = new BsonBinaryWriterContext(null, BsonWriteState.Initial);
 }
        public void TestBenchmarks()
        {
            int iterations;
            DateTime start;
            DateTime end;
            TimeSpan duration;

            iterations = 1;
            start = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++) {
                // about 2.06 on my machine
                //var doc = new BsonDocument {
                //    { "a", 1 },
                //    { "b", 2.0 },
                //    { "c", "hello" },
                //    { "d", DateTime.UtcNow },
                //    { "e", true }
                // };
                byte[] value = { 1, 2, 3, 4 };
                MemoryStream stream = new MemoryStream();
                for (int n = 0; n < 100000; n++) {
                    stream.Write(value, 0, 4);
                }
            }
            end = DateTime.UtcNow;
            duration = end - start;
            System.Diagnostics.Debug.WriteLine(duration);

            start = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++) {
                // about 2.22 on my machine
                //var doc = new BsonDocument {
                //    { "a", BsonValue.Create((object) 1) },
                //    { "b", BsonValue.Create((object) 2.0) },
                //    { "c", BsonValue.Create((object) "hello") },
                //    { "d", BsonValue.Create((object) DateTime.UtcNow) },
                //    { "e", BsonValue.Create((object) true) }
                //};
                byte[] value = { 1, 2, 3, 4 };
                var buffer = new BsonBuffer();
                for (int n = 0; n < 100000; n++) {
                    buffer.WriteBytes(value);
                }
            }
            end = DateTime.UtcNow;
            duration = end - start;
            System.Diagnostics.Debug.WriteLine(duration);
        }
Exemplo n.º 11
0
 public static BsonReader Create(
     BsonBuffer buffer
 )
 {
     return Create(buffer, BsonBinaryReaderSettings.Defaults);
 }
 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);
 }