示例#1
0
        public void Buffer_Write_String()
        {
            var source = new BufferSlice(new byte[1000], 0, 1000);

            // direct string into byte[]

            using (var w = new BufferWriter(source))
            {
                w.WriteString("abc123", false);
                w.Position.Should().Be(6);
            }

            Encoding.UTF8.GetString(source.Array, 0, 6).Should().Be("abc123");

            source.Fill(0);

            // BSON string specs

            using (var w = new BufferWriter(source))
            {
                w.WriteString("abc123", true);
            }

            source.ReadInt32(0).Should().Be(7);
            source.ReadString(4, 6).Should().Be("abc123");
            ((char)source.ReadByte(10)).Should().Be('\0');
        }
示例#2
0
        public void Buffer_Write_String()
        {
            var source = new BufferSlice(new byte[1000], 0, 1000);

            // direct string into byte[]

            using (var w = new BufferWriter(source))
            {
                w.WriteString("abc123", false);
                Assert.AreEqual(6, w.Position);
            }

            Assert.AreEqual("abc123", Encoding.UTF8.GetString(source.Array, 0, 6));

            source.Fill(0);

            // BSON string specs

            using (var w = new BufferWriter(source))
            {
                w.WriteString("abc123", true);
            }

            Assert.AreEqual(7, source.ReadInt32(0));
            Assert.AreEqual("abc123", source.ReadString(4, 6));
            Assert.AreEqual('\0', (char)source.ReadByte(10));
        }