Esempio n. 1
0
        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);
        }
Esempio n. 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));
        }
Esempio n. 3
0
 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);
Esempio n. 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);
Esempio n. 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);
Esempio n. 7
0
 ValueTask <Guid> IAsyncBinaryReader.ReadGuidAsync(StringLengthEncoding lengthFormat, DecodingContext context, string format, CancellationToken token)
 => StreamExtensions.ReadGuidAsync(input, lengthFormat, context, buffer, format, token);
Esempio n. 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);
Esempio n. 9
0
 public ValueTask <string> ReadStringAsync(StringLengthEncoding lengthFormat, DecodingContext context, CancellationToken token = default)
 => StreamExtensions.ReadStringAsync(input, lengthFormat, context, buffer, token);
Esempio n. 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);
Esempio n. 11
0
 /// <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);
Esempio n. 12
0
 ValueTask <Guid> IAsyncBinaryReader.ReadGuidAsync(StringLengthEncoding lengthFormat, DecodingContext context, string format, CancellationToken token)
 => EndOfStream <Guid>();
Esempio n. 13
0
 ValueTask <TimeSpan> IAsyncBinaryReader.ReadTimeSpanAsync(StringLengthEncoding lengthFormat, DecodingContext context, string[] formats, TimeSpanStyles style, IFormatProvider?provider, CancellationToken token)
 => EndOfStream <TimeSpan>();
Esempio n. 14
0
 ValueTask <DateTimeOffset> IAsyncBinaryReader.ReadDateTimeOffsetAsync(StringLengthEncoding lengthFormat, DecodingContext context, string[] formats, DateTimeStyles style, IFormatProvider?provider, CancellationToken token)
 => EndOfStream <DateTimeOffset>();
Esempio n. 15
0
 ValueTask <decimal> IAsyncBinaryReader.ReadDecimalAsync(StringLengthEncoding lengthFormat, DecodingContext context, NumberStyles style, IFormatProvider?provider, CancellationToken token)
 => EndOfStream <decimal>();