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

Add opt-in support for unknown fields #574

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

Conversation

andrewhickman
Copy link
Contributor

@andrewhickman andrewhickman commented Dec 20, 2021

Adds a new option to prost-build:

     .include_unknown_fields(".my_package.MyMessage", "unknown_fields");

which adds an extra field to the generated code:

#[derive(prost::Message)]
struct MyMessage {
  #[prost(uint32, tag = "1")]
  foo: u32,
  #[prost(unknown)]
  unknown_fields: prost::UnknownFieldSet,
}

When decoding the message, unknown fields are added to the new field.

The API of UnknownFieldSet is fairly minimal at the moment, it is mostly intended to allow roundtripping the fields

Closes #2

@andrewhickman
Copy link
Contributor Author

I just noticed there was a previous, quite similar attempt at this in #117 . This is PR is a bit more conservative in that it doesn't change any existing messages, e.g. those in prost_types. I think its possible for consumers to work around that by using Config::compile_well_known_types though, if they really care.

@andrewhickman andrewhickman changed the title Add optional support for unknown fields Add opt-in support for unknown fields Dec 20, 2021
@andrewhickman
Copy link
Contributor Author

Reopening this since I noticed unknown fields were mentioned in #624 . I don't personally need this functionality any more but hopefully it can be useful as a starting point

@andrewhickman andrewhickman reopened this Apr 28, 2022
@QuentinPerez
Copy link
Contributor

QuentinPerez commented Nov 14, 2022

Would like to revive this topic, just wanted to know what is missing here and how we can help with it.
It's starting to be critical for us. (Otherwise, we will have to rewrite some parts of our business in Go)

Q: Why not having unknown fields by default instead enabling them one by one ?
Edit: because it breaks the API as unknown_fields is required Message { .., unknown_fields: Default::default() }

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.

Add support for unknown fields
2 participants