public async Task <VInt> ParseNextVInt() { const int byteSize = 8; const int vintDataSizePerByte = byteSize - 1; var buffer = new byte[byteSize]; await DataAccessor.ReadAsync(buffer, 0, 1).ConfigureAwait(false); if (buffer[0] == 0) { throw new FileNotLoadedException($"VInt at position {DataAccessor.Position - 1:X} was not initialized"); } var vintWidth = vintDataSizePerByte - buffer[0].GetMostSignificantBit(); // Validate range. It actually can't be outside this range, therefore its just a temporary assert Debug.Assert(vintWidth <= vintDataSizePerByte && vintWidth >= 0, "Invalid Vint Width"); await DataAccessor.ReadAsync(buffer, 1, vintWidth).ConfigureAwait(false); if (buffer.All(x => x == 0)) { throw new FileNotLoadedException($"VInt at position {DataAccessor.Position - 1 - vintWidth:X} was not initialized"); } buffer = Utility.ConvertEndiannes(buffer, vintWidth + 1); var value = BitConverter.ToInt64(buffer, 0); return(VInt.FromValue(value)); }