コード例 #1
0
ファイル: PipeExtensions.cs プロジェクト: woaisoft/dotNext
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 public ValueTask <string> ReadStringAsync(StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token)
 => EndOfStream <string>();
コード例 #4
0
 ValueTask <string> IAsyncBinaryReader.ReadStringAsync(StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token)
 => reader.ReadStringAsync(lengthFormat, context, token);
コード例 #5
0
 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);
コード例 #6
0
 ValueTask <DateTimeOffset> IAsyncBinaryReader.ReadDateTimeOffsetAsync(StringLengthEncoding lengthFormat, DecodingContext context, DateTimeStyles style, IFormatProvider?provider, CancellationToken token)
 => StreamExtensions.ReadDateTimeOffsetAsync(input, lengthFormat, context, buffer, style, provider, token);
コード例 #7
0
 ValueTask <Guid> IAsyncBinaryReader.ReadGuidAsync(StringLengthEncoding lengthFormat, DecodingContext context, string format, CancellationToken token)
 => StreamExtensions.ReadGuidAsync(input, lengthFormat, context, buffer, format, token);
コード例 #8
0
 ValueTask <double> IAsyncBinaryReader.ReadDoubleAsync(StringLengthEncoding lengthFormat, DecodingContext context, NumberStyles style, IFormatProvider?provider, CancellationToken token)
 => StreamExtensions.ReadDoubleAsync(input, lengthFormat, context, buffer, style, provider, token);
コード例 #9
0
 public ValueTask <string> ReadStringAsync(StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token = default)
 => StreamExtensions.ReadStringAsync(input, lengthFormat, context, buffer, token);
コード例 #10
0
 ValueTask IAsyncBinaryWriter.WriteTimeSpanAsync(TimeSpan value, StringLengthEncoding lengthFormat, EncodingContext context, string?format, IFormatProvider?provider, CancellationToken token)
 => output.WriteTimeSpanAsync(value, lengthFormat, context, buffer, format, provider, token);
コード例 #11
0
ファイル: PipeExtensions.cs プロジェクト: woaisoft/dotNext
 /// <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);
コード例 #12
0
 ValueTask <Guid> IAsyncBinaryReader.ReadGuidAsync(StringLengthEncoding lengthFormat, DecodingContext context, string format, CancellationToken token)
 => EndOfStream <Guid>();
コード例 #13
0
 ValueTask <TimeSpan> IAsyncBinaryReader.ReadTimeSpanAsync(StringLengthEncoding lengthFormat, DecodingContext context, string[] formats, TimeSpanStyles style, IFormatProvider?provider, CancellationToken token)
 => EndOfStream <TimeSpan>();
コード例 #14
0
 ValueTask <DateTimeOffset> IAsyncBinaryReader.ReadDateTimeOffsetAsync(StringLengthEncoding lengthFormat, DecodingContext context, string[] formats, DateTimeStyles style, IFormatProvider?provider, CancellationToken token)
 => EndOfStream <DateTimeOffset>();
コード例 #15
0
 ValueTask <decimal> IAsyncBinaryReader.ReadDecimalAsync(StringLengthEncoding lengthFormat, DecodingContext context, NumberStyles style, IFormatProvider?provider, CancellationToken token)
 => EndOfStream <decimal>();