Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. private static SequencePosition ReadItems(in ReadOnlySequence<byte> sequence, bool isCompleted)
  2. {
  3. var reader = new SequenceReader<byte>(sequence);
  4.  
  5. while (!reader.End) // loop until we've read the entire sequence
  6. {
  7. if (reader.TryReadTo(out ReadOnlySpan<byte> itemBytes, Comma, advancePastDelimiter: true)) // we have an item to handle
  8. {
  9. var stringLine = Encoding.UTF8.GetString(itemBytes);
  10. Console.WriteLine(stringLine);
  11. }
  12. else if (isCompleted) // read last item which has no final delimiter
  13. {
  14. var stringLine = ReadLastItem(sequence.Slice(reader.Position));
  15. Console.WriteLine(stringLine);
  16. reader.Advance(sequence.Length); // advance reader to the end
  17. }
  18. else // no more items in this sequence
  19. {
  20. break;
  21. }
  22. }
  23.  
  24. return reader.Position;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement