Coded*Stream streamlining.

Remove ICodedInputStream and ICodedOutputStream, and rewrite CodedInputStream and CodedOutputStream to be specific to the binary format. If we want to support text-based formats, that can be a whole different serialization mechanism.
pull/515/head
Jon Skeet 10 years ago
parent 39aaf21d51
commit 96ddf01aed
  1. 53
      csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs
  2. 43
      csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs
  3. 18
      csharp/src/ProtocolBuffers.Test/TestProtos/UnittestImportProto3.cs
  4. 18
      csharp/src/ProtocolBuffers.Test/TestProtos/UnittestImportPublicProto3.cs
  5. 100
      csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs
  6. 1000
      csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs
  7. 427
      csharp/src/ProtocolBuffers/CodedInputStream.cs
  8. 132
      csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
  9. 249
      csharp/src/ProtocolBuffers/CodedOutputStream.cs
  10. 719
      csharp/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
  11. 2
      csharp/src/ProtocolBuffers/Extensions.cs
  12. 293
      csharp/src/ProtocolBuffers/ICodedInputStream.cs
  13. 347
      csharp/src/ProtocolBuffers/ICodedOutputStream.cs
  14. 4
      csharp/src/ProtocolBuffers/IMessage.cs
  15. 2
      csharp/src/ProtocolBuffers/MessageParser.cs
  16. 2
      csharp/src/ProtocolBuffers/ProtocolBuffers.csproj
  17. 16
      src/google/protobuf/compiler/csharp/csharp_enum_field.cc
  18. 17
      src/google/protobuf/compiler/csharp/csharp_message.cc
  19. 3
      src/google/protobuf/compiler/csharp/csharp_message_field.cc
  20. 16
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
  21. 4
      src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
  22. 4
      src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
  23. 6
      src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc

@ -336,13 +336,11 @@ namespace Google.Protobuf
CodedInputStream input = CodedInputStream.CreateInstance(ms); CodedInputStream input = CodedInputStream.CreateInstance(ms);
uint testtag; uint testtag;
string ignore; Assert.IsTrue(input.ReadTag(out testtag));
Assert.IsTrue(input.ReadTag(out testtag, out ignore));
Assert.AreEqual(tag, testtag); Assert.AreEqual(tag, testtag);
ByteString bytes = null;
// TODO(jonskeet): Should this be ArgumentNullException instead? // TODO(jonskeet): Should this be ArgumentNullException instead?
Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes(ref bytes)); Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes());
} }
private static TestRecursiveMessage MakeRecursiveMessage(int depth) private static TestRecursiveMessage MakeRecursiveMessage(int depth)
@ -435,13 +433,10 @@ namespace Google.Protobuf
CodedInputStream input = CodedInputStream.CreateInstance(ms); CodedInputStream input = CodedInputStream.CreateInstance(ms);
uint testtag; uint actualTag;
string ignored; Assert.IsTrue(input.ReadTag(out actualTag));
Assert.AreEqual(tag, actualTag);
Assert.IsTrue(input.ReadTag(out testtag, out ignored)); string text = input.ReadString();
Assert.AreEqual(tag, testtag);
string text = null;
input.ReadString(ref text);
Assert.AreEqual('\ufffd', text[0]); Assert.AreEqual('\ufffd', text[0]);
} }
@ -473,11 +468,8 @@ namespace Google.Protobuf
{ {
byte[] bytes = new byte[10] { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 }; byte[] bytes = new byte[10] { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 };
CodedInputStream input = CodedInputStream.CreateInstance(bytes); CodedInputStream input = CodedInputStream.CreateInstance(bytes);
int val = 0; Assert.AreEqual((int)TestNegEnum.Value, input.ReadEnum());
Assert.IsTrue(input.ReadEnum(ref val));
Assert.IsTrue(input.IsAtEnd); Assert.IsTrue(input.IsAtEnd);
Assert.AreEqual((int) TestNegEnum.Value, val);
} }
[Test] [Test]
@ -487,17 +479,16 @@ namespace Google.Protobuf
int msgSize = 1 + 1 + arraySize; int msgSize = 1 + 1 + arraySize;
byte[] bytes = new byte[msgSize]; byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes); CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WritePackedInt32Array(8, "", new RepeatedField<int> { 0, -1, -2, -3, -4, -5 }); output.WritePackedInt32Array(8, new RepeatedField<int> { 0, -1, -2, -3, -4, -5 });
Assert.AreEqual(0, output.SpaceLeft); Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes); CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag; uint tag;
string name; Assert.IsTrue(input.ReadTag(out tag));
Assert.IsTrue(input.ReadTag(out tag, out name));
List<TestNegEnum> values = new List<TestNegEnum>(); List<TestNegEnum> values = new List<TestNegEnum>();
input.ReadEnumArray(tag, name, values); input.ReadEnumArray(tag, values);
Assert.AreEqual(6, values.Count); Assert.AreEqual(6, values.Count);
Assert.AreEqual(TestNegEnum.None, values[0]); Assert.AreEqual(TestNegEnum.None, values[0]);
@ -512,17 +503,16 @@ namespace Google.Protobuf
int msgSize = arraySize; int msgSize = arraySize;
byte[] bytes = new byte[msgSize]; byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes); CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteInt32Array(8, "", new RepeatedField<int> { 0, -1, -2, -3, -4, -5 }); output.WriteInt32Array(8, new RepeatedField<int> { 0, -1, -2, -3, -4, -5 });
Assert.AreEqual(0, output.SpaceLeft); Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes); CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag; uint tag;
string name; Assert.IsTrue(input.ReadTag(out tag));
Assert.IsTrue(input.ReadTag(out tag, out name));
List<TestNegEnum> values = new List<TestNegEnum>(); List<TestNegEnum> values = new List<TestNegEnum>();
input.ReadEnumArray(tag, name, values); input.ReadEnumArray(tag, values);
Assert.AreEqual(6, values.Count); Assert.AreEqual(6, values.Count);
Assert.AreEqual(TestNegEnum.None, values[0]); Assert.AreEqual(TestNegEnum.None, values[0]);
@ -537,26 +527,21 @@ namespace Google.Protobuf
using (var ms = new MemoryStream()) using (var ms = new MemoryStream())
{ {
CodedOutputStream output = CodedOutputStream.CreateInstance(ms); CodedOutputStream output = CodedOutputStream.CreateInstance(ms);
output.WriteField(FieldType.Bytes, 1, "bytes", ByteString.CopyFrom(new byte[100])); output.WriteBytes(1, ByteString.CopyFrom(new byte[100]));
output.WriteField(FieldType.Bytes, 2, "bytes", ByteString.CopyFrom(new byte[100])); output.WriteBytes(2, ByteString.CopyFrom(new byte[100]));
output.Flush(); output.Flush();
ms.Position = 0; ms.Position = 0;
CodedInputStream input = CodedInputStream.CreateInstance(ms, new byte[ms.Length / 2]); CodedInputStream input = CodedInputStream.CreateInstance(ms, new byte[ms.Length / 2]);
uint tag; uint tag;
string ignore; Assert.IsTrue(input.ReadTag(out tag));
ByteString value;
Assert.IsTrue(input.ReadTag(out tag, out ignore));
Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag)); Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
value = ByteString.Empty; Assert.AreEqual(100, input.ReadBytes().Length);
Assert.IsTrue(input.ReadBytes(ref value) && value.Length == 100);
Assert.IsTrue(input.ReadTag(out tag, out ignore)); Assert.IsTrue(input.ReadTag(out tag));
Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag)); Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag));
value = ByteString.Empty; Assert.AreEqual(100, input.ReadBytes().Length);
Assert.IsTrue(input.ReadBytes(ref value) && value.Length == 100);
} }
} }
} }

@ -316,7 +316,7 @@ namespace Google.Protobuf
byte[] bytes = new byte[11]; byte[] bytes = new byte[11];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes); CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnum(8, "", (int) TestNegEnum.Value); output.WriteEnum(8, (int) TestNegEnum.Value);
Assert.AreEqual(0, output.SpaceLeft); Assert.AreEqual(0, output.SpaceLeft);
//fyi, 0x40 == 0x08 << 3 + 0, field num + wire format shift //fyi, 0x40 == 0x08 << 3 + 0, field num + wire format shift
@ -330,18 +330,17 @@ namespace Google.Protobuf
int msgSize = 1 + 1 + arraySize; int msgSize = 1 + 1 + arraySize;
byte[] bytes = new byte[msgSize]; byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes); CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WritePackedEnumArray(8, "", new RepeatedField<TestNegEnum> { output.WritePackedEnumArray(8, new RepeatedField<TestNegEnum> {
0, (TestNegEnum) (-1), TestNegEnum.Value, (TestNegEnum) (-3), (TestNegEnum) (-4), (TestNegEnum) (-5) }); 0, (TestNegEnum) (-1), TestNegEnum.Value, (TestNegEnum) (-3), (TestNegEnum) (-4), (TestNegEnum) (-5) });
Assert.AreEqual(0, output.SpaceLeft); Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes); CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag; uint tag;
string name; Assert.IsTrue(input.ReadTag(out tag));
Assert.IsTrue(input.ReadTag(out tag, out name));
List<int> values = new List<int>(); List<int> values = new List<int>();
input.ReadInt32Array(tag, name, values); input.ReadInt32Array(tag, values);
Assert.AreEqual(6, values.Count); Assert.AreEqual(6, values.Count);
for (int i = 0; i > -6; i--) for (int i = 0; i > -6; i--)
@ -355,17 +354,16 @@ namespace Google.Protobuf
int msgSize = arraySize; int msgSize = arraySize;
byte[] bytes = new byte[msgSize]; byte[] bytes = new byte[msgSize];
CodedOutputStream output = CodedOutputStream.CreateInstance(bytes); CodedOutputStream output = CodedOutputStream.CreateInstance(bytes);
output.WriteEnumArray(8, "", new RepeatedField<TestNegEnum> { output.WriteEnumArray(8, new RepeatedField<TestNegEnum> {
0, (TestNegEnum) (-1), TestNegEnum.Value, (TestNegEnum) (-3), (TestNegEnum) (-4), (TestNegEnum) (-5) }); 0, (TestNegEnum) (-1), TestNegEnum.Value, (TestNegEnum) (-3), (TestNegEnum) (-4), (TestNegEnum) (-5) });
Assert.AreEqual(0, output.SpaceLeft); Assert.AreEqual(0, output.SpaceLeft);
CodedInputStream input = CodedInputStream.CreateInstance(bytes); CodedInputStream input = CodedInputStream.CreateInstance(bytes);
uint tag; uint tag;
string name; Assert.IsTrue(input.ReadTag(out tag));
Assert.IsTrue(input.ReadTag(out tag, out name));
List<int> values = new List<int>(); List<int> values = new List<int>();
input.ReadInt32Array(tag, name, values); input.ReadInt32Array(tag, values);
Assert.AreEqual(6, values.Count); Assert.AreEqual(6, values.Count);
for (int i = 0; i > -6; i--) for (int i = 0; i > -6; i--)
@ -425,16 +423,14 @@ namespace Google.Protobuf
{ {
CodedInputStream cin = CodedInputStream.CreateInstance(new MemoryStream(bytes), new byte[50]); CodedInputStream cin = CodedInputStream.CreateInstance(new MemoryStream(bytes), new byte[50]);
uint tag; uint tag;
int intValue = 0;
string ignore;
Assert.AreEqual(0, cin.Position); Assert.AreEqual(0, cin.Position);
// Field 1: // Field 1:
Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 1); Assert.IsTrue(cin.ReadTag(out tag) && tag >> 3 == 1);
Assert.AreEqual(1, cin.Position); Assert.AreEqual(1, cin.Position);
Assert.IsTrue(cin.ReadInt32(ref intValue) && intValue == 500); Assert.AreEqual(500, cin.ReadInt32());
Assert.AreEqual(3, cin.Position); Assert.AreEqual(3, cin.Position);
//Field 2: //Field 2:
Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 2); Assert.IsTrue(cin.ReadTag(out tag) && tag >> 3 == 2);
Assert.AreEqual(4, cin.Position); Assert.AreEqual(4, cin.Position);
uint childlen = cin.ReadRawVarint32(); uint childlen = cin.ReadRawVarint32();
Assert.AreEqual(120u, childlen); Assert.AreEqual(120u, childlen);
@ -444,30 +440,31 @@ namespace Google.Protobuf
// Now we are reading child message // Now we are reading child message
{ {
// Field 11: numeric value: 500 // Field 11: numeric value: 500
Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 11); Assert.IsTrue(cin.ReadTag(out tag) && tag >> 3 == 11);
Assert.AreEqual(6, cin.Position); Assert.AreEqual(6, cin.Position);
Assert.IsTrue(cin.ReadInt32(ref intValue) && intValue == 500); Assert.AreEqual(500, cin.ReadInt32());
Assert.AreEqual(8, cin.Position); Assert.AreEqual(8, cin.Position);
//Field 12: length delimited 120 bytes //Field 12: length delimited 120 bytes
Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 12); Assert.IsTrue(cin.ReadTag(out tag) && tag >> 3 == 12);
Assert.AreEqual(9, cin.Position); Assert.AreEqual(9, cin.Position);
ByteString bstr = null; ByteString bstr = cin.ReadBytes();
Assert.IsTrue(cin.ReadBytes(ref bstr) && bstr.Length == 110 && bstr.ToByteArray()[109] == 109); Assert.AreEqual(110, bstr.Length);
Assert.AreEqual((byte) 109, bstr[109]);
Assert.AreEqual(120, cin.Position); Assert.AreEqual(120, cin.Position);
// Field 13: fixed numeric value: 501 // Field 13: fixed numeric value: 501
Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 13); Assert.IsTrue(cin.ReadTag(out tag) && tag >> 3 == 13);
// ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit // ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit
Assert.AreEqual(121, cin.Position); Assert.AreEqual(121, cin.Position);
Assert.IsTrue(cin.ReadSFixed32(ref intValue) && intValue == 501); Assert.AreEqual(501, cin.ReadSFixed32());
Assert.AreEqual(125, cin.Position); Assert.AreEqual(125, cin.Position);
Assert.IsTrue(cin.IsAtEnd); Assert.IsTrue(cin.IsAtEnd);
} }
cin.PopLimit(oldlimit); cin.PopLimit(oldlimit);
Assert.AreEqual(125, cin.Position); Assert.AreEqual(125, cin.Position);
// Field 3: fixed numeric value: 501 // Field 3: fixed numeric value: 501
Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 3); Assert.IsTrue(cin.ReadTag(out tag) && tag >> 3 == 3);
Assert.AreEqual(126, cin.Position); Assert.AreEqual(126, cin.Position);
Assert.IsTrue(cin.ReadSFixed32(ref intValue) && intValue == 501); Assert.AreEqual(501, cin.ReadSFixed32());
Assert.AreEqual(130, cin.Position); Assert.AreEqual(130, cin.Position);
Assert.IsTrue(cin.IsAtEnd); Assert.IsTrue(cin.IsAtEnd);
} }

@ -107,10 +107,9 @@ namespace Google.Protobuf.TestProtos {
return hash; return hash;
} }
public void WriteTo(pb::ICodedOutputStream output) { public void WriteTo(pb::CodedOutputStream output) {
string[] fieldNames = _fieldNames;
if (D != 0) { if (D != 0) {
output.WriteInt32(1, fieldNames[0], D); output.WriteInt32(1, D);
} }
} }
@ -130,16 +129,9 @@ namespace Google.Protobuf.TestProtos {
} }
} }
public void MergeFrom(pb::ICodedInputStream input) { public void MergeFrom(pb::CodedInputStream input) {
uint tag; uint tag;
string fieldName; while (input.ReadTag(out tag)) {
while (input.ReadTag(out tag, out fieldName)) {
if (tag == 0 && fieldName != null) {
int fieldOrdinal = global::System.Array.BinarySearch(_fieldNames, fieldName, global::System.StringComparer.Ordinal);
if (fieldOrdinal >= 0) {
tag = _fieldTags[fieldOrdinal];
}
}
switch(tag) { switch(tag) {
case 0: case 0:
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
@ -149,7 +141,7 @@ namespace Google.Protobuf.TestProtos {
} }
break; break;
case 8: { case 8: {
input.ReadInt32(ref d_); d_ = input.ReadInt32();
break; break;
} }
} }

@ -92,10 +92,9 @@ namespace Google.Protobuf.TestProtos {
return hash; return hash;
} }
public void WriteTo(pb::ICodedOutputStream output) { public void WriteTo(pb::CodedOutputStream output) {
string[] fieldNames = _fieldNames;
if (E != 0) { if (E != 0) {
output.WriteInt32(1, fieldNames[0], E); output.WriteInt32(1, E);
} }
} }
@ -115,16 +114,9 @@ namespace Google.Protobuf.TestProtos {
} }
} }
public void MergeFrom(pb::ICodedInputStream input) { public void MergeFrom(pb::CodedInputStream input) {
uint tag; uint tag;
string fieldName; while (input.ReadTag(out tag)) {
while (input.ReadTag(out tag, out fieldName)) {
if (tag == 0 && fieldName != null) {
int fieldOrdinal = global::System.Array.BinarySearch(_fieldNames, fieldName, global::System.StringComparer.Ordinal);
if (fieldOrdinal >= 0) {
tag = _fieldTags[fieldOrdinal];
}
}
switch(tag) { switch(tag) {
case 0: case 0:
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
@ -134,7 +126,7 @@ namespace Google.Protobuf.TestProtos {
} }
break; break;
case 8: { case 8: {
input.ReadInt32(ref e_); e_ = input.ReadInt32();
break; break;
} }
} }

@ -153,13 +153,12 @@ namespace UnitTest.Issues.TestProtos {
return hash; return hash;
} }
public void WriteTo(pb::ICodedOutputStream output) { public void WriteTo(pb::CodedOutputStream output) {
string[] fieldNames = _fieldNames;
if (Value != global::UnitTest.Issues.TestProtos.NegativeEnum.NEGATIVE_ENUM_ZERO) { if (Value != global::UnitTest.Issues.TestProtos.NegativeEnum.NEGATIVE_ENUM_ZERO) {
output.WriteEnum(1, fieldNames[1], (int) Value); output.WriteEnum(1, (int) Value);
} }
output.WriteEnumArray(2, fieldNames[2], values_); output.WriteEnumArray(2, values_);
output.WritePackedEnumArray(3, fieldNames[0], packedValues_); output.WritePackedEnumArray(3, packedValues_);
} }
public int CalculateSize() { public int CalculateSize() {
@ -201,16 +200,9 @@ namespace UnitTest.Issues.TestProtos {
packedValues_.Add(other.packedValues_); packedValues_.Add(other.packedValues_);
} }
public void MergeFrom(pb::ICodedInputStream input) { public void MergeFrom(pb::CodedInputStream input) {
uint tag; uint tag;
string fieldName; while (input.ReadTag(out tag)) {
while (input.ReadTag(out tag, out fieldName)) {
if (tag == 0 && fieldName != null) {
int fieldOrdinal = global::System.Array.BinarySearch(_fieldNames, fieldName, global::System.StringComparer.Ordinal);
if (fieldOrdinal >= 0) {
tag = _fieldTags[fieldOrdinal];
}
}
switch(tag) { switch(tag) {
case 0: case 0:
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
@ -220,18 +212,17 @@ namespace UnitTest.Issues.TestProtos {
} }
break; break;
case 8: { case 8: {
int tmp = 0; value_ = (global::UnitTest.Issues.TestProtos.NegativeEnum) input.ReadEnum();
input.ReadEnum(ref tmp); break;
value_ = (global::UnitTest.Issues.TestProtos.NegativeEnum) tmp;break;
} }
case 18: case 18:
case 16: { case 16: {
input.ReadEnumArray<global::UnitTest.Issues.TestProtos.NegativeEnum>(tag, fieldName, values_); input.ReadEnumArray<global::UnitTest.Issues.TestProtos.NegativeEnum>(tag, values_);
break; break;
} }
case 26: case 26:
case 24: { case 24: {
input.ReadEnumArray<global::UnitTest.Issues.TestProtos.NegativeEnum>(tag, fieldName, packedValues_); input.ReadEnumArray<global::UnitTest.Issues.TestProtos.NegativeEnum>(tag, packedValues_);
break; break;
} }
} }
@ -278,8 +269,7 @@ namespace UnitTest.Issues.TestProtos {
return hash; return hash;
} }
public void WriteTo(pb::ICodedOutputStream output) { public void WriteTo(pb::CodedOutputStream output) {
string[] fieldNames = _fieldNames;
} }
public int CalculateSize() { public int CalculateSize() {
@ -292,16 +282,9 @@ namespace UnitTest.Issues.TestProtos {
} }
} }
public void MergeFrom(pb::ICodedInputStream input) { public void MergeFrom(pb::CodedInputStream input) {
uint tag; uint tag;
string fieldName; while (input.ReadTag(out tag)) {
while (input.ReadTag(out tag, out fieldName)) {
if (tag == 0 && fieldName != null) {
int fieldOrdinal = global::System.Array.BinarySearch(_fieldNames, fieldName, global::System.StringComparer.Ordinal);
if (fieldOrdinal >= 0) {
tag = _fieldTags[fieldOrdinal];
}
}
switch(tag) { switch(tag) {
case 0: case 0:
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
@ -412,20 +395,19 @@ namespace UnitTest.Issues.TestProtos {
return hash; return hash;
} }
public void WriteTo(pb::ICodedOutputStream output) { public void WriteTo(pb::CodedOutputStream output) {
string[] fieldNames = _fieldNames;
if (PrimitiveValue != 0) { if (PrimitiveValue != 0) {
output.WriteInt32(1, fieldNames[5], PrimitiveValue); output.WriteInt32(1, PrimitiveValue);
} }
output.WritePackedInt32Array(2, fieldNames[4], primitiveArray_); output.WritePackedInt32Array(2, primitiveArray_);
if (messageValue_ != null) { if (messageValue_ != null) {
output.WriteMessage(3, fieldNames[3], MessageValue); output.WriteMessage(3, MessageValue);
} }
output.WriteMessageArray(4, fieldNames[2], messageArray_); output.WriteMessageArray(4, messageArray_);
if (EnumValue != global::UnitTest.Issues.TestProtos.DeprecatedEnum.DEPRECATED_ZERO) { if (EnumValue != global::UnitTest.Issues.TestProtos.DeprecatedEnum.DEPRECATED_ZERO) {
output.WriteEnum(5, fieldNames[1], (int) EnumValue); output.WriteEnum(5, (int) EnumValue);
} }
output.WritePackedEnumArray(6, fieldNames[0], enumArray_); output.WritePackedEnumArray(6, enumArray_);
} }
public int CalculateSize() { public int CalculateSize() {
@ -486,16 +468,9 @@ namespace UnitTest.Issues.TestProtos {
enumArray_.Add(other.enumArray_); enumArray_.Add(other.enumArray_);
} }
public void MergeFrom(pb::ICodedInputStream input) { public void MergeFrom(pb::CodedInputStream input) {
uint tag; uint tag;
string fieldName; while (input.ReadTag(out tag)) {
while (input.ReadTag(out tag, out fieldName)) {
if (tag == 0 && fieldName != null) {
int fieldOrdinal = global::System.Array.BinarySearch(_fieldNames, fieldName, global::System.StringComparer.Ordinal);
if (fieldOrdinal >= 0) {
tag = _fieldTags[fieldOrdinal];
}
}
switch(tag) { switch(tag) {
case 0: case 0:
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
@ -505,12 +480,12 @@ namespace UnitTest.Issues.TestProtos {
} }
break; break;
case 8: { case 8: {
input.ReadInt32(ref primitiveValue_); primitiveValue_ = input.ReadInt32();
break; break;
} }
case 18: case 18:
case 16: { case 16: {
input.ReadInt32Array(tag, fieldName, primitiveArray_); input.ReadInt32Array(tag, primitiveArray_);
break; break;
} }
case 26: { case 26: {
@ -521,17 +496,16 @@ namespace UnitTest.Issues.TestProtos {
break; break;
} }
case 34: { case 34: {
input.ReadMessageArray(tag, fieldName, messageArray_, global::UnitTest.Issues.TestProtos.DeprecatedChild.Parser); input.ReadMessageArray(tag, messageArray_, global::UnitTest.Issues.TestProtos.DeprecatedChild.Parser);
break; break;
} }
case 40: { case 40: {
int tmp = 0; enumValue_ = (global::UnitTest.Issues.TestProtos.DeprecatedEnum) input.ReadEnum();
input.ReadEnum(ref tmp); break;
enumValue_ = (global::UnitTest.Issues.TestProtos.DeprecatedEnum) tmp;break;
} }
case 50: case 50:
case 48: { case 48: {
input.ReadEnumArray<global::UnitTest.Issues.TestProtos.DeprecatedEnum>(tag, fieldName, enumArray_); input.ReadEnumArray<global::UnitTest.Issues.TestProtos.DeprecatedEnum>(tag, enumArray_);
break; break;
} }
} }
@ -588,10 +562,9 @@ namespace UnitTest.Issues.TestProtos {
return hash; return hash;
} }
public void WriteTo(pb::ICodedOutputStream output) { public void WriteTo(pb::CodedOutputStream output) {
string[] fieldNames = _fieldNames;
if (Item != 0) { if (Item != 0) {
output.WriteInt32(1, fieldNames[0], Item); output.WriteInt32(1, Item);
} }
} }
@ -611,16 +584,9 @@ namespace UnitTest.Issues.TestProtos {
} }
} }
public void MergeFrom(pb::ICodedInputStream input) { public void MergeFrom(pb::CodedInputStream input) {
uint tag; uint tag;
string fieldName; while (input.ReadTag(out tag)) {
while (input.ReadTag(out tag, out fieldName)) {
if (tag == 0 && fieldName != null) {
int fieldOrdinal = global::System.Array.BinarySearch(_fieldNames, fieldName, global::System.StringComparer.Ordinal);
if (fieldOrdinal >= 0) {
tag = _fieldTags[fieldOrdinal];
}
}
switch(tag) { switch(tag) {
case 0: case 0:
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
@ -630,7 +596,7 @@ namespace UnitTest.Issues.TestProtos {
} }
break; break;
case 8: { case 8: {
input.ReadInt32(ref item_); item_ = input.ReadInt32();
break; break;
} }
} }

File diff suppressed because it is too large Load Diff

@ -58,7 +58,7 @@ namespace Google.Protobuf
/// TODO(jonskeet): Consider whether recursion and size limits shouldn't be readonly, /// TODO(jonskeet): Consider whether recursion and size limits shouldn't be readonly,
/// set at construction time. /// set at construction time.
/// </remarks> /// </remarks>
public sealed class CodedInputStream : ICodedInputStream public sealed class CodedInputStream
{ {
private readonly byte[] buffer; private readonly byte[] buffer;
private int bufferSize; private int bufferSize;
@ -173,10 +173,6 @@ namespace Google.Protobuf
} }
} }
void ICodedInputStream.ReadMessageStart() { }
void ICodedInputStream.ReadMessageEnd() { }
#region Validation #region Validation
/// <summary> /// <summary>
@ -201,17 +197,16 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Attempt to peek at the next field tag. /// Attempt to peek at the next field tag.
/// </summary> /// </summary>
public bool PeekNextTag(out uint fieldTag, out string fieldName) public bool PeekNextTag(out uint fieldTag)
{ {
if (hasNextTag) if (hasNextTag)
{ {
fieldName = null;
fieldTag = nextTag; fieldTag = nextTag;
return true; return true;
} }
uint savedLast = lastTag; uint savedLast = lastTag;
hasNextTag = ReadTag(out nextTag, out fieldName); hasNextTag = ReadTag(out nextTag);
lastTag = savedLast; lastTag = savedLast;
fieldTag = nextTag; fieldTag = nextTag;
return hasNextTag; return hasNextTag;
@ -222,12 +217,9 @@ namespace Google.Protobuf
/// of the input data. /// of the input data.
/// </summary> /// </summary>
/// <param name="fieldTag">The 'tag' of the field (id * 8 + wire-format)</param> /// <param name="fieldTag">The 'tag' of the field (id * 8 + wire-format)</param>
/// <param name="fieldName">Not Supported - For protobuffer streams, this parameter is always null</param>
/// <returns>true if the next fieldTag was read</returns> /// <returns>true if the next fieldTag was read</returns>
public bool ReadTag(out uint fieldTag, out string fieldName) public bool ReadTag(out uint fieldTag)
{ {
fieldName = null;
if (hasNextTag) if (hasNextTag)
{ {
fieldTag = nextTag; fieldTag = nextTag;
@ -256,21 +248,21 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Read a double field from the stream. /// Read a double field from the stream.
/// </summary> /// </summary>
public bool ReadDouble(ref double value) public double ReadDouble()
{ {
value = FrameworkPortability.Int64ToDouble((long) ReadRawLittleEndian64()); return FrameworkPortability.Int64ToDouble((long) ReadRawLittleEndian64());
return true;
} }
/// <summary> /// <summary>
/// Read a float field from the stream. /// Read a float field from the stream.
/// </summary> /// </summary>
public bool ReadFloat(ref float value) public float ReadFloat()
{ {
if (BitConverter.IsLittleEndian && 4 <= bufferSize - bufferPos) if (BitConverter.IsLittleEndian && 4 <= bufferSize - bufferPos)
{ {
value = BitConverter.ToSingle(buffer, bufferPos); float ret = BitConverter.ToSingle(buffer, bufferPos);
bufferPos += 4; bufferPos += 4;
return ret;
} }
else else
{ {
@ -279,76 +271,68 @@ namespace Google.Protobuf
{ {
ByteArray.Reverse(rawBytes); ByteArray.Reverse(rawBytes);
} }
value = BitConverter.ToSingle(rawBytes, 0); return BitConverter.ToSingle(rawBytes, 0);
} }
return true;
} }
/// <summary> /// <summary>
/// Read a uint64 field from the stream. /// Read a uint64 field from the stream.
/// </summary> /// </summary>
public bool ReadUInt64(ref ulong value) public ulong ReadUInt64()
{ {
value = ReadRawVarint64(); return ReadRawVarint64();
return true;
} }
/// <summary> /// <summary>
/// Read an int64 field from the stream. /// Read an int64 field from the stream.
/// </summary> /// </summary>
public bool ReadInt64(ref long value) public long ReadInt64()
{ {
value = (long) ReadRawVarint64(); return (long) ReadRawVarint64();
return true;
} }
/// <summary> /// <summary>
/// Read an int32 field from the stream. /// Read an int32 field from the stream.
/// </summary> /// </summary>
public bool ReadInt32(ref int value) public int ReadInt32()
{ {
value = (int) ReadRawVarint32(); return (int) ReadRawVarint32();
return true;
} }
/// <summary> /// <summary>
/// Read a fixed64 field from the stream. /// Read a fixed64 field from the stream.
/// </summary> /// </summary>
public bool ReadFixed64(ref ulong value) public ulong ReadFixed64()
{ {
value = ReadRawLittleEndian64(); return ReadRawLittleEndian64();
return true;
} }
/// <summary> /// <summary>
/// Read a fixed32 field from the stream. /// Read a fixed32 field from the stream.
/// </summary> /// </summary>
public bool ReadFixed32(ref uint value) public uint ReadFixed32()
{ {
value = ReadRawLittleEndian32(); return ReadRawLittleEndian32();
return true;
} }
/// <summary> /// <summary>
/// Read a bool field from the stream. /// Read a bool field from the stream.
/// </summary> /// </summary>
public bool ReadBool(ref bool value) public bool ReadBool()
{ {
value = ReadRawVarint32() != 0; return ReadRawVarint32() != 0;
return true;
} }
/// <summary> /// <summary>
/// Reads a string field from the stream. /// Reads a string field from the stream.
/// </summary> /// </summary>
public bool ReadString(ref string value) public string ReadString()
{ {
int size = (int) ReadRawVarint32(); int size = (int) ReadRawVarint32();
// No need to read any data for an empty string. // No need to read any data for an empty string.
if (size == 0) if (size == 0)
{ {
value = ""; return "";
return true;
} }
if (size <= bufferSize - bufferPos) if (size <= bufferSize - bufferPos)
{ {
@ -356,12 +340,10 @@ namespace Google.Protobuf
// just copy directly from it. // just copy directly from it.
String result = Encoding.UTF8.GetString(buffer, bufferPos, size); String result = Encoding.UTF8.GetString(buffer, bufferPos, size);
bufferPos += size; bufferPos += size;
value = result; return result;
return true;
} }
// Slow path: Build a byte array first then copy it. // Slow path: Build a byte array first then copy it.
value = Encoding.UTF8.GetString(ReadRawBytes(size), 0, size); return Encoding.UTF8.GetString(ReadRawBytes(size), 0, size);
return true;
} }
/// <summary> /// <summary>
@ -400,7 +382,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Reads a bytes field value from the stream. /// Reads a bytes field value from the stream.
/// </summary> /// </summary>
public bool ReadBytes(ref ByteString value) public ByteString ReadBytes()
{ {
int size = (int) ReadRawVarint32(); int size = (int) ReadRawVarint32();
if (size <= bufferSize - bufferPos && size > 0) if (size <= bufferSize - bufferPos && size > 0)
@ -409,24 +391,21 @@ namespace Google.Protobuf
// just copy directly from it. // just copy directly from it.
ByteString result = ByteString.CopyFrom(buffer, bufferPos, size); ByteString result = ByteString.CopyFrom(buffer, bufferPos, size);
bufferPos += size; bufferPos += size;
value = result; return result;
return true;
} }
else else
{ {
// Slow path: Build a byte array and attach it to a new ByteString. // Slow path: Build a byte array and attach it to a new ByteString.
value = ByteString.AttachBytes(ReadRawBytes(size)); return ByteString.AttachBytes(ReadRawBytes(size));
return true;
} }
} }
/// <summary> /// <summary>
/// Reads a uint32 field value from the stream. /// Reads a uint32 field value from the stream.
/// </summary> /// </summary>
public bool ReadUInt32(ref uint value) public uint ReadUInt32()
{ {
value = ReadRawVarint32(); return ReadRawVarint32();
return true;
} }
/// <summary> /// <summary>
@ -434,47 +413,42 @@ namespace Google.Protobuf
/// then the ref value is set and it returns true. Otherwise the unknown output /// then the ref value is set and it returns true. Otherwise the unknown output
/// value is set and this method returns false. /// value is set and this method returns false.
/// </summary> /// </summary>
public bool ReadEnum(ref int value) public int ReadEnum()
{ {
// Currently just a pass-through, but it's nice to separate it logically from WriteInt32. // Currently just a pass-through, but it's nice to separate it logically from WriteInt32.
value = (int) ReadRawVarint32(); return (int) ReadRawVarint32();
return true;
} }
/// <summary> /// <summary>
/// Reads an sfixed32 field value from the stream. /// Reads an sfixed32 field value from the stream.
/// </summary> /// </summary>
public bool ReadSFixed32(ref int value) public int ReadSFixed32()
{ {
value = (int) ReadRawLittleEndian32(); return (int) ReadRawLittleEndian32();
return true;
} }
/// <summary> /// <summary>
/// Reads an sfixed64 field value from the stream. /// Reads an sfixed64 field value from the stream.
/// </summary> /// </summary>
public bool ReadSFixed64(ref long value) public long ReadSFixed64()
{ {
value = (long) ReadRawLittleEndian64(); return (long) ReadRawLittleEndian64();
return true;
} }
/// <summary> /// <summary>
/// Reads an sint32 field value from the stream. /// Reads an sint32 field value from the stream.
/// </summary> /// </summary>
public bool ReadSInt32(ref int value) public int ReadSInt32()
{ {
value = DecodeZigZag32(ReadRawVarint32()); return DecodeZigZag32(ReadRawVarint32());
return true;
} }
/// <summary> /// <summary>
/// Reads an sint64 field value from the stream. /// Reads an sint64 field value from the stream.
/// </summary> /// </summary>
public bool ReadSInt64(ref long value) public long ReadSInt64()
{ {
value = DecodeZigZag64(ReadRawVarint64()); return DecodeZigZag64(ReadRawVarint64());
return true;
} }
private bool BeginArray(uint fieldTag, out bool isPacked, out int oldLimit) private bool BeginArray(uint fieldTag, out bool isPacked, out int oldLimit)
@ -502,9 +476,8 @@ namespace Google.Protobuf
/// </summary> /// </summary>
private bool ContinueArray(uint currentTag) private bool ContinueArray(uint currentTag)
{ {
string ignore;
uint next; uint next;
if (PeekNextTag(out next, out ignore)) if (PeekNextTag(out next))
{ {
if (next == currentTag) if (next == currentTag)
{ {
@ -530,9 +503,8 @@ namespace Google.Protobuf
return true; return true;
} }
string ignore;
uint next; uint next;
if (PeekNextTag(out next, out ignore)) if (PeekNextTag(out next))
{ {
if (next == currentTag) if (next == currentTag)
{ {
@ -543,259 +515,194 @@ namespace Google.Protobuf
return false; return false;
} }
public void ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName, ICollection<object> list) public void ReadStringArray(uint fieldTag, ICollection<string> list)
{
WireFormat.WireType normal = WireFormat.GetWireType(fieldType);
WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag);
// 2.3 allows packed form even if the field is not declared packed.
if (normal != wformat && wformat == WireFormat.WireType.LengthDelimited)
{
int length = (int) (ReadRawVarint32() & int.MaxValue);
int limit = PushLimit(length);
while (!ReachedLimit)
{
Object value = null;
if (ReadPrimitiveField(fieldType, ref value))
{
list.Add(value);
}
}
PopLimit(limit);
}
else
{
Object value = null;
do
{
if (ReadPrimitiveField(fieldType, ref value))
{
list.Add(value);
}
} while (ContinueArray(fieldTag));
}
}
public void ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list)
{ {
string tmp = null;
do do
{ {
ReadString(ref tmp); list.Add(ReadString());
list.Add(tmp);
} while (ContinueArray(fieldTag)); } while (ContinueArray(fieldTag));
} }
public void ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list) public void ReadBytesArray(uint fieldTag, ICollection<ByteString> list)
{ {
ByteString tmp = null;
do do
{ {
ReadBytes(ref tmp); list.Add(ReadBytes());
list.Add(tmp);
} while (ContinueArray(fieldTag)); } while (ContinueArray(fieldTag));
} }
public void ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list) public void ReadBoolArray(uint fieldTag, ICollection<bool> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
bool tmp = false;
do do
{ {
ReadBool(ref tmp); list.Add(ReadBool());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list) public void ReadInt32Array(uint fieldTag, ICollection<int> list)
{ {
// TODO(jonskeet): Work out how this works for non-packed values. (It doesn't look like it does...)
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
int tmp = 0;
do do
{ {
ReadInt32(ref tmp); list.Add(ReadInt32());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list) public void ReadSInt32Array(uint fieldTag, ICollection<int> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
int tmp = 0;
do do
{ {
ReadSInt32(ref tmp); list.Add(ReadSInt32());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list) public void ReadUInt32Array(uint fieldTag, ICollection<uint> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
uint tmp = 0;
do do
{ {
ReadUInt32(ref tmp); list.Add(ReadUInt32());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list) public void ReadFixed32Array(uint fieldTag, ICollection<uint> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
uint tmp = 0;
do do
{ {
ReadFixed32(ref tmp); list.Add(ReadFixed32());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list) public void ReadSFixed32Array(uint fieldTag, ICollection<int> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
int tmp = 0;
do do
{ {
ReadSFixed32(ref tmp); list.Add(ReadSFixed32());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list) public void ReadInt64Array(uint fieldTag, ICollection<long> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
long tmp = 0;
do do
{ {
ReadInt64(ref tmp); list.Add(ReadInt64());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list) public void ReadSInt64Array(uint fieldTag, ICollection<long> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
long tmp = 0;
do do
{ {
ReadSInt64(ref tmp); list.Add(ReadSInt64());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list) public void ReadUInt64Array(uint fieldTag, ICollection<ulong> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
ulong tmp = 0;
do do
{ {
ReadUInt64(ref tmp); list.Add(ReadUInt64());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list) public void ReadFixed64Array(uint fieldTag, ICollection<ulong> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
ulong tmp = 0;
do do
{ {
ReadFixed64(ref tmp); list.Add(ReadFixed64());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list) public void ReadSFixed64Array(uint fieldTag, ICollection<long> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
long tmp = 0;
do do
{ {
ReadSFixed64(ref tmp); list.Add(ReadSFixed64());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list) public void ReadDoubleArray(uint fieldTag, ICollection<double> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
double tmp = 0;
do do
{ {
ReadDouble(ref tmp); list.Add(ReadDouble());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list) public void ReadFloatArray(uint fieldTag, ICollection<float> list)
{ {
bool isPacked; bool isPacked;
int holdLimit; int holdLimit;
if (BeginArray(fieldTag, out isPacked, out holdLimit)) if (BeginArray(fieldTag, out isPacked, out holdLimit))
{ {
float tmp = 0;
do do
{ {
ReadFloat(ref tmp); list.Add(ReadFloat());
list.Add(tmp);
} while (ContinueArray(fieldTag, isPacked, holdLimit)); } while (ContinueArray(fieldTag, isPacked, holdLimit));
} }
} }
public void ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list) public void ReadEnumArray<T>(uint fieldTag, ICollection<T> list)
where T : struct, IComparable, IFormattable where T : struct, IComparable, IFormattable
{ {
int value = 0;
WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag); WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag);
// 2.3 allows packed form even if the field is not declared packed. // 2.3 allows packed form even if the field is not declared packed.
@ -805,9 +712,8 @@ namespace Google.Protobuf
int limit = PushLimit(length); int limit = PushLimit(length);
while (!ReachedLimit) while (!ReachedLimit)
{ {
ReadEnum(ref value);
// TODO(jonskeet): Avoid this horrible boxing! // TODO(jonskeet): Avoid this horrible boxing!
list.Add((T)(object)value); list.Add((T)(object) ReadEnum());
} }
PopLimit(limit); PopLimit(limit);
} }
@ -815,14 +721,12 @@ namespace Google.Protobuf
{ {
do do
{ {
ReadEnum(ref value); list.Add((T)(object) ReadEnum());
// TODO(jonskeet): Avoid this horrible boxing!
list.Add((T)(object) value);
} while (ContinueArray(fieldTag)); } while (ContinueArray(fieldTag));
} }
} }
public void ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, MessageParser<T> messageParser) public void ReadMessageArray<T>(uint fieldTag, ICollection<T> list, MessageParser<T> messageParser)
where T : IMessage<T> where T : IMessage<T>
{ {
do do
@ -833,7 +737,7 @@ namespace Google.Protobuf
} while (ContinueArray(fieldTag)); } while (ContinueArray(fieldTag));
} }
public void ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, MessageParser<T> messageParser) public void ReadGroupArray<T>(uint fieldTag, ICollection<T> list, MessageParser<T> messageParser)
where T : IMessage<T> where T : IMessage<T>
{ {
do do
@ -843,178 +747,6 @@ namespace Google.Protobuf
list.Add(message); list.Add(message);
} while (ContinueArray(fieldTag)); } while (ContinueArray(fieldTag));
} }
/// <summary>
/// Reads a field of any primitive type. Enums, groups and embedded
/// messages are not handled by this method.
/// </summary>
public bool ReadPrimitiveField(FieldType fieldType, ref object value)
{
switch (fieldType)
{
case FieldType.Double:
{
double tmp = 0;
if (ReadDouble(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Float:
{
float tmp = 0;
if (ReadFloat(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Int64:
{
long tmp = 0;
if (ReadInt64(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.UInt64:
{
ulong tmp = 0;
if (ReadUInt64(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Int32:
{
int tmp = 0;
if (ReadInt32(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Fixed64:
{
ulong tmp = 0;
if (ReadFixed64(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Fixed32:
{
uint tmp = 0;
if (ReadFixed32(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Bool:
{
bool tmp = false;
if (ReadBool(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.String:
{
string tmp = null;
if (ReadString(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Bytes:
{
ByteString tmp = null;
if (ReadBytes(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.UInt32:
{
uint tmp = 0;
if (ReadUInt32(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.SFixed32:
{
int tmp = 0;
if (ReadSFixed32(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.SFixed64:
{
long tmp = 0;
if (ReadSFixed64(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.SInt32:
{
int tmp = 0;
if (ReadSInt32(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.SInt64:
{
long tmp = 0;
if (ReadSInt64(ref tmp))
{
value = tmp;
return true;
}
return false;
}
case FieldType.Group:
throw new ArgumentException("ReadPrimitiveField() cannot handle nested groups.");
case FieldType.Message:
throw new ArgumentException("ReadPrimitiveField() cannot handle embedded messages.");
// We don't handle enums because we don't know what to do if the
// value is not recognized.
case FieldType.Enum:
throw new ArgumentException("ReadPrimitiveField() cannot handle enums.");
default:
throw new ArgumentOutOfRangeException("Invalid field type " + fieldType);
}
}
#endregion #endregion
#region Underlying reading primitives #region Underlying reading primitives
@ -1622,8 +1354,7 @@ namespace Google.Protobuf
public void SkipMessage() public void SkipMessage()
{ {
uint tag; uint tag;
string name; while (ReadTag(out tag))
while (ReadTag(out tag, out name))
{ {
if (!SkipField()) if (!SkipField())
{ {

@ -413,41 +413,12 @@ namespace Google.Protobuf
return ComputeRawVarint64Size(EncodeZigZag64(value)); return ComputeRawVarint64Size(EncodeZigZag64(value));
} }
/*
* Compute the number of bytes that would be needed to encode a
* MessageSet extension to the stream. For historical reasons,
* the wire format differs from normal fields.
*/
/// <summary>
/// Compute the number of bytes that would be needed to encode a
/// MessageSet extension to the stream. For historical reasons,
/// the wire format differs from normal fields.
/// </summary>
public static int ComputeMessageSetExtensionSize(int fieldNumber, IMessage value)
{
return ComputeTagSize(WireFormat.MessageSetField.Item)*2 +
ComputeUInt32Size(WireFormat.MessageSetField.TypeID, (uint) fieldNumber) +
ComputeMessageSize(WireFormat.MessageSetField.Message, value);
}
/// <summary>
/// Compute the number of bytes that would be needed to encode an
/// unparsed MessageSet extension field to the stream. For
/// historical reasons, the wire format differs from normal fields.
/// </summary>
public static int ComputeRawMessageSetExtensionSize(int fieldNumber, ByteString value)
{
return ComputeTagSize(WireFormat.MessageSetField.Item)*2 +
ComputeUInt32Size(WireFormat.MessageSetField.TypeID, (uint) fieldNumber) +
ComputeBytesSize(WireFormat.MessageSetField.Message, value);
}
/// <summary> /// <summary>
/// Compute the number of bytes that would be needed to encode a varint. /// Compute the number of bytes that would be needed to encode a varint.
/// </summary> /// </summary>
public static int ComputeRawVarint32Size(uint value) public static int ComputeRawVarint32Size(uint value)
{ {
// TODO(jonskeet): Look at optimizing this to just hard-coded comparisons.
if ((value & (0xffffffff << 7)) == 0) if ((value & (0xffffffff << 7)) == 0)
{ {
return 1; return 1;
@ -472,6 +443,7 @@ namespace Google.Protobuf
/// </summary> /// </summary>
public static int ComputeRawVarint64Size(ulong value) public static int ComputeRawVarint64Size(ulong value)
{ {
// TODO(jonskeet): Look at optimizing this to just hard-coded comparisons.
if ((value & (0xffffffffffffffffL << 7)) == 0) if ((value & (0xffffffffffffffffL << 7)) == 0)
{ {
return 1; return 1;
@ -511,106 +483,6 @@ namespace Google.Protobuf
return 10; return 10;
} }
/// <summary>
/// Compute the number of bytes that would be needed to encode a
/// field of arbitrary type, including the tag, to the stream.
/// </summary>
// TODO(jonskeet): Why do we need this?
public static int ComputeFieldSize(FieldType fieldType, int fieldNumber, Object value)
{
switch (fieldType)
{
case FieldType.Double:
return ComputeDoubleSize(fieldNumber, (double) value);
case FieldType.Float:
return ComputeFloatSize(fieldNumber, (float) value);
case FieldType.Int64:
return ComputeInt64Size(fieldNumber, (long) value);
case FieldType.UInt64:
return ComputeUInt64Size(fieldNumber, (ulong) value);
case FieldType.Int32:
return ComputeInt32Size(fieldNumber, (int) value);
case FieldType.Fixed64:
return ComputeFixed64Size(fieldNumber, (ulong) value);
case FieldType.Fixed32:
return ComputeFixed32Size(fieldNumber, (uint) value);
case FieldType.Bool:
return ComputeBoolSize(fieldNumber, (bool) value);
case FieldType.String:
return ComputeStringSize(fieldNumber, (string) value);
case FieldType.Group:
return ComputeGroupSize(fieldNumber, (IMessage) value);
case FieldType.Message:
return ComputeMessageSize(fieldNumber, (IMessage) value);
case FieldType.Bytes:
return ComputeBytesSize(fieldNumber, (ByteString) value);
case FieldType.UInt32:
return ComputeUInt32Size(fieldNumber, (uint) value);
case FieldType.SFixed32:
return ComputeSFixed32Size(fieldNumber, (int) value);
case FieldType.SFixed64:
return ComputeSFixed64Size(fieldNumber, (long) value);
case FieldType.SInt32:
return ComputeSInt32Size(fieldNumber, (int) value);
case FieldType.SInt64:
return ComputeSInt64Size(fieldNumber, (long) value);
case FieldType.Enum:
return ComputeEnumSize(fieldNumber, (int) value);
default:
throw new ArgumentOutOfRangeException("Invalid field type " + fieldType);
}
}
/// <summary>
/// Compute the number of bytes that would be needed to encode a
/// field of arbitrary type, excluding the tag, to the stream.
/// </summary>
// TODO(jonskeet): Why do we need this?
public static int ComputeFieldSizeNoTag(FieldType fieldType, Object value)
{
switch (fieldType)
{
case FieldType.Double:
return ComputeDoubleSizeNoTag((double) value);
case FieldType.Float:
return ComputeFloatSizeNoTag((float) value);
case FieldType.Int64:
return ComputeInt64SizeNoTag((long) value);
case FieldType.UInt64:
return ComputeUInt64SizeNoTag((ulong) value);
case FieldType.Int32:
return ComputeInt32SizeNoTag((int) value);
case FieldType.Fixed64:
return ComputeFixed64SizeNoTag((ulong) value);
case FieldType.Fixed32:
return ComputeFixed32SizeNoTag((uint) value);
case FieldType.Bool:
return ComputeBoolSizeNoTag((bool) value);
case FieldType.String:
return ComputeStringSizeNoTag((string) value);
case FieldType.Group:
return ComputeGroupSizeNoTag((IMessage) value);
case FieldType.Message:
return ComputeMessageSizeNoTag((IMessage) value);
case FieldType.Bytes:
return ComputeBytesSizeNoTag((ByteString) value);
case FieldType.UInt32:
return ComputeUInt32SizeNoTag((uint) value);
case FieldType.SFixed32:
return ComputeSFixed32SizeNoTag((int) value);
case FieldType.SFixed64:
return ComputeSFixed64SizeNoTag((long) value);
case FieldType.SInt32:
return ComputeSInt32SizeNoTag((int) value);
case FieldType.SInt64:
return ComputeSInt64SizeNoTag((long) value);
case FieldType.Enum:
return ComputeEnumSizeNoTag((int) value);
default:
throw new ArgumentOutOfRangeException("Invalid field type " + fieldType);
}
}
/// <summary> /// <summary>
/// Compute the number of bytes that would be needed to encode a tag. /// Compute the number of bytes that would be needed to encode a tag.
/// </summary> /// </summary>

@ -57,7 +57,7 @@ namespace Google.Protobuf
/// methods are taken from the protocol buffer type names, not .NET types. /// methods are taken from the protocol buffer type names, not .NET types.
/// (Hence WriteFloat instead of WriteSingle, and WriteBool instead of WriteBoolean.) /// (Hence WriteFloat instead of WriteSingle, and WriteBool instead of WriteBoolean.)
/// </remarks> /// </remarks>
public sealed partial class CodedOutputStream : ICodedOutputStream public sealed partial class CodedOutputStream
{ {
private static readonly Encoding UTF8 = Encoding.UTF8; private static readonly Encoding UTF8 = Encoding.UTF8;
@ -143,76 +143,11 @@ namespace Google.Protobuf
} }
} }
void ICodedOutputStream.WriteMessageStart() { }
void ICodedOutputStream.WriteMessageEnd() { Flush(); }
#region Writing of tags and fields #region Writing of tags and fields
// TODO(jonskeet): Do we need this?
public void WriteField(FieldType fieldType, int fieldNumber, string fieldName, object value)
{
switch (fieldType)
{
case FieldType.String:
WriteString(fieldNumber, fieldName, (string) value);
break;
case FieldType.Message:
WriteMessage(fieldNumber, fieldName, (IMessage) value);
break;
case FieldType.Group:
WriteGroup(fieldNumber, fieldName, (IMessage) value);
break;
case FieldType.Bytes:
WriteBytes(fieldNumber, fieldName, (ByteString) value);
break;
case FieldType.Bool:
WriteBool(fieldNumber, fieldName, (bool) value);
break;
case FieldType.Enum:
throw new NotImplementedException();
case FieldType.Int32:
WriteInt32(fieldNumber, fieldName, (int) value);
break;
case FieldType.Int64:
WriteInt64(fieldNumber, fieldName, (long) value);
break;
case FieldType.UInt32:
WriteUInt32(fieldNumber, fieldName, (uint) value);
break;
case FieldType.UInt64:
WriteUInt64(fieldNumber, fieldName, (ulong) value);
break;
case FieldType.SInt32:
WriteSInt32(fieldNumber, fieldName, (int) value);
break;
case FieldType.SInt64:
WriteSInt64(fieldNumber, fieldName, (long) value);
break;
case FieldType.Fixed32:
WriteFixed32(fieldNumber, fieldName, (uint) value);
break;
case FieldType.Fixed64:
WriteFixed64(fieldNumber, fieldName, (ulong) value);
break;
case FieldType.SFixed32:
WriteSFixed32(fieldNumber, fieldName, (int) value);
break;
case FieldType.SFixed64:
WriteSFixed64(fieldNumber, fieldName, (long) value);
break;
case FieldType.Double:
WriteDouble(fieldNumber, fieldName, (double) value);
break;
case FieldType.Float:
WriteFloat(fieldNumber, fieldName, (float) value);
break;
}
}
/// <summary> /// <summary>
/// Writes a double field value, including tag, to the stream. /// Writes a double field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteDouble(int fieldNumber, string fieldName, double value) public void WriteDouble(int fieldNumber, double value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Fixed64); WriteTag(fieldNumber, WireFormat.WireType.Fixed64);
WriteDoubleNoTag(value); WriteDoubleNoTag(value);
@ -221,7 +156,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes a float field value, including tag, to the stream. /// Writes a float field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteFloat(int fieldNumber, string fieldName, float value) public void WriteFloat(int fieldNumber, float value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Fixed32); WriteTag(fieldNumber, WireFormat.WireType.Fixed32);
WriteFloatNoTag(value); WriteFloatNoTag(value);
@ -230,7 +165,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes a uint64 field value, including tag, to the stream. /// Writes a uint64 field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteUInt64(int fieldNumber, string fieldName, ulong value) public void WriteUInt64(int fieldNumber, ulong value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteRawVarint64(value); WriteRawVarint64(value);
@ -239,7 +174,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes an int64 field value, including tag, to the stream. /// Writes an int64 field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteInt64(int fieldNumber, string fieldName, long value) public void WriteInt64(int fieldNumber, long value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteRawVarint64((ulong) value); WriteRawVarint64((ulong) value);
@ -248,7 +183,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes an int32 field value, including tag, to the stream. /// Writes an int32 field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteInt32(int fieldNumber, string fieldName, int value) public void WriteInt32(int fieldNumber, int value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
if (value >= 0) if (value >= 0)
@ -265,7 +200,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes a fixed64 field value, including tag, to the stream. /// Writes a fixed64 field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteFixed64(int fieldNumber, string fieldName, ulong value) public void WriteFixed64(int fieldNumber, ulong value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Fixed64); WriteTag(fieldNumber, WireFormat.WireType.Fixed64);
WriteRawLittleEndian64(value); WriteRawLittleEndian64(value);
@ -274,7 +209,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes a fixed32 field value, including tag, to the stream. /// Writes a fixed32 field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteFixed32(int fieldNumber, string fieldName, uint value) public void WriteFixed32(int fieldNumber, uint value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Fixed32); WriteTag(fieldNumber, WireFormat.WireType.Fixed32);
WriteRawLittleEndian32(value); WriteRawLittleEndian32(value);
@ -283,7 +218,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes a bool field value, including tag, to the stream. /// Writes a bool field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteBool(int fieldNumber, string fieldName, bool value) public void WriteBool(int fieldNumber, bool value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteRawByte(value ? (byte) 1 : (byte) 0); WriteRawByte(value ? (byte) 1 : (byte) 0);
@ -292,7 +227,7 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes a string field value, including tag, to the stream. /// Writes a string field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteString(int fieldNumber, string fieldName, string value) public void WriteString(int fieldNumber, string value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited); WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
// Optimise the case where we have enough space to write // Optimise the case where we have enough space to write
@ -324,80 +259,63 @@ namespace Google.Protobuf
/// <summary> /// <summary>
/// Writes a group field value, including tag, to the stream. /// Writes a group field value, including tag, to the stream.
/// </summary> /// </summary>
public void WriteGroup(int fieldNumber, string fieldName, IMessage value) public void WriteGroup(int fieldNumber, IMessage value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.StartGroup); WriteTag(fieldNumber, WireFormat.WireType.StartGroup);
value.WriteTo(this); value.WriteTo(this);
WriteTag(fieldNumber, WireFormat.WireType.EndGroup); WriteTag(fieldNumber, WireFormat.WireType.EndGroup);
} }
public void WriteMessage(int fieldNumber, string fieldName, IMessage value) public void WriteMessage(int fieldNumber, IMessage value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited); WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
WriteRawVarint32((uint) value.CalculateSize()); WriteRawVarint32((uint) value.CalculateSize());
value.WriteTo(this); value.WriteTo(this);
} }
public void WriteBytes(int fieldNumber, string fieldName, ByteString value) public void WriteBytes(int fieldNumber, ByteString value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited); WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
WriteRawVarint32((uint) value.Length); WriteRawVarint32((uint) value.Length);
value.WriteRawBytesTo(this); value.WriteRawBytesTo(this);
} }
public void WriteUInt32(int fieldNumber, string fieldName, uint value) public void WriteUInt32(int fieldNumber, uint value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteRawVarint32(value); WriteRawVarint32(value);
} }
public void WriteEnum(int fieldNumber, string fieldName, int value) public void WriteEnum(int fieldNumber, int value)
{ {
// Currently just a pass-through, but it's nice to separate it logically from WriteInt32. // Currently just a pass-through, but it's nice to separate it logically from WriteInt32.
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteInt32NoTag(value); WriteInt32NoTag(value);
} }
public void WriteSFixed32(int fieldNumber, string fieldName, int value) public void WriteSFixed32(int fieldNumber, int value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Fixed32); WriteTag(fieldNumber, WireFormat.WireType.Fixed32);
WriteRawLittleEndian32((uint) value); WriteRawLittleEndian32((uint) value);
} }
public void WriteSFixed64(int fieldNumber, string fieldName, long value) public void WriteSFixed64(int fieldNumber, long value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Fixed64); WriteTag(fieldNumber, WireFormat.WireType.Fixed64);
WriteRawLittleEndian64((ulong) value); WriteRawLittleEndian64((ulong) value);
} }
public void WriteSInt32(int fieldNumber, string fieldName, int value) public void WriteSInt32(int fieldNumber, int value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteRawVarint32(EncodeZigZag32(value)); WriteRawVarint32(EncodeZigZag32(value));
} }
public void WriteSInt64(int fieldNumber, string fieldName, long value) public void WriteSInt64(int fieldNumber, long value)
{ {
WriteTag(fieldNumber, WireFormat.WireType.Varint); WriteTag(fieldNumber, WireFormat.WireType.Varint);
WriteRawVarint64(EncodeZigZag64(value)); WriteRawVarint64(EncodeZigZag64(value));
} }
public void WriteMessageSetExtension(int fieldNumber, string fieldName, IMessage value)
{
WriteTag(WireFormat.MessageSetField.Item, WireFormat.WireType.StartGroup);
WriteUInt32(WireFormat.MessageSetField.TypeID, "type_id", (uint) fieldNumber);
WriteMessage(WireFormat.MessageSetField.Message, "message", value);
WriteTag(WireFormat.MessageSetField.Item, WireFormat.WireType.EndGroup);
}
public void WriteMessageSetExtension(int fieldNumber, string fieldName, ByteString value)
{
WriteTag(WireFormat.MessageSetField.Item, WireFormat.WireType.StartGroup);
WriteUInt32(WireFormat.MessageSetField.TypeID, "type_id", (uint) fieldNumber);
WriteBytes(WireFormat.MessageSetField.Message, "message", value);
WriteTag(WireFormat.MessageSetField.Item, WireFormat.WireType.EndGroup);
}
#endregion #endregion
#region Writing of values without tags #region Writing of values without tags
@ -625,155 +543,145 @@ namespace Google.Protobuf
#endregion #endregion
#region Write array members #region Write array members
public void WriteGroupArray<T>(int fieldNumber, RepeatedField<T> list)
// TODO(jonskeet): Remove?
public void WriteArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list)
{
foreach (object element in list)
{
WriteField(fieldType, fieldNumber, fieldName, element);
}
}
public void WriteGroupArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
where T : IMessage where T : IMessage
{ {
foreach (IMessage value in list) foreach (IMessage value in list)
{ {
WriteGroup(fieldNumber, fieldName, value); WriteGroup(fieldNumber, value);
} }
} }
public void WriteMessageArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list) public void WriteMessageArray<T>(int fieldNumber, RepeatedField<T> list)
where T : IMessage where T : IMessage
{ {
foreach (IMessage value in list) foreach (IMessage value in list)
{ {
WriteMessage(fieldNumber, fieldName, value); WriteMessage(fieldNumber, value);
} }
} }
public void WriteStringArray(int fieldNumber, string fieldName, RepeatedField<string> list) public void WriteStringArray(int fieldNumber, RepeatedField<string> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteString(fieldNumber, fieldName, value); WriteString(fieldNumber, value);
} }
} }
public void WriteBytesArray(int fieldNumber, string fieldName, RepeatedField<ByteString> list) public void WriteBytesArray(int fieldNumber, RepeatedField<ByteString> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteBytes(fieldNumber, fieldName, value); WriteBytes(fieldNumber, value);
} }
} }
public void WriteBoolArray(int fieldNumber, string fieldName, RepeatedField<bool> list) public void WriteBoolArray(int fieldNumber, RepeatedField<bool> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteBool(fieldNumber, fieldName, value); WriteBool(fieldNumber, value);
} }
} }
public void WriteInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list) public void WriteInt32Array(int fieldNumber, RepeatedField<int> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteInt32(fieldNumber, fieldName, value); WriteInt32(fieldNumber, value);
} }
} }
public void WriteSInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list) public void WriteSInt32Array(int fieldNumber, RepeatedField<int> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteSInt32(fieldNumber, fieldName, value); WriteSInt32(fieldNumber, value);
} }
} }
public void WriteUInt32Array(int fieldNumber, string fieldName, RepeatedField<uint> list) public void WriteUInt32Array(int fieldNumber, RepeatedField<uint> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteUInt32(fieldNumber, fieldName, value); WriteUInt32(fieldNumber, value);
} }
} }
public void WriteFixed32Array(int fieldNumber, string fieldName, RepeatedField<uint> list) public void WriteFixed32Array(int fieldNumber, RepeatedField<uint> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteFixed32(fieldNumber, fieldName, value); WriteFixed32(fieldNumber, value);
} }
} }
public void WriteSFixed32Array(int fieldNumber, string fieldName, RepeatedField<int> list) public void WriteSFixed32Array(int fieldNumber, RepeatedField<int> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteSFixed32(fieldNumber, fieldName, value); WriteSFixed32(fieldNumber, value);
} }
} }
public void WriteInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list) public void WriteInt64Array(int fieldNumber, RepeatedField<long> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteInt64(fieldNumber, fieldName, value); WriteInt64(fieldNumber, value);
} }
} }
public void WriteSInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list) public void WriteSInt64Array(int fieldNumber, RepeatedField<long> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteSInt64(fieldNumber, fieldName, value); WriteSInt64(fieldNumber, value);
} }
} }
public void WriteUInt64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list) public void WriteUInt64Array(int fieldNumber, RepeatedField<ulong> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteUInt64(fieldNumber, fieldName, value); WriteUInt64(fieldNumber, value);
} }
} }
public void WriteFixed64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list) public void WriteFixed64Array(int fieldNumber, RepeatedField<ulong> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteFixed64(fieldNumber, fieldName, value); WriteFixed64(fieldNumber, value);
} }
} }
public void WriteSFixed64Array(int fieldNumber, string fieldName, RepeatedField<long> list) public void WriteSFixed64Array(int fieldNumber, RepeatedField<long> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteSFixed64(fieldNumber, fieldName, value); WriteSFixed64(fieldNumber, value);
} }
} }
public void WriteDoubleArray(int fieldNumber, string fieldName, RepeatedField<double> list) public void WriteDoubleArray(int fieldNumber, RepeatedField<double> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteDouble(fieldNumber, fieldName, value); WriteDouble(fieldNumber, value);
} }
} }
public void WriteFloatArray(int fieldNumber, string fieldName, RepeatedField<float> list) public void WriteFloatArray(int fieldNumber, RepeatedField<float> list)
{ {
foreach (var value in list) foreach (var value in list)
{ {
WriteFloat(fieldNumber, fieldName, value); WriteFloat(fieldNumber, value);
} }
} }
public void WriteEnumArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list) public void WriteEnumArray<T>(int fieldNumber, RepeatedField<T> list)
where T : struct, IComparable, IFormattable where T : struct, IComparable, IFormattable
{ {
if (list.Count == 0) if (list.Count == 0)
@ -783,34 +691,15 @@ namespace Google.Protobuf
// TODO(jonskeet): Avoid the Cast call here. Work out a better mass "T to int" conversion. // TODO(jonskeet): Avoid the Cast call here. Work out a better mass "T to int" conversion.
foreach (int value in list.Cast<int>()) foreach (int value in list.Cast<int>())
{ {
WriteEnum(fieldNumber, fieldName, value); WriteEnum(fieldNumber, value);
} }
} }
#endregion #endregion
#region Write packed array members #region Write packed array members
// TODO(jonskeet): Remove?
public void WritePackedArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list)
{
int calculatedSize = 0;
foreach (object element in list)
{
calculatedSize += ComputeFieldSizeNoTag(fieldType, element);
}
WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
WriteRawVarint32((uint) calculatedSize);
foreach (object element in list)
{
WriteFieldNoTag(fieldType, element);
}
}
// TODO(jonskeet): A lot of these are really inefficient, due to method group conversions. Fix! // TODO(jonskeet): A lot of these are really inefficient, due to method group conversions. Fix!
public void WritePackedBoolArray(int fieldNumber, string fieldName, RepeatedField<bool> list) public void WritePackedBoolArray(int fieldNumber, RepeatedField<bool> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -825,7 +714,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list) public void WritePackedInt32Array(int fieldNumber, RepeatedField<int> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -840,7 +729,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedSInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list) public void WritePackedSInt32Array(int fieldNumber, RepeatedField<int> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -855,7 +744,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedUInt32Array(int fieldNumber, string fieldName, RepeatedField<uint> list) public void WritePackedUInt32Array(int fieldNumber, RepeatedField<uint> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -870,7 +759,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedFixed32Array(int fieldNumber, string fieldName, RepeatedField<uint> list) public void WritePackedFixed32Array(int fieldNumber, RepeatedField<uint> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -885,7 +774,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedSFixed32Array(int fieldNumber, string fieldName, RepeatedField<int> list) public void WritePackedSFixed32Array(int fieldNumber, RepeatedField<int> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -900,7 +789,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list) public void WritePackedInt64Array(int fieldNumber, RepeatedField<long> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -915,7 +804,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedSInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list) public void WritePackedSInt64Array(int fieldNumber, RepeatedField<long> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -930,7 +819,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedUInt64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list) public void WritePackedUInt64Array(int fieldNumber, RepeatedField<ulong> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -945,7 +834,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedFixed64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list) public void WritePackedFixed64Array(int fieldNumber, RepeatedField<ulong> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -960,7 +849,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedSFixed64Array(int fieldNumber, string fieldName, RepeatedField<long> list) public void WritePackedSFixed64Array(int fieldNumber, RepeatedField<long> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -975,7 +864,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedDoubleArray(int fieldNumber, string fieldName, RepeatedField<double> list) public void WritePackedDoubleArray(int fieldNumber, RepeatedField<double> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -990,7 +879,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedFloatArray(int fieldNumber, string fieldName, RepeatedField<float> list) public void WritePackedFloatArray(int fieldNumber, RepeatedField<float> list)
{ {
if (list.Count == 0) if (list.Count == 0)
{ {
@ -1005,7 +894,7 @@ namespace Google.Protobuf
} }
} }
public void WritePackedEnumArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list) public void WritePackedEnumArray<T>(int fieldNumber, RepeatedField<T> list)
where T : struct, IComparable, IFormattable where T : struct, IComparable, IFormattable
{ {
if (list.Count == 0) if (list.Count == 0)

@ -49,7 +49,7 @@ namespace Google.Protobuf
codedOutput.Flush(); codedOutput.Flush();
} }
public static void WriteTo(this IMessage message, ICodedOutputStream output) public static void WriteTo(this IMessage message, CodedOutputStream output)
{ {
message.WriteTo(output); message.WriteTo(output);
} }

@ -1,293 +0,0 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections.Generic;
using Google.Protobuf.Descriptors;
//Disable warning CS3010: CLS-compliant interfaces must have only CLS-compliant members
#pragma warning disable 3010
namespace Google.Protobuf
{
public interface ICodedInputStream
{
/// <summary>
/// Reads any message initialization data expected from the input stream
/// </summary>
/// <remarks>
/// This is primarily used by text formats and unnecessary for protobuffers' own
/// binary format. The API for MessageStart/End was added for consistent handling
/// of output streams regardless of the actual writer implementation.
/// </remarks>
void ReadMessageStart();
/// <summary>
/// Reads any message finalization data expected from the input stream
/// </summary>
/// <remarks>
/// This is primarily used by text formats and unnecessary for protobuffers' own
/// binary format. The API for MessageStart/End was added for consistent handling
/// of output streams regardless of the actual writer implementation.
/// </remarks>
void ReadMessageEnd();
/// <summary>
/// Attempt to read a field tag, returning false if we have reached the end
/// of the input data.
/// </summary>
/// <remarks>
/// <para>
/// If fieldTag is non-zero and ReadTag returns true then the value in fieldName
/// may or may not be populated. However, if fieldTag is zero and ReadTag returns
/// true, then fieldName should be populated with a non-null field name.
/// </para><para>
/// In other words if ReadTag returns true then either fieldTag will be non-zero OR
/// fieldName will be non-zero. In some cases both may be populated, however the
/// builders will always prefer the fieldTag over fieldName.
/// </para>
/// </remarks>
bool ReadTag(out uint fieldTag, out string fieldName);
/// <summary>
/// Read a double field from the stream.
/// </summary>
bool ReadDouble(ref double value);
/// <summary>
/// Read a float field from the stream.
/// </summary>
bool ReadFloat(ref float value);
/// <summary>
/// Read a uint64 field from the stream.
/// </summary>
bool ReadUInt64(ref ulong value);
/// <summary>
/// Read an int64 field from the stream.
/// </summary>
bool ReadInt64(ref long value);
/// <summary>
/// Read an int32 field from the stream.
/// </summary>
bool ReadInt32(ref int value);
/// <summary>
/// Read a fixed64 field from the stream.
/// </summary>
bool ReadFixed64(ref ulong value);
/// <summary>
/// Read a fixed32 field from the stream.
/// </summary>
bool ReadFixed32(ref uint value);
/// <summary>
/// Read a bool field from the stream.
/// </summary>
bool ReadBool(ref bool value);
/// <summary>
/// Reads a string field from the stream.
/// </summary>
bool ReadString(ref string value);
/// <summary>
/// Reads a group field value from the stream.
/// </summary>
void ReadGroup(int fieldNumber, IMessage message);
/// <summary>
/// Reads an embedded message field value from the stream.
/// </summary>
void ReadMessage(IMessage message);
/// <summary>
/// Reads a bytes field value from the stream.
/// </summary>
bool ReadBytes(ref ByteString value);
/// <summary>
/// Reads a uint32 field value from the stream.
/// </summary>
bool ReadUInt32(ref uint value);
/// <summary>
/// Reads an enum field value from the stream. This performs no checking
/// as to whether the enum value is known to the enum type as it was present
/// when the code was generated.
/// </summary>
bool ReadEnum(ref int value);
/// <summary>
/// Reads an sfixed32 field value from the stream.
/// </summary>
bool ReadSFixed32(ref int value);
/// <summary>
/// Reads an sfixed64 field value from the stream.
/// </summary>
bool ReadSFixed64(ref long value);
/// <summary>
/// Reads an sint32 field value from the stream.
/// </summary>
bool ReadSInt32(ref int value);
/// <summary>
/// Reads an sint64 field value from the stream.
/// </summary>
bool ReadSInt64(ref long value);
/// <summary>
/// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed and the
/// type is numeric, it will read a packed array.
/// </summary>
void ReadPrimitiveArray(FieldType fieldType, uint fieldTag, string fieldName, ICollection<object> list);
/// <summary>
/// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed, it will
/// read a packed array.
/// </summary>
void ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list)
where T : struct, IComparable, IFormattable;
/// <summary>
/// Reads a set of messages using the <paramref name="parser"/> to read individual messages.
/// </summary>
void ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, MessageParser<T> parser) where T : IMessage<T>;
/// <summary>
/// Reads a set of messages using the <paramref name="parser"/> as a template.
/// </summary>
void ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, MessageParser<T> parser) where T : IMessage<T>;
/// <summary>
/// Reads a field of any primitive type. Enums, groups and embedded
/// messages are not handled by this method.
/// </summary>
bool ReadPrimitiveField(FieldType fieldType, ref object value);
/// <summary>
/// Returns true if the stream has reached the end of the input. This is the
/// case if either the end of the underlying input source has been reached or
/// the stream has reached a limit created using PushLimit.
/// </summary>
bool IsAtEnd { get; }
/// <summary>
/// Reads and discards a single field, given its tag value.
/// </summary>
/// <returns>false if the tag is an end-group tag, in which case
/// nothing is skipped. Otherwise, returns true.</returns>
bool SkipField();
/// <summary>
/// Reads one or more repeated string field values from the stream.
/// </summary>
void ReadStringArray(uint fieldTag, string fieldName, ICollection<string> list);
/// <summary>
/// Reads one or more repeated ByteString field values from the stream.
/// </summary>
void ReadBytesArray(uint fieldTag, string fieldName, ICollection<ByteString> list);
/// <summary>
/// Reads one or more repeated boolean field values from the stream.
/// </summary>
void ReadBoolArray(uint fieldTag, string fieldName, ICollection<bool> list);
/// <summary>
/// Reads one or more repeated Int32 field values from the stream.
/// </summary>
void ReadInt32Array(uint fieldTag, string fieldName, ICollection<int> list);
/// <summary>
/// Reads one or more repeated SInt32 field values from the stream.
/// </summary>
void ReadSInt32Array(uint fieldTag, string fieldName, ICollection<int> list);
/// <summary>
/// Reads one or more repeated UInt32 field values from the stream.
/// </summary>
void ReadUInt32Array(uint fieldTag, string fieldName, ICollection<uint> list);
/// <summary>
/// Reads one or more repeated Fixed32 field values from the stream.
/// </summary>
void ReadFixed32Array(uint fieldTag, string fieldName, ICollection<uint> list);
/// <summary>
/// Reads one or more repeated SFixed32 field values from the stream.
/// </summary>
void ReadSFixed32Array(uint fieldTag, string fieldName, ICollection<int> list);
/// <summary>
/// Reads one or more repeated Int64 field values from the stream.
/// </summary>
void ReadInt64Array(uint fieldTag, string fieldName, ICollection<long> list);
/// <summary>
/// Reads one or more repeated SInt64 field values from the stream.
/// </summary>
void ReadSInt64Array(uint fieldTag, string fieldName, ICollection<long> list);
/// <summary>
/// Reads one or more repeated UInt64 field values from the stream.
/// </summary>
void ReadUInt64Array(uint fieldTag, string fieldName, ICollection<ulong> list);
/// <summary>
/// Reads one or more repeated Fixed64 field values from the stream.
/// </summary>
void ReadFixed64Array(uint fieldTag, string fieldName, ICollection<ulong> list);
/// <summary>
/// Reads one or more repeated SFixed64 field values from the stream.
/// </summary>
void ReadSFixed64Array(uint fieldTag, string fieldName, ICollection<long> list);
/// <summary>
/// Reads one or more repeated Double field values from the stream.
/// </summary>
void ReadDoubleArray(uint fieldTag, string fieldName, ICollection<double> list);
/// <summary>
/// Reads one or more repeated Float field values from the stream.
/// </summary>
void ReadFloatArray(uint fieldTag, string fieldName, ICollection<float> list);
}
}

@ -1,347 +0,0 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections;
using Google.Protobuf.Collections;
using Google.Protobuf.Descriptors;
//Disable warning CS3010: CLS-compliant interfaces must have only CLS-compliant members
#pragma warning disable 3010
namespace Google.Protobuf
{
/// <summary>
/// Provides an interface that is used write a message. Most often proto buffers are written
/// in their binary form by creating a instance via the CodedOutputStream.CreateInstance
/// static factory.
/// </summary>
public interface ICodedOutputStream
{
/// <summary>
/// Writes any message initialization data needed to the output stream
/// </summary>
/// <remarks>
/// This is primarily used by text formats and unnecessary for protobuffers' own
/// binary format. The API for MessageStart/End was added for consistent handling
/// of output streams regardless of the actual writer implementation.
/// </remarks>
void WriteMessageStart();
/// <summary>
/// Writes any message finalization data needed to the output stream
/// </summary>
/// <remarks>
/// This is primarily used by text formats and unnecessary for protobuffers' own
/// binary format. The API for MessageStart/End was added for consistent handling
/// of output streams regardless of the actual writer implementation.
/// </remarks>
void WriteMessageEnd();
/// <summary>
/// Indicates that all temporary buffers be written to the final output.
/// </summary>
void Flush();
/// <summary>
/// Writes a field value, including tag, to the stream.
/// </summary>
void WriteField(FieldType fieldType, int fieldNumber, string fieldName, object value);
/// <summary>
/// Writes a double field value, including tag, to the stream.
/// </summary>
void WriteDouble(int fieldNumber, string fieldName, double value);
/// <summary>
/// Writes a float field value, including tag, to the stream.
/// </summary>
void WriteFloat(int fieldNumber, string fieldName, float value);
/// <summary>
/// Writes a uint64 field value, including tag, to the stream.
/// </summary>
void WriteUInt64(int fieldNumber, string fieldName, ulong value);
/// <summary>
/// Writes an int64 field value, including tag, to the stream.
/// </summary>
void WriteInt64(int fieldNumber, string fieldName, long value);
/// <summary>
/// Writes an int32 field value, including tag, to the stream.
/// </summary>
void WriteInt32(int fieldNumber, string fieldName, int value);
/// <summary>
/// Writes a fixed64 field value, including tag, to the stream.
/// </summary>
void WriteFixed64(int fieldNumber, string fieldName, ulong value);
/// <summary>
/// Writes a fixed32 field value, including tag, to the stream.
/// </summary>
void WriteFixed32(int fieldNumber, string fieldName, uint value);
/// <summary>
/// Writes a bool field value, including tag, to the stream.
/// </summary>
void WriteBool(int fieldNumber, string fieldName, bool value);
/// <summary>
/// Writes a string field value, including tag, to the stream.
/// </summary>
void WriteString(int fieldNumber, string fieldName, string value);
/// <summary>
/// Writes a group field value, including tag, to the stream.
/// </summary>
void WriteGroup(int fieldNumber, string fieldName, IMessage value);
/// <summary>
/// Writes a message field value, including tag, to the stream.
/// </summary>
void WriteMessage(int fieldNumber, string fieldName, IMessage value);
/// <summary>
/// Writes a byte array field value, including tag, to the stream.
/// </summary>
void WriteBytes(int fieldNumber, string fieldName, ByteString value);
/// <summary>
/// Writes a UInt32 field value, including tag, to the stream.
/// </summary>
void WriteUInt32(int fieldNumber, string fieldName, uint value);
/// <summary>
/// Writes an enum field value, including tag, to the stream.
/// </summary>
void WriteEnum(int fieldNumber, string fieldName, int value);
/// <summary>
/// Writes a fixed 32-bit field value, including tag, to the stream.
/// </summary>
void WriteSFixed32(int fieldNumber, string fieldName, int value);
/// <summary>
/// Writes a signed fixed 64-bit field value, including tag, to the stream.
/// </summary>
void WriteSFixed64(int fieldNumber, string fieldName, long value);
/// <summary>
/// Writes a signed 32-bit field value, including tag, to the stream.
/// </summary>
void WriteSInt32(int fieldNumber, string fieldName, int value);
/// <summary>
/// Writes a signed 64-bit field value, including tag, to the stream.
/// </summary>
void WriteSInt64(int fieldNumber, string fieldName, long value);
/// <summary>
/// Writes a repeated field value, including tag(s), to the stream.
/// </summary>
void WriteArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list);
/// <summary>
/// Writes a repeated group value, including tag(s), to the stream.
/// </summary>
void WriteGroupArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
where T : IMessage;
/// <summary>
/// Writes a repeated message value, including tag(s), to the stream.
/// </summary>
void WriteMessageArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
where T : IMessage;
/// <summary>
/// Writes a repeated string value, including tag(s), to the stream.
/// </summary>
void WriteStringArray(int fieldNumber, string fieldName, RepeatedField<string> list);
/// <summary>
/// Writes a repeated ByteString value, including tag(s), to the stream.
/// </summary>
void WriteBytesArray(int fieldNumber, string fieldName, RepeatedField<ByteString> list);
/// <summary>
/// Writes a repeated boolean value, including tag(s), to the stream.
/// </summary>
void WriteBoolArray(int fieldNumber, string fieldName, RepeatedField<bool> list);
/// <summary>
/// Writes a repeated Int32 value, including tag(s), to the stream.
/// </summary>
void WriteInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
/// <summary>
/// Writes a repeated SInt32 value, including tag(s), to the stream.
/// </summary>
void WriteSInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
/// <summary>
/// Writes a repeated UInt32 value, including tag(s), to the stream.
/// </summary>
void WriteUInt32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
/// <summary>
/// Writes a repeated Fixed32 value, including tag(s), to the stream.
/// </summary>
void WriteFixed32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
/// <summary>
/// Writes a repeated SFixed32 value, including tag(s), to the stream.
/// </summary>
void WriteSFixed32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
/// <summary>
/// Writes a repeated Int64 value, including tag(s), to the stream.
/// </summary>
void WriteInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
/// <summary>
/// Writes a repeated SInt64 value, including tag(s), to the stream.
/// </summary>
void WriteSInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
/// <summary>
/// Writes a repeated UInt64 value, including tag(s), to the stream.
/// </summary>
void WriteUInt64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
/// <summary>
/// Writes a repeated Fixed64 value, including tag(s), to the stream.
/// </summary>
void WriteFixed64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
/// <summary>
/// Writes a repeated SFixed64 value, including tag(s), to the stream.
/// </summary>
void WriteSFixed64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
/// <summary>
/// Writes a repeated Double value, including tag(s), to the stream.
/// </summary>
void WriteDoubleArray(int fieldNumber, string fieldName, RepeatedField<double> list);
/// <summary>
/// Writes a repeated Float value, including tag(s), to the stream.
/// </summary>
void WriteFloatArray(int fieldNumber, string fieldName, RepeatedField<float> list);
/// <summary>
/// Writes a repeated enumeration value of type T, including tag(s), to the stream.
/// </summary>
void WriteEnumArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
where T : struct, IComparable, IFormattable;
/// <summary>
/// Writes a packed repeated primitive, including tag and length, to the stream.
/// </summary>
void WritePackedArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list);
/// <summary>
/// Writes a packed repeated boolean, including tag and length, to the stream.
/// </summary>
void WritePackedBoolArray(int fieldNumber, string fieldName, RepeatedField<bool> list);
/// <summary>
/// Writes a packed repeated Int32, including tag and length, to the stream.
/// </summary>
void WritePackedInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
/// <summary>
/// Writes a packed repeated SInt32, including tag and length, to the stream.
/// </summary>
void WritePackedSInt32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
/// <summary>
/// Writes a packed repeated UInt32, including tag and length, to the stream.
/// </summary>
void WritePackedUInt32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
/// <summary>
/// Writes a packed repeated Fixed32, including tag and length, to the stream.
/// </summary>
void WritePackedFixed32Array(int fieldNumber, string fieldName, RepeatedField<uint> list);
/// <summary>
/// Writes a packed repeated SFixed32, including tag and length, to the stream.
/// </summary>
void WritePackedSFixed32Array(int fieldNumber, string fieldName, RepeatedField<int> list);
/// <summary>
/// Writes a packed repeated Int64, including tag and length, to the stream.
/// </summary>
void WritePackedInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
/// <summary>
/// Writes a packed repeated SInt64, including tag and length, to the stream.
/// </summary>
void WritePackedSInt64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
/// <summary>
/// Writes a packed repeated UInt64, including tag and length, to the stream.
/// </summary>
void WritePackedUInt64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
/// <summary>
/// Writes a packed repeated Fixed64, including tag and length, to the stream.
/// </summary>
void WritePackedFixed64Array(int fieldNumber, string fieldName, RepeatedField<ulong> list);
/// <summary>
/// Writes a packed repeated SFixed64, including tag and length, to the stream.
/// </summary>
void WritePackedSFixed64Array(int fieldNumber, string fieldName, RepeatedField<long> list);
/// <summary>
/// Writes a packed repeated Double, including tag and length, to the stream.
/// </summary>
void WritePackedDoubleArray(int fieldNumber, string fieldName, RepeatedField<double> list);
/// <summary>
/// Writes a packed repeated Float, including tag and length, to the stream.
/// </summary>
void WritePackedFloatArray(int fieldNumber, string fieldName, RepeatedField<float> list);
/// <summary>
/// Writes a packed repeated enumeration of type T, including tag and length, to the stream.
/// </summary>
void WritePackedEnumArray<T>(int fieldNumber, string fieldName, RepeatedField<T> list)
where T : struct, IComparable, IFormattable;
}
}

@ -51,8 +51,8 @@ namespace Google.Protobuf
public interface IMessage public interface IMessage
{ {
void MergeFrom(ICodedInputStream input); void MergeFrom(CodedInputStream input);
void WriteTo(ICodedOutputStream output); void WriteTo(CodedOutputStream output);
int CalculateSize(); int CalculateSize();
} }

@ -47,7 +47,7 @@ namespace Google.Protobuf
return message; return message;
} }
public T ParseFrom(ICodedInputStream input) public T ParseFrom(CodedInputStream input)
{ {
T message = factory(); T message = factory();
message.MergeFrom(input); message.MergeFrom(input);

@ -93,8 +93,6 @@
<Compile Include="FieldAccess\FieldAccessorTable.cs" /> <Compile Include="FieldAccess\FieldAccessorTable.cs" />
<Compile Include="FieldAccess\OneofAccessor.cs" /> <Compile Include="FieldAccess\OneofAccessor.cs" />
<Compile Include="FrameworkPortability.cs" /> <Compile Include="FrameworkPortability.cs" />
<Compile Include="ICodedInputStream.cs" />
<Compile Include="ICodedOutputStream.cs" />
<Compile Include="IMessage.cs" /> <Compile Include="IMessage.cs" />
<Compile Include="InvalidProtocolBufferException.cs" /> <Compile Include="InvalidProtocolBufferException.cs" />
<Compile Include="LimitedInputStream.cs" /> <Compile Include="LimitedInputStream.cs" />

@ -54,17 +54,14 @@ EnumFieldGenerator::~EnumFieldGenerator() {
} }
void EnumFieldGenerator::GenerateParsingCode(io::Printer* printer) { void EnumFieldGenerator::GenerateParsingCode(io::Printer* printer) {
// TODO(jonskeet): Get rid of the temporary variable when we sanitize CodedInputStream not to use ref.
printer->Print(variables_, printer->Print(variables_,
"int tmp = 0;\n" "$name$_ = ($type_name$) input.ReadEnum();\n");
"input.ReadEnum(ref tmp);\n"
"$name$_ = ($type_name$) tmp;");
} }
void EnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) { void EnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
printer->Print(variables_, printer->Print(variables_,
"if ($has_property_check$) {\n" "if ($has_property_check$) {\n"
" output.WriteEnum($number$, fieldNames[$field_ordinal$], (int) $property_name$);\n" " output.WriteEnum($number$, (int) $property_name$);\n"
"}\n"); "}\n");
} }
@ -88,18 +85,15 @@ void EnumOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) {
// TODO(jonskeet): What about if we read the default value? // TODO(jonskeet): What about if we read the default value?
printer->Print( printer->Print(
variables_, variables_,
"int enumValue = 0;\n" "$oneof_name$_ = input.ReadEnum();\n"
"if(input.ReadEnum(ref enumValue)) {\n" "$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
" $oneof_name$_ = enumValue;\n"
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n"
"}\n");
} }
void EnumOneofFieldGenerator::GenerateSerializationCode(io::Printer* printer) { void EnumOneofFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
printer->Print( printer->Print(
variables_, variables_,
"if ($has_property_check$) {\n" "if ($has_property_check$) {\n"
" output.WriteEnum($number$, fieldNames[$field_ordinal$], (int) $property_name$);\n" " output.WriteEnum($number$, (int) $property_name$);\n"
"}\n"); "}\n");
} }

@ -350,9 +350,8 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
void MessageGenerator::GenerateMessageSerializationMethods(io::Printer* printer) { void MessageGenerator::GenerateMessageSerializationMethods(io::Printer* printer) {
printer->Print( printer->Print(
"public void WriteTo(pb::ICodedOutputStream output) {\n"); "public void WriteTo(pb::CodedOutputStream output) {\n");
printer->Indent(); printer->Indent();
printer->Print("string[] fieldNames = _fieldNames;\n");
// Serialize all the fields // Serialize all the fields
for (int i = 0; i < fields_by_number().size(); i++) { for (int i = 0; i < fields_by_number().size(); i++) {
@ -423,21 +422,13 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
} }
printer->Outdent(); printer->Outdent();
printer->Print("}\n\n"); printer->Print("}\n\n");
printer->Print("public void MergeFrom(pb::ICodedInputStream input) {\n"); printer->Print("public void MergeFrom(pb::CodedInputStream input) {\n");
printer->Indent(); printer->Indent();
printer->Print( printer->Print(
"uint tag;\n" "uint tag;\n"
"string fieldName;\n" "while (input.ReadTag(out tag)) {\n"
"while (input.ReadTag(out tag, out fieldName)) {\n"); " switch(tag) {\n");
printer->Indent(); printer->Indent();
printer->Print(
"if (tag == 0 && fieldName != null) {\n"
" int fieldOrdinal = global::System.Array.BinarySearch(_fieldNames, fieldName, global::System.StringComparer.Ordinal);\n"
" if (fieldOrdinal >= 0) {\n"
" tag = _fieldTags[fieldOrdinal];\n"
" }\n"
"}\n"
"switch(tag) {\n");
printer->Indent(); printer->Indent();
printer->Print( printer->Print(
"case 0:\n" // 0 signals EOF / limit reached "case 0:\n" // 0 signals EOF / limit reached

@ -87,6 +87,7 @@ void MessageFieldGenerator::GenerateParsingCode(io::Printer* printer) {
"if ($has_not_property_check$) {\n" "if ($has_not_property_check$) {\n"
" $name$_ = new $type_name$();\n" " $name$_ = new $type_name$();\n"
"}\n" "}\n"
// TODO(jonskeet): Do we really need merging behaviour like this?
"input.ReadMessage($name$_);\n"); // No need to support TYPE_GROUP... "input.ReadMessage($name$_);\n"); // No need to support TYPE_GROUP...
} }
@ -95,7 +96,7 @@ void MessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
printer->Print( printer->Print(
variables_, variables_,
"if ($has_property_check$) {\n" "if ($has_property_check$) {\n"
" output.WriteMessage($number$, fieldNames[$field_ordinal$], $property_name$);\n" " output.WriteMessage($number$, $property_name$);\n"
"}\n"); "}\n");
} }

@ -73,7 +73,6 @@ void PrimitiveFieldGenerator::GenerateMembers(io::Printer* printer) {
printer->Print( printer->Print(
variables_, variables_,
" set { $name$_ = value; }\n"); " set { $name$_ = value; }\n");
} else { } else {
printer->Print( printer->Print(
variables_, variables_,
@ -93,14 +92,14 @@ void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) {
void PrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer) { void PrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer) {
printer->Print( printer->Print(
variables_, variables_,
"input.Read$capitalized_type_name$(ref $name$_);\n"); "$name$_ = input.Read$capitalized_type_name$();\n");
} }
void PrimitiveFieldGenerator::GenerateSerializationCode(io::Printer* printer) { void PrimitiveFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
printer->Print( printer->Print(
variables_, variables_,
"if ($has_property_check$) {\n" "if ($has_property_check$) {\n"
" output.Write$capitalized_type_name$($number$, fieldNames[$field_ordinal$], $property_name$);\n" " output.Write$capitalized_type_name$($number$, $property_name$);\n"
"}\n"); "}\n");
} }
@ -169,13 +168,10 @@ void PrimitiveOneofFieldGenerator::WriteToString(io::Printer* printer) {
void PrimitiveOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) { void PrimitiveOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) {
// TODO(jonskeet): What if the value we read is the default value for the type? // TODO(jonskeet): What if the value we read is the default value for the type?
printer->Print( printer->Print(
variables_, variables_,
"$type_name$ value = $default_value$;\n" "$oneof_name$_ = input.Read$capitalized_type_name$()\n;"
"if (input.Read$capitalized_type_name$(ref value)) {\n" "$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
" $oneof_name$_ = value;\n"
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n"
"}\n");
} }
} // namespace csharp } // namespace csharp

@ -76,7 +76,7 @@ void RepeatedEnumFieldGenerator::GenerateMergingCode(io::Printer* printer) {
void RepeatedEnumFieldGenerator::GenerateParsingCode(io::Printer* printer) { void RepeatedEnumFieldGenerator::GenerateParsingCode(io::Printer* printer) {
printer->Print( printer->Print(
variables_, variables_,
"input.ReadEnumArray<$type_name$>(tag, fieldName, $name$_);\n"); "input.ReadEnumArray<$type_name$>(tag, $name$_);\n");
} }
void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) { void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
@ -84,7 +84,7 @@ void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer)
// The Write* call should make that cheap though - no need to generate it every time. // The Write* call should make that cheap though - no need to generate it every time.
printer->Print( printer->Print(
variables_, variables_,
"output.Write$packed$EnumArray($number$, fieldNames[$field_ordinal$], $name$_);\n"); "output.Write$packed$EnumArray($number$, $name$_);\n");
} }
void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {

@ -75,7 +75,7 @@ void RepeatedMessageFieldGenerator::GenerateMergingCode(io::Printer* printer) {
void RepeatedMessageFieldGenerator::GenerateParsingCode(io::Printer* printer) { void RepeatedMessageFieldGenerator::GenerateParsingCode(io::Printer* printer) {
printer->Print( printer->Print(
variables_, variables_,
"input.ReadMessageArray(tag, fieldName, $name$_, $type_name$.Parser);\n"); "input.ReadMessageArray(tag, $name$_, $type_name$.Parser);\n");
} }
void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) { void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
@ -83,7 +83,7 @@ void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* print
// The Write* call should make that cheap though - no need to generate it every time. // The Write* call should make that cheap though - no need to generate it every time.
printer->Print( printer->Print(
variables_, variables_,
"output.WriteMessageArray($number$, fieldNames[$field_ordinal$], $name$_);\n"); "output.WriteMessageArray($number$, $name$_);\n");
} }
void RepeatedMessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { void RepeatedMessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {

@ -74,7 +74,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer)
void RepeatedPrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer) { void RepeatedPrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer) {
printer->Print(variables_, printer->Print(variables_,
"input.Read$capitalized_type_name$Array(tag, fieldName, $name$_);\n"); "input.Read$capitalized_type_name$Array(tag, $name$_);\n");
} }
void RepeatedPrimitiveFieldGenerator::GenerateSerializationCode( void RepeatedPrimitiveFieldGenerator::GenerateSerializationCode(
@ -83,10 +83,10 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializationCode(
// The Write* call should make that cheap though - no need to generate it every time. // The Write* call should make that cheap though - no need to generate it every time.
if (descriptor_->is_packed()) { if (descriptor_->is_packed()) {
printer->Print(variables_, printer->Print(variables_,
"output.WritePacked$capitalized_type_name$Array($number$, fieldNames[$field_ordinal$], $name$_);\n"); "output.WritePacked$capitalized_type_name$Array($number$, $name$_);\n");
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"output.Write$capitalized_type_name$Array($number$, fieldNames[$field_ordinal$], $name$_);\n"); "output.Write$capitalized_type_name$Array($number$, $name$_);\n");
} }
} }

Loading…
Cancel
Save