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

Specify IntegerValue encoding #232

Closed
justinsb opened this issue Mar 6, 2015 · 5 comments
Closed

Specify IntegerValue encoding #232

justinsb opened this issue Mar 6, 2015 · 5 comments

Comments

@justinsb
Copy link

justinsb commented Mar 6, 2015

I understand that proto3 will have well-known types, like IntegerValue, which will restore the proto2 optional behavior for primitive types.

However, it is not clear what the encoding of these types will be. (Is there a design document?)

I very much hope that they will be encoded identically to optional primitives in proto2.

I (and some others it seems) am very concerned that proto3 will have an incompatible (and less efficient) encoding than proto2. Rewriting protobuf spec files to replace "optional int" -> "IntegerValue" is painful but doable; having to rewrite all the code that uses protobuf would be a Sisyphean task.

@justinsb
Copy link
Author

justinsb commented Mar 6, 2015

Ah ... or is it the case that default values are not output? That seems to be what the current Java code & golang code is doing (?).

If that's the case, that gives me reasonable real-world compatibility between proto2 and proto3.

@liujisi
Copy link
Contributor

liujisi commented Mar 6, 2015

Unfortunately wrapper types change the wire format. The wire format will be the same as if these wrappers types are just normal messages. That said, changing primitive type to wrapper type isn't a wire compatible change. It should only be used in new proto3 syntax files that require field presence data.

Regarding encoding efficiency, the wrapper encoding will take one or two more bytes than the plain primitive fields. However, the wrapper types are only introduced for special cases, and are not encouraged to replace the optional primitive fields in proto2. We expect that most of the cases, field presence info is not needed. In proto3, optional primitives that equal to their defaults are not serialized, thus binary size should not be a concern.

@liujisi liujisi closed this as completed Mar 6, 2015
@justinsb
Copy link
Author

justinsb commented Mar 7, 2015

Thanks for confirming that missing values are not output. I think that is an important thing to emphasize in discussions of the dropping of optional values. I think that is probably a step forward for usability, and I now much better understand why proto3 is dropping optional values (even though it is technically less powerful and maybe even less correct).

This doesn't solve my other complaint that hasX is gone, but that is probably me (ab)using protobuf for a purpose for which it wasn't intended.

I'm now much more excited about proto3!

@zackangelo
Copy link

@pherl have these primitive wrapper types landed in master somewhere yet? I can't seem to find them.

@liujisi
Copy link
Contributor

liujisi commented Dec 16, 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

3 participants