Local API binary output support + qml image example

This commit is contained in:
Gioacchino Mazzurco 2017-05-18 21:57:24 +02:00
parent e59366d0fd
commit db3dad3e23
2 changed files with 53 additions and 2 deletions

View file

@ -105,9 +105,17 @@ readPath:
resource_api::Request req(reqJson);
req.mMethod = reqMeth;
req.setPath(reqPath);
std::string resultString = mApiServer->handleRequest(req);
mLocalSocket->write(resultString.c_str(), resultString.length());
// Need this idiom because binary result may contains \0
std::string&& resultString = mApiServer->handleRequest(req);
QByteArray rB(resultString.data(), resultString.length());
// Dirty trick to support avatars answers
if(rB.contains("\n") || !rB.startsWith("{") || !rB.endsWith("}"))
mLocalSocket->write(rB.toBase64());
else mLocalSocket->write(rB);
mLocalSocket->write("\n\0");
mState = WAITING_PATH;
/* Because QLocalSocket is SOCK_STREAM some clients implementations