aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jon Skeet <skeet@pobox.com>2015-06-19 17:30:13 +0100
committerGravatar Jon Skeet <skeet@pobox.com>2015-06-19 17:30:13 +0100
commitcdeda4b87625084f5687115bb1fd7772b7c34ad6 (patch)
tree373f4c38dbfb318626037ff204c30466574ab876
parentd7dda2fed8c37a83e2d4cd7ecc4201b628588c4c (diff)
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
-rw-r--r--csharp/src/AddressBook/Addressbook.cs4
-rw-r--r--csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs4
-rw-r--r--csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs4
-rw-r--r--csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs10
-rw-r--r--csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs124
-rw-r--r--csharp/src/ProtocolBuffers/ByteArray.cs9
-rw-r--r--csharp/src/ProtocolBuffers/CodedInputStream.cs90
-rw-r--r--csharp/src/ProtocolBuffers/CodedOutputStream.cs5
-rw-r--r--csharp/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs60
-rw-r--r--csharp/src/ProtocolBuffers/FrameworkPortability.cs68
-rw-r--r--csharp/src/ProtocolBuffers/IMessage.cs43
-rw-r--r--csharp/src/ProtocolBuffers/MessageExtensions.cs (renamed from csharp/src/ProtocolBuffers/Extensions.cs)25
-rw-r--r--csharp/src/ProtocolBuffers/MessageParser.cs37
-rw-r--r--csharp/src/ProtocolBuffers/ProtocolBuffers.csproj4
-rw-r--r--csharp/src/ProtocolBuffers/ThrowHelper.cs17
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc2
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc2
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc2
18 files changed, 256 insertions, 254 deletions
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<TestNegEnum> values = new RepeatedField<TestNegEnum>();
- 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<TestNegEnum> values = new RepeatedField<TestNegEnum>();
- 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<int> values = new List<int>();
- 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<int> values = new List<int>();
- 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<global::UnitTest.Issues.TestProtos.NegativeEnum>(tag, values_);
+ input.ReadEnumArray<global::UnitTest.Issues.TestProtos.NegativeEnum>(values_);
break;
}
case 26:
case 24: {
- input.ReadEnumArray<global::UnitTest.Issues.TestProtos.NegativeEnum>(tag, packedValues_);
+ input.ReadEnumArray<global::UnitTest.Issues.TestProtos.NegativeEnum>(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<global::UnitTest.Issues.TestProtos.DeprecatedEnum>(tag, enumArray_);
+ input.ReadEnumArray<global::UnitTest.Issues.TestProtos.DeprecatedEnum>(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<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum>(tag, repeatedNestedEnum_);
+ input.ReadEnumArray<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum>(repeatedNestedEnum_);
break;
}
case 418:
case 416: {
- input.ReadEnumArray<global::Google.Protobuf.TestProtos.ForeignEnum>(tag, repeatedForeignEnum_);
+ input.ReadEnumArray<global::Google.Protobuf.TestProtos.ForeignEnum>(repeatedForeignEnum_);
break;
}
case 426:
case 424: {
- input.ReadEnumArray<global::Google.Protobuf.TestProtos.ImportEnum>(tag, repeatedImportEnum_);
+ input.ReadEnumArray<global::Google.Protobuf.TestProtos.ImportEnum>(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<global::Google.Protobuf.TestProtos.ForeignEnum>(tag, repeatedEnumField_);
+ input.ReadEnumArray<global::Google.Protobuf.TestProtos.ForeignEnum>(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<global::Google.Protobuf.TestProtos.ForeignEnum>(tag, packedEnum_);
+ input.ReadEnumArray<global::Google.Protobuf.TestProtos.ForeignEnum>(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<global::Google.Protobuf.TestProtos.ForeignEnum>(tag, unpackedEnum_);
+ input.ReadEnumArray<global::Google.Protobuf.TestProtos.ForeignEnum>(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
/// <summary>
/// Determines which copy routine to use based on the number of bytes to be copied.
/// </summary>
- 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
/// <summary>
/// Copy the bytes provided with a for loop, faster when there are only a few bytes to copy
/// </summary>
- 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
/// <summary>
/// Reverses the order of bytes in the array
/// </summary>
- 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
/// </summary>
/// <exception cref="InvalidProtocolBufferException">The last
/// tag read was not the one specified</exception>
- public void CheckLastTagWas(uint value)
+ internal void CheckLastTagWas(uint value)
{
if (lastTag != value)
{
@@ -251,7 +249,7 @@ namespace Google.Protobuf
/// </summary>
public double ReadDouble()
{
- return FrameworkPortability.Int64ToDouble((long) ReadRawLittleEndian64());
+ return BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64());
}
/// <summary>
@@ -348,21 +346,6 @@ namespace Google.Protobuf
}
/// <summary>
- /// Reads a group field value from the stream.
- /// </summary>
- 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;
- }
-
- /// <summary>
/// Reads an embedded message field value from the stream.
/// </summary>
public void ReadMessage(IMessage builder)
@@ -516,24 +499,34 @@ namespace Google.Protobuf
return false;
}
- public void ReadStringArray(uint fieldTag, ICollection<string> list)
+ /// <summary>
+ /// Reads a string array.
+ /// </summary>
+ /// <remarks>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.</remarks>
+ /// <param name="list"></param>
+ public void ReadStringArray(ICollection<string> list)
{
+ uint fieldTag = lastTag;
do
{
list.Add(ReadString());
} while (ContinueArray(fieldTag));
}
- public void ReadBytesArray(uint fieldTag, ICollection<ByteString> list)
+ public void ReadBytesArray(ICollection<ByteString> list)
{
+ uint fieldTag = lastTag;
do
{
list.Add(ReadBytes());
} while (ContinueArray(fieldTag));
}
- public void ReadBoolArray(uint fieldTag, ICollection<bool> list)
+ public void ReadBoolArray(ICollection<bool> 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<int> list)
+ public void ReadInt32Array(ICollection<int> 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<int> list)
+ public void ReadSInt32Array(ICollection<int> 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<uint> list)
+ public void ReadUInt32Array(ICollection<uint> 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<uint> list)
+ public void ReadFixed32Array(ICollection<uint> 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<int> list)
+ public void ReadSFixed32Array(ICollection<int> 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<long> list)
+ public void ReadInt64Array(ICollection<long> 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<long> list)
+ public void ReadSInt64Array(ICollection<long> 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<ulong> list)
+ public void ReadUInt64Array(ICollection<ulong> 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<ulong> list)
+ public void ReadFixed64Array(ICollection<ulong> 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<long> list)
+ public void ReadSFixed64Array(ICollection<long> 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<double> list)
+ public void ReadDoubleArray(ICollection<double> 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<float> list)
+ public void ReadFloatArray(ICollection<float> 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<T>(uint fieldTag, RepeatedField<T> list)
+ public void ReadEnumArray<T>(RepeatedField<T> 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<T>(uint fieldTag, ICollection<T> list, MessageParser<T> messageParser)
+ public void ReadMessageArray<T>(ICollection<T> list, MessageParser<T> messageParser)
where T : IMessage<T>
{
+ uint fieldTag = lastTag;
do
{
T message = messageParser.CreateTemplate();
@@ -737,17 +744,6 @@ namespace Google.Protobuf
list.Add(message);
} while (ContinueArray(fieldTag));
}
-
- public void ReadGroupArray<T>(uint fieldTag, ICollection<T> list, MessageParser<T> messageParser)
- where T : IMessage<T>
- {
- 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
/// </summary>
public void WriteDouble(double value)
{
- WriteRawLittleEndian64((ulong)FrameworkPortability.DoubleToInt64(value));
+ WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
}
/// <summary>
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/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
/// </summary>
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?
+
+ /// <summary>
+ /// Reflection support for a specific message type. message
+ /// </summary>
+ /// <typeparam name="T">The message type being reflected.</typeparam>
public interface IReflectedMessage<T> where T : IMessage<T>
{
FieldAccessorTable<T> Fields { get; }
+ // TODO(jonskeet): Descriptor? Or a single property which has "all you need for reflection"?
}
+ /// <summary>
+ /// Interface for a Protocol Buffers message, supporting
+ /// basic operations required for serialization.
+ /// </summary>
public interface IMessage
{
+ /// <summary>
+ /// Merges the data from the specified coded input stream with the current message.
+ /// </summary>
+ /// <remarks>See the user guide for precise merge semantics.</remarks>
+ /// <param name="input"></param>
void MergeFrom(CodedInputStream input);
+
+ /// <summary>
+ /// Writes the data to the given coded output stream.
+ /// </summary>
+ /// <param name="output">Coded output stream to write the data to. Must not be null.</param>
void WriteTo(CodedOutputStream output);
+
+ /// <summary>
+ /// Calculates the size of this message in Protocol Buffer wire format, in bytes.
+ /// </summary>
+ /// <returns>The number of bytes required to write this message
+ /// to a coded output stream.</returns>
int CalculateSize();
}
+ /// <summary>
+ /// Generic interface for a Protocol Buffers message,
+ /// where the type parameter is expected to be the same type as
+ /// the implementation class.
+ /// </summary>
+ /// <typeparam name="T">The message type.</typeparam>
public interface IMessage<T> : IMessage where T : IMessage<T>
{
+ /// <summary>
+ /// Merges the given message into this one.
+ /// </summary>
+ /// <remarks>See the user guide for precise merge semantics.</remarks>
+ /// <param name="message">The message to merge with this one. Must not be null.</param>
void MergeFrom(T message);
}
} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers/Extensions.cs b/csharp/src/ProtocolBuffers/MessageExtensions.cs
index 7f23057e..57cecfd4 100644
--- a/csharp/src/ProtocolBuffers/Extensions.cs
+++ b/csharp/src/ProtocolBuffers/MessageExtensions.cs
@@ -2,11 +2,15 @@
namespace Google.Protobuf
{
- // TODO: MessageExtensions?
- public static class Extensions
+ /// <summary>
+ /// Extension methods on <see cref="IMessage"/> and <see cref="IMessage{T}"/>.
+ /// </summary>
+ 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);
@@ -14,6 +18,8 @@ namespace Google.Protobuf
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);
@@ -21,6 +27,8 @@ namespace Google.Protobuf
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);
@@ -28,6 +36,8 @@ namespace Google.Protobuf
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);
@@ -35,6 +45,7 @@ namespace Google.Protobuf
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);
@@ -44,18 +55,17 @@ namespace Google.Protobuf
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 WriteTo(this IMessage message, CodedOutputStream output)
- {
- message.WriteTo(output);
- }
-
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);
@@ -64,6 +74,7 @@ namespace Google.Protobuf
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
{
+ /// <summary>
+ /// A parser for a specific message type.
+ /// </summary>
+ /// <remarks>
+ /// <p>
+ /// This delegates most behavior to the
+ /// <see cref="IMessage.MergeFrom"/> implementation within the original type, but
+ /// provides convenient overloads to parse from a variety of sources.
+ /// </p>
+ /// <p>
+ /// Most applications will never need to create their own instances of this type;
+ /// instead, use the static <c>Parser</c> property of a generated message type to obtain a
+ /// parser for that type.
+ /// </p>
+ /// </remarks>
+ /// <typeparam name="T">The type of message to be parsed.</typeparam>
public sealed class MessageParser<T> where T : IMessage<T>
{
private readonly Func<T> factory;
+ /// <summary>
+ /// Creates a new parser.
+ /// </summary>
+ /// <remarks>
+ /// The factory method is effectively an optimization over using a generic constraint
+ /// to require a parameterless constructor: delegates are significantly faster to execute.
+ /// </remarks>
+ /// <param name="factory">Function to invoke when a new, empty message is required.</param>
public MessageParser(Func<T> factory)
{
this.factory = factory;
}
- // Creates a template instance ready for population.
+ /// <summary>
+ /// Creates a template instance ready for population.
+ /// </summary>
+ /// <returns>An empty message.</returns>
internal T CreateTemplate()
{
return factory();
}
+ /// <summary>
+ /// Parses a message from a byte array.
+ /// </summary>
+ /// <param name="data">The byte array containing the message. Must not be null.</param>
+ /// <returns>The newly parsed message.</returns>
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 @@
<Compile Include="Descriptors\MethodDescriptor.cs" />
<Compile Include="Descriptors\PackageDescriptor.cs" />
<Compile Include="Descriptors\ServiceDescriptor.cs" />
- <Compile Include="Extensions.cs" />
+ <Compile Include="FrameworkPortability.cs" />
+ <Compile Include="MessageExtensions.cs" />
<Compile Include="FieldAccess\FieldAccessorBase.cs" />
<Compile Include="FieldAccess\ReflectionUtil.cs" />
<Compile Include="FieldAccess\RepeatedFieldAccessor.cs" />
@@ -92,7 +93,6 @@
<Compile Include="FieldAccess\IFieldAccessor.cs" />
<Compile Include="FieldAccess\FieldAccessorTable.cs" />
<Compile Include="FieldAccess\OneofAccessor.cs" />
- <Compile Include="FrameworkPortability.cs" />
<Compile Include="IMessage.cs" />
<Compile Include="InvalidProtocolBufferException.cs" />
<Compile Include="LimitedInputStream.cs" />
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
/// <summary>
/// Helper methods for throwing exceptions
/// </summary>
- public static class ThrowHelper
+ internal static class ThrowHelper
{
/// <summary>
/// Throws an ArgumentNullException if the given value is null.
/// </summary>
- 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
/// <summary>
/// Throws an ArgumentNullException if the given value is null.
/// </summary>
- public static void ThrowIfNull(object value)
+ internal static void ThrowIfNull(object value)
{
if (value == null)
{
@@ -69,7 +69,7 @@ namespace Google.Protobuf
/// <summary>
/// Throws an ArgumentNullException if the given value or any element within it is null.
/// </summary>
- public static void ThrowIfAnyNull<T>(IEnumerable<T> sequence)
+ internal static void ThrowIfAnyNull<T>(IEnumerable<T> 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(