Since proto3
, the protobuf spec got rid of the optional
and required
fields. Now the only way to find out if a field in the message is optional only by looking at the docs, which is not very convenient. How about we use optional_
as the prefix on the field name for optional fields.
Without optional_
prefix:
Protobuf
message User {
string user_id = 1;
string name = 2;
string email = 3;
}
Code
# Don't know which fields are optional, we have to check the docs:
user.user_id = 1
user.name = "bob"
user.email = "bob@gmail.com"
With optional_
prefix:
Protobuf
message User {
string user_id = 1;
string optional_name = 2;
string optional_email = 3;
}
Code
# it is more informative but doesn't read naturally in English.
user.user_id = 1
user.optional_name = "bob"
user.optional_email = "bob@gmail.com"
I have not usually seen optional fields named like that. It was used in one of my past teams and it was very convenient. Do you have any particular opinion on this?