Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional primitives in proto3 (feature idea) #223

Closed
ejball opened this issue Feb 27, 2015 · 1 comment
Closed

Optional primitives in proto3 (feature idea) #223

ejball opened this issue Feb 27, 2015 · 1 comment

Comments

@ejball
Copy link

ejball commented Feb 27, 2015

As regards the removal of presence logic for primitives in proto3, I wonder if you could consider supporting nullable<T>.

It would be like map<K,V>, but for primitives that need presence logic. For example, these messages could be effectively equivalent:

message A {
  nullable<string> name = 1;
}
message B {
  message NullableString {
    string value = 1;
  }
  NullableString name = 1;
}

I'd certainly be open to a better name. Perhaps optional<string>, if it isn't too confusing, since optional means something somewhat different in proto2.

@liujisi
Copy link
Contributor

liujisi commented Feb 28, 2015

There will be well know types added in the default protobuf runtime in the next release. See the wrappers.proto:
https://github.com/google/protobuf/blob/96e379ff8bc6907d044c62c1381b8e5a793b6a7a/src/google/protobuf/wrappers.proto
It provides field presence info for primitive fields without introducing new syntax. Runtime libraries that support well know types may choose to use a more efficient representation for the messages (or provide additional functions). Binary format will be compatible as if they are normal wrapper messages.

@liujisi liujisi closed this as completed Feb 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants