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

Correctly set ExtensionRegistry when parsing with MessageParser, but using an already existing CodedInputStream #7246

Merged
merged 2 commits into from Oct 13, 2021

Conversation

ObsidianMinor
Copy link
Contributor

Fixes #7241

byte[] bytes = message.ToByteArray();
using (CodedInputStream input = new CodedInputStream(bytes))
{
var parsed = TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalBoolExtension }).ParseFrom(input);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

If at all possible, can there also be a way to pass an extension registry to ParseFrom/MergeFrom? It would be useful to be able to use the static MessageParser that's already present for a message and not have to construct a new one, or to be able to construct a new message and use MergeFrom with some stream and an extension registry. The current behavior of having WithExtensionRegistry create a new MessageParser each time is not ideal when parsing many different types of messages very quickly e.g. in an RPC system.

@jtattermusch
Copy link
Contributor

It this PR still needed to fix a problem?

@ObsidianMinor
Copy link
Contributor Author

I think so, assuming by the fact that there's still no conflicts. It should've been swapping out the extension registry the whole time like it does with DiscardUnknownFields.

Copy link
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

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

LGTM.

@jtattermusch jtattermusch changed the title Swap registry from input when parsing from existing input Correctly set ExtensionRegistry when parsing with MessageParser, but using an already existing CodedInputStream Oct 13, 2021
@jtattermusch jtattermusch merged commit 3c8c0ae into protocolbuffers:master Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ParseFrom(CodedInputStream) does not properly deserialize proto2 extensions
5 participants