[protobuf] Re: Debugging parsing errors (C++)

2013-01-31 Thread Naoum
I actually got to the bottom of this and it was a pretty silly mistake. The 
problem was in string conversions:
My message callback looks like this:

messageHandler(const RWCString& buffer_) 

and the parse method signature is this:

ParseFromString(const string& data);


So to convert between the two string types I was calling buffer_.data() 
which returns the char * and then std::string was created from that. Now it 
looks like the string representation of the GPB probably has something like 
\0 in it which caused the std::string to truncate it. Once I switched to 
the RWCString::std() function to do the conversion it all worked out fine.

On Wednesday, January 30, 2013 10:31:34 PM UTC-5, Feng Xiao wrote:
>
>
>
> On Thursday, January 31, 2013 4:07:55 AM UTC+8, Naoum wrote:
>>
>> Hi,
>>
>> I am constructing a message on a client using the generated setter 
>> methods for the GPB class and sending it over the network to my server. On 
>> the server side, however, the message fails to parse and ParseFromString() 
>> returns false. Any tips on how to debug parsing failure errors?
>>
> You can try to use ParsePartialFromString() and see if it succeeds. If it 
> does, then you are missing some required fields in your proto. If it 
> doesn't, it means the data is corrupted somehow. A probable cause is that 
> the data stream is trimmed.
>  
>
>>
>> I've actually traced this to only happen when an optional double value is 
>> present in the message. Any ideas why that might be? The following class is 
>> nested several levels inside my msg and when it only has a stringValue it 
>> works fine, but when it has a doubleValue it fails to parse. Any thoughts? 
>> I will try it again without the nesting but am wondering what could be 
>> causing this.
>>
>>   message Field {
>> required string name = 1;
>> optional double doubleValue = 2;
>> optional string stringValue = 3;
>>   }
>>
>>
>> Thanks,
>> N
>>
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[protobuf] Re: Debugging parsing errors (C++)

2013-01-30 Thread Feng Xiao


On Thursday, January 31, 2013 4:07:55 AM UTC+8, Naoum wrote:
>
> Hi,
>
> I am constructing a message on a client using the generated setter methods 
> for the GPB class and sending it over the network to my server. On the 
> server side, however, the message fails to parse and ParseFromString() 
> returns false. Any tips on how to debug parsing failure errors?
>
You can try to use ParsePartialFromString() and see if it succeeds. If it 
does, then you are missing some required fields in your proto. If it 
doesn't, it means the data is corrupted somehow. A probable cause is that 
the data stream is trimmed.
 

>
> I've actually traced this to only happen when an optional double value is 
> present in the message. Any ideas why that might be? The following class is 
> nested several levels inside my msg and when it only has a stringValue it 
> works fine, but when it has a doubleValue it fails to parse. Any thoughts? 
> I will try it again without the nesting but am wondering what could be 
> causing this.
>
>   message Field {
> required string name = 1;
> optional double doubleValue = 2;
> optional string stringValue = 3;
>   }
>
>
> Thanks,
> N
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.