public virtual void TestReadIntPosition() { var readInt = _input.ReadInt(2); var theInt = BytesExtensions.ReadInt(InitData, 2, Endianness.BigEndian); Assert.AreEqual(theInt, readInt); }
public void ReadIntSequence() { var bytes = new byte[] { 0 }; var sequence = new ReadOnlySequence <byte>(bytes); Assert.Throws <ArgumentException>(() => _ = BytesExtensions.ReadInt(ref sequence)); bytes = new byte[] { 7, 91, 205, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; sequence = new ReadOnlySequence <byte>(bytes); Assert.That(BytesExtensions.ReadInt(ref sequence), Is.EqualTo(123456789)); Assert.That(sequence.Length, Is.EqualTo(12)); bytes = new byte[] { 21, 205, 91, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; sequence = new ReadOnlySequence <byte>(bytes); Assert.That(BytesExtensions.ReadInt(ref sequence, Endianness.LittleEndian), Is.EqualTo(123456789)); Assert.That(sequence.Length, Is.EqualTo(12)); var bytes1 = new byte[] { 7, 91 }; var bytes2 = new byte[] { 205, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var firstSegment = new MemorySegment <byte>(bytes1); var lastSegment = firstSegment.Append(bytes2); sequence = new ReadOnlySequence <byte>(firstSegment, 0, lastSegment, lastSegment.Memory.Length); Assert.That(BytesExtensions.ReadInt(ref sequence), Is.EqualTo(123456789)); Assert.That(sequence.Length, Is.EqualTo(12)); }
public virtual void TestReadFloatPosition() { double readFloat = _input.ReadFloat(2); var intB = BytesExtensions.ReadInt(InitData, 2, Endianness.BigEndian); double aFloat = BitConverter.ToSingle(BitConverter.GetBytes(intB), 0); Assert.AreEqual(aFloat, readFloat, 0); }
public virtual void TestWriteIntV() { var expected = 100; _output.Write(expected); var actual = BytesExtensions.ReadInt(_output.Buffer, 0, Endianness.BigEndian); Assert.AreEqual(actual, expected); }
public virtual void TestWriteFloatV() { var v = 1.1f; _output.Write(v); var expected = BitConverter.ToInt32(BitConverter.GetBytes(v), 0); var actual = BytesExtensions.ReadInt(_output.Buffer, 0, Endianness.BigEndian); Assert.AreEqual(actual, expected); }
public void Sequences1() { const int origin = 1234; var bytes = new byte[4]; bytes.WriteInt(0, origin, Endianness.BigEndian); var buffer = new ReadOnlySequence <byte>(bytes); var value = BytesExtensions.ReadInt(ref buffer, Endianness.BigEndian); NUnit.Framework.Assert.AreEqual(origin, value); }
public virtual void TestReadFloat() { // expected 9.2557164867118492E-41 which is what the original code reads // now we read 66051.0d? -- but ReadInt *does* return 66051 on original code, how can that become? meh? // so our reading of the int is ok, our conversion to aFloat is ok // but our reading (and writing?) of a float is not? double readFloat = _input.ReadFloat(); var intB = BytesExtensions.ReadInt(InitData, 0, Endianness.BigEndian); double aFloat = BitConverter.ToSingle(BitConverter.GetBytes(intB), 0); Assert.AreEqual(aFloat, readFloat, 0); }
/// <summary> /// Reads the length of the frame from a sequence of bytes, and slice the sequence accordingly. /// </summary> /// <param name="bytes">The sequence of bytes.</param> /// <returns>The length of the frame.</returns> public static int ReadLength(ref ReadOnlySequence <byte> bytes) => BytesExtensions.ReadInt(ref bytes, Endianness.LittleEndian);