ethanglide
c9a50d363e
Got multiple remote calls from one client working Improved error messages Got function name and arguments sent over as well as return values
57 lines
941 B
C++
57 lines
941 B
C++
#include "Response.hpp"
|
|
|
|
#include <sstream>
|
|
|
|
namespace eRPC
|
|
{
|
|
Response::Response(int msgid, bool ok, std::string result)
|
|
: msgid(msgid), ok(ok), result(result)
|
|
{
|
|
}
|
|
|
|
Response::Response(std::string msg) : msgid(-1), ok(false), result()
|
|
{
|
|
std::string line;
|
|
std::istringstream iss(msg);
|
|
|
|
std::getline(iss, line);
|
|
if (line != "eRPC 1.0")
|
|
{
|
|
throw std::runtime_error("Invalid Response");
|
|
}
|
|
|
|
std::getline(iss, line);
|
|
msgid = std::stoi(line);
|
|
|
|
std::getline(iss, line);
|
|
ok = (line == "OK");
|
|
|
|
std::getline(iss, result);
|
|
}
|
|
|
|
std::string Response::serialize()
|
|
{
|
|
std::string msg = "eRPC 1.0\n";
|
|
|
|
msg += std::to_string(msgid) + "\n";
|
|
msg += ok ? "OK\n" : "ERROR\n";
|
|
msg += result;
|
|
|
|
return msg;
|
|
}
|
|
|
|
int Response::getMsgid()
|
|
{
|
|
return msgid;
|
|
}
|
|
|
|
bool Response::isOk()
|
|
{
|
|
return ok;
|
|
}
|
|
|
|
std::string Response::getResult()
|
|
{
|
|
return result;
|
|
}
|
|
} |