I am trying to get the type of a data member inside a protobuf message and
call the appropriate message from it.
message ControlMessage{}
message AdminMessage{}
message ExecMessage{}
message IncomingMessage{
optional ControlMessage cmsg = 1 ;
optional AdminMessage amsg = 2 ;
optional ExecMessage emsg = 3 ;}
void onMsg(const ControlMessage&){}void onMsg(const AdminMessage&){}void
onMsg(const ExecMessage&){}
int main(){
IncomingMessage msg ;
msg.mutable_cmsg() ;
msg.mutable_emsg() ;
auto metadata = msg.GetMetaData() ;
auto reflection = metadata.reflection ;
auto descriptor = metadata.descriptor ;
std::vector<const FieldDescriptor*> all_fields ;
reflection->ListFields( msg, &all_fields ) ;
for(auto msgItr : all_fields)
{
// Somehow call the onMsg() overloads
// for all the fields set inside the msg
// msgItr is the FieldDescriptor
}
}
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/fc826c44-e139-4987-8dab-c7da3dc4858d%40googlegroups.com.