コード例 #1
0
ファイル: BufferSegRStreamTests.cs プロジェクト: zhabis/nfx
        public void T3_2()
        {
            var arr = new byte[] { 1, 2, 3, 4, 5 };
            var s   = new BufferSegmentReadingStream();

            s.BindBuffer(arr, 2, 3);

            Aver.AreEqual(0, s.Position);
            Aver.AreEqual(3, s.Length);

            var a2 = new byte[10];

            Aver.AreEqual(2, s.Read(a2, 1, 2));
            Aver.AreEqual(0, a2[0]);
            Aver.AreEqual(3, a2[1]);
            Aver.AreEqual(4, a2[2]);
            Aver.AreEqual(0, a2[3]);
            Aver.AreEqual(2, s.Position);
        }
コード例 #2
0
ファイル: BufferSegRStreamTests.cs プロジェクト: zhabis/nfx
        public void T2()
        {
            var arr = new byte[] { 1, 2, 3, 4, 5 };
            var s   = new BufferSegmentReadingStream();

            s.BindBuffer(arr, 0, 3);

            Aver.AreEqual(3, s.Length);

            Aver.AreEqual(0, s.Position);
            Aver.AreEqual(1, s.ReadByte());
            Aver.AreEqual(1, s.Position);
            Aver.AreEqual(2, s.ReadByte());
            Aver.AreEqual(2, s.Position);
            Aver.AreEqual(3, s.ReadByte());
            Aver.AreEqual(3, s.Position);
            Aver.AreEqual(-1, s.ReadByte());
            Aver.AreEqual(3, s.Position);
        }
コード例 #3
0
        private Stream readSocket()
        {
            var nets  = m_TcpClient.GetStream();
            var total = BinUtils.ReadInt32(nets);

            if (total >= Protocol.BSON_SIZE_LIMIT)
            {
                throw new MongoDBConnectorProtocolException(StringConsts.PROTO_SOCKET_READ_EXCEED_LIMIT_ERROR.Args(total, Protocol.BSON_SIZE_LIMIT));
            }

            var leftToRead = total - sizeof(Int32); //the total size includes the 4 bytes

            m_BufferStream.SetLength(total);
            var buffer = m_BufferStream.GetBuffer();

            BinUtils.WriteInt32(buffer, total, 0);
            socketRead(nets, buffer, sizeof(Int32), leftToRead);
            m_Received.BindBuffer(buffer, 0, total);
            return(m_Received);
            //todo stats
        }