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

Method parserGetCode

app/src/API/Handlers/ProjectHandler.cpp:2998–3035  ·  view source on GitHub ↗

* @brief Get frame parser code for a source. */

Source from the content-addressed store, hash-verified

2996 * @brief Get frame parser code for a source.
2997 */
2998API::CommandResponse API::Handlers::ProjectHandler::parserGetCode(const QString& id,
2999 const QJsonObject& params)
3000{
3001 const int sourceId = params.contains(Keys::SourceId) ? params.value(Keys::SourceId).toInt() : 0;
3002 const auto& model = DataModel::ProjectModel::instance();
3003 const int srcCount = static_cast<int>(model.sources().size());
3004
3005 if (sourceId < 0 || sourceId >= srcCount)
3006 return CommandResponse::makeError(
3007 id, ErrorCode::InvalidParam, QStringLiteral("Invalid sourceId"));
3008
3009 QString code =
3010 sourceId == 0 ? model.frameParserCode() : model.sources()[sourceId].frameParserCode;
3011
3012 QJsonObject result;
3013 result[Keys::SourceId] = sourceId;
3014 result[QStringLiteral("language")] = model.frameParserLanguage(sourceId);
3015
3016 if (model.frameParserLanguage(sourceId) == SerialStudio::Native) {
3017 QString template_id = model.frameParserTemplate(sourceId);
3018 if (template_id.isEmpty())
3019 template_id = DataModel::defaultNativeTemplateId();
3020
3021 QJsonObject template_params = model.frameParserParams(sourceId);
3022 if (template_params.isEmpty()) {
3023 if (const auto* tmpl = DataModel::nativeTemplateById(template_id))
3024 template_params = DataModel::nativeTemplateDefaults(*tmpl);
3025 }
3026
3027 code = DataModel::CFrameParser::buildDescriptor(template_id, template_params);
3028 result[QStringLiteral("template")] = template_id;
3029 result[QStringLiteral("params")] = template_params;
3030 }
3031
3032 result[QStringLiteral("code")] = code;
3033 result[QStringLiteral("codeLength")] = code.length();
3034 return CommandResponse::makeSuccess(id, result);
3035}
3036
3037/**
3038 * @brief Set the scripting language for a frame parser source.

Callers

nothing calls this directly

Calls 9

frameParserCodeMethod · 0.80
frameParserLanguageMethod · 0.80
frameParserTemplateMethod · 0.80
isEmptyMethod · 0.80
frameParserParamsMethod · 0.80
lengthMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected