NightOwl888 commented on code in PR #1170: URL: https://github.com/apache/lucenenet/pull/1170#discussion_r2309095676
########## src/Lucene.Net/Support/IO/StreamExtensions.cs: ########## @@ -210,5 +213,154 @@ public static long ReadInt64(this Stream stream) buff[6] << 16 | buff[7] << 24); return (long)((ulong)hi) << 32 | lo; } + + //async versions of the above methods + public static async Task WriteInt32Async(this Stream output, int value, CancellationToken cancellationToken = default) + { + if (output is null) + throw new ArgumentNullException(nameof(output)); + + byte[] buff = new byte[4]; + buff[0] = (byte)(value >> 24); + buff[1] = (byte)(value >> 16); + buff[2] = (byte)(value >> 8); + buff[3] = (byte)value; + + await output.WriteAsync(buff, 0, buff.Length, cancellationToken).ConfigureAwait(false); + } + + public static async Task WriteInt64Async(this Stream output, long value, CancellationToken cancellationToken = default) + { + if (output is null) + throw new ArgumentNullException(nameof(output)); + + byte[] buff = new byte[8]; + buff[0] = (byte)(value >> 56); + buff[1] = (byte)(value >> 48); + buff[2] = (byte)(value >> 40); + buff[3] = (byte)(value >> 32); + buff[4] = (byte)(value >> 24); + buff[5] = (byte)(value >> 16); + buff[6] = (byte)(value >> 8); + buff[7] = (byte)value; + + await output.WriteAsync(buff, 0, buff.Length, cancellationToken).ConfigureAwait(false); + } + + public static async Task WriteUTFAsync(this Stream output, string value, CancellationToken cancellationToken = default) + { + if (output is null) + throw new ArgumentNullException(nameof(output)); + if (value is null) + throw new ArgumentNullException(nameof(value)); + + long utfCount = CountUTFBytes(value); + if (utfCount > ushort.MaxValue) + throw new EncoderFallbackException("Encoded string too long."); + + byte[] buffer = new byte[(int)utfCount + 2]; + int offset = 0; + offset = WriteInt16ToBuffer((int)utfCount, buffer, offset); + offset = WriteUTFBytesToBuffer(value, (int)utfCount, buffer, offset); + + await output.WriteAsync(buffer, 0, offset, cancellationToken).ConfigureAwait(false); + } + + public static async Task<int> ReadInt32Async(this Stream input, CancellationToken cancellationToken = default) + { + if (input is null) + throw new ArgumentNullException(nameof(input)); + + byte[] buff = new byte[4]; + int read = await input.ReadAsync(buff, 0, buff.Length, cancellationToken).ConfigureAwait(false); + if (read < buff.Length) throw new EndOfStreamException(); + + return (buff[0] << 24) | (buff[1] << 16) | (buff[2] << 8) | buff[3]; + } + + public static async Task<long> ReadInt64Async(this Stream input, CancellationToken cancellationToken = default) + { + if (input is null) + throw new ArgumentNullException(nameof(input)); + + byte[] buff = new byte[8]; + int read = await input.ReadAsync(buff, 0, buff.Length, cancellationToken).ConfigureAwait(false); + if (read < buff.Length) throw new EndOfStreamException(); + + return ((long)buff[0] << 56) | + ((long)buff[1] << 48) | + ((long)buff[2] << 40) | + ((long)buff[3] << 32) | + ((long)buff[4] << 24) | + ((long)buff[5] << 16) | + ((long)buff[6] << 8) | + buff[7]; + } + + public static async Task<string> ReadUTFAsync(this Stream input, CancellationToken cancellationToken = default) + { + if (input is null) + throw new ArgumentNullException(nameof(input)); + + byte[] lenBuff = new byte[2]; + int readLen = await input.ReadAsync(lenBuff, 0, lenBuff.Length, cancellationToken).ConfigureAwait(false); + if (readLen < lenBuff.Length) throw new EndOfStreamException(); + + int length = (lenBuff[0] << 8) | lenBuff[1]; + byte[] buffer = new byte[length]; Review Comment: I guess we should get onto the same page as to what the goal is. Previously, I @paulirwin mentioned that the `Lucene.Net.Replicator.Http` tests would be moved to the `lucenenet-extensions` repository, which would ensure that there wouldn't be any circular dependencies between the repositories. If that is where you are running the tests and they are functioning asynchronously, it should be fine. But, I don't understand why the tests would still exist in this repository if that is the case. Shouldn't this PR be removing them? Or are you keeping them synchronous here because they have changed in some other way in `lucenenet-extensions`? If the tests are to remain here for the time being and this repo is meant to test them asyncrhously, please update this PR with the changes to test the server with async/await. That would demonstrate that the functionality works and rule out any configuration issues with my setup. Alternatively, I could update the code on this branch and demonstrate the failure, if preferred - let me know. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org