예제 #1
0
		public void ReadIntLongIntStructLittleEndian ()
		{
			// (ixi) and (1, 2, 3)
			byte[] data = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0 };
			MessageReader reader = new MessageReader (EndianFlag.Little, data);

			TestStruct stct = (TestStruct)reader.ReadStruct (typeof (TestStruct));
			Assert.AreEqual (1, stct.Item1);
			Assert.AreEqual (2, stct.Item2);
			Assert.AreEqual (3, stct.Item3);
		}
예제 #2
0
		public void ReadSameAlignementStructNonNativeEndian ()
		{
			// Will test the fast path with mixed types but same alignement
			byte[] data = new byte[8 * 3];
			Array.Copy (BitConverter.GetBytes ((long)1), 0, data, 0, 8);
			Array.Copy (BitConverter.GetBytes (ulong.MaxValue), 0, data, 8, 8);
			Array.Copy (BitConverter.GetBytes ((double)3.3), 0, data, 16, 8);
			// Swap value to simulate other endianess
			for (int i = 0; i < data.Length; i += 8) {
				for (int j = 0; j < 4; j++) {
					data[i + j] = (byte)(data[i + j] ^ data[i + 7 - j]);
					data[i + 7 - j] = (byte)(data[i + j] ^ data[i + 7 - j]);
					data[i + j] = (byte)(data[i + j] ^ data[i + 7 - j]);
				}
			}

			MessageReader reader = new MessageReader (!BitConverter.IsLittleEndian ? EndianFlag.Little : EndianFlag.Big, data);

			TestStruct3 stct = (TestStruct3)reader.ReadStruct (typeof (TestStruct3));
			Assert.AreEqual (1, stct.Item1);
			Assert.AreEqual (ulong.MaxValue, stct.Item2);
			Assert.AreEqual (3.3, stct.Item3);
		}
예제 #3
0
		public void ReadIntIntIntStructLittleEndianGeneric ()
		{
			// Will test the fast path
			byte[] data = new byte[] { 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 };
			MessageReader reader = new MessageReader (EndianFlag.Little, data);

			TestStruct2 stct = reader.ReadStruct<TestStruct2> ();
			Assert.AreEqual (1, stct.Item1);
			Assert.AreEqual (2, stct.Item2);
			Assert.AreEqual (3, stct.Item3);
		}
예제 #4
0
		public void ReadSameAlignementStructNativeEndian ()
		{
			// Will test the fast path with mixed types but same alignement
			byte[] data = new byte[8 * 3];
			Array.Copy (BitConverter.GetBytes ((long)1), 0, data, 0, 8);
			Array.Copy (BitConverter.GetBytes (ulong.MaxValue), 0, data, 8, 8);
			Array.Copy (BitConverter.GetBytes ((double)3.3), 0, data, 16, 8);

			MessageReader reader = new MessageReader (BitConverter.IsLittleEndian ? EndianFlag.Little : EndianFlag.Big, data);

			TestStruct3 stct = (TestStruct3)reader.ReadStruct (typeof (TestStruct3));
			Assert.AreEqual (1, stct.Item1);
			Assert.AreEqual (ulong.MaxValue, stct.Item2);
			Assert.AreEqual (3.3, stct.Item3);
		}
예제 #5
0
		public void ReadIntLongIntStructNonAlignedLittleEndian ()
		{
			// (ixi) and (1, 2, 3)
			byte[] data = new byte[] { 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0 };
			MessageReader reader = new MessageReader (EndianFlag.Little, data);

			TestStruct stct = (TestStruct)reader.ReadStruct (typeof (TestStruct));
		}