Exemplo n.º 1
0
        public void ReadTest()
        {
            using NativeBuffer buffer = new NativeBuffer(20);
            buffer.Write(10);
            buffer.Write(40L);
            buffer.Write('a');
            buffer.Write('z');
            buffer.Write(4f);

            Assert.AreEqual(10, buffer.Read <int>(0));
            Assert.AreEqual(40L, buffer.Read <long>(4));
            Assert.AreEqual('a', buffer.Read <char>(12));
            Assert.AreEqual('z', buffer.Read <char>(14));
            Assert.AreEqual(4f, buffer.Read <float>(16));

            Assert.Throws <InvalidOperationException>(() => buffer.Read <byte>(-1));
            Assert.Throws <InvalidOperationException>(() => buffer.Read <byte>(20));
        }