internal static ByteSpan SliceTo(ByteSpan buffer, byte terminatorFirst, byte terminatorSecond, out int consumedBytes) { int index = 0; while (index < buffer.Length) { if (buffer[index] == terminatorFirst && buffer.Length > index + 1 && buffer[index + 1] == terminatorSecond) { consumedBytes = index + 2; return buffer.Slice(0, index); } index++; } consumedBytes = 0; unsafe { return new ByteSpan(null, 0); // TODO: Empty instance should be used } }