Thank you - that is actually a really clear example. I thought that more 
information than that was going with the protobuf, or that more 
intelligence was built into the parsing than is.

What I'm trying at the moment is just adding a first field to all of the 
messages in this set that is a string of the type of the message, in which 
case my example above becomes:

void CModule::ProcessMessages( CMOOSMsg &msg )
{   
    // Declare message types
    MyMessages::TypeA type_a;
    MyMessages::TypeB type_b;
     
    // Parse a message of type A
    if( type_a.ParseFromString( msg.GetString() ) && ( type_a.type() == 
"TypeA" ) )
    {
        printf( "Received a message of type A\n" );
    }
    // Parse a message of type B
    else if( type_b.ParseFromString( msg.GetString() ) && ( type_b.type() == 
"TypeB" ) )
    {
        printf( "Received a message of type B\n" );
    }
    else
    {
        printf( "ERROR: Unrecognized message type" );
    }
}

Perhaps not the most elegant solution, but if I understand how things work 
now I think that it should solve my issue.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to