public void LEB128_Int64(long value, int byteCount) { // determine the number of bytes the encoding will take int encodedByteCount = Leb128EncodingHelper.GetByteCount(value); Assert.Equal(byteCount, encodedByteCount); // write to array byte[] buffer_array = new byte[encodedByteCount]; int count_array = Leb128EncodingHelper.Write(buffer_array, 0, value); Assert.Equal(byteCount, count_array); // write to span byte[] buffer_span = new byte[encodedByteCount]; int count_span = Leb128EncodingHelper.Write(buffer_span.AsSpan(), value); Assert.Equal(byteCount, count_span); // read from array long reverse_array = Leb128EncodingHelper.ReadInt64(buffer_array, 0, count_array, out int size_array); Assert.Equal(byteCount, size_array); Assert.Equal(value, reverse_array); // read from stream Stream ms = new MemoryStream(buffer_array); long reverse_stream = Leb128EncodingHelper.ReadInt64(ms); Assert.Equal(byteCount, ms.Position); Assert.Equal(value, reverse_stream); }
public void LEB128_Int64(long value, int byteCount) { int count1 = Leb128EncodingHelper.GetByteCount(value); int count2 = Leb128EncodingHelper.Write(mBuffer, 0, value); long reverse = Leb128EncodingHelper.ReadInt64(mBuffer, 0, count2, out int size); Assert.Equal(byteCount, count1); Assert.Equal(byteCount, count2); Assert.Equal(byteCount, size); Assert.Equal(value, reverse); }