Mercurial > hg > piper-cpp
diff utilities/vampipe-server.cpp @ 73:7bfc07576830
Ensure id is passed through properly in convert and in server
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 10 Oct 2016 15:03:47 +0100 |
parents | a5ba837bca28 |
children |
line wrap: on
line diff
--- a/utilities/vampipe-server.cpp Fri Oct 07 16:43:18 2016 +0100 +++ b/utilities/vampipe-server.cpp Mon Oct 10 15:03:47 2016 +0100 @@ -30,6 +30,38 @@ static CountingPluginHandleMapper mapper; +static RequestOrResponse::RpcId readId(const RpcRequest::Reader &r) +{ + int number; + string tag; + switch (r.getId().which()) { + case RpcRequest::Id::Which::NUMBER: + number = r.getId().getNumber(); + return { RequestOrResponse::RpcId::Number, number, "" }; + case RpcRequest::Id::Which::TAG: + tag = r.getId().getTag(); + return { RequestOrResponse::RpcId::Tag, 0, tag }; + case RpcRequest::Id::Which::NONE: + return { RequestOrResponse::RpcId::Absent, 0, "" }; + } + return {}; +} + +static void buildId(RpcResponse::Builder &b, const RequestOrResponse::RpcId &id) +{ + switch (id.type) { + case RequestOrResponse::RpcId::Number: + b.getId().setNumber(id.number); + break; + case RequestOrResponse::RpcId::Tag: + b.getId().setTag(id.tag); + break; + case RequestOrResponse::RpcId::Absent: + b.getId().setNone(); + break; + } +} + RequestOrResponse readRequestCapnp() { @@ -48,6 +80,7 @@ RpcRequest::Reader reader = message.getRoot<RpcRequest>(); rr.type = VampnProto::getRequestResponseType(reader); + rr.id = readId(reader); switch (rr.type) { @@ -80,6 +113,8 @@ ::capnp::MallocMessageBuilder message; RpcResponse::Builder builder = message.initRoot<RpcResponse>(); + buildId(builder, rr.id); + if (!rr.success) { VampnProto::buildRpcResponse_Error(builder, rr.errorText, rr.type); @@ -240,6 +275,7 @@ } RequestOrResponse response = handleRequest(request); + response.id = request.id; cerr << "vampipe-server: request handled, writing response" << endl;