Protobuf for client/server messaging?

969 views
Skip to first unread message

bwp

unread,
Jul 14, 2010, 4:36:03 AM7/14/10
to Protocol Buffers
We're currently looking at using protobuf for communication between a
number of clients (java and iPhone) and a java server but I'm a bit
confused how to best implement our protocol.

Our protocol consists of a big number of possible messages but I can't
seem to find a way for protobuf to help me decide which message was
sent.
Writing and parsing messages is really easy when I know what exact
message is being sent but this will never be the case in our
application.

We could write a field first in the message with some identifier of
what message type is being sent but this feels to me like something a
protocol tool should solve. If we have to go down that route what
would be a good identifier? Is the index of the messages descriptor
good enough or do I have to define it in the proto-file somehow?

I guess these are very simple questions but I've been trying to find
the answers in the documentation and at least I can't find it. Maybe
add an example of how to handle multiple possible messages, the
current Address Book example feels a little too basic.

BR
Per

Peter Keen

unread,
Jul 14, 2010, 1:22:56 PM7/14/10
to bwp, Protocol Buffers
On Wed, Jul 14, 2010 at 1:36 AM, bwp <per.m...@gmail.com> wrote:
> Our protocol consists of a big number of possible messages but I can't
> seem to find a way for protobuf to help me decide which message was
> sent.
> Writing and parsing messages is really easy when I know what exact
> message is being sent but this will never be the case in our
> application.

There's an example on the Techniques wiki page:

http://code.google.com/apis/protocolbuffers/docs/techniques.html#union

--Pete

Evan Jones

unread,
Jul 14, 2010, 3:49:59 PM7/14/10
to bwp, Protocol Buffers
On Jul 14, 2010, at 4:36 , bwp wrote:
> If we have to go down that route what would be a good identifier?

See Peter's email. But you can also use
msg.getDescriptorForType().getFullName() to get a unique string for
each protocol buffer message type. This is what I do for my own RPC
system, which needs to be able to handle *any* message type (hence the
"union" or "extension" approaches are not really correct). This needs
the non-lite runtime, in order to have descriptors for messages. See:

http://code.google.com/apis/protocolbuffers/docs/reference/java/com/google/protobuf/Descriptors.Descriptor.html#getFullName()

Evan

--
Evan Jones
http://evanjones.ca/

Reply all
Reply to author
Forward
0 new messages