Commit 3899f19f authored by Joseph Larralde's avatar Joseph Larralde

serialization / deserialization now working in rapidPiPoHost

parent d688c72b
......@@ -131,7 +131,7 @@ RapidPiPoHost::toJSON()
{
Json::Value root;
/*
//*
root["docType"] = "rapid-mix:signal-processing";
root["docVersion"] = RAPIDMIX_JSON_DOC_VERSION;
......@@ -181,8 +181,40 @@ RapidPiPoHost::toJSON()
Json::Value param;
PiPo::Attr *a = this->graph->getAttr(i);
param["name"] = a->getName();
param["type"] = 0; // DO SOMETHING TO GET TYPES FROM PIPO IN A NICE WAY
param["value"] = a->getDbl(0);
switch (a->getType())
{
case PiPo::Bool:
param["type"] = "Bool";
param["value"] = a->getInt(0);
break;
case PiPo::Enum:
param["type"] = "Enum";
param["value"] = std::string(a->getStr(0));
break;
case PiPo::String:
param["type"] = "String";
param["value"] = std::string(a->getStr(0));
break;
case PiPo::Int:
param["type"] = "Int";
param["value"] = Json::Value(Json::arrayValue);
for (int i = 0; i < a->getSize(); ++i)
{
param["value"].append(a->getInt(i));
}
break;
case PiPo::Double:
param["type"] = "Double";
param["value"] = Json::Value(Json::arrayValue);
for (int i = 0; i < a->getSize(); ++i)
{
param["value"].append(a->getDbl(i));
}
break;
default:
std::cout << a->getType() << std::endl;
break;
}
params[i] = param;
}
......@@ -197,20 +229,52 @@ RapidPiPoHost::toJSON()
bool
RapidPiPoHost::fromJSON(Json::Value &jv)
{
/*
//*
if (jv["docType"].asString().compare("rapid-mix:signal-processing") == 0 &&
//jv["docVersion"].asString().compare(RAPIDMIX_JSON_DOC_VERSION) == 0 &&
jv["target"]["name"].asString().compare("pipo") == 0 &&
jv["payload"].size() > 0) {
this->setGraph(jv["pipodata"]["description"].asString());
this->setGraph(jv["payload"]["description"].asString());
Json::Value params = jv["payload"]["parameters"]
Json::Value params = jv["payload"]["parameters"];
unsigned int nAttrs = params.size();
for (unsigned int i = 0; i < nAttrs; ++i)
{
std::string type = params[i]["type"].asString();
const char *name = params[i]["name"].asString().c_str();
if (type.compare("Bool") == 0)
{
this->setAttr(name, params[i]["value"].asInt());
}
else if (type.compare("Enum") == 0 || type.compare("String") == 0)
{
this->setAttr(name, params[i]["value"].asString());
}
else if (type.compare("Int") == 0)
{
std::vector<int> values;
for (int j = 0; j < params[i]["value"].size(); ++j)
{
values.push_back(params[i]["value"][j].asInt());
}
this->setAttr(name, values);
}
else if (type.compare("Double") == 0)
{
std::vector<double> values;
for (int j = 0; j < params[i]["value"].size(); ++j)
{
values.push_back(params[i]["value"][j].asDouble());
}
this->setAttr(name, values);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment