Skip to content

Support for Unknown Fields (Rebase of #574) - #1340

Open
blizzardfinnegan wants to merge 42 commits into
tokio-rs:masterfrom
blizzardfinnegan:feature/unknown_fields_support
Open

Support for Unknown Fields (Rebase of #574)#1340
blizzardfinnegan wants to merge 42 commits into
tokio-rs:masterfrom
blizzardfinnegan:feature/unknown_fields_support

Conversation

@blizzardfinnegan

Copy link
Copy Markdown

For more information see Issue #2

This PR is largely similar to #574 , rebased to main, and with edits suggested by the maintainer on said PR implemented to the best of my ability.

Blizzard Finnegan added 18 commits September 22, 2025 11:14
Does not compile, incomplete.
- Rename UnknownFieldSet to UnknownFieldList, as requested by maintainer
  caspermeijn
- Change fixed32 and fixed64 representation to be consistent with C++
  implementation, as requested by caspermeijn
- start resolving build-time errors
    - Currently failing with reexported crate issues
- TODO: What endianness is protobuf?
This section should be added back (and/or modified to fit new
standards), but commenting out for now to reduce points of failure to
resolve creating bad Copy derives
Instead of checking against empty, which can fail differently.
Attempting to force fields with unknown to not have a derived Copy.
While this is a change made by rustfmt/clippy, it's outside the scope of
this PR, so it's been removed
Seems like local clippy check runs in rust edition 2021, CI runs in 2024
@blizzardfinnegan blizzardfinnegan changed the title Support for Unknown Fields Support for Unknown Fields (Rebase of #574) Oct 8, 2025
@blizzardfinnegan

Copy link
Copy Markdown
Author

@caspermeijn
If there are any objections or additional comments on this, I would love to know. This is an important feature, and one the company I work with is dependent on.

Unfortunately, Github doesn't have a clear way to request reviews on a PR for someone outside the org and/or not a direct developer on the project, otherwise I would have done so. Apologies for the ping if that isn't the right channel.

@alebar42

alebar42 commented Oct 9, 2025

Copy link
Copy Markdown

@blizzardfinnegan AFAIK you could remove or comment out the ignored tests here in order to verify the implementation: https://github.com/blizzardfinnegan/prost/blob/feature/unknown_fields_support/conformance/failing_tests.txt

@blizzardfinnegan

blizzardfinnegan commented Oct 9, 2025

Copy link
Copy Markdown
Author

@alebar42 Thank you for the correction and clarification!
I made the relevant changes, and pushed them to my branch. It doesn't seem to have passed through to the PR yet? Might be a CI issue... 🤷

Either way, the tests do in fact pass (locally, at least).

Edit: Unclear what was the issue, but said changes are now in the PR, which is the important part.

@blizzardfinnegan

Copy link
Copy Markdown
Author

@caspermeijn
Any chance there's some movement on this?

@aidandj

aidandj commented Nov 14, 2025

Copy link
Copy Markdown

Ran into an issue using pbjson_build with this. Because when you generate unknown fields, pbjson_build doesn't know what to do with them and it errors:

error[E0063]: missing field `unknown_fields` in initializer of `google::protobuf::generated_code_info::Annotation`
    --> /out/pbjson/google.protobuf.serde.rs:3929:20
     |
3929 |                 Ok(super::tonic::google::protobuf::generated_code_info::Annotation {

@caspermeijn caspermeijn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for taking this forward. It is a large PR, so it takes some time for me to respond.

I miss user facing documentation. Could you add a section to the README that describes this new functionality?

Comment thread prost-build/src/config.rs Outdated
Comment thread prost-build/src/context.rs
Comment thread prost-derive/src/field/mod.rs
Comment thread prost-derive/src/field/unknown.rs Outdated
Comment thread prost-derive/src/lib.rs Outdated
Comment thread prost/src/unknown.rs Outdated
Comment thread prost/src/unknown.rs Outdated
Comment thread prost/src/unknown.rs Outdated
Comment thread tests/src/decode_error.rs
Comment thread conformance/failing_tests.txt
@blizzardfinnegan

Copy link
Copy Markdown
Author

Thank you for the review! I pretty much did as clean of a direct uplift as I could with the original MR, without changing too much. I'll go through and add docs and resolve the issues you pointed out.

Apologies for the repeated pings. It's definitely a bear of a PR, I wasn't sure if you had seen it or not.

- Remove Option wrapper on unknown fields
- Actually utilise custom iterator instead of nested for loops
- use Iterator.sum() instead of manual counter
- use Buf.get_u64_le() and Buf.get_u32_le() instead of manual copies
- Update conformance to not require failing_tests.txt
- remove empty failing_tests.txt
@aidandj

aidandj commented Nov 21, 2025

Copy link
Copy Markdown

Random thought. Protobuf naming guide recommends not using underscores as the initial character. Although it's not enforced, suggesting or using a default struct field name with a underscore prefix would be much more unlikely to have naming conflicts.

https://protobuf.dev/programming-guides/style/

@blizzardfinnegan

blizzardfinnegan commented Nov 25, 2025

Copy link
Copy Markdown
Author

Protobuf naming guide recommends not using underscores as the initial character.

This makes sense; Protobuf is language-agnostic, and some languages use underscores to denote private fields (python(?)), so useful to encourage people to not use it. Thank you for the information! I've updated accordingly.

@caspermeijn caspermeijn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the progress. I would like to see some small changes.

Comment thread prost-build/src/config.rs Outdated
Comment thread prost-build/src/lib.rs Outdated
Comment thread prost-build/src/lib.rs Outdated
Comment thread prost-build/src/lib.rs Outdated
Comment thread prost-derive/src/lib.rs
Comment thread prost/src/unknown.rs
Comment thread prost/src/unknown.rs
Comment thread tests/build.rs Outdated
@blizzardfinnegan

Copy link
Copy Markdown
Author

@caspermeijn Just checking in on the status of this MR; I know the past however long has been holidays, so projects and whatnot have probably taken a bit of a break, wanted to make sure it's still on the radar.

@caspermeijn

Copy link
Copy Markdown
Member

@caspermeijn Just checking in on the status of this MR; I know the past however long has been holidays, so projects and whatnot have probably taken a bit of a break, wanted to make sure it's still on the radar.

Yes, I see your progress. Thank you for that. It is difficult for me to find the time to review this large PR, as it needs a long block of time to fully understand the context. Please hang in there!

I did move one of your fixes of the bench to a seperate small PR ;-) #1404

@blizzardfinnegan

Copy link
Copy Markdown
Author

Entirely understandable! Big, fundamental PRs like this take a ton of energy.

Thank you for catching that unrelated-to-this-PR change, I can make changes to pull that out of this specific PR in the next week or so; I think clippy may have auto-applied it and I didn't catch it in a git add.

Apologies for the repeated pings; this PR is the biggest hold-up for a decently-sized RIIR effort at work, and other devs at work are eager to play with it instead of using the google rust wrapper crate thingy. Please don't take that as a request for urgency though, I want to make sure it's done right (even if it is a first pass that needs more refinement and/or additional features added later).

Blizzard Finnegan added 2 commits February 19, 2026 09:24
Make clear the name of the unknown fields field in the generated code
_must_ be chosen. Resolve poor wording in prost-build docs.
Comment thread prost-build/src/config.rs Outdated
blizzardfinnegan and others added 3 commits March 3, 2026 11:46
Underscore at end of name is more idiomatic for Rust; approved by
original suggestor of prepended underscore as acceptable alternative
- Fix failing test due to incomplete conversion
- revert change to prost-derive/src/field/unknown.rs that resulted in
  failing tests
@blizzardfinnegan

blizzardfinnegan commented Mar 3, 2026

Copy link
Copy Markdown
Author

CI failures seem to be largely due to Github internal issues; will force a rerun tomorrow, hoping they (Github/Microslop) get their issues resolved.

@blizzardfinnegan

Copy link
Copy Markdown
Author

@caspermeijn
Been a while, just checking back in on the progress for this MR.

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.

5 participants