Skip to content

Commit

Permalink
Fixed regression
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 12, 2024
1 parent 33ca241 commit 78ad1f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/DotNext.IO/Buffers/BufferReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal static SequencePosition Append<TParser>(this ref TParser parser, in Rea
where TParser : struct, IBufferReader
{
var position = input.Start;
for (int consumedBytes, remainingBytes; (remainingBytes = parser.RemainingBytes) > 0; position = input.GetPosition(consumedBytes, position))
for (int consumedBytes, remainingBytes; (remainingBytes = parser.RemainingBytes) > 0 && input.TryGet(ref position, out var block, advance: false) && !block.IsEmpty; position = input.GetPosition(consumedBytes, position))
{
var block = input.NextBlock(ref position).TrimLength(remainingBytes);
parser.Invoke(block);
block = block.TrimLength(remainingBytes);
parser.Invoke(block.Span);
consumedBytes = block.Length;
}

Expand All @@ -28,7 +28,4 @@ internal static void EndOfStream<TParser>(this ref TParser parser)
internal static TResult EndOfStream<TResult, TParser>(this ref TParser parser)
where TParser : struct, IBufferReader, ISupplier<TResult>
=> parser.RemainingBytes is 0 || !TParser.ThrowOnPartialData ? parser.Invoke() : throw new EndOfStreamException();

private static ReadOnlySpan<byte> NextBlock(this in ReadOnlySequence<byte> sequence, ref SequencePosition position)
=> sequence.TryGet(ref position, out var block, advance: false) && !block.IsEmpty ? block.Span : throw new EndOfStreamException();
}
2 changes: 1 addition & 1 deletion src/DotNext.Tests/IO/Pipelines/PipeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public static async Task EncodeDecodeValue2()
{
static async void WriteValueAsync(PipeWriter writer)
{
writer.WriteLittleEndian(0L);
writer.WriteLittleEndian(20L);
writer.WriteLittleEndian(0L);
await writer.FlushAsync();
await writer.CompleteAsync();
}
Expand Down

0 comments on commit 78ad1f9

Please sign in to comment.