private static async ValueTask <int> ReadLengthAsync(this PipeReader reader, StringLengthEncoding lengthFormat, CancellationToken token) { ValueTask <int> result; var littleEndian = BitConverter.IsLittleEndian; switch (lengthFormat) { default: throw new ArgumentOutOfRangeException(nameof(lengthFormat)); case StringLengthEncoding.Plain: result = reader.ReadAsync <int>(token); break; case StringLengthEncoding.PlainLittleEndian: littleEndian = true; goto case StringLengthEncoding.Plain; case StringLengthEncoding.PlainBigEndian: littleEndian = false; goto case StringLengthEncoding.Plain; case StringLengthEncoding.Compressed: result = reader.Read7BitEncodedIntAsync(token); break; } var length = await result.ConfigureAwait(false); length.ReverseIfNeeded(littleEndian); return(length); }
ValueTask IAsyncBinaryWriter.WriteTimeSpanAsync(TimeSpan value, StringLengthEncoding lengthFormat, EncodingContext context, string?format, IFormatProvider?provider, CancellationToken token) { Task result; if (token.IsCancellationRequested) { result = Task.FromCanceled(token); } else { try { writer.WriteTimeSpan(value, lengthFormat, in context, format, provider); result = FlushAsync(token); } catch (Exception e) { result = Task.FromException(e); } } return(new ValueTask(result)); }
public ValueTask <string> ReadStringAsync(StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token) => EndOfStream <string>();
ValueTask <string> IAsyncBinaryReader.ReadStringAsync(StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token) => reader.ReadStringAsync(lengthFormat, context, token);
ValueTask <TimeSpan> IAsyncBinaryReader.ReadTimeSpanAsync(StringLengthEncoding lengthFormat, DecodingContext context, string[] formats, TimeSpanStyles style, IFormatProvider?provider, CancellationToken token) => StreamExtensions.ReadTimeSpanAsync(input, lengthFormat, context, buffer, formats, style, provider, token);
ValueTask <DateTimeOffset> IAsyncBinaryReader.ReadDateTimeOffsetAsync(StringLengthEncoding lengthFormat, DecodingContext context, DateTimeStyles style, IFormatProvider?provider, CancellationToken token) => StreamExtensions.ReadDateTimeOffsetAsync(input, lengthFormat, context, buffer, style, provider, token);
ValueTask <Guid> IAsyncBinaryReader.ReadGuidAsync(StringLengthEncoding lengthFormat, DecodingContext context, string format, CancellationToken token) => StreamExtensions.ReadGuidAsync(input, lengthFormat, context, buffer, format, token);
ValueTask <double> IAsyncBinaryReader.ReadDoubleAsync(StringLengthEncoding lengthFormat, DecodingContext context, NumberStyles style, IFormatProvider?provider, CancellationToken token) => StreamExtensions.ReadDoubleAsync(input, lengthFormat, context, buffer, style, provider, token);
public ValueTask <string> ReadStringAsync(StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token = default) => StreamExtensions.ReadStringAsync(input, lengthFormat, context, buffer, token);
ValueTask IAsyncBinaryWriter.WriteTimeSpanAsync(TimeSpan value, StringLengthEncoding lengthFormat, EncodingContext context, string?format, IFormatProvider?provider, CancellationToken token) => output.WriteTimeSpanAsync(value, lengthFormat, context, buffer, format, provider, token);
/// <summary> /// Decodes string asynchronously from pipe. /// </summary> /// <param name="reader">The pipe reader.</param> /// <param name="lengthFormat">Represents string length encoding format.</param> /// <param name="context">The text decoding context.</param> /// <param name="token">The token that can be used to cancel the operation.</param> /// <returns>The decoded string.</returns> /// <exception cref="EndOfStreamException"><paramref name="reader"/> doesn't contain the necessary number of bytes to restore string.</exception> /// <exception cref="OperationCanceledException">The operation has been canceled.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="lengthFormat"/> is invalid.</exception> public static async ValueTask <string> ReadStringAsync(this PipeReader reader, StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token = default) => await ReadStringAsync(reader, await reader.ReadLengthAsync(lengthFormat, token).ConfigureAwait(false), context, token).ConfigureAwait(false);
ValueTask <Guid> IAsyncBinaryReader.ReadGuidAsync(StringLengthEncoding lengthFormat, DecodingContext context, string format, CancellationToken token) => EndOfStream <Guid>();
ValueTask <TimeSpan> IAsyncBinaryReader.ReadTimeSpanAsync(StringLengthEncoding lengthFormat, DecodingContext context, string[] formats, TimeSpanStyles style, IFormatProvider?provider, CancellationToken token) => EndOfStream <TimeSpan>();
ValueTask <DateTimeOffset> IAsyncBinaryReader.ReadDateTimeOffsetAsync(StringLengthEncoding lengthFormat, DecodingContext context, string[] formats, DateTimeStyles style, IFormatProvider?provider, CancellationToken token) => EndOfStream <DateTimeOffset>();
ValueTask <decimal> IAsyncBinaryReader.ReadDecimalAsync(StringLengthEncoding lengthFormat, DecodingContext context, NumberStyles style, IFormatProvider?provider, CancellationToken token) => EndOfStream <decimal>();