Merge pull request #7246 from ObsidianMinor/csharp/issue7241
Correctly set ExtensionRegistry when parsing with MessageParser, but using an already existing CodedInputStream
This commit is contained in:
commit
3c8c0ae725
@ -380,5 +380,18 @@ namespace Google.Protobuf
|
||||
TestGroupExtension.Parser.WithExtensionRegistry(new ExtensionRegistry() { TestNestedExtension.Extensions.OptionalGroupExtension }),
|
||||
message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RoundTrip_ParseUsingCodedInput()
|
||||
{
|
||||
var message = new TestAllExtensions();
|
||||
message.SetExtension(UnittestExtensions.OptionalBoolExtension, true);
|
||||
byte[] bytes = message.ToByteArray();
|
||||
using (CodedInputStream input = new CodedInputStream(bytes))
|
||||
{
|
||||
var parsed = TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalBoolExtension }).ParseFrom(input);
|
||||
Assert.AreEqual(message, parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,14 +187,17 @@ namespace Google.Protobuf
|
||||
internal void MergeFrom(IMessage message, CodedInputStream codedInput)
|
||||
{
|
||||
bool originalDiscard = codedInput.DiscardUnknownFields;
|
||||
ExtensionRegistry originalRegistry = codedInput.ExtensionRegistry;
|
||||
try
|
||||
{
|
||||
codedInput.DiscardUnknownFields = DiscardUnknownFields;
|
||||
codedInput.ExtensionRegistry = Extensions;
|
||||
message.MergeFrom(codedInput);
|
||||
}
|
||||
finally
|
||||
{
|
||||
codedInput.DiscardUnknownFields = originalDiscard;
|
||||
codedInput.ExtensionRegistry = originalRegistry;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user