-
Notifications
You must be signed in to change notification settings - Fork 153
Closed
Description
In protobuf messages when we have enum or scalar types they can't be nil. To make it nil
, a way of doing it is to wrap in a message. This pattern is very common, we can see for example in google protobufs wrappers:
And it makes writing code like:
message User {
StringValue first_name = 1;
}
Later in Elixir, we'll have to access like:
# when present
user.first_name
%Google.Protobuf.StringValue{value: "Abilidebob"}
# when not present
user.first_name
%Google.Protobuf.StringValue{value: nil}
I wonder if it would not be cool this library can understand this pattern and unwrap and wrap automatically for us when decoding/encoding?
Then we could have something like:
# when present
user.first_name
"Abilidebob"
# when not present
user.first_name
nil
Of course, to make it compatible with previous versions, it should by default false, but you can turn as an option.
For example:
protoc --elixir_out=./lib --plugin=./protoc-gen-elixir --elixir_opt=value_wrapper=true myproto.proto
What do you folks think? Do we have space for such a feature in this library?
Metadata
Metadata
Assignees
Labels
No labels