-
Notifications
You must be signed in to change notification settings - Fork 585
Support for Unknown Fields (Rebase of #574) #1340
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
Open
blizzardfinnegan
wants to merge
29
commits into
tokio-rs:master
Choose a base branch
from
blizzardfinnegan:feature/unknown_fields_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+465
−19
Open
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
af54e00
Blind copy of changes in PR #574
63ad830
Begin implementing necessary changes
f0101e1
continue fixed32/fixed64 tweaks
d0dac13
Clarify endianness of unknown fields
7b7c95e
Resolve minor testing issues
7d727f8
Rename derive attribute
7bbaabc
Rename test messages to be more clear
fe9c170
Temporarily comment out section
89dedaa
Modify unknown fields to be Option
cf6dd55
Update code-generator to support Option unknown
387f369
Update name of unknown field in derive builds
c4d52ba
Fix bad derive Copy error
dd7d163
Messages should be passed to config individually
2bb62e5
Finalise commits for first pass
1fcbce8
rustfmt and clippy
257f260
Undo edit to otherwise untouched file
5f24936
Resolve CI/clippy issue
3064aef
Merge remote-tracking branch 'upstream/master' into feature/unknown_f…
2c28f1b
Merge branch 'tokio-rs:master' into feature/unknown_fields_support
blizzardfinnegan 81dc2f6
Confirm Protobuf unknown field tests pass
e55ed6c
Implement some suggested changes
8579f8b
Continue with requested changes
20ca085
Merge branch 'tokio-rs:master' into feature/unknown_fields_support
blizzardfinnegan 0a75b29
Resolve DecodeError CI error msg
59e57f1
rustfmt && clippy
b201428
Implement some changes suggested by @caspermeijn
74ee2e1
Remove custom iterator in favour of flat_map
f52050a
Remove edge-case of multiple unknown fields
2c25635
Move unknown_fields to _unknown_fields to avoid collisions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +0,0 @@ | ||
| # TODO(tokio-rs/prost#2): prost doesn't preserve unknown fields. | ||
| Required.Proto2.ProtobufInput.UnknownVarint.ProtobufOutput | ||
| Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| use anyhow::{bail, Error}; | ||
| use proc_macro2::TokenStream; | ||
| use quote::quote; | ||
| use syn::Meta; | ||
|
|
||
| use crate::field::{set_bool, word_attr}; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct Field {} | ||
|
|
||
| impl Field { | ||
| pub fn new(attrs: &[Meta]) -> Result<Option<Field>, Error> { | ||
| let mut unknown = false; | ||
| let mut unknown_attrs = Vec::new(); | ||
|
|
||
| for attr in attrs { | ||
| if word_attr("unknown_fields", attr) { | ||
| set_bool(&mut unknown, "duplicate message attribute")?; | ||
blizzardfinnegan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| unknown_attrs.push(attr); | ||
| } | ||
| } | ||
|
|
||
| if !unknown { | ||
| return Ok(None); | ||
| } | ||
|
|
||
| match unknown_attrs.len() { | ||
| 0 => (), | ||
| 1 => bail!( | ||
| "unknown attribute for unknown field set: {:?}", | ||
| unknown_attrs[0] | ||
| ), | ||
| _ => bail!( | ||
| "unknown attributes for unknown field set: {:?}", | ||
| unknown_attrs | ||
| ), | ||
| } | ||
|
|
||
| Ok(Some(Field {})) | ||
| } | ||
|
|
||
| pub fn encode(&self, ident: TokenStream) -> TokenStream { | ||
| quote! { | ||
| #ident.encode_raw(buf) | ||
| } | ||
| } | ||
|
|
||
| pub fn merge(&self, ident: TokenStream) -> TokenStream { | ||
| quote! { | ||
| #ident.merge_field(tag, wire_type, buf, ctx) | ||
| } | ||
| } | ||
|
|
||
| pub fn encoded_len(&self, ident: TokenStream) -> TokenStream { | ||
| quote! { | ||
| #ident.encoded_len() | ||
| } | ||
| } | ||
|
|
||
| pub fn clear(&self, ident: TokenStream) -> TokenStream { | ||
| quote! { | ||
| #ident.clear() | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.