Skip to content

Commit

Permalink
Flatten internal non-exception replies for #7
Browse files Browse the repository at this point in the history
  • Loading branch information
GothAck committed Feb 28, 2020
1 parent 954885d commit 9e9e20a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
27 changes: 14 additions & 13 deletions compiler/flatrpcc_inja/flatrpc.cpp.inja
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,25 @@ void {{ service.nameClient }}::makeRequest(
TResponsePromiseVar &&resProm
) {
thread_local LocalSocket socket(_context, zmqpp::socket_type::dealer);
auto nativeReq = make_shared<TIntNative>();
nativeReq->requestId = nextRequestId(move(resProm), callName);
nativeReq->type = RPCType::CLIENT_REQ;
nativeReq->name = callName;
nativeReq->data = visit(overloaded {

auto buf = packInt(
nextRequestId(move(resProm), callName),
RPCType::CLIENT_REQ,
callName,
visit(overloaded {
## for request in service.requests
[&]({{ request.local }}TPtr &ptr) {
flatbuffers::FlatBufferBuilder fbb;
[&]({{ request.local }}TPtr &ptr) {
flatbuffers::FlatBufferBuilder fbb;

auto rep = {{ request.cpp }}::Pack(fbb, ptr.get());
fbb.Finish(rep);
auto rep = {{ request.cpp }}::Pack(fbb, ptr.get());
fbb.Finish(rep);

return vector<signed char>(fbb.GetBufferPointer(), fbb.GetBufferPointer() + fbb.GetSize());
},
return vector<signed char>(fbb.GetBufferPointer(), fbb.GetBufferPointer() + fbb.GetSize());
},
## endfor
}, req);
}, req)
);

auto buf = packInt(nativeReq);
zmqpp::message msg;
msg << "";
msg << buf;
Expand Down
2 changes: 2 additions & 0 deletions rpc/include/flatrpc/rpcbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class RpcBase : public RpcSockets, public virtual RpcRunnable {
TIntNativePtr unpackInt(std::string &&data);

std::string packInt(TIntNativePtr nativePtr);
std::string packInt(uint64_t requestId, quteos::rpc::RPCType type, const std::string& name, std::vector<signed char> data);
std::string packInt(uint64_t requestId, quteos::rpc::RPCType type, const std::string& name, std::exception &exception);

TIntNativePtr makeReply(TIntNativePtr req);

Expand Down
26 changes: 26 additions & 0 deletions rpc/rpcbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using namespace std;
using namespace zmqpp;
using namespace flatbuffers;
using namespace quteos::rpc;

RpcBase::RpcBase(zmqpp::context &ctx, zmqpp
::socket_type type) :
Expand Down Expand Up @@ -156,3 +158,27 @@ void RpcBase::stop() {
void RpcBase::joinReactor() {
_reactorThread.join();
}

std::string RpcBase::packInt(uint64_t requestId, quteos::rpc::RPCType type, const std::string& name, std::vector<signed char> data) {
FlatBufferBuilder fbb;
auto fbbName = fbb.CreateString(name);
auto fbbData = fbb.CreateVector<int8_t>(data);

auto rpc = CreateRPC(fbb, requestId, type, fbbName, fbbData);
fbb.Finish(rpc);

return {fbb.GetBufferPointer(), fbb.GetBufferPointer() + fbb.GetSize()};
}

std::string RpcBase::packInt(uint64_t requestId, quteos::rpc::RPCType type, const std::string& name, std::exception &exception) {
FlatBufferBuilder fbb;
auto fbbName = fbb.CreateString(name);
auto fbbWhat = fbb.CreateString(exception.what());
auto fbbException = CreateException(fbb, fbbWhat);


auto rpc = CreateRPC(fbb, requestId, type, fbbName, 0, fbbException);
fbb.Finish(rpc);

return {fbb.GetBufferPointer(), fbb.GetBufferPointer() + fbb.GetSize()};
}

0 comments on commit 9e9e20a

Please sign in to comment.