-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add ignore-unknown-fields flag #145
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start! We should definitely add some tests for individual messages. https://github.com/planetscale/vtprotobuf/blob/main/testproto/pool/pool.proto is an example of testing an ext flag; simply adding another package under testproto
and ensuring that the generated code compiles successfully will be enough to test this feature, as all it's doing is removing fields from the codegen.
Thanks for the pointer! I have added a simple .proto file and adapted the Makefile to generate Go code from it as well as compile the generated code (through I have named the new package "ignore_unknown_fields". This is not idiomatic, as Go package names should be short. I felt that it's OK in this case, since this is not a package anyone is going to import. |
7a697aa
to
4aac21f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Now to wrap this up, I think we should make the flag more consistent and ignore unknown fields everywhere (in marshalling and size calculations), not only when unmarshalling. I've commented on the leftover usages that can be removed from codegen when the flag is set.
I had not changed the code you mentioned, because it wouldn't do anything, if I wasn't quite sure what the best approach in such a scenario would be and thought it might be best to assume the I have not extended the documentation for the newly adapted methods, as I feel like the changes won't be interesting for most of the users. PS: I assume you are aware, but just to be sure: The |
4aac21f
to
c51a11e
Compare
I think it makes a lot of sense to not fail equality when you're working on a message where you've explicitly opted in to ignore unknown fields. Likewise, if you've Unmarshalled with protobuf, we still don't want to emit unknown fields when you serialize with this library, and so on. Any other behavior would be IMO inconsistent, so fully cleaning up the codegen of all PS: thanks again for all your effort here! |
c51a11e
to
ae37910
Compare
Thank you! |
Thanks a lot for your help and patience! |
I'm happily picking up the suggestion from #143 to add an
ignoreUnknownFields
flag with this pull request. Similarly to the mempool flag, it can either be used as an option in the .proto file, or as a flag on the CLI.I was able to test the change with a command line flag on the CLI, but was unable to test it with the option in the .proto file. Unfortunately I still don't fully understand how to use the
ext.proto
file in a project (the importgoogle/protobuf/descriptor.proto
failed).I'm also unsure whether I should add new test cases for the feature and if so, how.