Thanks for the reply Adam -I did a simple sub into my code with your
suggestion, but it doesn't work.  However, now it's made me think of
more questions.....

If protocol buffers doesn't use object I/O streams, which streams does
it use?  The argument in Java simply asks for an OutputStream
argument, and of course that could mean File, ByteArray, Object, Data,
etc....

And perhaps more importantly, will the choice of Java stream types
impact how GPB objects may be reconstituted in C++?  At the simplest
level I assume this can be done:

I can create a GPB class called "GPBCar".
I have an outputstream (of some type, not sure!) over a socket in Java
I want to write to.
After creating my GPBCar object, I use the GPB "writeTo(output)"
method on the Java side.
My C++ app takes some form of this byte stream and reconstitutes my
GPBCar instance by using the equivalent of the "parseFrom" method from
the GPBCar.

My understanding is that I have converted my GPBCar to a series of
bytes that represent that GPBCar instance. Now I have a C++ app at the
other end of the socket connection.   But will the series of bytes be
in the correct order (endianness?).  Will the outputstream type be
particular to Java, or will I encounter problems by using certain
specific Java outputstreams?  Should I only be using the
CodedDataOutputStream provided by GPB? (I note that there is
implementations of this stream in both the C++ and Java GPB
implementations).

I should add I've tried to find answers to these questions on the
board and web, but with no luck.  Again, if anyone has a simple
example of how they used GPB to communicate over a socket from a Java
to a C++ app, I'd love to see it (or just point me in the right
direction).


On Dec 2, 1:14 pm, Adam Vartanian <[email protected]> wrote:
>
> Protocol buffer code doesn't use object streams, so when you pass one
> to its writeTo/parseFrom methods, you're actually passing the object
> stream as a regular OutputStream or InputStream, ie, your code is
> already serializing to and from bytes.  If you'd rather be explicit
> about it, you can just switch your stream's type from
> ObjectOutputStream to OutputStream (similarly with Input) and it
> should continue to work the same.  All that should require is instead
> of doing something like
>
> ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
> message.writeTo(output);
>
> you do something like
>
> OutputStream output = socket.getOutputStream();
> message.writeTo(output);
>
> For interacting with C++, you should be able to use the standard C++
> API for reading in messages, since the data is already on the wire in
> byte format.
>
> - Adam

--

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.


Reply via email to