* @brief Runs the Lua parse function over a binary frame (1-indexed byte table). */
| 540 | * @brief Runs the Lua parse function over a binary frame (1-indexed byte table). |
| 541 | */ |
| 542 | QList<QStringList> DataModel::LuaScriptEngine::parseBinary(const QByteArray& frame) |
| 543 | { |
| 544 | Q_ASSERT(!frame.isEmpty()); |
| 545 | Q_ASSERT(m_state != nullptr); |
| 546 | |
| 547 | if (!m_loaded || m_disabled) |
| 548 | return {}; |
| 549 | |
| 550 | try { |
| 551 | lua_rawgeti(m_state, LUA_REGISTRYINDEX, m_parseRef); |
| 552 | |
| 553 | lua_createtable(m_state, frame.size(), 0); |
| 554 | const auto* data = reinterpret_cast<const quint8*>(frame.constData()); |
| 555 | for (int i = 0; i < frame.size(); ++i) { |
| 556 | lua_pushinteger(m_state, data[i]); |
| 557 | lua_rawseti(m_state, -2, i + 1); |
| 558 | } |
| 559 | |
| 560 | m_deadline.setRemainingTime(kRuntimeWatchdogMs); |
| 561 | const int status = guardedPcall(m_state, 1, 1, 0); |
| 562 | m_deadline = QDeadlineTimer(QDeadlineTimer::Forever); |
| 563 | |
| 564 | if (status != LUA_OK) [[unlikely]] { |
| 565 | const QString err = QString::fromUtf8(lua_tostring(m_state, -1)); |
| 566 | lua_pop(m_state, 1); |
| 567 | qWarning() << "[LuaScriptEngine] Parse error:" << err; |
| 568 | if (err.contains(QLatin1String("timed out"))) |
| 569 | (void)noteTimeoutAndCheckDisabled(0); |
| 570 | |
| 571 | return {}; |
| 572 | } |
| 573 | |
| 574 | resetTimeoutCounter(); |
| 575 | return convertResult(); |
| 576 | } catch (const std::exception& e) { |
| 577 | qWarning() << "[LuaScriptEngine] parseBinary uncaught exception:" << e.what(); |
| 578 | } catch (...) { |
| 579 | qWarning() << "[LuaScriptEngine] parseBinary uncaught non-std exception"; |
| 580 | } |
| 581 | |
| 582 | m_deadline = QDeadlineTimer(QDeadlineTimer::Forever); |
| 583 | lua_settop(m_state, 0); |
| 584 | return {}; |
| 585 | } |
| 586 | |
| 587 | //-------------------------------------------------------------------------------------------------- |
| 588 | // Result conversion |
nothing calls this directly
no test coverage detected