You can get the ->message_type() (assuming the ->type() is TYPE_MESSAGE), which gets you a Descriptor which in turn has a ->name() / ->full_name() function.
Cheers, -ilia On Tue, May 21, 2019 at 7:13 PM Kiran Kumar <[email protected]> wrote: > > I have protobuf messages defined as below. I need to find the message type > from the attribute name. For example, when the input is "cfgMsg" the output > should be ConfigMsg or CfgServerMsg.ConfigMsg (full name). > > > message CfgServerMsg { > string name = 1; > ConfigMsg cfgMsg = 2; > } > > message ConfigMsg { > string cfgName = 1; > uint32 msgId = 2; > } > > > I have the below code. However, this is working for well defined types like > string, int, float etc. and for messages it just prints "message" as the > output. > > I removed some code and presented only that is relevant to this question. So > this is obviously not the complete code. > > > google::protobuf::Message *modObj = new ModObj(); > > const google::protobuf::Descriptor *outModDesc > = modObj->GetDescriptor(); > const Reflection *outModRefl = modObj->GetReflection(); > const FieldDescriptor *field; > > // Loop to iterate over all the fields > { > field = outModDesc->FindFieldByName(tmp_name); > std::string type = field->type_name(); > std::cout << "Type:" << type << std::endl; > } > > > Output: > > Type:string > > Type:message > > > However, I want to get the actual message type which is "ConfigMsg" instead > of just "message". Is there any such API available from protobuf ? > > > I did check this page > https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.descriptor#FileDescriptor.name.details > thoroughly, but couldn't find any thing useful for this. > > > If anyone has done similar thing or know some thing around this, it would be > useful. > > > Thanks, > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/protobuf. > To view this discussion on the web visit > https://groups.google.com/d/msgid/protobuf/68cf3dd3-8b5e-4f5c-8b87-b708b4e787da%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/CAKb7Uvi-xrwhRSZc%2BRXrro%2B70hr9-mb7pB5HmHumtA92fEE9Zw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
