aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs')
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs106
1 files changed, 5 insertions, 101 deletions
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