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

Use packed encoding if there are any values, not just more than 1 #270

Merged
merged 1 commit into from Aug 22, 2019

Conversation

kellycampbell
Copy link
Contributor

@kellycampbell kellycampbell commented Aug 21, 2019

I found this via a problem with the JS protoc generated code which doesn't properly decode unpacked enums when the proto definition says the field is packed.

Here's what the protobuf documentation at https://developers.google.com/protocol-buffers/docs/encoding#packed says:

A packed repeated field containing zero elements does not appear in the encoded message. Otherwise, all of the elements of the field are packed into a single key-value pair with wire type 2 (length-delimited).

Here's an example of the JS error stack when this happened:

Error [AssertionError]: Assertion failed
    at new goog.asserts.AssertionError (node_modules/google-protobuf/google-protobuf.js:79:876)
    at Object.goog.asserts.doAssertFailure_ (node_modules/google-protobuf/google-protobuf.js:80:257)
    at Object.goog.asserts.assert [as assert] (node_modules/google-protobuf/google-protobuf.js:81:83)
    at jspb.BinaryReader.readPackedField_ (node_modules/google-protobuf/google-protobuf.js:261:71)
    at jspb.BinaryReader.readPackedEnum (node_modules/google-protobuf/google-protobuf.js:266:287)

@jhump
Copy link
Owner

jhump commented Aug 22, 2019

@kellycampbell, this patch is fine.

However, you may also want to file a bug against the JS project, because the spec (just below the part you pasted) also states this:

Protocol buffer parsers must be able to parse repeated fields that were compiled as packed as if they were not packed, and vice versa.

@jhump jhump merged commit c47b58f into jhump:master Aug 22, 2019
@kellycampbell
Copy link
Contributor Author

However, you may also want to file a bug against the JS project, because the spec (just below the part you pasted) also states this:

Protocol buffer parsers must be able to parse repeated fields that were compiled as packed as if they were not packed, and vice versa.

Thanks. I should have mentioned the JS project has an issue already reported on this here: protocolbuffers/protobuf#1701

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

Successfully merging this pull request may close these issues.

None yet

2 participants