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

Method writeRawBytes

app/src/Sessions/Export.cpp:487–521  ·  view source on GitHub ↗

* @brief Drains the raw bytes queue and writes entries to the database. */

Source from the content-addressed store, hash-verified

485 * @brief Drains the raw bytes queue and writes entries to the database.
486 */
487void Sessions::ExportWorker::writeRawBytes()
488{
489 Q_ASSERT(m_dbOpen);
490
491 if (!m_db || !m_rawBytesQuery) [[unlikely]]
492 return;
493
494 constexpr size_t kMaxRawBatch = 1000;
495 TimestampedRawBytes entry;
496 size_t count = 0;
497
498 m_db->transaction();
499 while (count < kMaxRawBatch && m_rawQueue->try_dequeue(entry)) {
500 const auto elapsed = entry.data->timestamp - m_steadyBaseline;
501 qint64 ns = std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
502
503 if (ns < 0) [[unlikely]]
504 ns = 0;
505 if (ns <= m_lastRawBytesNs)
506 ns = m_lastRawBytesNs + 1;
507
508 m_lastRawBytesNs = ns;
509
510 m_rawBytesQuery->bindValue(0, m_sessionId);
511 m_rawBytesQuery->bindValue(1, ns);
512 m_rawBytesQuery->bindValue(2, entry.deviceId);
513 m_rawBytesQuery->bindValue(3, entry.data ? entry.data->data : QByteArray());
514
515 if (!m_rawBytesQuery->exec()) [[unlikely]]
516 qWarning() << "[SQLite] Insert raw_bytes failed:" << m_rawBytesQuery->lastError().text();
517
518 ++count;
519 }
520 m_db->commit();
521}
522
523/**
524 * @brief Drains the table snapshot queue and writes register changes to the database.

Callers

nothing calls this directly

Calls 6

execMethod · 0.80
commitMethod · 0.80
try_dequeueMethod · 0.45
countMethod · 0.45
textMethod · 0.45
lastErrorMethod · 0.45

Tested by

no test coverage detected