MethodDescriptor.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc.
  3. // http://code.google.com/p/protobuf/
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. using Google.ProtocolBuffers.DescriptorProtos;
  17. namespace Google.ProtocolBuffers.Descriptors {
  18. /// <summary>
  19. /// Describes a single method in a service.
  20. /// </summary>
  21. public sealed class MethodDescriptor : IndexedDescriptorBase<MethodDescriptorProto, MethodOptions> {
  22. private readonly ServiceDescriptor service;
  23. private MessageDescriptor inputType;
  24. private MessageDescriptor outputType;
  25. /// <value>
  26. /// The service this method belongs to.
  27. /// </value>
  28. public ServiceDescriptor Service {
  29. get { return service; }
  30. }
  31. /// <value>
  32. /// The method's input type.
  33. /// </value>
  34. public MessageDescriptor InputType {
  35. get { return inputType; }
  36. }
  37. /// <value>
  38. /// The method's input type.
  39. /// </value>
  40. public MessageDescriptor OutputType {
  41. get { return outputType; }
  42. }
  43. internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file,
  44. ServiceDescriptor parent, int index)
  45. : base(proto, file, parent.FullName + "." + proto.Name, index) {
  46. service = parent;
  47. file.DescriptorPool.AddSymbol(this);
  48. }
  49. internal void CrossLink() {
  50. IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this);
  51. if (!(lookup is MessageDescriptor)) {
  52. throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type.");
  53. }
  54. inputType = (MessageDescriptor) lookup;
  55. lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this);
  56. if (!(lookup is MessageDescriptor)) {
  57. throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type.");
  58. }
  59. outputType = (MessageDescriptor) lookup;
  60. }
  61. }
  62. }