C#: Allow ByteBuffer to use faster unsafe mode

If your C# runtime environment supports unsafe mode, you can use
the #define UNSAFE_BYTEBUFFER setting and build the FlatBuffers assembly
in unsafe mode for greatly increased performance.

Tested: Tested FlatBuffersTest on Windows using VS2010 with both safe
and unsafe versions. Added ByteBufferTest to test the byte reversing
functions.

Change-Id: I21334468b339334f9abf4317e6291b648b97f57b
This commit is contained in:
Jon Simantov
2014-12-11 14:23:10 -08:00
parent 3a27013732
commit 4390254e6a
2 changed files with 241 additions and 2 deletions

View File

@@ -239,6 +239,34 @@ namespace FlatBuffers.Test
var uut = new ByteBuffer(buffer);
Assert.Throws<ArgumentOutOfRangeException>(() => uut.GetLong(0));
}
public void ByteBuffer_ReverseBytesUshort()
{
ushort original = (ushort)0x1234U;
ushort reverse = ByteBuffer.ReverseBytes(original);
Assert.AreEqual(0x3412U, reverse);
ushort rereverse = ByteBuffer.ReverseBytes(reverse);
Assert.AreEqual(original, rereverse);
}
public void ByteBuffer_ReverseBytesUint()
{
uint original = 0x12345678;
uint reverse = ByteBuffer.ReverseBytes(original);
Assert.AreEqual(0x78563412U, reverse);
uint rereverse = ByteBuffer.ReverseBytes(reverse);
Assert.AreEqual(original, rereverse);
}
public void ByteBuffer_ReverseBytesUlong()
{
ulong original = 0x1234567890ABCDEFUL;
ulong reverse = ByteBuffer.ReverseBytes(original);
Assert.AreEqual(0xEFCDAB9078563412UL, reverse);
ulong rereverse = ByteBuffer.ReverseBytes(reverse);
Assert.AreEqual(original, rereverse);
}
}
}