aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-06-03 21:35:02 -0500
committerrogerk <devnull@localhost>2011-06-03 21:35:02 -0500
commitd2af9e923f4f2d7f7c56a2e74d5a26536aae0369 (patch)
tree786a89b7f356bf8e4d897453d6fe45dab80d2dea /src/ProtocolBuffers
parent9928441649bde7a5e3bb84808821f1a5bef0bba6 (diff)
downloadprotobuf-d2af9e923f4f2d7f7c56a2e74d5a26536aae0369.tar.gz
protobuf-d2af9e923f4f2d7f7c56a2e74d5a26536aae0369.tar.bz2
protobuf-d2af9e923f4f2d7f7c56a2e74d5a26536aae0369.zip
Refactoring of CodedInputStream.Read??? to use boolean return with out param.
Diffstat (limited to 'src/ProtocolBuffers')
-rw-r--r--src/ProtocolBuffers/CodedInputStream.cs398
-rw-r--r--src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs48
-rw-r--r--src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs228
-rw-r--r--src/ProtocolBuffers/Descriptors/EnumDescriptor.cs4
-rw-r--r--src/ProtocolBuffers/EnumLite.cs9
-rw-r--r--src/ProtocolBuffers/ExtendableBuilder.cs4
-rw-r--r--src/ProtocolBuffers/ExtendableBuilderLite.cs158
-rw-r--r--src/ProtocolBuffers/GeneratedBuilder.cs2
-rw-r--r--src/ProtocolBuffers/GeneratedBuilderLite.cs2
-rw-r--r--src/ProtocolBuffers/UnknownFieldSet.cs197
10 files changed, 636 insertions, 414 deletions
diff --git a/src/ProtocolBuffers/CodedInputStream.cs b/src/ProtocolBuffers/CodedInputStream.cs
index 33986d3f..92e547fc 100644
--- a/src/ProtocolBuffers/CodedInputStream.cs
+++ b/src/ProtocolBuffers/CodedInputStream.cs
@@ -201,88 +201,100 @@ namespace Google.ProtocolBuffers
/// <summary>
/// Read a double field from the stream.
/// </summary>
- public double ReadDouble()
+ public bool ReadDouble(ref double value)
{
#if SILVERLIGHT2 || COMPACT_FRAMEWORK_35
- byte[] bytes = ReadRawBytes(8);
- return BitConverter.ToDouble(bytes, 0);
+ byte[] rawBytes = ReadRawBytes(8);
+ if (!BitConverter.IsLittleEndian)
+ Array.Reverse(rawBytes);
+ value = BitConverter.ToDouble(rawBytes, 0);
+ return true;
#else
- return BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64());
+ value = BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64());
+ return true;
#endif
}
/// <summary>
/// Read a float field from the stream.
/// </summary>
- public float ReadFloat()
+ public bool ReadFloat(ref float value)
{
- // TODO(jonskeet): Test this on different endiannesses
- uint raw = ReadRawLittleEndian32();
- byte[] rawBytes = BitConverter.GetBytes(raw);
- return BitConverter.ToSingle(rawBytes, 0);
+ byte[] rawBytes = ReadRawBytes(4);
+ if (!BitConverter.IsLittleEndian)
+ Array.Reverse(rawBytes);
+ value = BitConverter.ToSingle(rawBytes, 0);
+ return true;
}
/// <summary>
/// Read a uint64 field from the stream.
/// </summary>
[CLSCompliant(false)]
- public ulong ReadUInt64()
+ public bool ReadUInt64(ref ulong value)
{
- return ReadRawVarint64();
+ value = ReadRawVarint64();
+ return true;
}
/// <summary>
/// Read an int64 field from the stream.
/// </summary>
- public long ReadInt64()
+ public bool ReadInt64(ref long value)
{
- return (long) ReadRawVarint64();
+ value = (long) ReadRawVarint64();
+ return true;
}
/// <summary>
/// Read an int32 field from the stream.
/// </summary>
- public int ReadInt32()
+ public bool ReadInt32(ref int value)
{
- return (int) ReadRawVarint32();
+ value = (int)ReadRawVarint32();
+ return true;
}
/// <summary>
/// Read a fixed64 field from the stream.
/// </summary>
[CLSCompliant(false)]
- public ulong ReadFixed64()
+ public bool ReadFixed64(ref ulong value)
{
- return ReadRawLittleEndian64();
+ value = ReadRawLittleEndian64();
+ return true;
}
/// <summary>
/// Read a fixed32 field from the stream.
/// </summary>
[CLSCompliant(false)]
- public uint ReadFixed32()
+ public bool ReadFixed32(ref uint value)
{
- return ReadRawLittleEndian32();
+ value = ReadRawLittleEndian32();
+ return true;
}
/// <summary>
/// Read a bool field from the stream.
/// </summary>
- public bool ReadBool()
+ public bool ReadBool(ref bool value)
{
- return ReadRawVarint32() != 0;
+ value = ReadRawVarint32() != 0;
+ return true;
}
/// <summary>
/// Reads a string field from the stream.
/// </summary>
- public String ReadString()
+ public bool ReadString(ref string value)
{
int size = (int) ReadRawVarint32();
// No need to read any data for an empty string.
if (size == 0)
{
- return "";
+ value = "";
+ return true;
}
if (size <= bufferSize - bufferPos)
{
@@ -290,10 +302,12 @@ namespace Google.ProtocolBuffers
// just copy directly from it.
String result = Encoding.UTF8.GetString(buffer, bufferPos, size);
bufferPos += size;
- return result;
+ value = result;
+ return true;
}
// Slow path: Build a byte array first then copy it.
- return Encoding.UTF8.GetString(ReadRawBytes(size), 0, size);
+ value = Encoding.UTF8.GetString(ReadRawBytes(size), 0, size);
+ return true;
}
/// <summary>
@@ -350,7 +364,7 @@ namespace Google.ProtocolBuffers
/// <summary>
/// Reads a bytes field value from the stream.
/// </summary>
- public ByteString ReadBytes()
+ public bool ReadBytes(ref ByteString value)
{
int size = (int) ReadRawVarint32();
if (size < bufferSize - bufferPos && size > 0)
@@ -359,12 +373,14 @@ namespace Google.ProtocolBuffers
// just copy directly from it.
ByteString result = ByteString.CopyFrom(buffer, bufferPos, size);
bufferPos += size;
- return result;
+ value = result;
+ return true;
}
else
{
// Slow path: Build a byte array first then copy it.
- return ByteString.AttachBytes(ReadRawBytes(size));
+ value = ByteString.AttachBytes(ReadRawBytes(size));
+ return true;
}
}
@@ -372,90 +388,358 @@ namespace Google.ProtocolBuffers
/// Reads a uint32 field value from the stream.
/// </summary>
[CLSCompliant(false)]
- public uint ReadUInt32()
+ public bool ReadUInt32(ref uint value)
{
- return ReadRawVarint32();
+ value = ReadRawVarint32();
+ return true;
}
/// <summary>
/// Reads an enum field value from the stream. The caller is responsible
/// for converting the numeric value to an actual enum.
/// </summary>
- public int ReadEnum()
+ public bool ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
+ {
+ int rawValue = (int)ReadRawVarint32();
+
+ value = mapping.FindValueByNumber(rawValue);
+ if (value != null)
+ {
+ unknown = null;
+ return true;
+ }
+ unknown = rawValue;
+ return false;
+ }
+
+ /// <summary>
+ /// Reads an enum field value from the stream. If the enum is valid for type T,
+ /// then the ref value is set and it returns true. Otherwise the unkown output
+ /// value is set and this method returns false.
+ /// </summary>
+ [CLSCompliant(false)]
+ public bool ReadEnum<T>(ref T value, out object unknown)
+ where T : struct, IComparable, IFormattable, IConvertible
{
- return (int) ReadRawVarint32();
+ int number = (int)ReadRawVarint32();
+ if (Enum.IsDefined(typeof(T), number))
+ {
+ unknown = null;
+ value = (T)(object)number;
+ return true;
+ }
+ unknown = number;
+ return false;
}
/// <summary>
/// Reads an sfixed32 field value from the stream.
/// </summary>
- public int ReadSFixed32()
+ public bool ReadSFixed32(ref int value)
{
- return (int) ReadRawLittleEndian32();
+ value = (int)ReadRawLittleEndian32();
+ return true;
}
/// <summary>
/// Reads an sfixed64 field value from the stream.
/// </summary>
- public long ReadSFixed64()
+ public bool ReadSFixed64(ref long value)
{
- return (long) ReadRawLittleEndian64();
+ value = (long)ReadRawLittleEndian64();
+ return true;
}
/// <summary>
/// Reads an sint32 field value from the stream.
/// </summary>
- public int ReadSInt32()
+ public bool ReadSInt32(ref int value)
{
- return DecodeZigZag32(ReadRawVarint32());
+ value = DecodeZigZag32(ReadRawVarint32());
+ return true;
}
/// <summary>
/// Reads an sint64 field value from the stream.
/// </summary>
- public long ReadSInt64()
+ public bool ReadSInt64(ref long value)
+ {
+ value = DecodeZigZag64(ReadRawVarint64());
+ return true;
+ }
+
+ [CLSCompliant(false)]
+ public void ReadPrimitiveArray<T>(FieldType fieldType, uint fieldTag, string fieldName, ICollection<T> 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((T)value);
+ }
+ PopLimit(limit);
+ }
+ else
+ {
+ Object value = null;
+ if (ReadPrimitiveField(fieldType, ref value))
+ list.Add((T)value);
+ }
+ }
+
+ [CLSCompliant(false)]
+ public void ReadEnumArray(uint fieldTag, string fieldName, ICollection<IEnumLite> list, out ICollection<object> unknown, IEnumLiteMap mapping)
+ {
+ unknown = null;
+ object unkval;
+ IEnumLite value = null;
+ WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag);
+
+ // 2.3 allows packed form even if the field is not declared packed.
+ if (wformat == WireFormat.WireType.LengthDelimited)
+ {
+ int length = (int)(ReadRawVarint32() & int.MaxValue);
+ int limit = PushLimit(length);
+ while (!ReachedLimit)
+ {
+ if (ReadEnum(ref value, out unkval, mapping))
+ list.Add(value);
+ else
+ {
+ if (unknown == null)
+ unknown = new List<object>();
+ unknown.Add(unkval);
+ }
+ }
+ PopLimit(limit);
+ }
+ else
+ {
+ if (ReadEnum(ref value, out unkval, mapping))
+ list.Add(value);
+ else
+ unknown = new object[] { unkval };
+ }
+ }
+
+ [CLSCompliant(false)]
+ public void ReadEnumArray<T>(uint fieldTag, string fieldName, ICollection<T> list, out ICollection<object> unknown)
+ where T : struct, IComparable, IFormattable, IConvertible
+ {
+ unknown = null;
+ object unkval;
+ T value = default(T);
+ WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag);
+
+ // 2.3 allows packed form even if the field is not declared packed.
+ if (wformat == WireFormat.WireType.LengthDelimited)
+ {
+ int length = (int)(ReadRawVarint32() & int.MaxValue);
+ int limit = PushLimit(length);
+ while (!ReachedLimit)
+ {
+ if (ReadEnum<T>(ref value, out unkval))
+ list.Add(value);
+ else
+ {
+ if (unknown == null)
+ unknown = new List<object>();
+ unknown.Add(unkval);
+ }
+ }
+ PopLimit(limit);
+ }
+ else
+ {
+ if (ReadEnum(ref value, out unkval))
+ list.Add(value);
+ else
+ unknown = new object[] { unkval };
+ }
+ }
+
+ [CLSCompliant(false)]
+ public void ReadMessageArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType, ExtensionRegistry registry) where T : IMessageLite
+ {
+ IBuilderLite builder = messageType.WeakCreateBuilderForType();
+ ReadMessage(builder, registry);
+ list.Add((T)builder.WeakBuildPartial());
+ }
+
+ [CLSCompliant(false)]
+ public void ReadGroupArray<T>(uint fieldTag, string fieldName, ICollection<T> list, T messageType, ExtensionRegistry registry) where T : IMessageLite
{
- return DecodeZigZag64(ReadRawVarint64());
+ IBuilderLite builder = messageType.WeakCreateBuilderForType();
+ ReadGroup(WireFormat.GetTagFieldNumber(fieldTag), builder, registry);
+ list.Add((T)builder.WeakBuildPartial());
}
/// <summary>
/// Reads a field of any primitive type. Enums, groups and embedded
/// messages are not handled by this method.
/// </summary>
- public object ReadPrimitiveField(FieldType fieldType)
+ public bool ReadPrimitiveField(FieldType fieldType, ref object value)
{
switch (fieldType)
{
case FieldType.Double:
- return ReadDouble();
+ {
+ double tmp = 0;
+ if (ReadDouble(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.Float:
- return ReadFloat();
+ {
+ float tmp = 0;
+ if (ReadFloat(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.Int64:
- return ReadInt64();
+ {
+ long tmp = 0;
+ if (ReadInt64(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.UInt64:
- return ReadUInt64();
+ {
+ ulong tmp = 0;
+ if (ReadUInt64(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.Int32:
- return ReadInt32();
+ {
+ int tmp = 0;
+ if (ReadInt32(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.Fixed64:
- return ReadFixed64();
+ {
+ ulong tmp = 0;
+ if (ReadFixed64(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.Fixed32:
- return ReadFixed32();
+ {
+ uint tmp = 0;
+ if (ReadFixed32(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.Bool:
- return ReadBool();
+ {
+ bool tmp = false;
+ if (ReadBool(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.String:
- return ReadString();
+ {
+ string tmp = null;
+ if (ReadString(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.Bytes:
- return ReadBytes();
+ {
+ ByteString tmp = null;
+ if (ReadBytes(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.UInt32:
- return ReadUInt32();
+ {
+ uint tmp = 0;
+ if (ReadUInt32(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.SFixed32:
- return ReadSFixed32();
+ {
+ int tmp = 0;
+ if (ReadSFixed32(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.SFixed64:
- return ReadSFixed64();
+ {
+ long tmp = 0;
+ if (ReadSFixed64(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.SInt32:
- return ReadSInt32();
+ {
+ int tmp = 0;
+ if (ReadSInt32(ref tmp))
+ {
+ value = tmp;
+ return true;
+ }
+ return false;
+ }
case FieldType.SInt64:
- return ReadSInt64();
+ {
+ 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:
@@ -1047,7 +1331,7 @@ namespace Google.ProtocolBuffers
switch (WireFormat.GetTagWireType(tag))
{
case WireFormat.WireType.Varint:
- ReadInt32();
+ ReadRawVarint64();
return true;
case WireFormat.WireType.Fixed64:
ReadRawLittleEndian64();
diff --git a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
index 36040cbd..5dbab8c8 100644
--- a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
+++ b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
@@ -531,66 +531,66 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Namespace = input.ReadString();
+ result.hasNamespace |= input.ReadString(ref result.namespace_);
break;
}
case 18: {
- UmbrellaClassname = input.ReadString();
+ result.hasUmbrellaClassname |= input.ReadString(ref result.umbrellaClassname_);
break;
}
case 24: {
- PublicClasses = input.ReadBool();
+ result.hasPublicClasses |= input.ReadBool(ref result.publicClasses_);
break;
}
case 32: {
- MultipleFiles = input.ReadBool();
+ result.hasMultipleFiles |= input.ReadBool(ref result.multipleFiles_);
break;
}
case 40: {
- NestClasses = input.ReadBool();
+ result.hasNestClasses |= input.ReadBool(ref result.nestClasses_);
break;
}
case 48: {
- CodeContracts = input.ReadBool();
+ result.hasCodeContracts |= input.ReadBool(ref result.codeContracts_);
break;
}
case 56: {
- ExpandNamespaceDirectories = input.ReadBool();
+ result.hasExpandNamespaceDirectories |= input.ReadBool(ref result.expandNamespaceDirectories_);
break;
}
case 64: {
- ClsCompliance = input.ReadBool();
+ result.hasClsCompliance |= input.ReadBool(ref result.clsCompliance_);
break;
}
case 1770: {
- FileExtension = input.ReadString();
+ result.hasFileExtension |= input.ReadString(ref result.fileExtension_);
break;
}
case 1778: {
- UmbrellaNamespace = input.ReadString();
+ result.hasUmbrellaNamespace |= input.ReadString(ref result.umbrellaNamespace_);
break;
}
case 1786: {
- OutputDirectory = input.ReadString();
+ result.hasOutputDirectory |= input.ReadString(ref result.outputDirectory_);
break;
}
case 1792: {
- IgnoreGoogleProtobuf = input.ReadBool();
+ result.hasIgnoreGoogleProtobuf |= input.ReadBool(ref result.ignoreGoogleProtobuf_);
break;
}
case 1800: {
- int rawValue = input.ReadEnum();
- if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceType), rawValue)) {
+ object unknown;
+ if(input.ReadEnum(ref result.serviceGeneratorType_, out unknown)) {
+ result.hasServiceGeneratorType = true;
+ } else if(unknown is int) {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- unknownFields.MergeVarintField(225, (ulong) rawValue);
- } else {
- ServiceGeneratorType = (global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceType) rawValue;
+ unknownFields.MergeVarintField(225, (ulong)(int)unknown);
}
break;
}
@@ -1032,11 +1032,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- PropertyName = input.ReadString();
+ result.hasPropertyName |= input.ReadString(ref result.propertyName_);
break;
}
}
@@ -1257,11 +1257,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- InterfaceId = input.ReadString();
+ result.hasInterfaceId |= input.ReadString(ref result.interfaceId_);
break;
}
}
@@ -1482,11 +1482,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 8: {
- DispatchId = input.ReadInt32();
+ result.hasDispatchId |= input.ReadInt32(ref result.dispatchId_);
break;
}
}
diff --git a/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs b/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
index 0dca0463..365a0449 100644
--- a/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
+++ b/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
@@ -417,13 +417,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddFile(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.file_, global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
}
@@ -831,43 +829,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Name = input.ReadString();
+ result.hasName |= input.ReadString(ref result.name_);
break;
}
case 18: {
- Package = input.ReadString();
+ result.hasPackage |= input.ReadString(ref result.package_);
break;
}
case 26: {
- AddDependency(input.ReadString());
+ input.ReadPrimitiveArray(pbd::FieldType.String, tag, field_name, result.dependency_);
break;
}
case 34: {
- global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddMessageType(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.messageType_, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 42: {
- global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddEnumType(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.enumType_, global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 50: {
- global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddService(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.service_, global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 58: {
- global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddExtension(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.extension_, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 66: {
@@ -1381,15 +1371,15 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 8: {
- Start = input.ReadInt32();
+ result.hasStart |= input.ReadInt32(ref result.start_);
break;
}
case 16: {
- End = input.ReadInt32();
+ result.hasEnd |= input.ReadInt32(ref result.end_);
break;
}
}
@@ -1749,41 +1739,31 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Name = input.ReadString();
+ result.hasName |= input.ReadString(ref result.name_);
break;
}
case 18: {
- global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddField(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.field_, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 26: {
- global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddNestedType(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.nestedType_, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 34: {
- global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddEnumType(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.enumType_, global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 42: {
- global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddExtensionRange(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.extensionRange_, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange.DefaultInstance, extensionRegistry);
break;
}
case 50: {
- global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddExtension(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.extension_, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 58: {
@@ -2414,51 +2394,51 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Name = input.ReadString();
+ result.hasName |= input.ReadString(ref result.name_);
break;
}
case 18: {
- Extendee = input.ReadString();
+ result.hasExtendee |= input.ReadString(ref result.extendee_);
break;
}
case 24: {
- Number = input.ReadInt32();
+ result.hasNumber |= input.ReadInt32(ref result.number_);
break;
}
case 32: {
- int rawValue = input.ReadEnum();
- if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Label), rawValue)) {
+ object unknown;
+ if(input.ReadEnum(ref result.label_, out unknown)) {
+ result.hasLabel = true;
+ } else if(unknown is int) {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- unknownFields.MergeVarintField(4, (ulong) rawValue);
- } else {
- Label = (global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Label) rawValue;
+ unknownFields.MergeVarintField(4, (ulong)(int)unknown);
}
break;
}
case 40: {
- int rawValue = input.ReadEnum();
- if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Type), rawValue)) {
+ object unknown;
+ if(input.ReadEnum(ref result.type_, out unknown)) {
+ result.hasType = true;
+ } else if(unknown is int) {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- unknownFields.MergeVarintField(5, (ulong) rawValue);
- } else {
- Type = (global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Type) rawValue;
+ unknownFields.MergeVarintField(5, (ulong)(int)unknown);
}
break;
}
case 50: {
- TypeName = input.ReadString();
+ result.hasTypeName |= input.ReadString(ref result.typeName_);
break;
}
case 58: {
- DefaultValue = input.ReadString();
+ result.hasDefaultValue |= input.ReadString(ref result.defaultValue_);
break;
}
case 66: {
@@ -2882,17 +2862,15 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Name = input.ReadString();
+ result.hasName |= input.ReadString(ref result.name_);
break;
}
case 18: {
- global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddValue(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.value_, global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 26: {
@@ -3237,15 +3215,15 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Name = input.ReadString();
+ result.hasName |= input.ReadString(ref result.name_);
break;
}
case 16: {
- Number = input.ReadInt32();
+ result.hasNumber |= input.ReadInt32(ref result.number_);
break;
}
case 26: {
@@ -3576,17 +3554,15 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Name = input.ReadString();
+ result.hasName |= input.ReadString(ref result.name_);
break;
}
case 18: {
- global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddMethod(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.method_, global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto.DefaultInstance, extensionRegistry);
break;
}
case 26: {
@@ -3950,19 +3926,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- Name = input.ReadString();
+ result.hasName |= input.ReadString(ref result.name_);
break;
}
case 18: {
- InputType = input.ReadString();
+ result.hasInputType |= input.ReadString(ref result.inputType_);
break;
}
case 26: {
- OutputType = input.ReadString();
+ result.hasOutputType |= input.ReadString(ref result.outputType_);
break;
}
case 34: {
@@ -4426,49 +4402,47 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- JavaPackage = input.ReadString();
+ result.hasJavaPackage |= input.ReadString(ref result.javaPackage_);
break;
}
case 66: {
- JavaOuterClassname = input.ReadString();
+ result.hasJavaOuterClassname |= input.ReadString(ref result.javaOuterClassname_);
break;
}
case 72: {
- int rawValue = input.ReadEnum();
- if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.Types.OptimizeMode), rawValue)) {
+ object unknown;
+ if(input.ReadEnum(ref result.optimizeFor_, out unknown)) {
+ result.hasOptimizeFor = true;
+ } else if(unknown is int) {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- unknownFields.MergeVarintField(9, (ulong) rawValue);
- } else {
- OptimizeFor = (global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.Types.OptimizeMode) rawValue;
+ unknownFields.MergeVarintField(9, (ulong)(int)unknown);
}
break;
}
case 80: {
- JavaMultipleFiles = input.ReadBool();
+ result.hasJavaMultipleFiles |= input.ReadBool(ref result.javaMultipleFiles_);
break;
}
case 128: {
- CcGenericServices = input.ReadBool();
+ result.hasCcGenericServices |= input.ReadBool(ref result.ccGenericServices_);
break;
}
case 136: {
- JavaGenericServices = input.ReadBool();
+ result.hasJavaGenericServices |= input.ReadBool(ref result.javaGenericServices_);
break;
}
case 144: {
- PyGenericServices = input.ReadBool();
+ result.hasPyGenericServices |= input.ReadBool(ref result.pyGenericServices_);
break;
}
case 7994: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddUninterpretedOption(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.uninterpretedOption_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance, extensionRegistry);
break;
}
}
@@ -4885,21 +4859,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 8: {
- MessageSetWireFormat = input.ReadBool();
+ result.hasMessageSetWireFormat |= input.ReadBool(ref result.messageSetWireFormat_);
break;
}
case 16: {
- NoStandardDescriptorAccessor = input.ReadBool();
+ result.hasNoStandardDescriptorAccessor |= input.ReadBool(ref result.noStandardDescriptorAccessor_);
break;
}
case 7994: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddUninterpretedOption(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.uninterpretedOption_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance, extensionRegistry);
break;
}
}
@@ -5278,37 +5250,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 8: {
- int rawValue = input.ReadEnum();
- if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.Types.CType), rawValue)) {
+ object unknown;
+ if(input.ReadEnum(ref result.ctype_, out unknown)) {
+ result.hasCtype = true;
+ } else if(unknown is int) {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- unknownFields.MergeVarintField(1, (ulong) rawValue);
- } else {
- Ctype = (global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.Types.CType) rawValue;
+ unknownFields.MergeVarintField(1, (ulong)(int)unknown);
}
break;
}
case 16: {
- Packed = input.ReadBool();
+ result.hasPacked |= input.ReadBool(ref result.packed_);
break;
}
case 24: {
- Deprecated = input.ReadBool();
+ result.hasDeprecated |= input.ReadBool(ref result.deprecated_);
break;
}
case 74: {
- ExperimentalMapKey = input.ReadString();
+ result.hasExperimentalMapKey |= input.ReadString(ref result.experimentalMapKey_);
break;
}
case 7994: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddUninterpretedOption(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.uninterpretedOption_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance, extensionRegistry);
break;
}
}
@@ -5632,13 +5602,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 7994: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddUninterpretedOption(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.uninterpretedOption_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance, extensionRegistry);
break;
}
}
@@ -5889,13 +5857,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 7994: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddUninterpretedOption(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.uninterpretedOption_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance, extensionRegistry);
break;
}
}
@@ -6146,13 +6112,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 7994: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddUninterpretedOption(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.uninterpretedOption_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance, extensionRegistry);
break;
}
}
@@ -6403,13 +6367,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 7994: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddUninterpretedOption(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.uninterpretedOption_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance, extensionRegistry);
break;
}
}
@@ -6700,15 +6662,15 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 10: {
- NamePart_ = input.ReadString();
+ result.hasNamePart_ |= input.ReadString(ref result.namePart_);
break;
}
case 16: {
- IsExtension = input.ReadBool();
+ result.hasIsExtension |= input.ReadBool(ref result.isExtension_);
break;
}
}
@@ -7027,33 +6989,31 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
- ParseUnknownField(input, unknownFields, extensionRegistry, tag);
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 18: {
- global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.Builder subBuilder = global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.CreateBuilder();
- input.ReadMessage(subBuilder, extensionRegistry);
- AddName(subBuilder.BuildPartial());
+ input.ReadMessageArray(tag, field_name, result.name_, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.DefaultInstance, extensionRegistry);
break;
}
case 26: {
- IdentifierValue = input.ReadString();
+ result.hasIdentifierValue |= input.ReadString(ref result.identifierValue_);
break;
}
case 32: {
- PositiveIntValue = input.ReadUInt64();
+ result.hasPositiveIntValue |= input.ReadUInt64(ref result.positiveIntValue_);
break;
}
case 40: {
- NegativeIntValue = input.ReadInt64();
+ result.hasNegativeIntValue |= input.ReadInt64(ref result.negativeIntValue_);
break;
}
case 49: {
- DoubleValue = input.ReadDouble();
+ result.hasDoubleValue |= input.ReadDouble(ref result.doubleValue_);
break;
}
case 58: {
- StringValue = input.ReadBytes();
+ result.hasStringValue |= input.ReadBytes(ref result.stringValue_);
break;
}
}
diff --git a/src/ProtocolBuffers/Descriptors/EnumDescriptor.cs b/src/ProtocolBuffers/Descriptors/EnumDescriptor.cs
index 80c2bd0f..2922190d 100644
--- a/src/ProtocolBuffers/Descriptors/EnumDescriptor.cs
+++ b/src/ProtocolBuffers/Descriptors/EnumDescriptor.cs
@@ -98,6 +98,10 @@ namespace Google.ProtocolBuffers.Descriptors
{
return FindValueByNumber(number);
}
+ IEnumLite IEnumLiteMap.FindValueByName(string name)
+ {
+ return FindValueByName(name);
+ }
/// <summary>
/// Finds an enum value by name.
diff --git a/src/ProtocolBuffers/EnumLite.cs b/src/ProtocolBuffers/EnumLite.cs
index 4c2f8b75..35223fcd 100644
--- a/src/ProtocolBuffers/EnumLite.cs
+++ b/src/ProtocolBuffers/EnumLite.cs
@@ -70,6 +70,7 @@ namespace Google.ProtocolBuffers
{
bool IsValidValue(IEnumLite value);
IEnumLite FindValueByNumber(int number);
+ IEnumLite FindValueByName(string name);
}
public class EnumLiteMap<TEnum> : IEnumLiteMap<IEnumLite>
@@ -125,6 +126,14 @@ namespace Google.ProtocolBuffers
return items.TryGetValue(number, out val) ? val : null;
}
+ public IEnumLite FindValueByName(string name)
+ {
+ IEnumLite val;
+ if(Enum.IsDefined(typeof(TEnum), name))
+ return items.TryGetValue((int)Enum.Parse(typeof(TEnum), name, false), out val) ? val : null;
+ return null;
+ }
+
public bool IsValidValue(IEnumLite value)
{
return items.ContainsKey(value.Number);
diff --git a/src/ProtocolBuffers/ExtendableBuilder.cs b/src/ProtocolBuffers/ExtendableBuilder.cs
index 532520ed..49265f4b 100644
--- a/src/ProtocolBuffers/ExtendableBuilder.cs
+++ b/src/ProtocolBuffers/ExtendableBuilder.cs
@@ -131,9 +131,9 @@ namespace Google.ProtocolBuffers
/// <returns>true unless the tag is an end-group tag</returns>
[CLSCompliant(false)]
protected override bool ParseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields,
- ExtensionRegistry extensionRegistry, uint tag)
+ ExtensionRegistry extensionRegistry, uint tag, string fieldName)
{
- return unknownFields.MergeFieldFrom(input, extensionRegistry, this, tag);
+ return unknownFields.MergeFieldFrom(input, extensionRegistry, this, tag, fieldName);
}
// ---------------------------------------------------------------
diff --git a/src/ProtocolBuffers/ExtendableBuilderLite.cs b/src/ProtocolBuffers/ExtendableBuilderLite.cs
index fc748e6f..f9508d4a 100644
--- a/src/ProtocolBuffers/ExtendableBuilderLite.cs
+++ b/src/ProtocolBuffers/ExtendableBuilderLite.cs
@@ -134,7 +134,7 @@ namespace Google.ProtocolBuffers
/// <returns>true unless the tag is an end-group tag</returns>
[CLSCompliant(false)]
protected override bool ParseUnknownField(CodedInputStream input,
- ExtensionRegistry extensionRegistry, uint tag)
+ ExtensionRegistry extensionRegistry, uint tag, string fieldName)
{
FieldSet extensions = MessageBeingBuilt.Extensions;
@@ -142,119 +142,81 @@ namespace Google.ProtocolBuffers
int fieldNumber = WireFormat.GetTagFieldNumber(tag);
IGeneratedExtensionLite extension = extensionRegistry[DefaultInstanceForType, fieldNumber];
- bool unknown = false;
- bool packed = false;
- if (extension == null)
- {
- unknown = true; // Unknown field.
- }
- else if (wireType ==
- FieldMappingAttribute.WireTypeFromFieldType(extension.Descriptor.FieldType, false /* isPacked */))
- {
- packed = false; // Normal, unpacked value.
- }
- else if (extension.Descriptor.IsRepeated &&
- //?? just returns true ?? extension.Descriptor.type.isPackable() &&
- wireType ==
- FieldMappingAttribute.WireTypeFromFieldType(extension.Descriptor.FieldType, true /* isPacked */))
- {
- packed = true; // Packed value.
- }
- else
- {
- unknown = true; // Wrong wire type.
- }
+ if (extension == null)//unknown field
+ return input.SkipField();
- if (unknown)
- {
- // Unknown field or wrong wire type. Skip.
+ IFieldDescriptorLite field = extension.Descriptor;
+ if (!field.IsRepeated && wireType != WireFormat.GetWireType(field.FieldType)) //invalid wire type
return input.SkipField();
- }
- if (packed)
+ switch (field.FieldType)
{
- int length = (int) Math.Min(int.MaxValue, input.ReadRawVarint32());
- int limit = input.PushLimit(length);
- if (extension.Descriptor.FieldType == FieldType.Enum)
- {
- while (!input.ReachedLimit)
+ case FieldType.Group:
+ case FieldType.Message:
{
- int rawValue = input.ReadEnum();
- Object value =
- extension.Descriptor.EnumType.FindValueByNumber(rawValue);
- if (value == null)
+ if (!field.IsRepeated)
+ {
+ IMessageLite message = extensions[extension.Descriptor] as IMessageLite;
+ IBuilderLite subBuilder = (message ?? extension.MessageDefaultInstance).WeakToBuilder();
+
+ if (field.FieldType == FieldType.Group)
+ input.ReadGroup(field.FieldNumber, subBuilder, extensionRegistry);
+ else
+ input.ReadMessage(subBuilder, extensionRegistry);
+
+ extensions[field] = subBuilder.WeakBuild();
+ }
+ else
{
- // If the number isn't recognized as a valid value for this
- // enum, drop it (don't even add it to unknownFields).
+ List<IMessageLite> list = new List<IMessageLite>();
+ if (field.FieldType == FieldType.Group)
+ input.ReadGroupArray(tag, fieldName, list, extension.MessageDefaultInstance, extensionRegistry);
+ else
+ input.ReadMessageArray(tag, fieldName, list, extension.MessageDefaultInstance, extensionRegistry);
+
+ foreach (IMessageLite m in list)
+ extensions.AddRepeatedField(field, m);
return true;
}
- extensions.AddRepeatedField(extension.Descriptor, value);
+ break;
}
- }
- else
- {
- while (!input.ReachedLimit)
+ case FieldType.Enum:
{
- Object value = input.ReadPrimitiveField(extension.Descriptor.FieldType);
- extensions.AddRepeatedField(extension.Descriptor, value);
- }
- }
- input.PopLimit(limit);
- }
- else
- {
- Object value;
- switch (extension.Descriptor.MappedType)
- {
- case MappedType.Message:
+ if (!field.IsRepeated)
{
- IBuilderLite subBuilder = null;
- if (!extension.Descriptor.IsRepeated)
- {
- IMessageLite existingValue = extensions[extension.Descriptor] as IMessageLite;
- if (existingValue != null)
- {
- subBuilder = existingValue.WeakToBuilder();
- }
- }
- if (subBuilder == null)
- {
- subBuilder = extension.MessageDefaultInstance.WeakCreateBuilderForType();
- }
- if (extension.Descriptor.FieldType == FieldType.Group)
- {
- input.ReadGroup(extension.Number, subBuilder, extensionRegistry);
- }
- else
- {
- input.ReadMessage(subBuilder, extensionRegistry);
- }
- value = subBuilder.WeakBuild();
- break;
+ object unknown;
+ IEnumLite value = null;
+ if (input.ReadEnum(ref value, out unknown, field.EnumType))
+ extensions[field] = value;
}
- case MappedType.Enum:
- int rawValue = input.ReadEnum();
- value = extension.Descriptor.EnumType.FindValueByNumber(rawValue);
- // If the number isn't recognized as a valid value for this enum,
- // drop it.
- if (value == null)
+ else
{
- return true;
+ ICollection<object> unknown;
+ List<IEnumLite> list = new List<IEnumLite>();
+ input.ReadEnumArray(tag, fieldName, list, out unknown, field.EnumType);
+
+ foreach (IEnumLite en in list)
+ extensions.AddRepeatedField(field, en);
}
break;
- default:
- value = input.ReadPrimitiveField(extension.Descriptor.FieldType);
+ }
+ default:
+ {
+ if (!field.IsRepeated)
+ {
+ object value = null;
+ if (input.ReadPrimitiveField(field.FieldType, ref value))
+ extensions[field] = value;
+ }
+ else
+ {
+ List<object> list = new List<object>();
+ input.ReadPrimitiveArray(field.FieldType, tag, fieldName, list);
+ foreach (object oval in list)
+ extensions.AddRepeatedField(field, oval);
+ }
break;
- }
-
- if (extension.Descriptor.IsRepeated)
- {
- extensions.AddRepeatedField(extension.Descriptor, value);
- }
- else
- {
- extensions[extension.Descriptor] = value;
- }
+ }
}
return true;
diff --git a/src/ProtocolBuffers/GeneratedBuilder.cs b/src/ProtocolBuffers/GeneratedBuilder.cs
index b44cd639..699320ab 100644
--- a/src/ProtocolBuffers/GeneratedBuilder.cs
+++ b/src/ProtocolBuffers/GeneratedBuilder.cs
@@ -116,7 +116,7 @@ namespace Google.ProtocolBuffers
/// <returns>true unless the tag is an end-group tag</returns>
[CLSCompliant(false)]
protected virtual bool ParseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields,
- ExtensionRegistry extensionRegistry, uint tag)
+ ExtensionRegistry extensionRegistry, uint tag, string fieldName)
{
return unknownFields.MergeFieldFrom(tag, input);
}
diff --git a/src/ProtocolBuffers/GeneratedBuilderLite.cs b/src/ProtocolBuffers/GeneratedBuilderLite.cs
index 810324cc..25628422 100644
--- a/src/ProtocolBuffers/GeneratedBuilderLite.cs
+++ b/src/ProtocolBuffers/GeneratedBuilderLite.cs
@@ -99,7 +99,7 @@ namespace Google.ProtocolBuffers
/// <returns>true unless the tag is an end-group tag</returns>
[CLSCompliant(false)]
protected virtual bool ParseUnknownField(CodedInputStream input,
- ExtensionRegistry extensionRegistry, uint tag)
+ ExtensionRegistry extensionRegistry, uint tag, string fieldName)
{
return input.SkipField();
}
diff --git a/src/ProtocolBuffers/UnknownFieldSet.cs b/src/ProtocolBuffers/UnknownFieldSet.cs
index ff6a1534..e0f1cfff 100644
--- a/src/ProtocolBuffers/UnknownFieldSet.cs
+++ b/src/ProtocolBuffers/UnknownFieldSet.cs
@@ -450,14 +450,33 @@ namespace Google.ProtocolBuffers
switch (WireFormat.GetTagWireType(tag))
{
case WireFormat.WireType.Varint:
- GetFieldBuilder(number).AddVarint(input.ReadUInt64());
- return true;
+ {
+ ulong uint64 = 0;
+ if(input.ReadUInt64(ref uint64))
+ GetFieldBuilder(number).AddVarint(uint64);
+ return true;
+ }
+ case WireFormat.WireType.Fixed32:
+ {
+ uint uint32 = 0;
+ if (input.ReadFixed32(ref uint32))
+ GetFieldBuilder(number).AddFixed32(uint32);
+ return true;
+ }
case WireFormat.WireType.Fixed64:
- GetFieldBuilder(number).AddFixed64(input.ReadFixed64());
- return true;
+ {
+ ulong uint64 = 0;
+ if (input.ReadFixed64(ref uint64))
+ GetFieldBuilder(number).AddFixed64(uint64);
+ return true;
+ }
case WireFormat.WireType.LengthDelimited:
- GetFieldBuilder(number).AddLengthDelimited(input.ReadBytes());
- return true;
+ {
+ ByteString bytes = null;
+ if (input.ReadBytes(ref bytes))
+ GetFieldBuilder(number).AddLengthDelimited(bytes);
+ return true;
+ }
case WireFormat.WireType.StartGroup:
{
Builder subBuilder = CreateBuilder();
@@ -469,9 +488,6 @@ namespace Google.ProtocolBuffers
}
case WireFormat.WireType.EndGroup:
return false;
- case WireFormat.WireType.Fixed32:
- GetFieldBuilder(number).AddFixed32(input.ReadFixed32());
- return true;
default:
throw InvalidProtocolBufferException.InvalidWireType();
}
@@ -598,7 +614,7 @@ namespace Google.ProtocolBuffers
break;
}
- if (!MergeFieldFrom(input, extensionRegistry, builder, tag))
+ if (!MergeFieldFrom(input, extensionRegistry, builder, tag, name))
{
// end group tag
break;
@@ -616,7 +632,7 @@ namespace Google.ProtocolBuffers
/// <param name="tag">The tag, which should already have been read from the input</param>
/// <returns>true unless the tag is an end-group tag</returns>
internal bool MergeFieldFrom(CodedInputStream input,
- ExtensionRegistry extensionRegistry, IBuilder builder, uint tag)
+ ExtensionRegistry extensionRegistry, IBuilder builder, uint tag, string fieldName)
{
MessageDescriptor type = builder.DescriptorForType;
if (type.Options.MessageSetWireFormat && tag == WireFormat.MessageSetTag.ItemStart)
@@ -655,92 +671,81 @@ namespace Google.ProtocolBuffers
return MergeFieldFrom(tag, input);
}
- if (field.IsPacked)
+ switch (field.FieldType)
{
- int length = (int) input.ReadRawVarint32();
- int limit = input.PushLimit(length);
- if (field.FieldType == FieldType.Enum)
- {
- while (!input.ReachedLimit)
+ case FieldType.Group:
+ case FieldType.Message:
{
- int rawValue = input.ReadEnum();
- object value = field.EnumType.FindValueByNumber(rawValue);
- if (value == null)
+ IBuilderLite subBuilder = (defaultFieldInstance != null) ? defaultFieldInstance.WeakCreateBuilderForType() : builder.CreateBuilderForField(field);
+ if (!field.IsRepeated)
+ {
+ subBuilder.WeakMergeFrom((IMessageLite)builder[field]);
+ if (field.FieldType == FieldType.Group)
+ input.ReadGroup(field.FieldNumber, subBuilder, extensionRegistry);
+ else
+ input.ReadMessage(subBuilder, extensionRegistry);
+ builder[field] = subBuilder.WeakBuild();
+ }
+ else
{
- // If the number isn't recognized as a valid value for this
- // enum, drop it (don't even add it to unknownFields).
+ List<IMessageLite> list = new List<IMessageLite>();
+ if (field.FieldType == FieldType.Group)
+ input.ReadGroupArray(tag, fieldName, list, subBuilder.WeakDefaultInstanceForType, extensionRegistry);
+ else
+ input.ReadMessageArray(tag, fieldName, list, subBuilder.WeakDefaultInstanceForType, extensionRegistry);
+
+ foreach (IMessageLite m in list)
+ builder.WeakAddRepeatedField(field, m);
return true;
}
- builder.WeakAddRepeatedField(field, value);
+ break;
}
- }
- else
- {
- while (!input.ReachedLimit)
+ case FieldType.Enum:
{
- Object value = input.ReadPrimitiveField(field.FieldType);
- builder.WeakAddRepeatedField(field, value);
- }
- }
- input.PopLimit(limit);
- }
- else
- {
- object value;
- switch (field.FieldType)
- {
- case FieldType.Group:
- case FieldType.Message:
+ if (!field.IsRepeated)
{
- IBuilderLite subBuilder;
- if (defaultFieldInstance != null)
- {
- subBuilder = defaultFieldInstance.WeakCreateBuilderForType();
- }
- else
- {
- subBuilder = builder.CreateBuilderForField(field);
- }
- if (!field.IsRepeated)
- {
- subBuilder.WeakMergeFrom((IMessageLite) builder[field]);
- }
- if (field.FieldType == FieldType.Group)
- {
- input.ReadGroup(field.FieldNumber, subBuilder, extensionRegistry);
- }
- else
- {
- input.ReadMessage(subBuilder, extensionRegistry);
- }
- value = subBuilder.WeakBuild();
- break;
+ object unknown;
+ IEnumLite value = null;
+ if (input.ReadEnum(ref value, out unknown, field.EnumType))
+ builder[field] = value;
+ else if(unknown is int)
+ MergeVarintField(fieldNumber, (ulong)(int)unknown);
}
- case FieldType.Enum:
+ else
{
- int rawValue = input.ReadEnum();
- value = field.EnumType.FindValueByNumber(rawValue);
- // If the number isn't recognized as a valid value for this enum,
- // drop it.
- if (value == null)
+ ICollection<object> unknown;
+ List<IEnumLite> list = new List<IEnumLite>();
+ input.ReadEnumArray(tag, fieldName, list, out unknown, field.EnumType);
+
+ foreach (IEnumLite en in list)
+ builder.WeakAddRepeatedField(field, en);
+
+ if (unknown != null)
{
- MergeVarintField(fieldNumber, (ulong) rawValue);
- return true;
+ foreach (object oval in unknown)
+ if (oval is int)
+ MergeVarintField(fieldNumber, (ulong)(int)oval);
}
- break;
}
- default:
- value = input.ReadPrimitiveField(field.FieldType);
break;
- }
- if (field.IsRepeated)
- {
- builder.WeakAddRepeatedField(field, value);
- }
- else
- {
- builder[field] = value;
- }
+ }
+ default:
+ {
+ if (!field.IsRepeated)
+ {
+ object value = null;
+ if (input.ReadPrimitiveField(field.FieldType, ref value))
+ builder[field] = value;
+ }
+ else
+ {
+ List<object> list = new List<object>();
+ input.ReadPrimitiveArray(field.FieldType, tag, fieldName, list);
+ foreach (object oval in list)
+ builder.WeakAddRepeatedField(field, oval);
+ }
+ break;
+ }
}
return true;
}
@@ -787,9 +792,9 @@ namespace Google.ProtocolBuffers
if (tag == WireFormat.MessageSetTag.TypeID)
{
- typeId = input.ReadInt32();
+ typeId = 0;
// Zero is not a valid type ID.
- if (typeId != 0)
+ if (input.ReadInt32(ref typeId) && typeId != 0)
{
ExtensionInfo extension = extensionRegistry[type, typeId];
if (extension != null)
@@ -824,23 +829,21 @@ namespace Google.ProtocolBuffers
}
else if (tag == WireFormat.MessageSetTag.Message)
{
- if (typeId == 0)
- {
- // We haven't seen a type ID yet, so we have to store the raw bytes for now.
- rawBytes = input.ReadBytes();
- }
- else if (subBuilder == null)
- {
- // We don't know how to parse this. Ignore it.
- MergeField(typeId,
- UnknownField.CreateBuilder().AddLengthDelimited(input.ReadBytes()).Build());
- }
- else
+ if(subBuilder != null)
{
// We already know the type, so we can parse directly from the input
// with no copying. Hooray!
input.ReadMessage(subBuilder, extensionRegistry);
}
+ else if (input.ReadBytes(ref rawBytes))
+ {
+ if (typeId != 0)
+ {
+ // We don't know how to parse this. Ignore it.
+ MergeField(typeId,
+ UnknownField.CreateBuilder().AddLengthDelimited(rawBytes).Build());
+ }
+ }
}
else
{