This is simplified version of my code:

        if ( !message.ParsePartialFromArray((void *) buffer, len ) ||
             !message.IsInitialized() ) {
           // error
           return;
        }
std::cout << "is_valid value: " << message.is_valid() << "\n";
        if( ! message.has_is_valid() ) {
std::cout << " does not have is_valid\n";
        }
        if( message.is_valid() ) {
std::cout << " IS valid\n";
        }
        if( ! message.is_valid() ) {
std::cout << " IS NOT valid\n";
        }

and the proto buf that I have is something similar to:

message foo {
...........
    optional bool     is_valid = 7 [default = true];
}

and the generated code for it is:
  ........
  static const int kIsValidFieldNumber = 7;
  inline bool is_valid() const;
  ..........

The messages that I am trying to parse do not have the attribute
is_valid set in them. The output of my code is:

is_valid value: 15
 does not have is_valid
 IS valid
 IS NOT valid

so:
1) how does the is_valid() function return 15, as opposed to 1 or 0
(bool).
2) how could both is_valid() and !is_valid() be true? (I guess this is
more like a c question :) ). Even if we assume that there is a memory
corruption somewhere, it is hard to imagine that the compiler is
looking in to 2 different memory locations for is_valid() and !
is_valid() calls, so how does it return true for both?

-M


-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to