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

Allow unpacked repeated primitives #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

arhik
Copy link

@arhik arhik commented Nov 9, 2022

When supporting an existing protocol which uses unpacked representation for encoding and decoding we need unpacked representation support. If it is strictly encoding and decoding at the other end it is not important. But before decoding if hash is used to verify the object received in remote session then we would get into issues. The hash of the encoded representation will be different and will be rejected in our use case. For now I had to make a fork with these changes and continue using it. It would be ideal if changes are in the upstream. I was assuming you guys must have a reason and didn’t bother to raise an issue. I hope you are convinced about the use-case. If I am the protocol designer and implementer I would definitely avoid unpacked representation but to adhere to existing protocol it would make sense to support it. If it is very rare scenario and it complexifies the repo maintainance I understand.

@codecov
Copy link

codecov bot commented Nov 9, 2022

Codecov Report

Base: 89.04% // Head: 89.23% // Increases project coverage by +0.19% 🎉

Coverage data is based on head (783a0b1) compared to base (d4dbff5).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #224      +/-   ##
==========================================
+ Coverage   89.04%   89.23%   +0.19%     
==========================================
  Files          25       25              
  Lines        2794     2797       +3     
==========================================
+ Hits         2488     2496       +8     
+ Misses        306      301       -5     
Impacted Files Coverage Δ
src/codegen/encode_methods.jl 97.77% <100.00%> (+0.07%) ⬆️
src/codec/decode.jl 86.91% <0.00%> (+0.46%) ⬆️
src/codegen/toplevel_definitions.jl 97.90% <0.00%> (+1.39%) ⬆️
src/codegen/CodeGenerators.jl 91.11% <0.00%> (+4.44%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Drvi
Copy link
Collaborator

Drvi commented Nov 9, 2022

Thank you for explanation!

So if my understanding is correct, you are relying on an implementation detail. ProtoBuf tries to be very flexible in the way you serialize your messages, e.g. it does not require you to process fields in order which is nice bc you can start creating your payload as your data arrives. It also means that that binary payload is not guaranteed to be stable, as well as its hash. This section of docs https://developers.google.com/protocol-buffers/docs/encoding#order seem to try to warn people against depending on the exact byte output of a serialized message. AFAIK, for all intended use cases, the packed representation is the superior one.

That being said I don't want to break your application, but I think we might want to make this strictly opt-in and hide it behind an options flag.

@arhik
Copy link
Author

arhik commented Nov 10, 2022

Thank you for heads up. Existing code has everything in place. I just uncommented the section where [packed=true/false] option is ignored. I believe this PR (existing commented code) is already respecting it as a option. works for me with this [packed=false] option set after these changes. Sorry if you are aware of it and I am just repeating what you are trying to mention.

But there are not tests around it. Is it ideal for you to have tests within this PR ? Let me know. I will give it a try.

@@ -30,15 +30,16 @@ function field_encode_expr(@nospecialize(f::FieldType), ctx::Context)
!isempty(encoding_val_type) && (encoding_val_type = ", Val{$encoding_val_type}")
# TODO: do we want to allow unpacked representation? Docs say that parsers must always handle both cases
# and since packed is strictly more efficient, currently we don't allow that.
# is_packed = parse(Bool, get(f.options, "packed", "false"))
# if is_packed
is_packed = parse(Bool, get(f.options, "packed", "false"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want get(f.options, "packed", "true") So people really have to make an effort to get the unpacked representation, i.e. they have to write [packed=false] in their proto files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Sorry. In my case i needed it other way around and forgot about it.

@Drvi
Copy link
Collaborator

Drvi commented Nov 11, 2022

Yes, adding tests would be great!

@Drvi
Copy link
Collaborator

Drvi commented Nov 11, 2022

I think this might mess up _encoded_size so we'll probably need to add similar codegen tweak + tests for that.

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.

2 participants