Exemplo n.º 1
0
        public static ValueTask <T> DeserializeAsync <T>(
            PipeReader reader,
            CborOptions?options     = null,
            CancellationToken token = default)
        {
            ValueTask <ReadOnlySequence <byte> > task = reader.FullReadAsync(token);

            if (task.IsCompletedSuccessfully)
            {
                ReadOnlySequence <byte> sequence = task.Result;
                T result = Deserialize <T>(sequence.GetSpan(), options);
                reader.AdvanceTo(sequence.End);
                return(new ValueTask <T>(result));
            }

            return(FinishDeserializeAsync(task));

            async ValueTask <T> FinishDeserializeAsync(ValueTask <ReadOnlySequence <byte> > localTask)
            {
                ReadOnlySequence <byte> sequence = await localTask.ConfigureAwait(false);

                T result = Deserialize <T>(sequence.GetSpan(), options);

                reader.AdvanceTo(sequence.End);
                return(result);
            }
        }