Can someone provide a short example of how to implement bi-directional 
streams with c++ and CapnProto? Thanks!

>From my understanding the server to client direction should look something 
like this, please correct me if I'm wrong :)

interface PointStream { 
# Define some point streaming interface.

next @0 (point :PointXYZI) -> stream;
# Server will call this to submit points.

done @1 ();
# Once the stream is done this will be called.
} 

pointStream @0 (callback :PointStream) -> (); 
# Define a function to get the point stream.


// 
=======================================================================================
class PointStreamImpl : public Scan::PointStream::Server {
// An implementation of the PointStream interface wrapping next() and 
done().
// We're implementing this on the client side and will pass a reference to
// the server. The server will then be able to make calls back to the 
client.

public:
PointStreamImpl() : doneCalled(false) {}

kj::Promise<void> next(NextContext context) {
KJ_REQUIRE(!doneCalled, "called next() after done()");
auto point = context.getParams().getPoint();

                // ... do something with the point

return kj::READY_NOW;
}

kj::Promise<void> done(NextContext context) {
KJ_REQUIRE(!doneCalled, "can only call done() once");
doneCalled = true;
return kj::READY_NOW;
}

private:
bool doneCalled;
};

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/543a14f3-216c-44d4-bfd6-4a6cf43f4a77%40googlegroups.com.

Reply via email to