In protobuf, we can't store null strings so to denote a string that isn't 
set we use the empty string. For this reason, the parsing is returning 
false to tell you that there isn't a field there but as you're seeing will 
still parse as an empty string.

On Wednesday, June 14, 2023 at 1:37:05 AM UTC-7 Krati Chordia wrote:

> Hi,
> I am trying to send a message on wire with the following protobuf structure
>
> message TestMsg {
>     string status = 1;
> }
>
> I create an instance of TestMsg and set status as empty and serialize it 
> to a string.
>
> TestMsg m1;
> m1.set_status("");
>
> std::string str = m1.SerializeAsString();
>
> Post serialization, str is sent over wire and tried to be parsed. 
> ParseFromString returns false whereas it should not. For any other value, 
> it parses successfully.
>
> TestMsg m2;
> m2.ParseFromString(str);  <----- this returns false
>
> Also, if I try to retrieve the value of m2.status(), it will return an 
> empty string even though the parsing returns false.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/57656589-532a-4780-9427-4a510107a1c4n%40googlegroups.com.

Reply via email to