/// <summary>
/// The underlying <see cref="ReadOnlySequence{T}"/> for the reader.
/// </summary>
- public readonly ReadOnlySequence<T> Sequence { get; }
+ public ReadOnlySequence<T> Sequence { get; }
/// <summary>
/// Gets the unread portion of the <see cref="Sequence"/>.
/// <summary>
/// The current segment in the <see cref="Sequence"/> as a span.
/// </summary>
- public ReadOnlySpan<T> CurrentSpan { readonly get; private set; }
+ public ReadOnlySpan<T> CurrentSpan { get; private set; }
/// <summary>
/// The index in the <see cref="CurrentSpan"/>.
/// </summary>
- public int CurrentSpanIndex { readonly get; private set; }
+ public int CurrentSpanIndex { get; private set; }
/// <summary>
/// The unread portion of the <see cref="CurrentSpan"/>.
/// <summary>
/// The total number of <typeparamref name="T"/>'s processed by the reader.
/// </summary>
- public long Consumed { readonly get; private set; }
+ public long Consumed { get; private set; }
/// <summary>
/// Remaining <typeparamref name="T"/>'s in the reader's <see cref="Sequence"/>.
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
}
+ if (count == 0)
+ {
+ return;
+ }
+
Consumed -= count;
if (CurrentSpanIndex >= count)
reader.Rewind(2);
Assert.Equal(new byte[] { 1, 2 }, reader.CurrentSpan.ToArray());
}
+
+ [Fact]
+ public void RewindZero_DoesNothing()
+ {
+ var emptySeq = ReadOnlySequence<byte>.Empty;
+ var reader = new SequenceReader<byte>(emptySeq);
+
+ Assert.True(reader.End);
+ Assert.False(reader.TryRead(out byte _));
+
+ reader.Rewind(0);
+
+ Assert.True(reader.End);
+ Assert.False(reader.TryRead(out byte _));
+ }
}
}