aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Descriptors
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtocolBuffers/Descriptors')
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/DescriptorUtil.cs4
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs186
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/FieldMappingAttribute.cs85
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/FieldType.cs36
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs65
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/MappedType.cs52
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs106
7 files changed, 44 insertions, 490 deletions
diff --git a/csharp/src/ProtocolBuffers/Descriptors/DescriptorUtil.cs b/csharp/src/ProtocolBuffers/Descriptors/DescriptorUtil.cs
index 9fc84c3e..db3e21f5 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/DescriptorUtil.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/DescriptorUtil.cs
@@ -30,7 +30,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System.Collections.Generic;
-using Google.Protobuf.Collections;
+using System.Collections.ObjectModel;
namespace Google.Protobuf.Descriptors
{
@@ -58,7 +58,7 @@ namespace Google.Protobuf.Descriptors
{
array[i] = converter(input[i], i);
}
- return Lists<TOutput>.AsReadOnly(array);
+ return new ReadOnlyCollection<TOutput>(array);
}
}
} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs b/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs
index c7d2e683..9605ee9a 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs
@@ -43,24 +43,21 @@ namespace Google.Protobuf.Descriptors
public sealed class FieldDescriptor : IndexedDescriptorBase<FieldDescriptorProto, FieldOptions>,
IComparable<FieldDescriptor>
{
- private readonly MessageDescriptor extensionScope;
private EnumDescriptor enumType;
private MessageDescriptor messageType;
private MessageDescriptor containingType;
private OneofDescriptor containingOneof;
private FieldType fieldType;
- private MappedType mappedType;
private readonly object optionsLock = new object();
internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file,
- MessageDescriptor parent, int index, bool isExtension)
+ MessageDescriptor parent, int index)
: base(proto, file, ComputeFullName(file, parent, proto.Name), index)
{
if (proto.Type != 0)
{
fieldType = GetFieldTypeFromProtoType(proto.Type);
- mappedType = FieldTypeToMappedTypeMap[fieldType];
}
if (FieldNumber <= 0)
@@ -68,38 +65,16 @@ namespace Google.Protobuf.Descriptors
throw new DescriptorValidationException(this,
"Field numbers must be positive integers.");
}
-
- if (isExtension)
+ containingType = parent;
+ if (proto.OneofIndex != 0)
{
- if (proto.Extendee != "")
+ if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count)
{
throw new DescriptorValidationException(this,
- "FieldDescriptorProto.Extendee not set for extension field.");
- }
- containingType = null; // Will be filled in when cross-linking
- if (parent != null)
- {
- extensionScope = parent;
- }
- else
- {
- extensionScope = null;
+ "FieldDescriptorProto.oneof_index is out of range for type " + parent.Name);
}
- }
- else
- {
- containingType = parent;
- if (proto.OneofIndex != 0)
- {
- if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count)
- {
- throw new DescriptorValidationException(this,
- "FieldDescriptorProto.oneof_index is out of range for type " + parent.Name);
- }
- containingOneof = parent.Oneofs[proto.OneofIndex];
- containingOneof.fieldCount ++;
- }
- extensionScope = null;
+ containingOneof = parent.Oneofs[proto.OneofIndex];
+ containingOneof.fieldCount ++;
}
file.DescriptorPool.AddSymbol(this);
@@ -151,51 +126,7 @@ namespace Google.Protobuf.Descriptors
default:
throw new ArgumentException("Invalid type specified");
}
- }
-
- /// <summary>
- /// Returns the default value for a mapped type.
- /// </summary>
- private static object GetDefaultValueForMappedType(MappedType type)
- {
- switch (type)
- {
- case MappedType.Int32:
- return 0;
- case MappedType.Int64:
- return (long) 0;
- case MappedType.UInt32:
- return (uint) 0;
- case MappedType.UInt64:
- return (ulong) 0;
- case MappedType.Single:
- return (float) 0;
- case MappedType.Double:
- return (double) 0;
- case MappedType.Boolean:
- return false;
- case MappedType.String:
- return "";
- case MappedType.ByteString:
- return ByteString.Empty;
- case MappedType.Message:
- return null;
- case MappedType.Enum:
- return null;
- default:
- throw new ArgumentException("Invalid type specified");
- }
- }
-
- public bool IsRequired
- {
- get { return Proto.Label == FieldDescriptorProto.Types.Label.LABEL_REQUIRED; }
- }
-
- public bool IsOptional
- {
- get { return Proto.Label == FieldDescriptorProto.Types.Label.LABEL_OPTIONAL; }
- }
+ }
public bool IsRepeated
{
@@ -205,16 +136,7 @@ namespace Google.Protobuf.Descriptors
public bool IsPacked
{
get { return Proto.Options.Packed; }
- }
-
- /// <value>
- /// Indicates whether or not this field is an extension. (Only relevant when parsing
- /// the proto2 descriptor...)
- /// </value>
- internal bool IsExtension
- {
- get { return Proto.Extendee != ""; }
- }
+ }
/// <summary>
/// Get the field's containing type. For extensions, this is the type being
@@ -229,46 +151,7 @@ namespace Google.Protobuf.Descriptors
public OneofDescriptor ContainingOneof
{
get { return containingOneof; }
- }
-
- /// <summary>
- /// For extensions defined nested within message types, gets
- /// the outer type. Not valid for non-extension fields.
- /// </summary>
- /// <example>
- /// <code>
- /// message Foo {
- /// extensions 1000 to max;
- /// }
- /// extend Foo {
- /// optional int32 baz = 1234;
- /// }
- /// message Bar {
- /// extend Foo {
- /// optional int32 qux = 4321;
- /// }
- /// }
- /// </code>
- /// The containing type for both <c>baz</c> and <c>qux</c> is <c>Foo</c>.
- /// However, the extension scope for <c>baz</c> is <c>null</c> while
- /// the extension scope for <c>qux</c> is <c>Bar</c>.
- /// </example>
- public MessageDescriptor ExtensionScope
- {
- get
- {
- if (!IsExtension)
- {
- throw new InvalidOperationException("This field is not an extension.");
- }
- return extensionScope;
- }
- }
-
- public MappedType MappedType
- {
- get { return mappedType; }
- }
+ }
public FieldType FieldType
{
@@ -303,7 +186,7 @@ namespace Google.Protobuf.Descriptors
{
get
{
- if (MappedType != MappedType.Enum)
+ if (fieldType != FieldType.Enum)
{
throw new InvalidOperationException("EnumType is only valid for enum fields.");
}
@@ -318,7 +201,7 @@ namespace Google.Protobuf.Descriptors
{
get
{
- if (MappedType != MappedType.Message)
+ if (fieldType != FieldType.Message)
{
throw new InvalidOperationException("MessageType is only valid for enum fields.");
}
@@ -327,25 +210,6 @@ namespace Google.Protobuf.Descriptors
}
/// <summary>
- /// Immutable mapping from field type to mapped type. Built using the attributes on
- /// FieldType values.
- /// </summary>
- public static readonly IDictionary<FieldType, MappedType> FieldTypeToMappedTypeMap = MapFieldTypes();
-
- private static IDictionary<FieldType, MappedType> MapFieldTypes()
- {
- var map = new Dictionary<FieldType, MappedType>();
- foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
- {
- FieldType fieldType = (FieldType) field.GetValue(null);
- FieldMappingAttribute mapping =
- (FieldMappingAttribute) field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
- map[fieldType] = mapping.MappedType;
- }
- return Dictionaries.AsReadOnly(map);
- }
-
- /// <summary>
/// Look up and cross-link all field types etc.
/// </summary>
internal void CrossLink()
@@ -361,12 +225,10 @@ namespace Google.Protobuf.Descriptors
if (typeDescriptor is MessageDescriptor)
{
fieldType = FieldType.Message;
- mappedType = MappedType.Message;
}
else if (typeDescriptor is EnumDescriptor)
{
fieldType = FieldType.Enum;
- mappedType = MappedType.Enum;
}
else
{
@@ -374,7 +236,7 @@ namespace Google.Protobuf.Descriptors
}
}
- if (MappedType == MappedType.Message)
+ if (fieldType == FieldType.Message)
{
if (!(typeDescriptor is MessageDescriptor))
{
@@ -388,7 +250,7 @@ namespace Google.Protobuf.Descriptors
throw new DescriptorValidationException(this, "Messages can't have default values.");
}
}
- else if (MappedType == Descriptors.MappedType.Enum)
+ else if (fieldType == FieldType.Enum)
{
if (!(typeDescriptor is EnumDescriptor))
{
@@ -403,7 +265,7 @@ namespace Google.Protobuf.Descriptors
}
else
{
- if (MappedType == MappedType.Message || MappedType == MappedType.Enum)
+ if (fieldType == FieldType.Message || fieldType == FieldType.Enum)
{
throw new DescriptorValidationException(this, "Field with message or enum type missing type_name.");
}
@@ -411,25 +273,11 @@ namespace Google.Protobuf.Descriptors
// Note: no attempt to perform any default value parsing
- if (!IsExtension)
- {
- File.DescriptorPool.AddFieldByNumber(this);
- }
+ File.DescriptorPool.AddFieldByNumber(this);
if (containingType != null && containingType.Options != null && containingType.Options.MessageSetWireFormat)
{
- if (IsExtension)
- {
- if (!IsOptional || FieldType != FieldType.Message)
- {
- throw new DescriptorValidationException(this,
- "Extensions of MessageSets must be optional messages.");
- }
- }
- else
- {
- throw new DescriptorValidationException(this, "MessageSets cannot have fields, only extensions.");
- }
+ throw new DescriptorValidationException(this, "MessageSet format is not supported.");
}
}
}
diff --git a/csharp/src/ProtocolBuffers/Descriptors/FieldMappingAttribute.cs b/csharp/src/ProtocolBuffers/Descriptors/FieldMappingAttribute.cs
deleted file mode 100644
index ab15eb01..00000000
--- a/csharp/src/ProtocolBuffers/Descriptors/FieldMappingAttribute.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-// 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.
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using Google.Protobuf.Collections;
-
-namespace Google.Protobuf.Descriptors
-{
- /// <summary>
- /// Defined specifically for the <see cref="FieldType" /> enumeration,
- /// this allows each field type to specify the mapped type and wire type.
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
- public sealed class FieldMappingAttribute : Attribute
- {
- public FieldMappingAttribute(MappedType mappedType, WireFormat.WireType wireType)
- {
- MappedType = mappedType;
- WireType = wireType;
- }
-
- public MappedType MappedType { get; private set; }
- public WireFormat.WireType WireType { get; private set; }
-
-
- /// <summary>
- /// Immutable mapping from field type to mapped type. Built using the attributes on
- /// FieldType values.
- /// </summary>
- private static readonly IDictionary<FieldType, FieldMappingAttribute> FieldTypeToMappedTypeMap = MapFieldTypes();
-
- private static IDictionary<FieldType, FieldMappingAttribute> MapFieldTypes()
- {
- var map = new Dictionary<FieldType, FieldMappingAttribute>();
- foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
- {
- FieldType fieldType = (FieldType) field.GetValue(null);
- FieldMappingAttribute mapping =
- (FieldMappingAttribute) field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
- map[fieldType] = mapping;
- }
- return Dictionaries.AsReadOnly(map);
- }
-
- internal static MappedType MappedTypeFromFieldType(FieldType type)
- {
- return FieldTypeToMappedTypeMap[type].MappedType;
- }
-
- internal static WireFormat.WireType WireTypeFromFieldType(FieldType type, bool packed)
- {
- return packed ? WireFormat.WireType.LengthDelimited : FieldTypeToMappedTypeMap[type].WireType;
- }
- }
-} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers/Descriptors/FieldType.cs b/csharp/src/ProtocolBuffers/Descriptors/FieldType.cs
index f7ec898e..628a6f78 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/FieldType.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/FieldType.cs
@@ -38,23 +38,23 @@ namespace Google.Protobuf.Descriptors
/// </summary>
public enum FieldType
{
- [FieldMapping(MappedType.Double, WireFormat.WireType.Fixed64)] Double,
- [FieldMapping(MappedType.Single, WireFormat.WireType.Fixed32)] Float,
- [FieldMapping(MappedType.Int64, WireFormat.WireType.Varint)] Int64,
- [FieldMapping(MappedType.UInt64, WireFormat.WireType.Varint)] UInt64,
- [FieldMapping(MappedType.Int32, WireFormat.WireType.Varint)] Int32,
- [FieldMapping(MappedType.UInt64, WireFormat.WireType.Fixed64)] Fixed64,
- [FieldMapping(MappedType.UInt32, WireFormat.WireType.Fixed32)] Fixed32,
- [FieldMapping(MappedType.Boolean, WireFormat.WireType.Varint)] Bool,
- [FieldMapping(MappedType.String, WireFormat.WireType.LengthDelimited)] String,
- [FieldMapping(MappedType.Message, WireFormat.WireType.StartGroup)] Group,
- [FieldMapping(MappedType.Message, WireFormat.WireType.LengthDelimited)] Message,
- [FieldMapping(MappedType.ByteString, WireFormat.WireType.LengthDelimited)] Bytes,
- [FieldMapping(MappedType.UInt32, WireFormat.WireType.Varint)] UInt32,
- [FieldMapping(MappedType.Int32, WireFormat.WireType.Fixed32)] SFixed32,
- [FieldMapping(MappedType.Int64, WireFormat.WireType.Fixed64)] SFixed64,
- [FieldMapping(MappedType.Int32, WireFormat.WireType.Varint)] SInt32,
- [FieldMapping(MappedType.Int64, WireFormat.WireType.Varint)] SInt64,
- [FieldMapping(MappedType.Enum, WireFormat.WireType.Varint)] Enum
+ Double,
+ Float,
+ Int64,
+ UInt64,
+ Int32,
+ Fixed64,
+ Fixed32,
+ Bool,
+ String,
+ Group,
+ Message,
+ Bytes,
+ UInt32,
+ SFixed32,
+ SFixed64,
+ SInt32,
+ SInt64,
+ Enum
}
} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs b/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
index 164406f9..5c933818 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
@@ -45,11 +45,10 @@ namespace Google.Protobuf.Descriptors
/// </summary>
public sealed class FileDescriptor : IDescriptor<FileDescriptorProto>
{
- private FileDescriptorProto proto;
+ private readonly FileDescriptorProto proto;
private readonly IList<MessageDescriptor> messageTypes;
private readonly IList<EnumDescriptor> enumTypes;
private readonly IList<ServiceDescriptor> services;
- private readonly IList<FieldDescriptor> extensions;
private readonly IList<FileDescriptor> dependencies;
private readonly IList<FileDescriptor> publicDependencies;
private readonly DescriptorPool pool;
@@ -86,10 +85,6 @@ namespace Google.Protobuf.Descriptors
services = DescriptorUtil.ConvertAndMakeReadOnly(proto.Service,
(service, index) =>
new ServiceDescriptor(service, this, index));
-
- extensions = DescriptorUtil.ConvertAndMakeReadOnly(proto.Extension,
- (field, index) =>
- new FieldDescriptor(field, this, null, index, true));
}
/// <summary>
@@ -129,9 +124,6 @@ namespace Google.Protobuf.Descriptors
return new ReadOnlyCollection<FileDescriptor>(publicDependencies);
}
-
- static readonly char[] PathSeperators = new char[] { '/', '\\' };
-
/// <value>
/// The descriptor in its protocol message representation.
/// </value>
@@ -190,14 +182,6 @@ namespace Google.Protobuf.Descriptors
}
/// <value>
- /// Unmodifiable list of top-level extensions declared in this file.
- /// </value>
- public IList<FieldDescriptor> Extensions
- {
- get { return extensions; }
- }
-
- /// <value>
/// Unmodifiable list of this file's dependencies (imports).
/// </value>
public IList<FileDescriptor> Dependencies
@@ -350,16 +334,6 @@ namespace Google.Protobuf.Descriptors
{
service.CrossLink();
}
-
- foreach (FieldDescriptor extension in extensions)
- {
- extension.CrossLink();
- }
-
- foreach (MessageDescriptor message in messageTypes)
- {
- message.CheckRequiredFields();
- }
}
/// <summary>
@@ -415,42 +389,7 @@ namespace Google.Protobuf.Descriptors
descriptorAssigner(result);
return result;
}
-
- /// <summary>
- /// Replace our FileDescriptorProto with the given one, which is
- /// identical except that it might contain extensions that weren't present
- /// in the original. This method is needed for bootstrapping when a file
- /// defines custom options. The options may be defined in the file itself,
- /// so we can't actually parse them until we've constructed the descriptors,
- /// but to construct the decsriptors we have to have parsed the descriptor
- /// protos. So, we have to parse the descriptor protos a second time after
- /// constructing the descriptors.
- /// </summary>
- private void ReplaceProto(FileDescriptorProto newProto)
- {
- proto = newProto;
-
- for (int i = 0; i < messageTypes.Count; i++)
- {
- messageTypes[i].ReplaceProto(proto.MessageType[i]);
- }
-
- for (int i = 0; i < enumTypes.Count; i++)
- {
- enumTypes[i].ReplaceProto(proto.EnumType[i]);
- }
-
- for (int i = 0; i < services.Count; i++)
- {
- services[i].ReplaceProto(proto.Service[i]);
- }
-
- for (int i = 0; i < extensions.Count; i++)
- {
- extensions[i].ReplaceProto(proto.Extension[i]);
- }
- }
-
+
public override string ToString()
{
return "FileDescriptor for " + proto.Name;
diff --git a/csharp/src/ProtocolBuffers/Descriptors/MappedType.cs b/csharp/src/ProtocolBuffers/Descriptors/MappedType.cs
deleted file mode 100644
index 97eed683..00000000
--- a/csharp/src/ProtocolBuffers/Descriptors/MappedType.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-// 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.
-
-namespace Google.Protobuf.Descriptors
-{
- /// <summary>
- /// Type as it's mapped onto a .NET type.
- /// </summary>
- public enum MappedType
- {
- Int32,
- Int64,
- UInt32,
- UInt64,
- Single,
- Double,
- Boolean,
- String,
- ByteString,
- Message,
- Enum
- }
-} \ No newline at end of file
diff --git a/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs b/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
index f0ac70ff..747cdc9a 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
@@ -44,10 +44,8 @@ namespace Google.Protobuf.Descriptors
private readonly IList<MessageDescriptor> nestedTypes;
private readonly IList<EnumDescriptor> enumTypes;
private readonly IList<FieldDescriptor> fields;
- private readonly IList<FieldDescriptor> extensions;
private readonly IList<OneofDescriptor> oneofs;
- private bool hasRequiredFields;
-
+
internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex)
: base(proto, file, ComputeFullName(file, parent, proto.Name), typeIndex)
{
@@ -68,11 +66,7 @@ namespace Google.Protobuf.Descriptors
// TODO(jonskeet): Sort fields first?
fields = DescriptorUtil.ConvertAndMakeReadOnly(proto.Field,
(field, index) =>
- new FieldDescriptor(field, file, this, index, false));
-
- extensions = DescriptorUtil.ConvertAndMakeReadOnly(proto.Extension,
- (field, index) =>
- new FieldDescriptor(field, file, this, index, true));
+ new FieldDescriptor(field, file, this, index));
for (int i = 0; i < proto.OneofDecl.Count; i++)
{
@@ -107,14 +101,6 @@ namespace Google.Protobuf.Descriptors
}
/// <value>
- /// An unmodifiable list of this message type's extensions.
- /// </value>
- public IList<FieldDescriptor> Extensions
- {
- get { return extensions; }
- }
-
- /// <value>
/// An unmodifiable list of this message type's nested types.
/// </value>
public IList<MessageDescriptor> NestedTypes
@@ -136,32 +122,6 @@ namespace Google.Protobuf.Descriptors
}
/// <summary>
- /// Returns a pre-computed result as to whether this message
- /// has required fields. This includes optional fields which are
- /// message types which in turn have required fields, and any
- /// extension fields.
- /// </summary>
- internal bool HasRequiredFields
- {
- get { return hasRequiredFields; }
- }
-
- /// <summary>
- /// Determines if the given field number is an extension.
- /// </summary>
- public bool IsExtensionNumber(int number)
- {
- foreach (DescriptorProto.Types.ExtensionRange range in Proto.ExtensionRange)
- {
- if (range.Start <= number && number < range.End)
- {
- return true;
- }
- }
- return false;
- }
-
- /// <summary>
/// Finds a field by field name.
/// </summary>
/// <param name="name">The unqualified name of the field (e.g. "foo").</param>
@@ -194,7 +154,7 @@ namespace Google.Protobuf.Descriptors
}
/// <summary>
- /// Looks up and cross-links all fields, nested types, and extensions.
+ /// Looks up and cross-links all fields and nested types.
/// </summary>
internal void CrossLink()
{
@@ -208,62 +168,11 @@ namespace Google.Protobuf.Descriptors
field.CrossLink();
}
- foreach (FieldDescriptor extension in extensions)
- {
- extension.CrossLink();
- }
-
foreach (OneofDescriptor oneof in oneofs)
{
- // oneof.C
- }
- }
-
- internal void CheckRequiredFields()
- {
- IDictionary<MessageDescriptor, byte> alreadySeen = new Dictionary<MessageDescriptor, byte>();
- hasRequiredFields = CheckRequiredFields(alreadySeen);
- }
-
- private bool CheckRequiredFields(IDictionary<MessageDescriptor, byte> alreadySeen)
- {
- if (alreadySeen.ContainsKey(this))
- {
- // The type is already in the cache. This means that either:
- // a. The type has no required fields.
- // b. We are in the midst of checking if the type has required fields,
- // somewhere up the stack. In this case, we know that if the type
- // has any required fields, they'll be found when we return to it,
- // and the whole call to HasRequiredFields() will return true.
- // Therefore, we don't have to check if this type has required fields
- // here.
- return false;
- }
- alreadySeen[this] = 0; // Value is irrelevant; we want set semantics
-
- // If the type allows extensions, an extension with message type could contain
- // required fields, so we have to be conservative and assume such an
- // extension exists.
- if (Proto.ExtensionRange.Count != 0)
- {
- return true;
+ // TODO(jonskeet): Do we need to do this?
+ // oneof.C
}
-
- foreach (FieldDescriptor field in Fields)
- {
- if (field.IsRequired)
- {
- return true;
- }
- if (field.MappedType == MappedType.Message)
- {
- if (field.MessageType.CheckRequiredFields(alreadySeen))
- {
- return true;
- }
- }
- }
- return false;
}
/// <summary>
@@ -287,11 +196,6 @@ namespace Google.Protobuf.Descriptors
{
fields[i].ReplaceProto(newProto.Field[i]);
}
-
- for (int i = 0; i < extensions.Count; i++)
- {
- extensions[i].ReplaceProto(newProto.Extension[i]);
- }
}
}
} \ No newline at end of file