MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / readEndDelimitedFrames

Method readEndDelimitedFrames

app/src/IO/FrameReader.cpp:360–412  ·  view source on GitHub ↗

* @brief Extracts frames terminated by an end delimiter from the buffer. */

Source from the content-addressed store, hash-verified

358 * @brief Extracts frames terminated by an end delimiter from the buffer.
359 */
360void IO::FrameReader::readEndDelimitedFrames()
361{
362 Q_ASSERT(m_circularBuffer.capacity() > 0);
363 Q_ASSERT(!m_finishSequences.isEmpty());
364 Q_ASSERT(m_operationMode == SerialStudio::QuickPlot
365 || m_frameDetectionMode == SerialStudio::EndDelimiterOnly);
366
367 constexpr int kMaxFramesPerCall = 32768;
368 int iterations = 0;
369 while (iterations < kMaxFramesPerCall) {
370 ++iterations;
371
372 int endIndex = -1;
373 const QByteArray* delimiter = nullptr;
374
375 if (m_finishSequences.size() == 1) [[likely]] {
376 endIndex = m_circularBuffer.findPatternKMP(m_finishSequences[0], m_finishSequenceLps[0]);
377 delimiter = &m_finishSequences[0];
378 } else {
379 const auto match = m_circularBuffer.findFirstOfPatterns(m_finishSequences);
380 if (match.position >= 0) {
381 endIndex = match.position;
382 delimiter = &m_finishSequences[match.patternIndex];
383 }
384 }
385
386 if (endIndex == -1)
387 break;
388
389 CapturedDataPtr ptr;
390 CapturedData* cd = claimCapturedSlot(ptr);
391 m_circularBuffer.peekRangeInto(0, endIndex, cd->data);
392
393 const auto crcPosition = endIndex + delimiter->size();
394 const auto frameEndPos = crcPosition + m_checksumLength;
395 if (cd->data.isEmpty()) {
396 consumeBytes(frameEndPos);
397 continue;
398 }
399
400 const auto result = checksum(cd->data, crcPosition);
401 if (result == ValidationStatus::ChecksumIncomplete)
402 break;
403
404 if (result == ValidationStatus::FrameOk)
405 enqueueCaptured(std::move(ptr), cd, frameEndPos);
406 else
407 consumeBytes(frameEndPos);
408 }
409
410 if (iterations >= kMaxFramesPerCall) [[unlikely]]
411 qWarning() << "[FrameReader] Loop iteration limit reached in readEndDelimitedFrames";
412}
413
414/**
415 * @brief Extracts frames bounded by consecutive start delimiters.

Callers

nothing calls this directly

Calls 5

isEmptyMethod · 0.80
findPatternKMPMethod · 0.80
peekRangeIntoMethod · 0.80
capacityMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected