Пример #1
0
        public int Read(BsonReader reader)
        {
            int len = 0;
            this.Expression = reader.ReadString();
            len += this.Expression.Length + 1;

            this.Options = reader.ReadString();
            len += this.Options.Length + 1;

            return len;
        }
Пример #2
0
        public void TestReadLongerString()
        {
            byte[] buf = HexToBytes("7465737474657374746573747465737474657374746573747465737474657374746573747465737400");
            MemoryStream ms = new MemoryStream(buf);
            BsonReader reader = new BsonReader(ms);

            String s = reader.ReadString();
            Assert.AreEqual("testtesttesttesttesttesttesttesttesttest",s);
        }
Пример #3
0
 public int Read(BsonReader reader)
 {
     sbyte typeNum = (sbyte)reader.ReadByte();
     int bytesRead;
     this.Name = reader.ReadString();
     this.Val = BsonConvert.Create((BsonDataType)typeNum);
     bytesRead = this.Val.Read(reader);
     bytesRead += (1 + this.Name.Length + 1); //type byte & name + term
     return bytesRead;
 }
        public void TestReadLongerString()
        {
            byte[]       buf    = HexToBytes("7465737474657374746573747465737474657374746573747465737474657374746573747465737400");
            MemoryStream ms     = new MemoryStream(buf);
            BsonReader   reader = new BsonReader(ms);

            String s = reader.ReadString();

            Assert.AreEqual("testtesttesttesttesttesttesttesttesttest", s);
        }
        public void TestReadString()
        {
            byte[]       buf    = HexToBytes("7465737400");
            MemoryStream ms     = new MemoryStream(buf);
            BsonReader   reader = new BsonReader(ms);

            String s = reader.ReadString();

            Assert.AreEqual("test", s);
            Assert.AreEqual(4, Encoding.UTF8.GetByteCount(s));
        }
        public void TestReadStringWithUKPound()
        {
            byte[]       buf    = HexToBytes("31323334C2A3353600");
            MemoryStream ms     = new MemoryStream(buf);
            BsonReader   reader = new BsonReader(ms);

            String s = reader.ReadString();

            Assert.AreEqual("1234£56", s);
            Assert.AreEqual(8, Encoding.UTF8.GetByteCount(s));
            Assert.AreEqual(9, reader.Position);
        }
Пример #7
0
 public int Read(BsonReader reader)
 {
     int len = reader.ReadInt32();
     this.Val = reader.ReadString(len);
     return 4 + len;
 }
Пример #8
0
        public int Read(BsonReader reader)
        {
            int size = reader.ReadInt32();
            int bytesRead = 4;

            int codeLen = reader.ReadInt32();
            this.Val = reader.ReadString(codeLen);
            bytesRead += 4 + codeLen;

            this.Scope = new BsonDocument();
            bytesRead += this.Scope.Read(reader);

            if(bytesRead != size){
                throw new System.IO.InvalidDataException(string.Format("Should have read {0} bytes from stream but only read {1}]", size, bytesRead));
            }

            return bytesRead;
        }
Пример #9
0
        public void TestReadStringWithUKPound()
        {
            byte[] buf = HexToBytes("31323334C2A3353600");
            MemoryStream ms = new MemoryStream(buf);
            BsonReader reader = new BsonReader(ms);

            String s = reader.ReadString();
            Assert.AreEqual("1234£56",s);
            Assert.AreEqual(8,Encoding.UTF8.GetByteCount(s));
            Assert.AreEqual(9,reader.Position);
        }
Пример #10
0
        public void TestReadString()
        {
            byte[] buf = HexToBytes("7465737400");
            MemoryStream ms = new MemoryStream(buf);
            BsonReader reader = new BsonReader(ms);

            String s = reader.ReadString();
            Assert.AreEqual("test",s);
            Assert.AreEqual(4,Encoding.UTF8.GetByteCount(s));
        }
Пример #11
0
        private string WriteAndReadString(string val)
        {
            byte[] buf = Encoding.UTF8.GetBytes(val + '\0');

            MemoryStream ms = new MemoryStream(buf);
            BsonReader reader = new BsonReader(ms);
            return reader.ReadString();
        }