Hi,
On Tue, Sep 22, 2009 at 15:39, Exaurdon <
alexric...@gmail.com> wrote:
>
> 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.
[...]
> Finally, am I going about this wrong? Is there a simpler way to accomplish what I am
> trying to do?
Not answering your question about the iterating here, but would it be
sufficient to just have a container protocol buffer that contains
several optional fields with the different message types you want to
transmit - then you can make use of proto-buffers way of generating
the messages for you
messasge ContainerMessage {
optional MyFirstMessageType foo = 1;
optional TheOtherMessageType bar = 2;
optional YetAnotherMessageType baz = 3;
// ... to be extended with more fields if more different types need
to be sent.
}
On the sending side, you just fill the right field and send the
ContainerMessage.
On the receiving side, you can check with has_foo() if the message has
been sent.
The overhead is minimal with this way because you essentially indicate
the type of the message with a single byte (the tag 1, 2, 3 would
indicate that). And the speed in encoding/decoding will be as fast as
it gets compared to a meta-data approach you're considering. It is
actually close to the 'having a type-id thing' - but just simply
implemented with the stuff that is already there; and even in a
typesafe manner because you have getters/setters that work with the
correct type.
-h