ServiceDescriptor.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 System;
  17. using System.Collections.Generic;
  18. using Google.ProtocolBuffers.DescriptorProtos;
  19. namespace Google.ProtocolBuffers.Descriptors {
  20. /// <summary>
  21. /// Describes a service type.
  22. /// </summary>
  23. public sealed class ServiceDescriptor : IndexedDescriptorBase<ServiceDescriptorProto, ServiceOptions> {
  24. private readonly IList<MethodDescriptor> methods;
  25. public ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index)
  26. : base(proto, file, ComputeFullName(file, null, proto.Name), index) {
  27. methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.MethodList,
  28. (method, i) => new MethodDescriptor(method, file, this, i));
  29. file.DescriptorPool.AddSymbol(this);
  30. }
  31. /// <value>
  32. /// An unmodifiable list of methods in this service.
  33. /// </value>
  34. public IList<MethodDescriptor> Methods {
  35. get { return methods; }
  36. }
  37. /// <summary>
  38. /// Finds a method by name.
  39. /// </summary>
  40. /// <param name="name">The unqualified name of the method (e.g. "Foo").</param>
  41. /// <returns>The method's decsriptor, or null if not found.</returns>
  42. public MethodDescriptor FindMethodByName(String name) {
  43. return File.DescriptorPool.FindSymbol<MethodDescriptor>(FullName + "." + name);
  44. }
  45. internal void CrossLink() {
  46. foreach (MethodDescriptor method in methods) {
  47. method.CrossLink();
  48. }
  49. }
  50. }
  51. }