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 namespace eRPC
{ {
Response::Response() : msgid(-1), ok(false), result()
{
}
Response::Response(int msgid, bool ok, std::string result) Response::Response(int msgid, bool ok, std::string result)
: msgid(msgid), ok(ok), result(result) : msgid(msgid), ok(ok), result(result)
{ {

View File

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

View File

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