Exactly. In an early implementation I treated null and empty string as the 
same - but it ends up being weird in all kinds of ways. (Either setting a 
property and then fetching it isn't a roundtrip, or serializing and 
deserializing isn't a roundtrip.)

In the end, I went with "stick to protobuf semantics: every string has a 
value, which is empty by default."

If you use the StringValue wrapper type, you then *can* use null, which 
means "there's no StringValue here".

On Tuesday, 3 October 2017 22:06:26 UTC+1, Marc Gravell wrote:
>
> Fields are optional but the implicit default for a string is a zero length 
> string, not a null length string. To be honest, either approach seems 
> perfectly reasonable as long as it is documented and any exception is clear 
> and obvious. For my separate implementation I chose to interpret nulls as 
> "meh, not set, ignore it", but... either is fine IMO.
>
> On 3 October 2017 at 19:35, Everton Araujo <[email protected] 
> <javascript:>> wrote:
>
>> Hi all,
>>
>> I'm facing the situation where a string value is not allowed to be null 
>> in Protobuf 3 using C# (CheckNotNull).
>> I do not understand it considering that fields are optional by default in 
>> proto3.
>> Does anyone knows the original reason for this constraint? As far as I 
>> could see, it happens for string and bytearrays.
>>
>> Regards,
>>
>> Everton
>>
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Regards, 
>
> Marc
>

-- 
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.

Reply via email to