public void PutInt(int index, int value, ByteOrder byteOrder) { BoundsCheck0(index, BitUtil.SIZE_OF_INT); value = EndianessConverter.ApplyInt32(byteOrder, value); *(int *)(_pBuffer + index) = value; }
public int GetInt(int index, ByteOrder byteOrder) { BoundsCheck0(index, BitUtil.SIZE_OF_INT); var value = *(int *)(_pBuffer + index); return(EndianessConverter.ApplyInt32(byteOrder, value)); }
public void ShouldPutInt32BigEndian(int value, int index) { _directBuffer.Int32PutBigEndian(index, value); var expected = EndianessConverter.ApplyInt32(ByteOrder.BigEndian, value); Assert.AreEqual(expected, *(int *)(_pBuffer + index)); }
public void ApplyIntWithLittleEndianShouldNoOp() { const int input = 12; var result = EndianessConverter.ApplyInt32(ByteOrder.LittleEndian, input); Assert.AreEqual(input, result); }
public void ApplyIntWithBigEndianShouldReverseBytes() { const int input = 12; var result = EndianessConverter.ApplyInt32(ByteOrder.BigEndian, input); int expected = BitConverter.ToInt32(BitConverter.GetBytes(input).Reverse().ToArray(), 0); Assert.AreEqual(expected, result); }
public void ShouldGetInt32BigEndian(int value, int index) { var bytes = BitConverter.GetBytes(value); Array.Copy(bytes, 0, _buffer, index, 4); var result = _directBuffer.Int32GetBigEndian(index); var expected = EndianessConverter.ApplyInt32(ByteOrder.BigEndian, value); Assert.AreEqual(expected, result); }