From df44ae4413109a7c3ce9f27fb7ae02f0414c29d9 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 25 Jun 2015 12:08:18 +0100 Subject: More map tests, and various production code improvements. Generated code in next commit. --- csharp/src/ProtocolBuffers/CodedInputStream.cs | 28 +++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'csharp/src/ProtocolBuffers/CodedInputStream.cs') diff --git a/csharp/src/ProtocolBuffers/CodedInputStream.cs b/csharp/src/ProtocolBuffers/CodedInputStream.cs index 905cdb9d..dab3e5e3 100644 --- a/csharp/src/ProtocolBuffers/CodedInputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedInputStream.cs @@ -456,14 +456,16 @@ namespace Google.Protobuf } /// - /// Returns true if the next tag is also part of the same unpacked array. + /// Peeks at the next tag in the stream. If it matches , + /// the tag is consumed and the method returns true; otherwise, the + /// stream is left in the original position and the method returns false. /// - private bool ContinueArray(uint currentTag) + public bool MaybeConsumeTag(uint tag) { uint next; if (PeekNextTag(out next)) { - if (next == currentTag) + if (next == tag) { hasNextTag = false; return true; @@ -486,17 +488,7 @@ namespace Google.Protobuf } return true; } - - uint next; - if (PeekNextTag(out next)) - { - if (next == currentTag) - { - hasNextTag = false; - return true; - } - } - return false; + return MaybeConsumeTag(currentTag); } /// @@ -512,7 +504,7 @@ namespace Google.Protobuf do { list.Add(ReadString()); - } while (ContinueArray(fieldTag)); + } while (MaybeConsumeTag(fieldTag)); } public void ReadBytesArray(ICollection list) @@ -521,7 +513,7 @@ namespace Google.Protobuf do { list.Add(ReadBytes()); - } while (ContinueArray(fieldTag)); + } while (MaybeConsumeTag(fieldTag)); } public void ReadBoolArray(ICollection list) @@ -729,7 +721,7 @@ namespace Google.Protobuf do { list.Add((T)(object) ReadEnum()); - } while (ContinueArray(fieldTag)); + } while (MaybeConsumeTag(fieldTag)); } } @@ -742,7 +734,7 @@ namespace Google.Protobuf T message = messageParser.CreateTemplate(); ReadMessage(message); list.Add(message); - } while (ContinueArray(fieldTag)); + } while (MaybeConsumeTag(fieldTag)); } #endregion -- cgit v1.2.3