2022-03-23 21:51:55 +00:00
|
|
|
#include "convert/convert.h"
|
2022-03-23 05:26:25 +00:00
|
|
|
|
|
|
|
struct ConvertEngine {
|
|
|
|
ConvertBuildf build;
|
|
|
|
ConvertRunf run;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct ConvertEngine kEngines[][2] = {
|
|
|
|
{{Convert1fBuild, Convert1fRun}, {Convert1rBuild, Convert1rRun}}};
|
|
|
|
|
|
|
|
int ConverterBuild(struct Converter *c, Handle data, Size datasz,
|
2022-03-25 17:33:24 +00:00
|
|
|
ConvertDirection direction)
|
2022-03-23 05:26:25 +00:00
|
|
|
{
|
2022-03-25 17:33:24 +00:00
|
|
|
int engine;
|
2022-03-23 05:26:25 +00:00
|
|
|
const struct ConvertEngine *funcs;
|
|
|
|
Handle out;
|
2022-03-25 17:33:24 +00:00
|
|
|
ErrorCode err;
|
2022-03-23 05:26:25 +00:00
|
|
|
|
|
|
|
if (datasz == 0) {
|
|
|
|
return kErrorBadData;
|
|
|
|
}
|
2022-03-25 17:33:24 +00:00
|
|
|
engine = (UInt8)(**data) - 1;
|
2022-03-23 05:26:25 +00:00
|
|
|
if (engine < 0 || (int)(sizeof(kEngines) / sizeof(*kEngines)) <= engine) {
|
|
|
|
/* Invalid engine. */
|
|
|
|
return kErrorBadData;
|
|
|
|
}
|
|
|
|
funcs = &kEngines[engine][direction];
|
|
|
|
if (funcs->build == NULL || funcs->run == NULL) {
|
|
|
|
/* Invalid engine. */
|
|
|
|
return kErrorBadData;
|
|
|
|
}
|
2022-03-25 17:33:24 +00:00
|
|
|
err = funcs->build(&out, data, datasz);
|
|
|
|
if (err != 0) {
|
|
|
|
return err;
|
2022-03-23 05:26:25 +00:00
|
|
|
}
|
|
|
|
c->data = out;
|
|
|
|
c->run = funcs->run;
|
|
|
|
return 0;
|
|
|
|
}
|