MethodDescriptor.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Google.ProtocolBuffers.DescriptorProtos;
  2. namespace Google.ProtocolBuffers.Descriptors {
  3. /// <summary>
  4. /// Describes a single method in a service.
  5. /// </summary>
  6. public class MethodDescriptor : IndexedDescriptorBase<MethodDescriptorProto, MethodOptions> {
  7. private readonly ServiceDescriptor service;
  8. private MessageDescriptor inputType;
  9. private MessageDescriptor outputType;
  10. /// <value>
  11. /// The service this method belongs to.
  12. /// </value>
  13. public ServiceDescriptor Service {
  14. get { return service; }
  15. }
  16. /// <value>
  17. /// The method's input type.
  18. /// </value>
  19. public MessageDescriptor InputType {
  20. get { return inputType; }
  21. }
  22. /// <value>
  23. /// The method's input type.
  24. /// </value>
  25. public MessageDescriptor OutputType {
  26. get { return outputType; }
  27. }
  28. internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file,
  29. ServiceDescriptor parent, int index)
  30. : base(proto, file, parent.FullName + "." + proto.Name, index) {
  31. service = parent;
  32. file.DescriptorPool.AddSymbol(this);
  33. }
  34. internal void CrossLink() {
  35. IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this);
  36. if (!(lookup is MessageDescriptor)) {
  37. throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type.");
  38. }
  39. inputType = (MessageDescriptor) lookup;
  40. lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this);
  41. if (!(lookup is MessageDescriptor)) {
  42. throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type.");
  43. }
  44. outputType = (MessageDescriptor) lookup;
  45. }
  46. }
  47. }