My message structure is similar to this (more complicated, but this is
the general idea)

message MyMessage

message InnerMessage

message command
required int32 setsomething = 1;

optional command SomeCommand = 1;


optional InnerMessage MessageInner = 1;


What I want to do is be able to specify command line arguments like
MessageInner SomeCommand setsomething [some number that will be the
value in setsomething field]

I initialize the overall MyMessage successfully, then pass it to a
function, which I call recursively, that looks at each part of the
command line, looks for a field by that name, and either creates the
message or sets the field.

But I'm having trouble.  When my function sees that the field is
TYPE_MESSAGE, I want it to create that message as part of the bigger
without having to know what it is at compile time. My function takes
&somemessage as input and I get the message reflection and the field
descriptor for my field (from the command line) and then I try to
create a new mutable message from the message reflection. I checked my
code and I'm 100% sure this has to do with me not understanding how to
use protocol buffers the way I want to and is not something in my c++
code in general.

I guess the simple question is this:
How do I create a new message that is part of another message without
knowing what inner message I'm going to create at compile time? (I DO
know that the message field is going to be in my .proto file already
or I will send an error message) In particular, I need to know more
about message factories (can you make them relate to a specific
message?), dynamic messages, reflections?

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