Swap: JSON format support

This commit is contained in:
李通洲
2023-09-06 16:01:10 +08:00
parent 8bb88d1806
commit a7c6e1165c
2 changed files with 18 additions and 1 deletions
+17 -1
View File
@@ -75,7 +75,7 @@ void ffPrintSwap(FFSwapOptions* options)
void ffInitSwapOptions(FFSwapOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SWAP_MODULE_NAME, ffParseSwapCommandOptions, ffParseSwapJsonObject, ffPrintSwap, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SWAP_MODULE_NAME, ffParseSwapCommandOptions, ffParseSwapJsonObject, ffPrintSwap, ffGenerateSwapJson);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -110,3 +110,19 @@ void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module)
ffPrintError(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateSwapJson(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFSwapResult storage;
const char* error = ffDetectSwap(&storage);
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_uint(doc, obj, "total", storage.bytesTotal);
yyjson_mut_obj_add_uint(doc, obj, "used", storage.bytesUsed);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitSwapOptions(FFSwapOptions* options);
bool ffParseSwapCommandOptions(FFSwapOptions* options, const char* key, const char* value);
void ffDestroySwapOptions(FFSwapOptions* options);
void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module);
void ffGenerateSwapJson(FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);