我有一个类型的缓冲区ReadOnlySequence<byte>。我想提取的亚序列(其中将包含0 - n条消息)通过知道从它与每一个消息结束0x1c, 0x0d(如所描述的在这里)。
我知道缓冲区有一个扩展方法PositionOf但它
返回第一次出现的位置
item的ReadOnlySequence<T>。
我正在寻找一种方法来返回最后一次出现的位置。我试图自己实现它,这是我迄今为止所拥有的
private SequencePosition? GetLastPosition(ReadOnlySequence<byte> buffer)
{
// Do not modify the real buffer
ReadOnlySequence<byte> temporaryBuffer = buffer;
SequencePosition? lastPosition = null;
do
{
/*
Find the first occurence of the delimiters in the buffer
This only takes a byte, what to do with the delimiters? { 0x1c, 0x0d }
*/
SequencePosition? foundPosition = temporaryBuffer.PositionOf(???);
// Is there still an occurence?
if (foundPosition …Run Code Online (Sandbox Code Playgroud)