Summary: I would really like to be able to iterate through the message
descriptors in a DescriptorPool, in particular the generated_pool.

I am sending various protocol buffers as messages across a transport.
On the receiving side of the transport, I need to use information
contained in a message header to instantiate an object of the correct
type. If I can get a descriptor for the transmitted message, then I
can use the factory method to instantiate an appropriately typed
object. So, I need a way to embed enough information into the header,
that I can use it to get a descriptor.

First, since .proto definitions are provided for the descriptor type,
I could transmit a DescriptorProto object with each message. This is a
lot of per-message overhead though. Second, I could transmit the
complete name of each message in the header, then I can look up the
descrptor in the generated descriptor pool. However, I would prefer
not to send the complete string name in each message. Finally, I can
assign a unquie id (int) to each message type, and send this int in
the header. This minimizes the number of overhead bytes, but now
presents the problem of associating each message with an int. By
embedding an enum 'MessageId' in each message, I can easily determine
the messageId of any message object. This works well, except that on
the 'receiving' side of the application, I need to iterate through the
complete list of protobuf messages to extract their ids. This should
be easy, since the generated_pool contains descriptors for each
message. Unfortunately, while you can search a pool for a specific
descriptor, there is no way to iterate through the descriptors in the

Is there any reason not to permit iteration of descriptors? Or is this
simply a feature that has not be requested/needed? Finally, am I going
about this wrong? Is there a simpler way to accomplish what I am
trying to do? (I.e. transmit a message's type from server to client)
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to