* @brief Extracts frames bounded by consecutive start delimiters. */
| 415 | * @brief Extracts frames bounded by consecutive start delimiters. |
| 416 | */ |
| 417 | void IO::FrameReader::readStartDelimitedFrames() |
| 418 | { |
| 419 | Q_ASSERT(!m_startSequences.isEmpty()); |
| 420 | Q_ASSERT(!m_startSequenceLps.isEmpty()); |
| 421 | Q_ASSERT(m_circularBuffer.capacity() > 0); |
| 422 | |
| 423 | const auto& startSeq = m_startSequences[0]; |
| 424 | const auto& startLps = m_startSequenceLps[0]; |
| 425 | |
| 426 | constexpr int kMaxFramesPerCall = 32768; |
| 427 | int iterations = 0; |
| 428 | while (iterations < kMaxFramesPerCall) { |
| 429 | ++iterations; |
| 430 | |
| 431 | int startIndex = m_circularBuffer.findPatternKMP(startSeq, startLps); |
| 432 | if (startIndex == -1) |
| 433 | break; |
| 434 | |
| 435 | if (startIndex > 0) |
| 436 | consumeBytes(startIndex); |
| 437 | |
| 438 | int nextStartIndex = m_circularBuffer.findPatternKMP(startSeq, startLps, startSeq.size()); |
| 439 | if (nextStartIndex == -1) |
| 440 | break; |
| 441 | |
| 442 | qsizetype frameStart = startSeq.size(); |
| 443 | qsizetype frameEndPos = nextStartIndex; |
| 444 | qsizetype frameLength = frameEndPos - frameStart; |
| 445 | |
| 446 | if (frameLength <= 0) { |
| 447 | consumeBytes(frameEndPos); |
| 448 | continue; |
| 449 | } |
| 450 | |
| 451 | const auto crcPosition = frameEndPos - m_checksumLength; |
| 452 | if (crcPosition < frameStart) { |
| 453 | consumeBytes(frameEndPos); |
| 454 | continue; |
| 455 | } |
| 456 | |
| 457 | CapturedDataPtr ptr; |
| 458 | CapturedData* cd = claimCapturedSlot(ptr); |
| 459 | m_circularBuffer.peekRangeInto(frameStart, frameLength - m_checksumLength, cd->data); |
| 460 | if (cd->data.isEmpty()) { |
| 461 | consumeBytes(frameEndPos); |
| 462 | continue; |
| 463 | } |
| 464 | |
| 465 | const auto result = checksum(cd->data, crcPosition); |
| 466 | if (result == ValidationStatus::ChecksumIncomplete) |
| 467 | break; |
| 468 | |
| 469 | if (result == ValidationStatus::FrameOk) |
| 470 | enqueueCaptured(std::move(ptr), cd, frameEndPos); |
| 471 | else |
| 472 | consumeBytes(frameEndPos); |
| 473 | } |
| 474 |
nothing calls this directly
no test coverage detected