From cdeda4b87625084f5687115bb1fd7772b7c34ad6 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 19 Jun 2015 17:30:13 +0100 Subject: Minor cleanup. - Make some members internal - Remove a lot of FrameworkPortability that isn't required - Start adding documentation comments - Remove some more group-based members - Not passing in "the last tag read" into Read*Array, g --- csharp/src/AddressBook/Addressbook.cs | 4 +- .../ProtocolBuffers.Test/CodedInputStreamTest.cs | 4 +- .../ProtocolBuffers.Test/CodedOutputStreamTest.cs | 4 +- .../TestProtos/UnittestIssues.cs | 10 +- .../TestProtos/UnittestProto3.cs | 124 ++++++++++----------- csharp/src/ProtocolBuffers/ByteArray.cs | 9 +- csharp/src/ProtocolBuffers/CodedInputStream.cs | 90 +++++++-------- csharp/src/ProtocolBuffers/CodedOutputStream.cs | 5 +- .../DescriptorProtos/DescriptorProtoFile.cs | 60 +++++----- csharp/src/ProtocolBuffers/Extensions.cs | 70 ------------ csharp/src/ProtocolBuffers/FrameworkPortability.cs | 68 +---------- csharp/src/ProtocolBuffers/IMessage.cs | 43 ++++++- csharp/src/ProtocolBuffers/MessageExtensions.cs | 81 ++++++++++++++ csharp/src/ProtocolBuffers/MessageParser.cs | 37 +++++- csharp/src/ProtocolBuffers/ProtocolBuffers.csproj | 4 +- csharp/src/ProtocolBuffers/ThrowHelper.cs | 17 +-- .../compiler/csharp/csharp_repeated_enum_field.cc | 2 +- .../csharp/csharp_repeated_message_field.cc | 2 +- .../csharp/csharp_repeated_primitive_field.cc | 2 +- 19 files changed, 319 insertions(+), 317 deletions(-) delete mode 100644 csharp/src/ProtocolBuffers/Extensions.cs create mode 100644 csharp/src/ProtocolBuffers/MessageExtensions.cs diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs index 480fb92a..322f85f7 100644 --- a/csharp/src/AddressBook/Addressbook.cs +++ b/csharp/src/AddressBook/Addressbook.cs @@ -214,7 +214,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { break; } case 34: { - input.ReadMessageArray(tag, phone_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Parser); + input.ReadMessageArray(phone_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Parser); break; } } @@ -432,7 +432,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } break; case 10: { - input.ReadMessageArray(tag, person_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Parser); + input.ReadMessageArray(person_, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Parser); break; } } diff --git a/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs b/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs index 0baa3a75..52757d4d 100644 --- a/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs +++ b/csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs @@ -489,7 +489,7 @@ namespace Google.Protobuf Assert.IsTrue(input.ReadTag(out tag)); RepeatedField values = new RepeatedField(); - input.ReadEnumArray(tag, values); + input.ReadEnumArray(values); Assert.AreEqual(6, values.Count); Assert.AreEqual(TestNegEnum.None, values[0]); @@ -513,7 +513,7 @@ namespace Google.Protobuf Assert.IsTrue(input.ReadTag(out tag)); RepeatedField values = new RepeatedField(); - input.ReadEnumArray(tag, values); + input.ReadEnumArray(values); Assert.AreEqual(6, values.Count); Assert.AreEqual(TestNegEnum.None, values[0]); diff --git a/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs b/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs index bc053e19..223374e0 100644 --- a/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs +++ b/csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs @@ -326,7 +326,7 @@ namespace Google.Protobuf Assert.IsTrue(input.ReadTag(out tag)); List values = new List(); - input.ReadInt32Array(tag, values); + input.ReadInt32Array(values); Assert.AreEqual(6, values.Count); for (int i = 0; i > -6; i--) @@ -349,7 +349,7 @@ namespace Google.Protobuf Assert.IsTrue(input.ReadTag(out tag)); List values = new List(); - input.ReadInt32Array(tag, values); + input.ReadInt32Array(values); Assert.AreEqual(6, values.Count); for (int i = 0; i > -6; i--) diff --git a/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs index 1ea3728d..959b3866 100644 --- a/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs +++ b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs @@ -218,12 +218,12 @@ namespace UnitTest.Issues.TestProtos { } case 18: case 16: { - input.ReadEnumArray(tag, values_); + input.ReadEnumArray(values_); break; } case 26: case 24: { - input.ReadEnumArray(tag, packedValues_); + input.ReadEnumArray(packedValues_); break; } } @@ -495,7 +495,7 @@ namespace UnitTest.Issues.TestProtos { } case 18: case 16: { - input.ReadInt32Array(tag, primitiveArray_); + input.ReadInt32Array(primitiveArray_); break; } case 26: { @@ -506,7 +506,7 @@ namespace UnitTest.Issues.TestProtos { break; } case 34: { - input.ReadMessageArray(tag, messageArray_, global::UnitTest.Issues.TestProtos.DeprecatedChild.Parser); + input.ReadMessageArray(messageArray_, global::UnitTest.Issues.TestProtos.DeprecatedChild.Parser); break; } case 40: { @@ -515,7 +515,7 @@ namespace UnitTest.Issues.TestProtos { } case 50: case 48: { - input.ReadEnumArray(tag, enumArray_); + input.ReadEnumArray(enumArray_); break; } } diff --git a/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs index a2c5d5f6..bbfa8c3e 100644 --- a/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs +++ b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs @@ -1547,106 +1547,106 @@ namespace Google.Protobuf.TestProtos { } case 250: case 248: { - input.ReadInt32Array(tag, repeatedInt32_); + input.ReadInt32Array(repeatedInt32_); break; } case 258: case 256: { - input.ReadInt64Array(tag, repeatedInt64_); + input.ReadInt64Array(repeatedInt64_); break; } case 266: case 264: { - input.ReadUInt32Array(tag, repeatedUint32_); + input.ReadUInt32Array(repeatedUint32_); break; } case 274: case 272: { - input.ReadUInt64Array(tag, repeatedUint64_); + input.ReadUInt64Array(repeatedUint64_); break; } case 282: case 280: { - input.ReadSInt32Array(tag, repeatedSint32_); + input.ReadSInt32Array(repeatedSint32_); break; } case 290: case 288: { - input.ReadSInt64Array(tag, repeatedSint64_); + input.ReadSInt64Array(repeatedSint64_); break; } case 298: case 301: { - input.ReadFixed32Array(tag, repeatedFixed32_); + input.ReadFixed32Array(repeatedFixed32_); break; } case 306: case 305: { - input.ReadFixed64Array(tag, repeatedFixed64_); + input.ReadFixed64Array(repeatedFixed64_); break; } case 314: case 317: { - input.ReadSFixed32Array(tag, repeatedSfixed32_); + input.ReadSFixed32Array(repeatedSfixed32_); break; } case 322: case 321: { - input.ReadSFixed64Array(tag, repeatedSfixed64_); + input.ReadSFixed64Array(repeatedSfixed64_); break; } case 330: case 333: { - input.ReadFloatArray(tag, repeatedFloat_); + input.ReadFloatArray(repeatedFloat_); break; } case 338: case 337: { - input.ReadDoubleArray(tag, repeatedDouble_); + input.ReadDoubleArray(repeatedDouble_); break; } case 346: case 344: { - input.ReadBoolArray(tag, repeatedBool_); + input.ReadBoolArray(repeatedBool_); break; } case 354: { - input.ReadStringArray(tag, repeatedString_); + input.ReadStringArray(repeatedString_); break; } case 362: { - input.ReadBytesArray(tag, repeatedBytes_); + input.ReadBytesArray(repeatedBytes_); break; } case 386: { - input.ReadMessageArray(tag, repeatedNestedMessage_, global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage.Parser); + input.ReadMessageArray(repeatedNestedMessage_, global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage.Parser); break; } case 394: { - input.ReadMessageArray(tag, repeatedForeignMessage_, global::Google.Protobuf.TestProtos.ForeignMessage.Parser); + input.ReadMessageArray(repeatedForeignMessage_, global::Google.Protobuf.TestProtos.ForeignMessage.Parser); break; } case 402: { - input.ReadMessageArray(tag, repeatedImportMessage_, global::Google.Protobuf.TestProtos.ImportMessage.Parser); + input.ReadMessageArray(repeatedImportMessage_, global::Google.Protobuf.TestProtos.ImportMessage.Parser); break; } case 410: case 408: { - input.ReadEnumArray(tag, repeatedNestedEnum_); + input.ReadEnumArray(repeatedNestedEnum_); break; } case 418: case 416: { - input.ReadEnumArray(tag, repeatedForeignEnum_); + input.ReadEnumArray(repeatedForeignEnum_); break; } case 426: case 424: { - input.ReadEnumArray(tag, repeatedImportEnum_); + input.ReadEnumArray(repeatedImportEnum_); break; } case 434: { - input.ReadMessageArray(tag, repeatedPublicImportMessage_, global::Google.Protobuf.TestProtos.PublicImportMessage.Parser); + input.ReadMessageArray(repeatedPublicImportMessage_, global::Google.Protobuf.TestProtos.PublicImportMessage.Parser); break; } case 888: { @@ -1919,7 +1919,7 @@ namespace Google.Protobuf.TestProtos { break; } case 26: { - input.ReadMessageArray(tag, repeatedChild_, global::Google.Protobuf.TestProtos.NestedTestAllTypes.Parser); + input.ReadMessageArray(repeatedChild_, global::Google.Protobuf.TestProtos.NestedTestAllTypes.Parser); break; } } @@ -2973,20 +2973,20 @@ namespace Google.Protobuf.TestProtos { } case 58: case 56: { - input.ReadInt32Array(tag, repeatedPrimitiveField_); + input.ReadInt32Array(repeatedPrimitiveField_); break; } case 66: { - input.ReadStringArray(tag, repeatedStringField_); + input.ReadStringArray(repeatedStringField_); break; } case 74: case 72: { - input.ReadEnumArray(tag, repeatedEnumField_); + input.ReadEnumArray(repeatedEnumField_); break; } case 82: { - input.ReadMessageArray(tag, repeatedMessageField_, global::Google.Protobuf.TestProtos.ForeignMessage.Parser); + input.ReadMessageArray(repeatedMessageField_, global::Google.Protobuf.TestProtos.ForeignMessage.Parser); break; } } @@ -3552,7 +3552,7 @@ namespace Google.Protobuf.TestProtos { } break; case 10: { - input.ReadStringArray(tag, data_); + input.ReadStringArray(data_); break; } } @@ -4716,72 +4716,72 @@ namespace Google.Protobuf.TestProtos { break; case 722: case 720: { - input.ReadInt32Array(tag, packedInt32_); + input.ReadInt32Array(packedInt32_); break; } case 730: case 728: { - input.ReadInt64Array(tag, packedInt64_); + input.ReadInt64Array(packedInt64_); break; } case 738: case 736: { - input.ReadUInt32Array(tag, packedUint32_); + input.ReadUInt32Array(packedUint32_); break; } case 746: case 744: { - input.ReadUInt64Array(tag, packedUint64_); + input.ReadUInt64Array(packedUint64_); break; } case 754: case 752: { - input.ReadSInt32Array(tag, packedSint32_); + input.ReadSInt32Array(packedSint32_); break; } case 762: case 760: { - input.ReadSInt64Array(tag, packedSint64_); + input.ReadSInt64Array(packedSint64_); break; } case 770: case 773: { - input.ReadFixed32Array(tag, packedFixed32_); + input.ReadFixed32Array(packedFixed32_); break; } case 778: case 777: { - input.ReadFixed64Array(tag, packedFixed64_); + input.ReadFixed64Array(packedFixed64_); break; } case 786: case 789: { - input.ReadSFixed32Array(tag, packedSfixed32_); + input.ReadSFixed32Array(packedSfixed32_); break; } case 794: case 793: { - input.ReadSFixed64Array(tag, packedSfixed64_); + input.ReadSFixed64Array(packedSfixed64_); break; } case 802: case 805: { - input.ReadFloatArray(tag, packedFloat_); + input.ReadFloatArray(packedFloat_); break; } case 810: case 809: { - input.ReadDoubleArray(tag, packedDouble_); + input.ReadDoubleArray(packedDouble_); break; } case 818: case 816: { - input.ReadBoolArray(tag, packedBool_); + input.ReadBoolArray(packedBool_); break; } case 826: case 824: { - input.ReadEnumArray(tag, packedEnum_); + input.ReadEnumArray(packedEnum_); break; } } @@ -5120,72 +5120,72 @@ namespace Google.Protobuf.TestProtos { break; case 722: case 720: { - input.ReadInt32Array(tag, unpackedInt32_); + input.ReadInt32Array(unpackedInt32_); break; } case 730: case 728: { - input.ReadInt64Array(tag, unpackedInt64_); + input.ReadInt64Array(unpackedInt64_); break; } case 738: case 736: { - input.ReadUInt32Array(tag, unpackedUint32_); + input.ReadUInt32Array(unpackedUint32_); break; } case 746: case 744: { - input.ReadUInt64Array(tag, unpackedUint64_); + input.ReadUInt64Array(unpackedUint64_); break; } case 754: case 752: { - input.ReadSInt32Array(tag, unpackedSint32_); + input.ReadSInt32Array(unpackedSint32_); break; } case 762: case 760: { - input.ReadSInt64Array(tag, unpackedSint64_); + input.ReadSInt64Array(unpackedSint64_); break; } case 770: case 773: { - input.ReadFixed32Array(tag, unpackedFixed32_); + input.ReadFixed32Array(unpackedFixed32_); break; } case 778: case 777: { - input.ReadFixed64Array(tag, unpackedFixed64_); + input.ReadFixed64Array(unpackedFixed64_); break; } case 786: case 789: { - input.ReadSFixed32Array(tag, unpackedSfixed32_); + input.ReadSFixed32Array(unpackedSfixed32_); break; } case 794: case 793: { - input.ReadSFixed64Array(tag, unpackedSfixed64_); + input.ReadSFixed64Array(unpackedSfixed64_); break; } case 802: case 805: { - input.ReadFloatArray(tag, unpackedFloat_); + input.ReadFloatArray(unpackedFloat_); break; } case 810: case 809: { - input.ReadDoubleArray(tag, unpackedDouble_); + input.ReadDoubleArray(unpackedDouble_); break; } case 818: case 816: { - input.ReadBoolArray(tag, unpackedBool_); + input.ReadBoolArray(unpackedBool_); break; } case 826: case 824: { - input.ReadEnumArray(tag, unpackedEnum_); + input.ReadEnumArray(unpackedEnum_); break; } } @@ -5378,32 +5378,32 @@ namespace Google.Protobuf.TestProtos { break; case 98: case 101: { - input.ReadFixed32Array(tag, repeatedFixed32_); + input.ReadFixed32Array(repeatedFixed32_); break; } case 106: case 104: { - input.ReadInt32Array(tag, repeatedInt32_); + input.ReadInt32Array(repeatedInt32_); break; } case 16370: case 16369: { - input.ReadFixed64Array(tag, repeatedFixed64_); + input.ReadFixed64Array(repeatedFixed64_); break; } case 16378: case 16376: { - input.ReadInt64Array(tag, repeatedInt64_); + input.ReadInt64Array(repeatedInt64_); break; } case 2097138: case 2097141: { - input.ReadFloatArray(tag, repeatedFloat_); + input.ReadFloatArray(repeatedFloat_); break; } case 2097146: case 2097144: { - input.ReadUInt64Array(tag, repeatedUint64_); + input.ReadUInt64Array(repeatedUint64_); break; } } diff --git a/csharp/src/ProtocolBuffers/ByteArray.cs b/csharp/src/ProtocolBuffers/ByteArray.cs index d367fc39..211a0e11 100644 --- a/csharp/src/ProtocolBuffers/ByteArray.cs +++ b/csharp/src/ProtocolBuffers/ByteArray.cs @@ -51,7 +51,7 @@ namespace Google.Protobuf /// /// Determines which copy routine to use based on the number of bytes to be copied. /// - public static void Copy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) + internal static void Copy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) { if (count > CopyThreshold) { @@ -66,7 +66,7 @@ namespace Google.Protobuf /// /// Copy the bytes provided with a for loop, faster when there are only a few bytes to copy /// - public static void ByteCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) + internal static void ByteCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) { int stop = srcOffset + count; for (int i = srcOffset; i < stop; i++) @@ -78,12 +78,11 @@ namespace Google.Protobuf /// /// Reverses the order of bytes in the array /// - public static void Reverse(byte[] bytes) + internal static void Reverse(byte[] bytes) { - byte temp; for (int first = 0, last = bytes.Length - 1; first < last; first++, last--) { - temp = bytes[first]; + byte temp = bytes[first]; bytes[first] = bytes[last]; bytes[last] = temp; } diff --git a/csharp/src/ProtocolBuffers/CodedInputStream.cs b/csharp/src/ProtocolBuffers/CodedInputStream.cs index 56283318..905cdb9d 100644 --- a/csharp/src/ProtocolBuffers/CodedInputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedInputStream.cs @@ -37,9 +37,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Text; using Google.Protobuf.Collections; -using Google.Protobuf.Descriptors; namespace Google.Protobuf { @@ -183,7 +181,7 @@ namespace Google.Protobuf /// /// The last /// tag read was not the one specified - public void CheckLastTagWas(uint value) + internal void CheckLastTagWas(uint value) { if (lastTag != value) { @@ -251,7 +249,7 @@ namespace Google.Protobuf /// public double ReadDouble() { - return FrameworkPortability.Int64ToDouble((long) ReadRawLittleEndian64()); + return BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64()); } /// @@ -347,21 +345,6 @@ namespace Google.Protobuf return CodedOutputStream.Utf8Encoding.GetString(ReadRawBytes(size), 0, size); } - /// - /// Reads a group field value from the stream. - /// - public void ReadGroup(int fieldNumber, IMessage message) - { - if (recursionDepth >= recursionLimit) - { - throw InvalidProtocolBufferException.RecursionLimitExceeded(); - } - ++recursionDepth; - message.MergeFrom(this); - CheckLastTagWas(WireFormat.MakeTag(fieldNumber, WireFormat.WireType.EndGroup)); - --recursionDepth; - } - /// /// Reads an embedded message field value from the stream. /// @@ -516,24 +499,34 @@ namespace Google.Protobuf return false; } - public void ReadStringArray(uint fieldTag, ICollection list) + /// + /// Reads a string array. + /// + /// The stream is assumed to be positioned after a tag indicating the field + /// repeated string value. A string is read, and then if the next tag is the same, + /// the process is repeated, until the next tag is a different one. + /// + public void ReadStringArray(ICollection list) { + uint fieldTag = lastTag; do { list.Add(ReadString()); } while (ContinueArray(fieldTag)); } - public void ReadBytesArray(uint fieldTag, ICollection list) + public void ReadBytesArray(ICollection list) { + uint fieldTag = lastTag; do { list.Add(ReadBytes()); } while (ContinueArray(fieldTag)); } - public void ReadBoolArray(uint fieldTag, ICollection list) + public void ReadBoolArray(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -545,8 +538,9 @@ namespace Google.Protobuf } } - public void ReadInt32Array(uint fieldTag, ICollection list) + public void ReadInt32Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -558,8 +552,9 @@ namespace Google.Protobuf } } - public void ReadSInt32Array(uint fieldTag, ICollection list) + public void ReadSInt32Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -571,8 +566,9 @@ namespace Google.Protobuf } } - public void ReadUInt32Array(uint fieldTag, ICollection list) + public void ReadUInt32Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -584,8 +580,9 @@ namespace Google.Protobuf } } - public void ReadFixed32Array(uint fieldTag, ICollection list) + public void ReadFixed32Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -597,8 +594,9 @@ namespace Google.Protobuf } } - public void ReadSFixed32Array(uint fieldTag, ICollection list) + public void ReadSFixed32Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -610,8 +608,9 @@ namespace Google.Protobuf } } - public void ReadInt64Array(uint fieldTag, ICollection list) + public void ReadInt64Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -623,8 +622,9 @@ namespace Google.Protobuf } } - public void ReadSInt64Array(uint fieldTag, ICollection list) + public void ReadSInt64Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -636,8 +636,9 @@ namespace Google.Protobuf } } - public void ReadUInt64Array(uint fieldTag, ICollection list) + public void ReadUInt64Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -649,8 +650,9 @@ namespace Google.Protobuf } } - public void ReadFixed64Array(uint fieldTag, ICollection list) + public void ReadFixed64Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -662,8 +664,9 @@ namespace Google.Protobuf } } - public void ReadSFixed64Array(uint fieldTag, ICollection list) + public void ReadSFixed64Array(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -675,8 +678,9 @@ namespace Google.Protobuf } } - public void ReadDoubleArray(uint fieldTag, ICollection list) + public void ReadDoubleArray(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -688,8 +692,9 @@ namespace Google.Protobuf } } - public void ReadFloatArray(uint fieldTag, ICollection list) + public void ReadFloatArray(ICollection list) { + uint fieldTag = lastTag; bool isPacked; int holdLimit; if (BeginArray(fieldTag, out isPacked, out holdLimit)) @@ -701,9 +706,10 @@ namespace Google.Protobuf } } - public void ReadEnumArray(uint fieldTag, RepeatedField list) + public void ReadEnumArray(RepeatedField list) where T : struct, IComparable, IFormattable { + uint fieldTag = lastTag; WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag); // 2.3 allows packed form even if the field is not declared packed. @@ -727,9 +733,10 @@ namespace Google.Protobuf } } - public void ReadMessageArray(uint fieldTag, ICollection list, MessageParser messageParser) + public void ReadMessageArray(ICollection list, MessageParser messageParser) where T : IMessage { + uint fieldTag = lastTag; do { T message = messageParser.CreateTemplate(); @@ -737,17 +744,6 @@ namespace Google.Protobuf list.Add(message); } while (ContinueArray(fieldTag)); } - - public void ReadGroupArray(uint fieldTag, ICollection list, MessageParser messageParser) - where T : IMessage - { - do - { - T message = messageParser.CreateTemplate(); - ReadGroup(WireFormat.GetTagFieldNumber(fieldTag), message); - list.Add(message); - } while (ContinueArray(fieldTag)); - } #endregion #region Underlying reading primitives diff --git a/csharp/src/ProtocolBuffers/CodedOutputStream.cs b/csharp/src/ProtocolBuffers/CodedOutputStream.cs index 1e6e7e55..e56ce789 100644 --- a/csharp/src/ProtocolBuffers/CodedOutputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedOutputStream.cs @@ -35,12 +35,9 @@ #endregion using System; -using System.Collections; using System.IO; -using System.Linq; using System.Text; using Google.Protobuf.Collections; -using Google.Protobuf.Descriptors; namespace Google.Protobuf { @@ -151,7 +148,7 @@ namespace Google.Protobuf /// public void WriteDouble(double value) { - WriteRawLittleEndian64((ulong)FrameworkPortability.DoubleToInt64(value)); + WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value)); } /// diff --git a/csharp/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs b/csharp/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs index 67938260..7b7abd8e 100644 --- a/csharp/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs +++ b/csharp/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs @@ -358,7 +358,7 @@ namespace Google.Protobuf.DescriptorProtos { } break; case 10: { - input.ReadMessageArray(tag, file_, global::Google.Protobuf.DescriptorProtos.FileDescriptorProto.Parser); + input.ReadMessageArray(file_, global::Google.Protobuf.DescriptorProtos.FileDescriptorProto.Parser); break; } } @@ -672,23 +672,23 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 26: { - input.ReadStringArray(tag, dependency_); + input.ReadStringArray(dependency_); break; } case 34: { - input.ReadMessageArray(tag, messageType_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Parser); + input.ReadMessageArray(messageType_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Parser); break; } case 42: { - input.ReadMessageArray(tag, enumType_, global::Google.Protobuf.DescriptorProtos.EnumDescriptorProto.Parser); + input.ReadMessageArray(enumType_, global::Google.Protobuf.DescriptorProtos.EnumDescriptorProto.Parser); break; } case 50: { - input.ReadMessageArray(tag, service_, global::Google.Protobuf.DescriptorProtos.ServiceDescriptorProto.Parser); + input.ReadMessageArray(service_, global::Google.Protobuf.DescriptorProtos.ServiceDescriptorProto.Parser); break; } case 58: { - input.ReadMessageArray(tag, extension_, global::Google.Protobuf.DescriptorProtos.FieldDescriptorProto.Parser); + input.ReadMessageArray(extension_, global::Google.Protobuf.DescriptorProtos.FieldDescriptorProto.Parser); break; } case 66: { @@ -707,12 +707,12 @@ namespace Google.Protobuf.DescriptorProtos { } case 82: case 80: { - input.ReadInt32Array(tag, publicDependency_); + input.ReadInt32Array(publicDependency_); break; } case 90: case 88: { - input.ReadInt32Array(tag, weakDependency_); + input.ReadInt32Array(weakDependency_); break; } case 98: { @@ -979,23 +979,23 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 18: { - input.ReadMessageArray(tag, field_, global::Google.Protobuf.DescriptorProtos.FieldDescriptorProto.Parser); + input.ReadMessageArray(field_, global::Google.Protobuf.DescriptorProtos.FieldDescriptorProto.Parser); break; } case 26: { - input.ReadMessageArray(tag, nestedType_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Parser); + input.ReadMessageArray(nestedType_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Parser); break; } case 34: { - input.ReadMessageArray(tag, enumType_, global::Google.Protobuf.DescriptorProtos.EnumDescriptorProto.Parser); + input.ReadMessageArray(enumType_, global::Google.Protobuf.DescriptorProtos.EnumDescriptorProto.Parser); break; } case 42: { - input.ReadMessageArray(tag, extensionRange_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Types.ExtensionRange.Parser); + input.ReadMessageArray(extensionRange_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Types.ExtensionRange.Parser); break; } case 50: { - input.ReadMessageArray(tag, extension_, global::Google.Protobuf.DescriptorProtos.FieldDescriptorProto.Parser); + input.ReadMessageArray(extension_, global::Google.Protobuf.DescriptorProtos.FieldDescriptorProto.Parser); break; } case 58: { @@ -1006,15 +1006,15 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 66: { - input.ReadMessageArray(tag, oneofDecl_, global::Google.Protobuf.DescriptorProtos.OneofDescriptorProto.Parser); + input.ReadMessageArray(oneofDecl_, global::Google.Protobuf.DescriptorProtos.OneofDescriptorProto.Parser); break; } case 74: { - input.ReadMessageArray(tag, reservedRange_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Types.ReservedRange.Parser); + input.ReadMessageArray(reservedRange_, global::Google.Protobuf.DescriptorProtos.DescriptorProto.Types.ReservedRange.Parser); break; } case 82: { - input.ReadStringArray(tag, reservedName_); + input.ReadStringArray(reservedName_); break; } } @@ -1800,7 +1800,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 18: { - input.ReadMessageArray(tag, value_, global::Google.Protobuf.DescriptorProtos.EnumValueDescriptorProto.Parser); + input.ReadMessageArray(value_, global::Google.Protobuf.DescriptorProtos.EnumValueDescriptorProto.Parser); break; } case 26: { @@ -2086,7 +2086,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 18: { - input.ReadMessageArray(tag, method_, global::Google.Protobuf.DescriptorProtos.MethodDescriptorProto.Parser); + input.ReadMessageArray(method_, global::Google.Protobuf.DescriptorProtos.MethodDescriptorProto.Parser); break; } case 26: { @@ -2735,7 +2735,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 7994: { - input.ReadMessageArray(tag, uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); + input.ReadMessageArray(uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); break; } } @@ -2933,7 +2933,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 7994: { - input.ReadMessageArray(tag, uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); + input.ReadMessageArray(uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); break; } } @@ -3167,7 +3167,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 7994: { - input.ReadMessageArray(tag, uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); + input.ReadMessageArray(uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); break; } } @@ -3323,7 +3323,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 7994: { - input.ReadMessageArray(tag, uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); + input.ReadMessageArray(uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); break; } } @@ -3437,7 +3437,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 7994: { - input.ReadMessageArray(tag, uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); + input.ReadMessageArray(uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); break; } } @@ -3551,7 +3551,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 7994: { - input.ReadMessageArray(tag, uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); + input.ReadMessageArray(uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); break; } } @@ -3665,7 +3665,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 7994: { - input.ReadMessageArray(tag, uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); + input.ReadMessageArray(uninterpretedOption_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Parser); break; } } @@ -3875,7 +3875,7 @@ namespace Google.Protobuf.DescriptorProtos { } break; case 18: { - input.ReadMessageArray(tag, name_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Types.NamePart.Parser); + input.ReadMessageArray(name_, global::Google.Protobuf.DescriptorProtos.UninterpretedOption.Types.NamePart.Parser); break; } case 26: { @@ -4111,7 +4111,7 @@ namespace Google.Protobuf.DescriptorProtos { } break; case 10: { - input.ReadMessageArray(tag, location_, global::Google.Protobuf.DescriptorProtos.SourceCodeInfo.Types.Location.Parser); + input.ReadMessageArray(location_, global::Google.Protobuf.DescriptorProtos.SourceCodeInfo.Types.Location.Parser); break; } } @@ -4287,12 +4287,12 @@ namespace Google.Protobuf.DescriptorProtos { break; case 10: case 8: { - input.ReadInt32Array(tag, path_); + input.ReadInt32Array(path_); break; } case 18: case 16: { - input.ReadInt32Array(tag, span_); + input.ReadInt32Array(span_); break; } case 26: { @@ -4304,7 +4304,7 @@ namespace Google.Protobuf.DescriptorProtos { break; } case 50: { - input.ReadStringArray(tag, leadingDetachedComments_); + input.ReadStringArray(leadingDetachedComments_); break; } } diff --git a/csharp/src/ProtocolBuffers/Extensions.cs b/csharp/src/ProtocolBuffers/Extensions.cs deleted file mode 100644 index 7f23057e..00000000 --- a/csharp/src/ProtocolBuffers/Extensions.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.IO; - -namespace Google.Protobuf -{ - // TODO: MessageExtensions? - public static class Extensions - { - public static void MergeFrom(this IMessage message, byte[] data) - { - CodedInputStream input = CodedInputStream.CreateInstance(data); - message.MergeFrom(input); - input.CheckLastTagWas(0); - } - - public static void MergeFrom(this IMessage message, ByteString data) - { - CodedInputStream input = data.CreateCodedInput(); - message.MergeFrom(input); - input.CheckLastTagWas(0); - } - - public static void MergeFrom(this IMessage message, Stream input) - { - CodedInputStream codedInput = CodedInputStream.CreateInstance(input); - message.MergeFrom(codedInput); - codedInput.CheckLastTagWas(0); - } - - public static void MergeDelimitedFrom(this IMessage message, Stream input) - { - int size = (int)CodedInputStream.ReadRawVarint32(input); - Stream limitedStream = new LimitedInputStream(input, size); - message.MergeFrom(limitedStream); - } - - public static byte[] ToByteArray(this IMessage message) - { - byte[] result = new byte[message.CalculateSize()]; - CodedOutputStream output = CodedOutputStream.CreateInstance(result); - message.WriteTo(output); - output.CheckNoSpaceLeft(); - return result; - } - - public static void WriteTo(this IMessage message, Stream output) - { - CodedOutputStream codedOutput = CodedOutputStream.CreateInstance(output); - message.WriteTo(codedOutput); - codedOutput.Flush(); - } - - public static void WriteTo(this IMessage message, CodedOutputStream output) - { - message.WriteTo(output); - } - - public static void WriteDelimitedTo(this IMessage message, Stream output) - { - CodedOutputStream codedOutput = CodedOutputStream.CreateInstance(output); - codedOutput.WriteRawVarint32((uint)message.CalculateSize()); - message.WriteTo(codedOutput); - codedOutput.Flush(); - } - - public static ByteString ToByteString(this IMessage message) - { - return ByteString.AttachBytes(message.ToByteArray()); - } - } -} diff --git a/csharp/src/ProtocolBuffers/FrameworkPortability.cs b/csharp/src/ProtocolBuffers/FrameworkPortability.cs index 5fa7c4e7..06246a9e 100644 --- a/csharp/src/ProtocolBuffers/FrameworkPortability.cs +++ b/csharp/src/ProtocolBuffers/FrameworkPortability.cs @@ -35,8 +35,6 @@ #endregion using System; -using System.Globalization; -using System.Reflection; using System.Text.RegularExpressions; namespace Google.Protobuf @@ -46,66 +44,10 @@ namespace Google.Protobuf /// internal static class FrameworkPortability { -#if COMPACT_FRAMEWORK - internal const string NewLine = "\n"; -#else - internal static readonly string NewLine = System.Environment.NewLine; -#endif - -#if CLIENTPROFILE - internal const RegexOptions CompiledRegexWhereAvailable = RegexOptions.Compiled; -#else - internal const RegexOptions CompiledRegexWhereAvailable = RegexOptions.None; -#endif - - internal static CultureInfo InvariantCulture - { - get { return CultureInfo.InvariantCulture; } - } - - internal static double Int64ToDouble(long value) - { -#if CLIENTPROFILE - return BitConverter.Int64BitsToDouble(value); -#else - double[] arresult = new double[1]; - Buffer.BlockCopy(new[] { value }, 0, arresult, 0, 8); - return arresult[0]; -#endif - } - - internal static long DoubleToInt64(double value) - { -#if CLIENTPROFILE - return BitConverter.DoubleToInt64Bits(value); -#else - long[] arresult = new long[1]; - Buffer.BlockCopy(new[] { value }, 0, arresult, 0, 8); - return arresult[0]; -#endif - } - - internal static bool TryParseInt32(string text, out int number) - { - return TryParseInt32(text, NumberStyles.Any, InvariantCulture, out number); - } - - internal static bool TryParseInt32(string text, NumberStyles style, IFormatProvider format, out int number) - { -#if COMPACT_FRAMEWORK - try - { - number = int.Parse(text, style, format); - return true; - } - catch - { - number = 0; - return false; - } -#else - return int.TryParse(text, style, format, out number); -#endif - } + // The value of RegexOptions.Compiled is 8. We can test for the presence at + // execution time using Enum.IsDefined, so a single build will do the right thing + // on each platform. + internal static readonly RegexOptions CompiledRegexWhereAvailable = + Enum.IsDefined(typeof(RegexOptions), 8) ? (RegexOptions)8 : RegexOptions.None; } } \ No newline at end of file diff --git a/csharp/src/ProtocolBuffers/IMessage.cs b/csharp/src/ProtocolBuffers/IMessage.cs index 55b6fc5d..9c2a2d85 100644 --- a/csharp/src/ProtocolBuffers/IMessage.cs +++ b/csharp/src/ProtocolBuffers/IMessage.cs @@ -34,30 +34,63 @@ #endregion -using System; -using System.Collections.Generic; -using System.IO; -using Google.Protobuf.Descriptors; using Google.Protobuf.FieldAccess; namespace Google.Protobuf { - // TODO(jonskeet): Do we want a "weak" version of IReflectedMessage? + // TODO(jonskeet): Do we want a "weak" (non-generic) version of IReflectedMessage? + + /// + /// Reflection support for a specific message type. message + /// + /// The message type being reflected. public interface IReflectedMessage where T : IMessage { FieldAccessorTable Fields { get; } + // TODO(jonskeet): Descriptor? Or a single property which has "all you need for reflection"? } + /// + /// Interface for a Protocol Buffers message, supporting + /// basic operations required for serialization. + /// public interface IMessage { + /// + /// Merges the data from the specified coded input stream with the current message. + /// + /// See the user guide for precise merge semantics. + /// void MergeFrom(CodedInputStream input); + + /// + /// Writes the data to the given coded output stream. + /// + /// Coded output stream to write the data to. Must not be null. void WriteTo(CodedOutputStream output); + + /// + /// Calculates the size of this message in Protocol Buffer wire format, in bytes. + /// + /// The number of bytes required to write this message + /// to a coded output stream. int CalculateSize(); } + /// + /// Generic interface for a Protocol Buffers message, + /// where the type parameter is expected to be the same type as + /// the implementation class. + /// + /// The message type. public interface IMessage : IMessage where T : IMessage { + /// + /// Merges the given message into this one. + /// + /// See the user guide for precise merge semantics. + /// The message to merge with this one. Must not be null. void MergeFrom(T message); } } \ No newline at end of file diff --git a/csharp/src/ProtocolBuffers/MessageExtensions.cs b/csharp/src/ProtocolBuffers/MessageExtensions.cs new file mode 100644 index 00000000..57cecfd4 --- /dev/null +++ b/csharp/src/ProtocolBuffers/MessageExtensions.cs @@ -0,0 +1,81 @@ +using System.IO; + +namespace Google.Protobuf +{ + /// + /// Extension methods on and . + /// + public static class MessageExtensions + { + public static void MergeFrom(this IMessage message, byte[] data) + { + ThrowHelper.ThrowIfNull(message, "message"); + ThrowHelper.ThrowIfNull(data, "data"); + CodedInputStream input = CodedInputStream.CreateInstance(data); + message.MergeFrom(input); + input.CheckLastTagWas(0); + } + + public static void MergeFrom(this IMessage message, ByteString data) + { + ThrowHelper.ThrowIfNull(message, "message"); + ThrowHelper.ThrowIfNull(data, "data"); + CodedInputStream input = data.CreateCodedInput(); + message.MergeFrom(input); + input.CheckLastTagWas(0); + } + + public static void MergeFrom(this IMessage message, Stream input) + { + ThrowHelper.ThrowIfNull(message, "message"); + ThrowHelper.ThrowIfNull(input, "input"); + CodedInputStream codedInput = CodedInputStream.CreateInstance(input); + message.MergeFrom(codedInput); + codedInput.CheckLastTagWas(0); + } + + public static void MergeDelimitedFrom(this IMessage message, Stream input) + { + ThrowHelper.ThrowIfNull(message, "message"); + ThrowHelper.ThrowIfNull(input, "input"); + int size = (int)CodedInputStream.ReadRawVarint32(input); + Stream limitedStream = new LimitedInputStream(input, size); + message.MergeFrom(limitedStream); + } + + public static byte[] ToByteArray(this IMessage message) + { + ThrowHelper.ThrowIfNull(message, "message"); + byte[] result = new byte[message.CalculateSize()]; + CodedOutputStream output = CodedOutputStream.CreateInstance(result); + message.WriteTo(output); + output.CheckNoSpaceLeft(); + return result; + } + + public static void WriteTo(this IMessage message, Stream output) + { + ThrowHelper.ThrowIfNull(message, "message"); + ThrowHelper.ThrowIfNull(output, "output"); + CodedOutputStream codedOutput = CodedOutputStream.CreateInstance(output); + message.WriteTo(codedOutput); + codedOutput.Flush(); + } + + public static void WriteDelimitedTo(this IMessage message, Stream output) + { + ThrowHelper.ThrowIfNull(message, "message"); + ThrowHelper.ThrowIfNull(output, "output"); + CodedOutputStream codedOutput = CodedOutputStream.CreateInstance(output); + codedOutput.WriteRawVarint32((uint)message.CalculateSize()); + message.WriteTo(codedOutput); + codedOutput.Flush(); + } + + public static ByteString ToByteString(this IMessage message) + { + ThrowHelper.ThrowIfNull(message, "message"); + return ByteString.AttachBytes(message.ToByteArray()); + } + } +} diff --git a/csharp/src/ProtocolBuffers/MessageParser.cs b/csharp/src/ProtocolBuffers/MessageParser.cs index 722435cc..18cda2dc 100644 --- a/csharp/src/ProtocolBuffers/MessageParser.cs +++ b/csharp/src/ProtocolBuffers/MessageParser.cs @@ -1,26 +1,58 @@ using System; using System.IO; -using Google.Protobuf; namespace Google.Protobuf { + /// + /// A parser for a specific message type. + /// + /// + ///

+ /// This delegates most behavior to the + /// implementation within the original type, but + /// provides convenient overloads to parse from a variety of sources. + ///

+ ///

+ /// Most applications will never need to create their own instances of this type; + /// instead, use the static Parser property of a generated message type to obtain a + /// parser for that type. + ///

+ ///
+ /// The type of message to be parsed. public sealed class MessageParser where T : IMessage { private readonly Func factory; + /// + /// Creates a new parser. + /// + /// + /// The factory method is effectively an optimization over using a generic constraint + /// to require a parameterless constructor: delegates are significantly faster to execute. + /// + /// Function to invoke when a new, empty message is required. public MessageParser(Func factory) { this.factory = factory; } - // Creates a template instance ready for population. + /// + /// Creates a template instance ready for population. + /// + /// An empty message. internal T CreateTemplate() { return factory(); } + /// + /// Parses a message from a byte array. + /// + /// The byte array containing the message. Must not be null. + /// The newly parsed message. public T ParseFrom(byte[] data) { + ThrowHelper.ThrowIfNull(data, "data"); T message = factory(); message.MergeFrom(data); return message; @@ -28,6 +60,7 @@ namespace Google.Protobuf public T ParseFrom(ByteString data) { + ThrowHelper.ThrowIfNull(data, "data"); T message = factory(); message.MergeFrom(data); return message; diff --git a/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj b/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj index 3a07e87f..33a32ff2 100644 --- a/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj +++ b/csharp/src/ProtocolBuffers/ProtocolBuffers.csproj @@ -84,7 +84,8 @@ - + + @@ -92,7 +93,6 @@ - diff --git a/csharp/src/ProtocolBuffers/ThrowHelper.cs b/csharp/src/ProtocolBuffers/ThrowHelper.cs index 097b5032..c12a48a3 100644 --- a/csharp/src/ProtocolBuffers/ThrowHelper.cs +++ b/csharp/src/ProtocolBuffers/ThrowHelper.cs @@ -42,12 +42,12 @@ namespace Google.Protobuf /// /// Helper methods for throwing exceptions /// - public static class ThrowHelper + internal static class ThrowHelper { /// /// Throws an ArgumentNullException if the given value is null. /// - public static void ThrowIfNull(object value, string name) + internal static void ThrowIfNull(object value, string name) { if (value == null) { @@ -58,7 +58,7 @@ namespace Google.Protobuf /// /// Throws an ArgumentNullException if the given value is null. /// - public static void ThrowIfNull(object value) + internal static void ThrowIfNull(object value) { if (value == null) { @@ -69,7 +69,7 @@ namespace Google.Protobuf /// /// Throws an ArgumentNullException if the given value or any element within it is null. /// - public static void ThrowIfAnyNull(IEnumerable sequence) + internal static void ThrowIfAnyNull(IEnumerable sequence) { foreach (T t in sequence) { @@ -79,14 +79,5 @@ namespace Google.Protobuf } } } - - public static Exception CreateMissingMethod(Type type, string methodName) - { -#if CLIENTPROFILE - return new System.MissingMethodException(type.FullName, methodName); -#else - return new System.ArgumentException(String.Format("The method '{0}' was not found on type {1}.", methodName, type)); -#endif - } } } \ No newline at end of file diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc index c78aaef6..29c931e3 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc @@ -76,7 +76,7 @@ void RepeatedEnumFieldGenerator::GenerateMergingCode(io::Printer* printer) { void RepeatedEnumFieldGenerator::GenerateParsingCode(io::Printer* printer) { printer->Print( variables_, - "input.ReadEnumArray<$type_name$>(tag, $name$_);\n"); + "input.ReadEnumArray<$type_name$>($name$_);\n"); } void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc index 3553fe12..3ab0b190 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc @@ -75,7 +75,7 @@ void RepeatedMessageFieldGenerator::GenerateMergingCode(io::Printer* printer) { void RepeatedMessageFieldGenerator::GenerateParsingCode(io::Printer* printer) { printer->Print( variables_, - "input.ReadMessageArray(tag, $name$_, $type_name$.Parser);\n"); + "input.ReadMessageArray($name$_, $type_name$.Parser);\n"); } void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc index fe8a4364..cc787d50 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc @@ -75,7 +75,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) void RepeatedPrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer) { printer->Print(variables_, - "input.Read$capitalized_type_name$Array(tag, $name$_);\n"); + "input.Read$capitalized_type_name$Array($name$_);\n"); } void RepeatedPrimitiveFieldGenerator::GenerateSerializationCode( -- cgit v1.2.3