public void SequencePositionOfMultiSegment() { var(first, last) = BufferList.Create( new byte[] { 1, 2 }, new byte[] { 3, 4 } ); var bytes = new ReadOnlySequence <byte>(first, 0, last, last.Memory.Length); Assert.Equal(4, bytes.Length); // Static method call to avoid calling instance methods Assert.False(Sequence.PositionOf(bytes, 0).HasValue); for (int i = 0; i < bytes.Length; i++) { var value = (byte)(i + 1); var listPosition = MemoryListExtensions.PositionOf(first, value).GetValueOrDefault(); var(node, index) = listPosition.Get <IMemoryList <byte> >(); if (listPosition != default) { Assert.Equal(value, node.Memory.Span[index]); } var robPosition = BuffersExtensions.PositionOf(bytes, value); var robSequencePosition = Sequence.PositionOf(bytes, value); Assert.Equal(listPosition, robPosition); Assert.Equal(listPosition, robSequencePosition); var robSlice = bytes.Slice(1); robPosition = BuffersExtensions.PositionOf(robSlice, value); robSequencePosition = Sequence.PositionOf(robSlice, value); if (i > 0) { Assert.Equal(listPosition, robPosition); Assert.Equal(listPosition, robSequencePosition); } else { Assert.False(robPosition.HasValue); Assert.False(robSequencePosition.HasValue); } if (listPosition != default) { robSlice = bytes.Slice(listPosition); Assert.Equal(value, robSlice.First.Span[0]); } } }
public void SequencePositionOfMultiSegment() { var(first, last) = MemoryList.Create( new byte[] { 1, 2 }, new byte[] { 3, 4 } ); var bytes = new ReadOnlyBytes(first, last); Assert.Equal(4, bytes.Length); // Static method call to avoid calling instance methods Assert.Equal(Position.End, Sequence.PositionOf(bytes, 0)); for (int i = 0; i < bytes.Length; i++) { var value = (byte)(i + 1); var listPosition = MemoryListExtensions.PositionOf(first, value); var(node, index) = listPosition.Get <IMemoryList <byte> >(); if (!listPosition.IsEnd) { Assert.Equal(value, node.Memory.Span[index]); } var robPosition = bytes.PositionOf(value); var robSequencePosition = Sequence.PositionOf(bytes, value); Assert.Equal(listPosition, robPosition); Assert.Equal(listPosition, robSequencePosition); var robSlice = bytes.Slice(1); robPosition = robSlice.PositionOf(value); robSequencePosition = Sequence.PositionOf(robSlice, value); if (i > 0) { Assert.Equal(listPosition, robPosition); Assert.Equal(listPosition, robSequencePosition); } else { Assert.Equal(Position.End, robPosition); Assert.Equal(Position.End, robSequencePosition); } if (listPosition != Position.End) { robSlice = bytes.Slice(listPosition); Assert.Equal(value, robSlice.Memory.Span[0]); } } }
public void SequencePositionOfMultiSegment() { var(first, last) = BufferList.Create( new byte[] { 1, 2 }, new byte[] { 3, 4 } ); var bytes = new ReadOnlySequence <byte>(first, 0, last, last.Memory.Length); Assert.Equal(4, bytes.Length); // Static method call to avoid calling instance methods Assert.False(Sequence.PositionOf(bytes, 0).HasValue); for (int i = 0; i < bytes.Length; i++) { var value = (byte)(i + 1); var listPosition = MemoryListExtensions.PositionOf(first, value).GetValueOrDefault(); var(node, index) = listPosition.Get <ReadOnlySequenceSegment <byte> >(); if (listPosition.Equals(default))