Here's an example from some code I wrote this weekend:

http://code.google.com/p/pbcap/source/browse/pbcap.proto -- Pay attention to
the "Stream" type.

http://code.google.com/p/pbcap/source/browse/Connection.java -- See
readOneMessage() and writeMessage().

The idea here is that the "Stream" message type is actually declaring a
protocol, not a message.  Its "fields" are actually messages within this
protocol that are sent one at a time.  On the sending end, we use
writeMessage() to write one message to the stream, and the receiving end
uses readOneMessage() to read the next message from the stream and handle
it.

The interesting thing is that if you were to dump the stream to a file, you
could later parse that file as a single big "Stream" message -- the format
on th wire is the same.

We should probably provide a class that encapsulates this better, so that
you don't have to know how to decode tags and such.

On Sun, Dec 6, 2009 at 9:02 PM, lexer <[email protected]> wrote:

> Adam, Could you please show simple example how to use tag number for
> dispatch purpose.
>
> On Dec 3, 9:59 pm, Adam Vartanian <[email protected]> wrote:
> > > Another option is to send some kind of identifier preceding the
> > > message (just like the total size of the message), right?
> >
> > Yep.  In fact, the wrapper message is effectively a protobuf-native
> > version of that, using the tag number as the type identifier.
> >
> > - 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]<protobuf%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>
>

--

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