EDIT: Support for "delimited" format is now part of the official protobuf library. The post below predates it being added.
I've written optimally-efficient versions of parseDelimitedFrom
and writeDelimitedTo
in C++ here (the read
and write
methods of Uncompressed
):
Feel free to copy.
These implementations read from / write to a ZeroCopyInputStream
/ ZeroCopyOutputStream
.(Hmm, for some reason my write
is declared to use FileOutputStream
, but you should be able to just change that to ZeroCopyOutputStream
.)
So, you'll need to create a ZeroCopyInputStream
which reads from your StreamSocket
, then pass it to my read()
.
It looks like StreamSocket
is a classic copying-read interface. You should therefore use CopyingInputStreamAdaptor
as your ZeroCopyInputStream
, wrapping an implementation of CopyingInputStream
which reads from your StreamSocket
.