public void LEB128_UInt64(ulong 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 ulong reverse_array = Leb128EncodingHelper.ReadUInt64(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); ulong reverse_stream = Leb128EncodingHelper.ReadUInt64(ms); Assert.Equal(byteCount, ms.Position); Assert.Equal(value, reverse_stream); }
public void LEB128_UInt64(ulong value, int byteCount) { int count1 = Leb128EncodingHelper.GetByteCount(value); int count2 = Leb128EncodingHelper.Write(mBuffer, 0, value); ulong reverse = Leb128EncodingHelper.ReadUInt64(mBuffer, 0, count2, out int size); Assert.Equal(byteCount, count1); Assert.Equal(byteCount, count2); Assert.Equal(byteCount, size); Assert.Equal(value, reverse); }