Commit 3351bb63 authored by Jon Skeet's avatar Jon Skeet

Descriptors are pretty much complete, with a slight issue of how to find the…

Descriptors are pretty much complete, with a slight issue of how to find the default type for a repeated field.
parent 5f7b68eb
......@@ -34,5 +34,7 @@ o There's a mixture of generic and non-generic code. This
IEnumerable. As an aside, this becomes a pain when trying to
create "the read-only version of this list, whose type I don't
know but I know it's a List<something>". Oh for mumble types.
o Nested types always end up under a "Types" static class which
is merely present to avoid name clashes.
o FileDescriptor.FindByName has been made generic to allow simple
type-safe searching for any nested type.
\ No newline at end of file
// This file contains quick hacks to represent code that will be autogenerated.
namespace Google.ProtocolBuffers.DescriptorProtos {
/// <summary>
/// This only exists until we've got the real code...
/// </summary>
/*
public abstract class TemporaryMessage<T> : IMessage<T> where T : IMessage<T> {
#region IMessage<T> Members
public IMessage<T> DefaultInstanceForType {
get { throw new System.NotImplementedException(); }
}
public IBuilder<T> CreateBuilderForType() {
throw new System.NotImplementedException();
}
#endregion
#region IMessage Members
public Google.ProtocolBuffers.Descriptors.MessageDescriptor DescriptorForType {
get { throw new System.NotImplementedException(); }
}
public System.Collections.Generic.IDictionary<Google.ProtocolBuffers.Descriptors.FieldDescriptor, object> AllFields {
get { throw new System.NotImplementedException(); }
}
public bool HasField(Google.ProtocolBuffers.Descriptors.FieldDescriptor field) {
throw new System.NotImplementedException();
}
public object this[Google.ProtocolBuffers.Descriptors.FieldDescriptor field] {
get { throw new System.NotImplementedException(); }
}
public int GetRepeatedFieldCount(Google.ProtocolBuffers.Descriptors.FieldDescriptor field) {
throw new System.NotImplementedException();
}
public object this[Google.ProtocolBuffers.Descriptors.FieldDescriptor field, int index] {
get { throw new System.NotImplementedException(); }
}
public UnknownFieldSet UnknownFields {
get { throw new System.NotImplementedException(); }
}
public bool IsInitialized {
get { throw new System.NotImplementedException(); }
}
public void WriteTo(CodedOutputStream output) {
throw new System.NotImplementedException();
}
public int SerializedSize {
get { throw new System.NotImplementedException(); }
}
public ByteString ToByteString() {
throw new System.NotImplementedException();
}
public byte[] ToByteArray() {
throw new System.NotImplementedException();
}
public void WriteTo(System.IO.Stream output) {
throw new System.NotImplementedException();
}
IMessage IMessage.DefaultInstanceForType {
get { throw new System.NotImplementedException(); }
}
IBuilder IMessage.CreateBuilderForType() {
throw new System.NotImplementedException();
}
#endregion
}
public partial class MessageOptions : TemporaryMessage<MessageOptions> {
public bool MessageSetWireFormat;
}
public partial class DescriptorProto : TemporaryMessage<DescriptorProto> {
public string Name { get; set; }
public string FullName { get; set; }
public MessageOptions Options { get; set; }
}
public partial class EnumDescriptorProto : TemporaryMessage<EnumDescriptorProto> {
public string Name { get; set; }
public string FullName { get; set; }
public EnumOptions Options { get; set; }
}
public partial class EnumOptions : TemporaryMessage<EnumOptions> { }
public partial class EnumValueDescriptorProto : TemporaryMessage<EnumValueDescriptorProto> {
public string Name { get; set; }
public string FullName { get; set; }
public EnumValueOptions Options { get; set; }
}
public partial class EnumValueOptions : TemporaryMessage <EnumValueOptions> { }
public partial class FieldDescriptorProto : TemporaryMessage<FieldDescriptorProto> {
public string Name { get; set; }
public string FullName { get; set; }
public FieldOptions Options { get; set; }
}
public partial class FieldOptions : TemporaryMessage<FieldOptions> { }
public partial class FileDescriptorProto : TemporaryMessage<FileDescriptorProto> {
public string Name { get; set; }
public string FullName { get; set; }
public FileOptions Options { get; set; }
public string Package { get; set; }
}
public partial class FileOptions : TemporaryMessage<FileOptions> { }
public partial class MethodDescriptorProto : TemporaryMessage<MethodDescriptorProto> {
public string Name { get; set; }
public string FullName { get; set; }
public MethodOptions Options { get; set; }
}
public partial class MethodOptions : TemporaryMessage<MethodOptions> { }
public partial class ServiceDescriptorProto : TemporaryMessage<ServiceDescriptorProto> {
public string Name { get; set; }
public string FullName { get; set; }
public ServiceOptions Options { get; set; }
}
public partial class ServiceOptions : TemporaryMessage<ServiceOptions> { } */
}
......@@ -2,21 +2,39 @@
using System.Collections.Generic;
using System.Text;
using Google.ProtocolBuffers.DescriptorProtos;
using Google.ProtocolBuffers.Collections;
namespace Google.ProtocolBuffers.Descriptors {
/// <summary>
/// Base class for all descriptors, providing common functionality.
/// Base class for nearly all descriptors, providing common functionality.
/// </summary>
/// <typeparam name="TProto">Type of the protocol buffer form of this descriptor</typeparam>
/// <typeparam name="TOptions">Type of the options protocol buffer for this descriptor</typeparam>
public abstract class DescriptorBase<TProto, TOptions> where TProto : IMessage<TProto>, IDescriptorProto<TOptions> {
public abstract class DescriptorBase<TProto, TOptions> : IDescriptor<TProto>
where TProto : IMessage, IDescriptorProto<TOptions> {
private readonly TProto proto;
private readonly FileDescriptor file;
private readonly string fullName;
protected DescriptorBase(TProto proto, FileDescriptor file) {
protected DescriptorBase(TProto proto, FileDescriptor file, string fullName) {
this.proto = proto;
this.file = file;
this.fullName = fullName;
}
protected static string ComputeFullName(FileDescriptor file, MessageDescriptor parent, string name) {
if (parent != null) {
return parent.FullName + "." + name;
}
if (file.Package.Length > 0) {
return file.Package + "." + name;
}
return name;
}
IMessage IDescriptor.Proto {
get { return proto; }
}
/// <summary>
......@@ -32,10 +50,9 @@ namespace Google.ProtocolBuffers.Descriptors {
/// <summary>
/// The fully qualified name of the descriptor's target.
/// TODO(jonskeet): Implement!
/// </summary>
public string FullName {
get { return null; }
get { return fullName; }
}
/// <summary>
......
using System.Collections.Generic;
using Google.ProtocolBuffers.Collections;
namespace Google.ProtocolBuffers.Descriptors {
/// <summary>
/// Internal class containing utility methods when working with descriptors.
/// </summary>
static class DescriptorUtil {
/// <summary>
/// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert
/// arrays.
/// </summary>
internal delegate TOutput IndexedConverter<TInput, TOutput>(TInput element, int index);
/// <summary>
/// Converts the given array into a read-only list, applying the specified conversion to
/// each input element.
/// </summary>
internal static IList<TOutput> ConvertAndMakeReadOnly<TInput, TOutput>(IList<TInput> input,
IndexedConverter<TInput, TOutput> converter) {
TOutput[] array = new TOutput[input.Count];
for (int i = 0; i < array.Length; i++) {
array[i] = converter(input[i], i);
}
return Lists<TOutput>.AsReadOnly(array);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Google.ProtocolBuffers.Descriptors {
public class DescriptorValidationException : Exception {
private readonly String name;
private readonly IMessage proto;
private readonly string description;
/// <value>
/// The full name of the descriptor where the error occurred.
/// </value>
public String ProblemSymbolName {
get { return name; }
}
/// <value>
/// The protocol message representation of the invalid descriptor.
/// </value>
public IMessage ProblemProto {
get { return proto; }
}
/// <value>
/// A human-readable description of the error. (The Message property
/// is made up of the descriptor's name and this description.)
/// </value>
public string Description {
get { return description; }
}
internal DescriptorValidationException(IDescriptor problemDescriptor, string description) :
base(problemDescriptor.FullName + ": " + description) {
// Note that problemDescriptor may be partially uninitialized, so we
// don't want to expose it directly to the user. So, we only provide
// the name and the original proto.
name = problemDescriptor.FullName;
proto = problemDescriptor.Proto;
this.description = description;
}
internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) :
base(problemDescriptor.FullName + ": " + description, cause) {
name = problemDescriptor.FullName;
proto = problemDescriptor.Proto;
this.description = description;
}
}
}

using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.DescriptorProtos;
namespace Google.ProtocolBuffers.Descriptors {
public class EnumDescriptor : IndexedDescriptorBase<EnumDescriptorProto, EnumOptions> {
internal EnumDescriptor(EnumDescriptorProto proto, EnumOptions options, FileDescriptor file, int index)
: base(proto, file, index) {
private readonly MessageDescriptor containingType;
private readonly IList<EnumValueDescriptor> values;
internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index)
: base(proto, file, ComputeFullName(file, parent, proto.Name), index) {
containingType = parent;
if (proto.ValueCount == 0) {
// We cannot allow enums with no values because this would mean there
// would be no valid default value for fields of this type.
throw new DescriptorValidationException(this, "Enums must contain at least one value.");
}
values = DescriptorUtil.ConvertAndMakeReadOnly(proto.ValueList,
(value, i) => new EnumValueDescriptor(value, file, this, i));
File.DescriptorPool.AddSymbol(this);
}
/// <value>
/// If this is a nested type, get the outer descriptor, otherwise null.
/// </value>
public MessageDescriptor ContainingType {
get { return containingType; }
}
/// <value>
/// An unmodifiable list of defined value descriptors for this enum.
/// </value>
public IList<EnumValueDescriptor> Values {
get { return values; }
}
/// <summary>
/// Finds an enum value by number. If multiple enum values have the
/// same number, this returns the first defined value with that number.
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
internal EnumValueDescriptor FindValueByNumber(int number) {
return File.DescriptorPool.FindEnumValueByNumber(this, number);
}
internal EnumValueDescriptor FindValueByNumber(int rawValue) {
throw new System.NotImplementedException();
/// <summary>
/// Finds an enum value by name.
/// </summary>
/// <param name="name">The unqualified name of the value (e.g. "FOO").</param>
/// <returns>The value's descriptor, or null if not found.</returns>
internal EnumValueDescriptor FindValueByName(string name) {
return File.DescriptorPool.FindSymbol<EnumValueDescriptor>(FullName + "." + name);
}
}
}
......@@ -6,15 +6,16 @@ namespace Google.ProtocolBuffers.Descriptors {
private readonly EnumDescriptor enumDescriptor;
internal EnumValueDescriptor(EnumValueDescriptorProto proto,
FileDescriptor file,
EnumDescriptor parent,
int index) : base (proto, file, index) {
internal EnumValueDescriptor(EnumValueDescriptorProto proto, FileDescriptor file,
EnumDescriptor parent, int index)
: base (proto, file, parent.FullName + "." + proto.Name, index) {
enumDescriptor = parent;
file.DescriptorPool.AddSymbol(this);
file.DescriptorPool.AddEnumValueByNumber(this);
}
public int Number {
get { throw new NotImplementedException(); }
get { return Proto.Number; }
}
public EnumDescriptor EnumDescriptor {
......
using System;
using System.Collections.ObjectModel;
using Google.ProtocolBuffers.DescriptorProtos;
using System.Collections.Generic;
using Google.ProtocolBuffers.Collections;
namespace Google.ProtocolBuffers.Descriptors {
public class FileDescriptor : DescriptorBase<FileDescriptorProto, FileOptions> {
/// <summary>
/// Describes a .proto file, including everything defined within.
/// IDescriptor is implemented such that the File property returns this descriptor,
/// and the FullName is the same as the Name.
/// </summary>
public class FileDescriptor : IDescriptor<FileDescriptorProto> {
private readonly FileDescriptorProto proto;
private readonly IList<MessageDescriptor> messageTypes;
private readonly IList<EnumDescriptor> enumTypes;
private readonly IList<ServiceDescriptor> services;
......@@ -11,7 +20,45 @@ namespace Google.ProtocolBuffers.Descriptors {
private readonly IList<FileDescriptor> dependencies;
private readonly DescriptorPool pool;
public FileDescriptor(FileDescriptorProto proto, FileDescriptor file) : base(proto, file) {
private FileDescriptor(FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool) {
this.pool = pool;
this.proto = proto;
this.dependencies = new ReadOnlyCollection<FileDescriptor>((FileDescriptor[]) dependencies.Clone());
pool.AddPackage(Package, this);
messageTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.MessageTypeList,
(message, index) => new MessageDescriptor(message, this, null, index));
enumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumTypeList,
(enumType, index) => new EnumDescriptor(enumType, this, null, index));
services = DescriptorUtil.ConvertAndMakeReadOnly(proto.ServiceList,
(service, index) => new ServiceDescriptor(service, this, index));
extensions = DescriptorUtil.ConvertAndMakeReadOnly(proto.ExtensionList,
(field, index) => new FieldDescriptor(field, this, null, index, true));
}
/// <value>
/// The descriptor in its protocol message representation.
/// </value>
public FileDescriptorProto Proto {
get { return proto; }
}
/// <value>
/// The <see cref="FileOptions" /> defined in <c>descriptor.proto</c>.
/// </value>
public FileOptions Options {
get { return proto.Options; }
}
/// <value>
/// The file name.
/// </value>
public string Name {
get { return proto.Name; }
}
/// <summary>
......@@ -19,7 +66,7 @@ namespace Google.ProtocolBuffers.Descriptors {
/// be equivalent to the .NET namespace of the generated classes.
/// </summary>
public string Package {
get { return Proto.Package; }
get { return proto.Package; }
}
/// <value>
......@@ -57,10 +104,110 @@ namespace Google.ProtocolBuffers.Descriptors {
get { return dependencies; }
}
public static FileDescriptor BuildFrom(FileDescriptorProto proto,
FileDescriptor[] dependencies) {
throw new NotImplementedException();
/// <value>
/// Implementation of IDescriptor.FullName - just returns the same as Name.
/// </value>
string IDescriptor.FullName {
get { return Name; }
}
/// <value>
/// Implementation of IDescriptor.File - just returns this descriptor.
/// </value>
FileDescriptor IDescriptor.File {
get { return this; }
}
/// <value>
/// Protocol buffer describing this descriptor.
/// </value>
IMessage IDescriptor.Proto {
get { return Proto; }
}
/// <value>
/// Pool containing symbol descriptors.
/// </value>
internal DescriptorPool DescriptorPool {
get { return pool; }
}
/// <summary>
/// Finds a type (message, enum, service or extension) in the file by name. Does not find nested types.
/// </summary>
/// <param name="name">The unqualified type name to look for.</param>
/// <typeparam name="T">The type of descriptor to look for (or ITypeDescriptor for any)</typeparam>
/// <returns>The type's descriptor, or null if not found.</returns>
public T FindTypeByName<T>(String name)
where T : class, IDescriptor {
// Don't allow looking up nested types. This will make optimization
// easier later.
if (name.IndexOf('.') != -1) {
return null;
}
if (Package.Length > 0) {
name = Package + "." + name;
}
T result = pool.FindSymbol<T>(name);
if (result != null && result.File == this) {
return result;
}
return null;
}
/// <summary>
/// Builds a FileDescriptor from its protocol buffer representation.
/// </summary>
/// <param name="proto">The protocol message form of the FileDescriptor.</param>
/// <param name="dependencies">FileDescriptors corresponding to all of the
/// file's dependencies, in the exact order listed in the .proto file</param>
/// <exception cref="DescriptorValidationException">If <paramref name="proto"/> is not
/// a valid descriptor. This can occur for a number of reasons, such as a field
/// having an undefined type or because two messages were defined with the same name.</exception>
public static FileDescriptor BuildFrom(FileDescriptorProto proto, FileDescriptor[] dependencies) {
// Building decsriptors involves two steps: translating and linking.
// In the translation step (implemented by FileDescriptor's
// constructor), we build an object tree mirroring the
// FileDescriptorProto's tree and put all of the descriptors into the
// DescriptorPool's lookup tables. In the linking step, we look up all
// type references in the DescriptorPool, so that, for example, a
// FieldDescriptor for an embedded message contains a pointer directly
// to the Descriptor for that message's type. We also detect undefined
// types in the linking step.
DescriptorPool pool = new DescriptorPool(dependencies);
FileDescriptor result = new FileDescriptor(proto, dependencies, pool);
if (dependencies.Length != proto.DependencyCount) {
throw new DescriptorValidationException(result,
"Dependencies passed to FileDescriptor.BuildFrom() don't match " +
"those listed in the FileDescriptorProto.");
}
for (int i = 0; i < proto.DependencyCount; i++) {
if (dependencies[i].Name != proto.DependencyList[i]) {
throw new DescriptorValidationException(result,
"Dependencies passed to FileDescriptor.BuildFrom() don't match " +
"those listed in the FileDescriptorProto.");
}
}
result.CrossLink();
return result;
}
private void CrossLink() {
foreach (MessageDescriptor message in messageTypes) {
message.CrossLink();
}
foreach (ServiceDescriptor service in services) {
service.CrossLink();
}
foreach (FieldDescriptor extension in extensions) {
extension.CrossLink();
}
}
/// <summary>
/// This method is to be called by generated code only. It is equivalent
/// to BuilderFrom except that the FileDescriptorProto is encoded in
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Google.ProtocolBuffers.Descriptors {
/// <summary>
/// The non-generic form of the IDescriptor interface. Useful for describing a general
/// descriptor.
/// </summary>
public interface IDescriptor {
string Name { get; }
string FullName { get; }
FileDescriptor File { get; }
IMessage Proto { get; }
}
/// <summary>
/// Strongly-typed form of the IDescriptor interface.
/// </summary>
/// <typeparam name="TProto">Protocol buffer type underlying this descriptor type</typeparam>
public interface IDescriptor<TProto> : IDescriptor where TProto : IMessage {
new TProto Proto { get; }
}
}
......@@ -13,8 +13,8 @@ namespace Google.ProtocolBuffers.Descriptors {
private readonly int index;
protected IndexedDescriptorBase(TProto proto, FileDescriptor file, int index)
: base(proto, file) {
protected IndexedDescriptorBase(TProto proto, FileDescriptor file, string fullName, int index)
: base(proto, file, fullName) {
this.index = index;
}
......

using System.Collections.Generic;
using System.Collections.Generic;
using Google.ProtocolBuffers.DescriptorProtos;
namespace Google.ProtocolBuffers.Descriptors {
public class MessageDescriptor : DescriptorBase<DescriptorProto, MessageOptions> {
public IList<FieldDescriptor> Fields;
internal MessageDescriptor(DescriptorProto proto, FileDescriptor file) : base(proto, file) {
/// <summary>
/// Describes a message type.
/// </summary>
public class MessageDescriptor : IndexedDescriptorBase<DescriptorProto, MessageOptions> {
private readonly MessageDescriptor containingType;
private readonly IList<MessageDescriptor> nestedTypes;
private readonly IList<EnumDescriptor> enumTypes;
private readonly IList<FieldDescriptor> fields;
private readonly IList<FieldDescriptor> extensions;
internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex)
: base(proto, file, ComputeFullName(file, parent, proto.Name), typeIndex) {
containingType = parent;
nestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.NestedTypeList,
(type, index) => new MessageDescriptor(type, file, null, index));
enumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumTypeList,
(type, index) => new EnumDescriptor(type, file, null, index));
fields = DescriptorUtil.ConvertAndMakeReadOnly(proto.FieldList,
(field, index) => new FieldDescriptor(field, file, null, index, false));
extensions = DescriptorUtil.ConvertAndMakeReadOnly(proto.ExtensionList,
(field, index) => new FieldDescriptor(field, file, null, index, true));
file.DescriptorPool.AddSymbol(this);
}
internal bool IsExtensionNumber(int fieldNumber) {
throw new System.NotImplementedException();
/// <value>
/// An unmodifiable list of this message type's fields.
/// </value>
public IList<FieldDescriptor> Fields {
get { return fields; }
}
internal FieldDescriptor FindFieldByNumber(int fieldNumber) {
throw new System.NotImplementedException();
/// <value>
/// An unmodifiable list of this message type's extensions.
/// </value>
public IList<FieldDescriptor> Extensions {
get { return extensions; }
}
/// <value>
/// List of message types nested within this one.
/// An unmodifiable list of this message type's nested types.
/// </value>
public IList<MessageDescriptor> NestedTypes {
get { throw new System.NotImplementedException(); }
get { return nestedTypes; }
}
/// <value>
/// An unmodifiable list of this message type's enum types.
/// </value>
public IList<EnumDescriptor> EnumTypes {
get { return enumTypes; }
}
/// <summary>
/// Determines if the given field number is an extension.
/// </summary>
public bool IsExtensionNumber(int number) {
foreach (DescriptorProto.Types.ExtensionRange range in Proto.ExtensionRangeList) {
if (range.Start <= number && number < range.End) {
return true;
}
}
return false;
}
/// <summary>
/// Finds a field by field number.
/// </summary>
/// <param name="number">The field number within this message type.</param>
/// <returns>The field's descriptor, or null if not found.</returns>
public FieldDescriptor FindFieldByNumber(int number) {
return File.DescriptorPool.FindFieldByNumber(this, number);
}
/// <summary>
/// Finds a nested descriptor by name. The is valid for fields, nested
/// message types and enums.
/// </summary>
/// <param name="name">The unqualified name of the descriptor, e.g. "Foo"</param>
/// <returns>The descriptor, or null if not found.</returns>
public T FindDescriptor<T>(string name)
where T : class, IDescriptor {
return File.DescriptorPool.FindSymbol<T>(FullName + "." + name);
}
/// <summary>
/// Looks up and cross-links all fields, nested types, and extensions.
/// </summary>
internal void CrossLink() {
foreach (MessageDescriptor message in nestedTypes) {
message.CrossLink();
}
foreach (FieldDescriptor field in fields) {
field.CrossLink();
}
foreach (FieldDescriptor extension in extensions) {
extension.CrossLink();
}
}
}
}
using Google.ProtocolBuffers.DescriptorProtos;
namespace Google.ProtocolBuffers.Descriptors {
/// <summary>
/// Describes a single method in a service.
/// </summary>
public class MethodDescriptor : IndexedDescriptorBase<MethodDescriptorProto, MethodOptions> {
private readonly ServiceDescriptor service;
private MessageDescriptor inputType;
private MessageDescriptor outputType;
/// <value>
/// The service this method belongs to.
/// </value>
public ServiceDescriptor Service {
get { return service; }
}
/// <value>
/// The method's input type.
/// </value>
public MessageDescriptor InputType {
get { return inputType; }
}
/// <value>
/// The method's input type.
/// </value>
public MessageDescriptor OutputType {
get { return inputType; }
}
internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file,
ServiceDescriptor parent, int index)
: base(proto, file, parent.FullName + "." + proto.Name, index) {
service = parent;
file.DescriptorPool.AddSymbol(this);
}
internal void CrossLink() {
IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this);
if (!(lookup is MessageDescriptor)) {
throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type.");
}
inputType = (MessageDescriptor) lookup;
lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this);
if (!(lookup is MessageDescriptor)) {
throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type.");
}
outputType = (MessageDescriptor) lookup;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Google.ProtocolBuffers.Descriptors {
/*
* Represents a package in the symbol table. We use PackageDescriptors
* just as placeholders so that someone cannot define, say, a message type
* that has the same name as an existing package.
*/
/// <summary>
/// Represents a package in the symbol table. We use PackageDescriptors
/// just as placeholders so that someone cannot define, say, a message type
/// that has the same name as an existing package.
/// </summary>
internal class PackageDescriptor : IDescriptor<IMessage> {
private readonly string name;
private readonly string fullName;
private readonly FileDescriptor file;
internal PackageDescriptor(string name, string fullName, FileDescriptor file) {
this.file = file;
this.fullName = fullName;
this.name = name;
}
public IMessage Proto {
get { return file.Proto; }
}
public string Name {
get { return name; }
}
public string FullName {
get { return fullName; }
}
public FileDescriptor File {
get { return file; }
}
}
}
......@@ -4,9 +4,34 @@ using System.Text;
using Google.ProtocolBuffers.DescriptorProtos;
namespace Google.ProtocolBuffers.Descriptors {
/// <summary>
/// Describes a service type.
/// </summary>
public class ServiceDescriptor : IndexedDescriptorBase<ServiceDescriptorProto, ServiceOptions> {
private readonly IList<MethodDescriptor> methods;
public ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index)
: base(proto, file, index) {
: base(proto, file, ComputeFullName(file, null, proto.Name), index) {
methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.MethodList,
(method, i) => new MethodDescriptor(method, file, this, i));
file.DescriptorPool.AddSymbol(this);
}
/// <value>
/// An unmodifiable list of methods in this service.
/// </value>
public IList<MethodDescriptor> Methods {
get { return methods; }
}
internal void CrossLink() {
foreach (MethodDescriptor method in methods) {
method.CrossLink();
}
}
}
}
......@@ -52,6 +52,8 @@
<Compile Include="DescriptorProtos\PartialClasses.cs" />
<Compile Include="Descriptors\DescriptorBase.cs" />
<Compile Include="Descriptors\DescriptorPool.cs" />
<Compile Include="Descriptors\DescriptorUtil.cs" />
<Compile Include="Descriptors\DescriptorValidationException.cs" />
<Compile Include="Descriptors\EnumDescriptor.cs" />
<Compile Include="Descriptors\EnumDescriptorIndexAttribute.cs" />
<Compile Include="Descriptors\EnumValueDescriptor.cs" />
......@@ -59,9 +61,12 @@
<Compile Include="Descriptors\FieldMappingAttribute.cs" />
<Compile Include="Descriptors\FieldType.cs" />
<Compile Include="Descriptors\FileDescriptor.cs" />
<Compile Include="Descriptors\IDescriptor.cs" />
<Compile Include="Descriptors\IndexedDescriptorBase.cs" />
<Compile Include="Descriptors\MappedType.cs" />
<Compile Include="Descriptors\MessageDescriptor.cs" />
<Compile Include="Descriptors\MethodDescriptor.cs" />
<Compile Include="Descriptors\PackageDescriptor.cs" />
<Compile Include="Descriptors\ServiceDescriptor.cs" />
<Compile Include="ExtensionInfo.cs" />
<Compile Include="ExtensionRegistry.cs" />
......
......@@ -11,5 +11,25 @@ namespace Google.ProtocolBuffers {
internal static string PrintToString(UnknownFieldSet unknownFieldSet) {
throw new NotImplementedException();
}
internal static object ParseUInt64(string p) {
throw new NotImplementedException();
}
internal static object ParseInt64(string p) {
throw new NotImplementedException();
}
internal static object ParseUInt32(string p) {
throw new NotImplementedException();
}
internal static object ParseInt32(string p) {
throw new NotImplementedException();
}
internal static object UnescapeBytes(string p) {
throw new NotImplementedException();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment