# HG changeset patch # User Chris Cannam # Date 1464095398 -3600 # Node ID 7062a3bebaa32b84d6c32ef1a02814fa7b0e7d96 # Parent b5005ebc5116f94cbc3d6b1d4f5ce13a70557423 Capnp writes diff -r b5005ebc5116 -r 7062a3bebaa3 utilities/vampipe-convert.cpp --- a/utilities/vampipe-convert.cpp Tue May 24 14:09:54 2016 +0100 +++ b/utilities/vampipe-convert.cpp Tue May 24 14:09:58 2016 +0100 @@ -305,6 +305,42 @@ return rr; } +void +writeRequestCapnp(RequestOrResponse &rr) +{ + ::capnp::MallocMessageBuilder message; + VampRequest::Builder builder = message.initRoot(); + + switch (rr.type) { + + case RRType::List: + VampnProto::buildVampRequest_List(builder); + break; + case RRType::Load: + VampnProto::buildVampRequest_Load(builder, rr.loadRequest); + break; + case RRType::Configure: + VampnProto::buildVampRequest_Configure(builder, + rr.configurationRequest, + rr.mapper); + break; + case RRType::Process: + VampnProto::buildVampRequest_Process(builder, + rr.processRequest, + rr.mapper); + break; + case RRType::Finish: + VampnProto::buildVampRequest_Finish(builder, + rr.finishPlugin, + rr.mapper); + break; + case RRType::NotValid: + break; + } + + writePackedMessageToFd(1, message); +} + RequestOrResponse readResponseCapnp() { @@ -341,6 +377,36 @@ return rr; } +void +writeResponseCapnp(RequestOrResponse &rr) +{ + ::capnp::MallocMessageBuilder message; + VampResponse::Builder builder = message.initRoot(); + + switch (rr.type) { + + case RRType::List: + VampnProto::buildVampResponse_List(builder, "", rr.listResponse); + break; + case RRType::Load: + VampnProto::buildVampResponse_Load(builder, rr.loadResponse, rr.mapper); + break; + case RRType::Configure: + VampnProto::buildVampResponse_Configure(builder, rr.configurationResponse); + break; + case RRType::Process: + VampnProto::buildVampResponse_Process(builder, rr.processResponse); + break; + case RRType::Finish: + VampnProto::buildVampResponse_Finish(builder, rr.finishResponse); + break; + case RRType::NotValid: + break; + } + + writePackedMessageToFd(1, message); +} + RequestOrResponse readInput(string format, RequestOrResponse::Direction direction) { @@ -370,6 +436,12 @@ } else { writeResponseJson(rr); } + } else if (format == "capnp") { + if (rr.direction == RequestOrResponse::Request) { + writeRequestCapnp(rr); + } else { + writeResponseCapnp(rr); + } } else { throw runtime_error("unknown output format \"" + format + "\""); } @@ -420,7 +492,10 @@ try { RequestOrResponse rr = readInput(informat, direction); + + // NotValid without an exception indicates EOF: if (rr.type == RRType::NotValid) break; + writeOutput(outformat, rr); } catch (std::exception &e) {