Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static SequencePosition ReadItems(in ReadOnlySequence<byte> sequence, bool isCompleted)
- {
- var reader = new SequenceReader<byte>(sequence);
- while (!reader.End) // loop until we've read the entire sequence
- {
- if (reader.TryReadTo(out ReadOnlySpan<byte> itemBytes, Comma, advancePastDelimiter: true)) // we have an item to handle
- {
- var stringLine = Encoding.UTF8.GetString(itemBytes);
- Console.WriteLine(stringLine);
- }
- else if (isCompleted) // read last item which has no final delimiter
- {
- var stringLine = ReadLastItem(sequence.Slice(reader.Position));
- Console.WriteLine(stringLine);
- reader.Advance(sequence.Length); // advance reader to the end
- }
- else // no more items in this sequence
- {
- break;
- }
- }
- return reader.Position;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement