Remove unnecessary constructor

Using cool smart pointers too wowie!
This commit is contained in:
ethanglide 2024-07-05 15:45:59 -04:00
parent 33d8277dc3
commit ed64fb05b1
3 changed files with 7 additions and 12 deletions

View File

@ -4,10 +4,6 @@
namespace eRPC
{
Response::Response() : msgid(-1), ok(false), result()
{
}
Response::Response(int msgid, bool ok, std::string result)
: msgid(msgid), ok(ok), result(result)
{

View File

@ -8,8 +8,6 @@ namespace eRPC
class Response
{
public:
Response();
/**
* Construct a response with the given message ID, status, and result.
*/

View File

@ -7,6 +7,7 @@
#include <stdexcept>
#include <unistd.h>
#include <iostream>
#include <memory>
namespace eRPC
{
@ -61,26 +62,26 @@ namespace eRPC
std::cout << "Received request:\n"
<< request.serialize() << std::endl;
Response response;
std::unique_ptr<Response> response;
if (methods.find(request.getMethod()) != methods.end())
{
std::function<void *()> method = methods[request.getMethod()];
method();
response = Response(
response = std::make_unique<Response>(Response(
request.getMsgid(),
true,
"RESULTS HERE");
"RESULTS HERE"));
}
else
{
response = Response(
response = std::make_unique<Response>(Response(
request.getMsgid(),
false,
"Method \"" + request.getMethod() + "\" not found");
"Method not found"));
}
std::string serialized = response.serialize();
std::string serialized = response->serialize();
write(connfd, serialized.c_str(), serialized.size() + 1);
close(connfd);