My problem is that when I receive a packet I have to check one field( say 
'int32 COMMAND' ) to decide 
the type of the inner packet. For example:

message OutterPkt {
    required fiexed32 Length = 1;
    required int32 COMMAND = 2;
    required string Content = 3;

message InnerPktA {
     required int32 UserID;
     required int16 UserGender;

message InnerPktB {
    required string UserName = 1;
    reruired string UserDescripton = 2;

my code to process this packet will be:

OuuterPkt outp;
if (outp.COMMAND == 1) {
    InnerPktA pkta;
} else if (outp.COMMAND == 2) {
    InnerPktB pktb;
} else {

My question is: I think the pseudo code above is not efficient because it 
parses the buffer twice and there are too many memcpy.
Is there a better way to deal with this situation?

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to