コード例 #1
0
        public void ShouldGetStringNullTerminated()
        {
            var          encoding = System.Text.Encoding.ASCII;
            const string value    = "abc123";
            var          bytes    = encoding.GetBytes(value);
            const int    index    = 0;
            var          written  = _directBuffer.SetBytes(index, bytes, 0, bytes.Length);

            Assert.AreEqual(bytes.Length, written);
            var written2 = _directBuffer.SetBytes(index + bytes.Length, new byte[] { Terminator }, 0, 1);

            Assert.AreEqual(1, written2);
            string result = _directBuffer.GetStringFromNullTerminatedBytes(encoding, index, _directBuffer.Capacity - index, Terminator);

            Assert.AreEqual(value, result);
        }