I'm using the MOOS communications framework, which allows me to send
messages between modules in a binary, string, or numerical format using a
centralized database. In order to minimize the number of new interfaces
that I need to create, I'd like to send multiple messages over the same
interface, then differentiate between them on the other end. The method I
struck on to do this was to use ParseFromString to see whether the received
message parsed successfully as a given type. Here's a simple example:
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() ) )
{
printf( "Received a message of type A\n" );
}
// Parse a message of type B
else if( type_b.ParseFromString( msg.GetString() ) )
{
printf( "Received a message of type B\n" );
}
else
{
printf( "ERROR: Unrecognized message type" );
}
}
I think that I have misunderstood how ParseFromString works, because
instead of the first call returning FALSE when msg is a serialized message
of type B, it attempts to shoehorn the fields from type B into type A; as
you might guess, this is causing all sorts of problems.
I've been looking into the MessageLite class and its ParseFromCodedStream
method. I think that it may do what I want, but I'm hesitant to go down the
rabbit hole of learning a new tool if I can talk to someone else and learn
if this is really what I want first. Does anyone here have any advice?
Thanks very much!
--
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.