コード例 #1
0
        private void CopyBsonDocument(BsonStream inputStream, BsonStream outputStream)
        {
            var documentLength = inputStream.ReadInt32();

            inputStream.Position -= 4;
            CopyBytes(inputStream, outputStream, documentLength);
        }
 private void EnsurePayloadEndedAtEndPosition(BsonStream stream, long sectionEndPosition)
 {
     if (stream.Position != sectionEndPosition)
     {
         throw new FormatException("Command message payload did not end at the expected end position.");
     }
 }
コード例 #3
0
        private void CopyType1Section(BsonStream inputStream, BsonStream outputStream)
        {
            var payloadType = (PayloadType)inputStream.ReadByte();

            if (payloadType != PayloadType.Type1)
            {
                throw new FormatException("Expected subsequent sections to be of type 1.");
            }

            var sectionStartPosition = inputStream.Position;
            var sectionSize          = inputStream.ReadInt32();
            var sectionEndPosition   = sectionStartPosition + sectionSize;
            var identifier           = inputStream.ReadCString(Utf8Encodings.Lenient);

            outputStream.WriteByte((byte)BsonType.Array);
            outputStream.WriteCString(identifier);
            var arrayStartPosition = outputStream.Position;

            outputStream.WriteInt32(0); // array length will be backpatched
            var index = 0;

            while (inputStream.Position < sectionEndPosition)
            {
                outputStream.WriteByte((byte)BsonType.Document);
                outputStream.WriteCString(index.ToString());
                CopyBsonDocument(inputStream, outputStream);
                index++;
            }
            outputStream.WriteByte(0);
            outputStream.BackpatchSize(arrayStartPosition);
        }
        public void BackpatchSize_should_throw_when_stream_is_null()
        {
            BsonStream stream = null;

            Action action = () => stream.BackpatchSize(0);

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream");
        }
        public void WriteBoolean_should_throw_when_stream_is_null()
        {
            BsonStream stream = null;

            Action action = () => stream.WriteBoolean(false);

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream");
        }
        public void ReadBytes_with_count_should_throw_when_stream_is_null()
        {
            BsonStream stream = null;

            Action action = () => stream.ReadBytes(1);

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream");
        }
        public void ReadBinarySubType_should_throw_when_stream_is_null()
        {
            BsonStream stream = null;

            Action action = () => stream.ReadBinarySubType();

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream");
        }
        public void WriteSlice_should_throw_when_stream_is_null()
        {
            BsonStream  stream = null;
            IByteBuffer slice  = null;

            Action action = () => stream.WriteSlice(slice);

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream");
        }
        public void ReadBytes_with_buffer_should_throw_when_stream_is_null()
        {
            BsonStream stream = null;
            var        buffer = new byte[0];

            Action action = () => stream.ReadBytes(buffer, 0, 0);

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream");
        }
コード例 #10
0
        private readonly BsonStream _originalMessageStream;  // not owned by this class

        /// <summary>
        /// Initializes a new instance of the <see cref="CompressedMessage"/> class.
        /// </summary>
        /// <param name="originalMessage">The original message.</param>
        /// <param name="originalMessageStream">The original message stream.</param>
        /// <param name="compressorType">The compressor type.</param>
        public CompressedMessage(
            MongoDBMessage originalMessage,
            BsonStream originalMessageStream,
            CompressorType compressorType)
        {
            _originalMessage       = Ensure.IsNotNull(originalMessage, nameof(originalMessage));
            _originalMessageStream = originalMessageStream;
            _compressorType        = compressorType;
        }
コード例 #11
0
 private void CopyBytes(BsonStream inputStream, BsonStream outputStream, int count)
 {
     while (count > 0)
     {
         var chunkSize = Math.Min(count, _buffer.Length);
         inputStream.ReadBytes(_buffer, 0, chunkSize);
         outputStream.WriteBytes(_buffer, 0, chunkSize);
         count -= chunkSize;
     }
 }
コード例 #12
0
            private Opcode PeekOpcode(BsonStream stream)
            {
                var savedPosition = stream.Position;

                stream.Position += 12;
                var opcode = (Opcode)stream.ReadInt32();

                stream.Position = savedPosition;
                return(opcode);
            }
コード例 #13
0
        private void CopyType0Section(BsonStream inputStream, BsonStream outputStream)
        {
            var payloadType = (PayloadType)inputStream.ReadByte();

            if (payloadType != PayloadType.Type0)
            {
                throw new FormatException("Expected first section to be of type 0.");
            }

            CopyBsonDocument(inputStream, outputStream);
        }
        public void WriteBytes_should_throw_when_stream_is_null()
        {
            BsonStream stream = null;
            var        buffer = new byte[0];
            var        offset = 0;
            var        count  = 0;

            Action action = () => stream.WriteBytes(buffer, offset, count);

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("stream");
        }
コード例 #15
0
 // constructors
 public PostProcessor(QueryMessage message, BsonStream stream, long messageStartPosition)
 {
     _message = message;
     _stream  = stream;
     _messageStartPosition = messageStartPosition;
 }