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

@ObsidianMinor ObsidianMinor commented Feb 23, 2020

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

@Jensaarai Jensaarai Feb 24, 2020

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

@jtattermusch jtattermusch commented Sep 17, 2021

It this PR still needed to fix a problem?

@ObsidianMinor
Copy link
Contributor Author

@ObsidianMinor ObsidianMinor commented Sep 24, 2021

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

LGTM.

@jtattermusch jtattermusch added the release notes: yes label Oct 13, 2021
@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
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c# cla: yes release notes: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants