get rid of extraneous ParserInternalState.codedInputStream field
diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs
index 2fda24d..4050cbe 100644
--- a/csharp/src/Google.Protobuf/CodedInputStream.cs
+++ b/csharp/src/Google.Protobuf/CodedInputStream.cs
@@ -145,7 +145,6 @@
this.state.sizeLimit = DefaultSizeLimit;
this.state.recursionLimit = DefaultRecursionLimit;
SegmentedBufferHelper.Initialize(this, out this.state.segmentedBufferHelper);
- this.state.codedInputStream = this;
this.leaveOpen = leaveOpen;
this.state.currentLimit = int.MaxValue;
diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs
index 1dc9213..48cd7ab 100644
--- a/csharp/src/Google.Protobuf/Collections/MapField.cs
+++ b/csharp/src/Google.Protobuf/Collections/MapField.cs
@@ -695,7 +695,7 @@
// Read it as if we'd seen input with no data (i.e. create a "default" message).
if (Value == null)
{
- if (ctx.state.codedInputStream != null)
+ if (ctx.state.CodedInputStream != null)
{
// the decoded message might not support parsing from ParseContext, so
// we need to allow fallback to the legacy MergeFrom(CodedInputStream) parsing.
diff --git a/csharp/src/Google.Protobuf/ParseContext.cs b/csharp/src/Google.Protobuf/ParseContext.cs
index d1fd38c..bf46236 100644
--- a/csharp/src/Google.Protobuf/ParseContext.cs
+++ b/csharp/src/Google.Protobuf/ParseContext.cs
@@ -99,7 +99,6 @@
SegmentedBufferHelper.Initialize(input, out ctx.state.segmentedBufferHelper, out ctx.buffer);
ctx.state.bufferPos = 0;
ctx.state.bufferSize = ctx.buffer.Length;
- ctx.state.codedInputStream = null;
ctx.state.DiscardUnknownFields = false;
ctx.state.ExtensionRegistry = null;
diff --git a/csharp/src/Google.Protobuf/ParserInternalState.cs b/csharp/src/Google.Protobuf/ParserInternalState.cs
index 3545b2b..4f0500b 100644
--- a/csharp/src/Google.Protobuf/ParserInternalState.cs
+++ b/csharp/src/Google.Protobuf/ParserInternalState.cs
@@ -81,11 +81,6 @@
internal int recursionDepth; // current recursion depth
internal SegmentedBufferHelper segmentedBufferHelper;
-
- // If non-null, the top level parse method was started with given coded input stream as an argument
- // which also means we can potentially fallback to calling MergeFrom(CodedInputStream cis) if needed.
- internal CodedInputStream codedInputStream;
-
/// <summary>
/// The last tag we read. 0 indicates we've read to the end of the stream
@@ -102,6 +97,10 @@
// these fields are configuration, they should be readonly
internal int sizeLimit;
internal int recursionLimit;
+
+ // If non-null, the top level parse method was started with given coded input stream as an argument
+ // which also means we can potentially fallback to calling MergeFrom(CodedInputStream cis) if needed.
+ internal CodedInputStream CodedInputStream => segmentedBufferHelper.CodedInputStream;
/// <summary>
/// Internal-only property; when set to true, unknown fields will be discarded while parsing.
diff --git a/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs b/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs
index ca653a1..b7097a2 100644
--- a/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs
+++ b/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs
@@ -182,7 +182,7 @@
// Regenerating the code from .proto files will remove this overhead because it will
// generate the InternalMergeFrom method we need.
- if (ctx.state.codedInputStream == null)
+ if (ctx.state.CodedInputStream == null)
{
// This can only happen when the parsing started without providing a CodedInputStream instance
// (e.g. ParseContext was created directly from a ReadOnlySequence).
@@ -192,15 +192,15 @@
throw new InvalidProtocolBufferException($"Message {message.GetType().Name} doesn't provide the generated method that enables ParseContext-based parsing. You might need to regenerate the generated protobuf code.");
}
- ctx.CopyStateTo(ctx.state.codedInputStream);
+ ctx.CopyStateTo(ctx.state.CodedInputStream);
try
{
// fallback parse using the CodedInputStream that started current parsing tree
- message.MergeFrom(ctx.state.codedInputStream);
+ message.MergeFrom(ctx.state.CodedInputStream);
}
finally
{
- ctx.LoadStateFrom(ctx.state.codedInputStream);
+ ctx.LoadStateFrom(ctx.state.CodedInputStream);
}
}
}
diff --git a/csharp/src/Google.Protobuf/SegmentedBufferHelper.cs b/csharp/src/Google.Protobuf/SegmentedBufferHelper.cs
index 105a1e9..b5441d3 100644
--- a/csharp/src/Google.Protobuf/SegmentedBufferHelper.cs
+++ b/csharp/src/Google.Protobuf/SegmentedBufferHelper.cs
@@ -186,7 +186,6 @@
state.bufferSize = 0;
while (readOnlySequenceEnumerator.MoveNext())
{
-
buffer = readOnlySequenceEnumerator.Current.Span;
state.bufferSize = buffer.Length;
if (buffer.Length != 0)