Home > Enterprise >  proto3 check if parameter is set
proto3 check if parameter is set

Time:04-20

since in proto3 all parameters are optional when parameter is not set and message is deserialized then unset parameter holds default value. I can not find a way to check if the parameter has been set or not. Is there any way to find if parameter has been set similary as in proto2? I see that there is a method has_<param_name>() but it is private.

CodePudding user response:

I don't think the distinction exists anymore in proto3. You are encouraged to have meaningful defaults.

But if you must, you can use a singular embedded message containing the value.

CodePudding user response:

It seems after Protobuf 3.15.0 you could use hasField in C again:

According to the CHANGELOG:

Now Proto3 Oneof fields have "has" methods for checking their presence in C .

  • Related