LM: add JSON format support

This commit is contained in:
李通洲
2023-09-05 16:22:37 +08:00
parent 39b21f95b7
commit f9cd032a5f
2 changed files with 32 additions and 0 deletions
+31
View File
@@ -86,3 +86,34 @@ void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module)
ffPrintError(FF_LM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateLMJson(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFLMResult result;
ffStrbufInit(&result.service);
ffStrbufInit(&result.type);
ffStrbufInit(&result.version);
const char* error = ffDetectLM(&result);
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
goto exit;
}
if(result.service.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "No LM service found");
goto exit;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "service", &result.service);
yyjson_mut_obj_add_strbuf(doc, obj, "type", &result.type);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
exit:
ffStrbufDestroy(&result.service);
ffStrbufDestroy(&result.type);
ffStrbufDestroy(&result.version);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitLMOptions(FFLMOptions* options);
bool ffParseLMCommandOptions(FFLMOptions* options, const char* key, const char* value);
void ffDestroyLMOptions(FFLMOptions* options);
void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module);
void ffGenerateLMJson(FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);