You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

667 line
26 KiB

  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package protoreflect
  5. // Descriptor provides a set of accessors that are common to every descriptor.
  6. // Each descriptor type wraps the equivalent google.protobuf.XXXDescriptorProto,
  7. // but provides efficient lookup and immutability.
  8. //
  9. // Each descriptor is comparable. Equality implies that the two types are
  10. // exactly identical. However, it is possible for the same semantically
  11. // identical proto type to be represented by multiple type descriptors.
  12. //
  13. // For example, suppose we have t1 and t2 which are both MessageDescriptors.
  14. // If t1 == t2, then the types are definitely equal and all accessors return
  15. // the same information. However, if t1 != t2, then it is still possible that
  16. // they still represent the same proto type (e.g., t1.FullName == t2.FullName).
  17. // This can occur if a descriptor type is created dynamically, or multiple
  18. // versions of the same proto type are accidentally linked into the Go binary.
  19. type Descriptor interface {
  20. // ParentFile returns the parent file descriptor that this descriptor
  21. // is declared within. The parent file for the file descriptor is itself.
  22. //
  23. // Support for this functionality is optional and may return nil.
  24. ParentFile() FileDescriptor
  25. // Parent returns the parent containing this descriptor declaration.
  26. // The following shows the mapping from child type to possible parent types:
  27. //
  28. // ╔═════════════════════╤═══════════════════════════════════╗
  29. // ║ Child type │ Possible parent types ║
  30. // ╠═════════════════════╪═══════════════════════════════════╣
  31. // ║ FileDescriptor │ nil ║
  32. // ║ MessageDescriptor │ FileDescriptor, MessageDescriptor ║
  33. // ║ FieldDescriptor │ FileDescriptor, MessageDescriptor ║
  34. // ║ OneofDescriptor │ MessageDescriptor ║
  35. // ║ EnumDescriptor │ FileDescriptor, MessageDescriptor ║
  36. // ║ EnumValueDescriptor │ EnumDescriptor ║
  37. // ║ ServiceDescriptor │ FileDescriptor ║
  38. // ║ MethodDescriptor │ ServiceDescriptor ║
  39. // ╚═════════════════════╧═══════════════════════════════════╝
  40. //
  41. // Support for this functionality is optional and may return nil.
  42. Parent() Descriptor
  43. // Index returns the index of this descriptor within its parent.
  44. // It returns 0 if the descriptor does not have a parent or if the parent
  45. // is unknown.
  46. Index() int
  47. // Syntax is the protobuf syntax.
  48. Syntax() Syntax // e.g., Proto2 or Proto3
  49. // Name is the short name of the declaration (i.e., FullName.Name).
  50. Name() Name // e.g., "Any"
  51. // FullName is the fully-qualified name of the declaration.
  52. //
  53. // The FullName is a concatenation of the full name of the type that this
  54. // type is declared within and the declaration name. For example,
  55. // field "foo_field" in message "proto.package.MyMessage" is
  56. // uniquely identified as "proto.package.MyMessage.foo_field".
  57. // Enum values are an exception to the rule (see EnumValueDescriptor).
  58. FullName() FullName // e.g., "google.protobuf.Any"
  59. // IsPlaceholder reports whether type information is missing since a
  60. // dependency is not resolved, in which case only name information is known.
  61. //
  62. // Placeholder types may only be returned by the following accessors
  63. // as a result of unresolved dependencies or weak imports:
  64. //
  65. // ╔═══════════════════════════════════╤═════════════════════╗
  66. // ║ Accessor │ Descriptor ║
  67. // ╠═══════════════════════════════════╪═════════════════════╣
  68. // ║ FileImports.FileDescriptor │ FileDescriptor ║
  69. // ║ FieldDescriptor.Enum │ EnumDescriptor ║
  70. // ║ FieldDescriptor.Message │ MessageDescriptor ║
  71. // ║ FieldDescriptor.DefaultEnumValue │ EnumValueDescriptor ║
  72. // ║ FieldDescriptor.ContainingMessage │ MessageDescriptor ║
  73. // ║ MethodDescriptor.Input │ MessageDescriptor ║
  74. // ║ MethodDescriptor.Output │ MessageDescriptor ║
  75. // ╚═══════════════════════════════════╧═════════════════════╝
  76. //
  77. // If true, only Name and FullName are valid.
  78. // For FileDescriptor, the Path is also valid.
  79. IsPlaceholder() bool
  80. // Options returns the descriptor options. The caller must not modify
  81. // the returned value.
  82. //
  83. // To avoid a dependency cycle, this function returns a proto.Message value.
  84. // The proto message type returned for each descriptor type is as follows:
  85. // ╔═════════════════════╤══════════════════════════════════════════╗
  86. // ║ Go type │ Protobuf message type ║
  87. // ╠═════════════════════╪══════════════════════════════════════════╣
  88. // ║ FileDescriptor │ google.protobuf.FileOptions ║
  89. // ║ EnumDescriptor │ google.protobuf.EnumOptions ║
  90. // ║ EnumValueDescriptor │ google.protobuf.EnumValueOptions ║
  91. // ║ MessageDescriptor │ google.protobuf.MessageOptions ║
  92. // ║ FieldDescriptor │ google.protobuf.FieldOptions ║
  93. // ║ OneofDescriptor │ google.protobuf.OneofOptions ║
  94. // ║ ServiceDescriptor │ google.protobuf.ServiceOptions ║
  95. // ║ MethodDescriptor │ google.protobuf.MethodOptions ║
  96. // ╚═════════════════════╧══════════════════════════════════════════╝
  97. //
  98. // This method returns a typed nil-pointer if no options are present.
  99. // The caller must import the descriptorpb package to use this.
  100. Options() ProtoMessage
  101. doNotImplement
  102. }
  103. // FileDescriptor describes the types in a complete proto file and
  104. // corresponds with the google.protobuf.FileDescriptorProto message.
  105. //
  106. // Top-level declarations:
  107. // EnumDescriptor, MessageDescriptor, FieldDescriptor, and/or ServiceDescriptor.
  108. type FileDescriptor interface {
  109. Descriptor // Descriptor.FullName is identical to Package
  110. // Path returns the file name, relative to the source tree root.
  111. Path() string // e.g., "path/to/file.proto"
  112. // Package returns the protobuf package namespace.
  113. Package() FullName // e.g., "google.protobuf"
  114. // Imports is a list of imported proto files.
  115. Imports() FileImports
  116. // Enums is a list of the top-level enum declarations.
  117. Enums() EnumDescriptors
  118. // Messages is a list of the top-level message declarations.
  119. Messages() MessageDescriptors
  120. // Extensions is a list of the top-level extension declarations.
  121. Extensions() ExtensionDescriptors
  122. // Services is a list of the top-level service declarations.
  123. Services() ServiceDescriptors
  124. // SourceLocations is a list of source locations.
  125. SourceLocations() SourceLocations
  126. isFileDescriptor
  127. }
  128. type isFileDescriptor interface{ ProtoType(FileDescriptor) }
  129. // FileImports is a list of file imports.
  130. type FileImports interface {
  131. // Len reports the number of files imported by this proto file.
  132. Len() int
  133. // Get returns the ith FileImport. It panics if out of bounds.
  134. Get(i int) FileImport
  135. doNotImplement
  136. }
  137. // FileImport is the declaration for a proto file import.
  138. type FileImport struct {
  139. // FileDescriptor is the file type for the given import.
  140. // It is a placeholder descriptor if IsWeak is set or if a dependency has
  141. // not been regenerated to implement the new reflection APIs.
  142. FileDescriptor
  143. // IsPublic reports whether this is a public import, which causes this file
  144. // to alias declarations within the imported file. The intended use cases
  145. // for this feature is the ability to move proto files without breaking
  146. // existing dependencies.
  147. //
  148. // The current file and the imported file must be within proto package.
  149. IsPublic bool
  150. // IsWeak reports whether this is a weak import, which does not impose
  151. // a direct dependency on the target file.
  152. //
  153. // Weak imports are a legacy proto1 feature. Equivalent behavior is
  154. // achieved using proto2 extension fields or proto3 Any messages.
  155. IsWeak bool
  156. }
  157. // MessageDescriptor describes a message and
  158. // corresponds with the google.protobuf.DescriptorProto message.
  159. //
  160. // Nested declarations:
  161. // FieldDescriptor, OneofDescriptor, FieldDescriptor, EnumDescriptor,
  162. // and/or MessageDescriptor.
  163. type MessageDescriptor interface {
  164. Descriptor
  165. // IsMapEntry indicates that this is an auto-generated message type to
  166. // represent the entry type for a map field.
  167. //
  168. // Map entry messages have only two fields:
  169. // • a "key" field with a field number of 1
  170. // • a "value" field with a field number of 2
  171. // The key and value types are determined by these two fields.
  172. //
  173. // If IsMapEntry is true, it implies that FieldDescriptor.IsMap is true
  174. // for some field with this message type.
  175. IsMapEntry() bool
  176. // Fields is a list of nested field declarations.
  177. Fields() FieldDescriptors
  178. // Oneofs is a list of nested oneof declarations.
  179. Oneofs() OneofDescriptors
  180. // ReservedNames is a list of reserved field names.
  181. ReservedNames() Names
  182. // ReservedRanges is a list of reserved ranges of field numbers.
  183. ReservedRanges() FieldRanges
  184. // RequiredNumbers is a list of required field numbers.
  185. // In Proto3, it is always an empty list.
  186. RequiredNumbers() FieldNumbers
  187. // ExtensionRanges is the field ranges used for extension fields.
  188. // In Proto3, it is always an empty ranges.
  189. ExtensionRanges() FieldRanges
  190. // ExtensionRangeOptions returns the ith extension range options.
  191. //
  192. // To avoid a dependency cycle, this method returns a proto.Message value,
  193. // which always contains a google.protobuf.ExtensionRangeOptions message.
  194. // This method returns a typed nil-pointer if no options are present.
  195. // The caller must import the descriptorpb package to use this.
  196. ExtensionRangeOptions(i int) ProtoMessage
  197. // Enums is a list of nested enum declarations.
  198. Enums() EnumDescriptors
  199. // Messages is a list of nested message declarations.
  200. Messages() MessageDescriptors
  201. // Extensions is a list of nested extension declarations.
  202. Extensions() ExtensionDescriptors
  203. isMessageDescriptor
  204. }
  205. type isMessageDescriptor interface{ ProtoType(MessageDescriptor) }
  206. // MessageType encapsulates a MessageDescriptor with a concrete Go implementation.
  207. // It is recommended that implementations of this interface also implement the
  208. // MessageFieldTypes interface.
  209. type MessageType interface {
  210. // New returns a newly allocated empty message.
  211. // It may return nil for synthetic messages representing a map entry.
  212. New() Message
  213. // Zero returns an empty, read-only message.
  214. // It may return nil for synthetic messages representing a map entry.
  215. Zero() Message
  216. // Descriptor returns the message descriptor.
  217. //
  218. // Invariant: t.Descriptor() == t.New().Descriptor()
  219. Descriptor() MessageDescriptor
  220. }
  221. // MessageFieldTypes extends a MessageType by providing type information
  222. // regarding enums and messages referenced by the message fields.
  223. type MessageFieldTypes interface {
  224. MessageType
  225. // Enum returns the EnumType for the ith field in Descriptor.Fields.
  226. // It returns nil if the ith field is not an enum kind.
  227. // It panics if out of bounds.
  228. //
  229. // Invariant: mt.Enum(i).Descriptor() == mt.Descriptor().Fields(i).Enum()
  230. Enum(i int) EnumType
  231. // Message returns the MessageType for the ith field in Descriptor.Fields.
  232. // It returns nil if the ith field is not a message or group kind.
  233. // It panics if out of bounds.
  234. //
  235. // Invariant: mt.Message(i).Descriptor() == mt.Descriptor().Fields(i).Message()
  236. Message(i int) MessageType
  237. }
  238. // MessageDescriptors is a list of message declarations.
  239. type MessageDescriptors interface {
  240. // Len reports the number of messages.
  241. Len() int
  242. // Get returns the ith MessageDescriptor. It panics if out of bounds.
  243. Get(i int) MessageDescriptor
  244. // ByName returns the MessageDescriptor for a message named s.
  245. // It returns nil if not found.
  246. ByName(s Name) MessageDescriptor
  247. doNotImplement
  248. }
  249. // FieldDescriptor describes a field within a message and
  250. // corresponds with the google.protobuf.FieldDescriptorProto message.
  251. //
  252. // It is used for both normal fields defined within the parent message
  253. // (e.g., MessageDescriptor.Fields) and fields that extend some remote message
  254. // (e.g., FileDescriptor.Extensions or MessageDescriptor.Extensions).
  255. type FieldDescriptor interface {
  256. Descriptor
  257. // Number reports the unique number for this field.
  258. Number() FieldNumber
  259. // Cardinality reports the cardinality for this field.
  260. Cardinality() Cardinality
  261. // Kind reports the basic kind for this field.
  262. Kind() Kind
  263. // HasJSONName reports whether this field has an explicitly set JSON name.
  264. HasJSONName() bool
  265. // JSONName reports the name used for JSON serialization.
  266. // It is usually the camel-cased form of the field name.
  267. // Extension fields are represented by the full name surrounded by brackets.
  268. JSONName() string
  269. // TextName reports the name used for text serialization.
  270. // It is usually the name of the field, except that groups use the name
  271. // of the inlined message, and extension fields are represented by the
  272. // full name surrounded by brackets.
  273. TextName() string
  274. // HasPresence reports whether the field distinguishes between unpopulated
  275. // and default values.
  276. HasPresence() bool
  277. // IsExtension reports whether this is an extension field. If false,
  278. // then Parent and ContainingMessage refer to the same message.
  279. // Otherwise, ContainingMessage and Parent likely differ.
  280. IsExtension() bool
  281. // HasOptionalKeyword reports whether the "optional" keyword was explicitly
  282. // specified in the source .proto file.
  283. HasOptionalKeyword() bool
  284. // IsWeak reports whether this is a weak field, which does not impose a
  285. // direct dependency on the target type.
  286. // If true, then Message returns a placeholder type.
  287. IsWeak() bool
  288. // IsPacked reports whether repeated primitive numeric kinds should be
  289. // serialized using a packed encoding.
  290. // If true, then it implies Cardinality is Repeated.
  291. IsPacked() bool
  292. // IsList reports whether this field represents a list,
  293. // where the value type for the associated field is a List.
  294. // It is equivalent to checking whether Cardinality is Repeated and
  295. // that IsMap reports false.
  296. IsList() bool
  297. // IsMap reports whether this field represents a map,
  298. // where the value type for the associated field is a Map.
  299. // It is equivalent to checking whether Cardinality is Repeated,
  300. // that the Kind is MessageKind, and that Message.IsMapEntry reports true.
  301. IsMap() bool
  302. // MapKey returns the field descriptor for the key in the map entry.
  303. // It returns nil if IsMap reports false.
  304. MapKey() FieldDescriptor
  305. // MapValue returns the field descriptor for the value in the map entry.
  306. // It returns nil if IsMap reports false.
  307. MapValue() FieldDescriptor
  308. // HasDefault reports whether this field has a default value.
  309. HasDefault() bool
  310. // Default returns the default value for scalar fields.
  311. // For proto2, it is the default value as specified in the proto file,
  312. // or the zero value if unspecified.
  313. // For proto3, it is always the zero value of the scalar.
  314. // The Value type is determined by the Kind.
  315. Default() Value
  316. // DefaultEnumValue returns the enum value descriptor for the default value
  317. // of an enum field, and is nil for any other kind of field.
  318. DefaultEnumValue() EnumValueDescriptor
  319. // ContainingOneof is the containing oneof that this field belongs to,
  320. // and is nil if this field is not part of a oneof.
  321. ContainingOneof() OneofDescriptor
  322. // ContainingMessage is the containing message that this field belongs to.
  323. // For extension fields, this may not necessarily be the parent message
  324. // that the field is declared within.
  325. ContainingMessage() MessageDescriptor
  326. // Enum is the enum descriptor if Kind is EnumKind.
  327. // It returns nil for any other Kind.
  328. Enum() EnumDescriptor
  329. // Message is the message descriptor if Kind is
  330. // MessageKind or GroupKind. It returns nil for any other Kind.
  331. Message() MessageDescriptor
  332. isFieldDescriptor
  333. }
  334. type isFieldDescriptor interface{ ProtoType(FieldDescriptor) }
  335. // FieldDescriptors is a list of field declarations.
  336. type FieldDescriptors interface {
  337. // Len reports the number of fields.
  338. Len() int
  339. // Get returns the ith FieldDescriptor. It panics if out of bounds.
  340. Get(i int) FieldDescriptor
  341. // ByName returns the FieldDescriptor for a field named s.
  342. // It returns nil if not found.
  343. ByName(s Name) FieldDescriptor
  344. // ByJSONName returns the FieldDescriptor for a field with s as the JSON name.
  345. // It returns nil if not found.
  346. ByJSONName(s string) FieldDescriptor
  347. // ByTextName returns the FieldDescriptor for a field with s as the text name.
  348. // It returns nil if not found.
  349. ByTextName(s string) FieldDescriptor
  350. // ByNumber returns the FieldDescriptor for a field numbered n.
  351. // It returns nil if not found.
  352. ByNumber(n FieldNumber) FieldDescriptor
  353. doNotImplement
  354. }
  355. // OneofDescriptor describes a oneof field set within a given message and
  356. // corresponds with the google.protobuf.OneofDescriptorProto message.
  357. type OneofDescriptor interface {
  358. Descriptor
  359. // IsSynthetic reports whether this is a synthetic oneof created to support
  360. // proto3 optional semantics. If true, Fields contains exactly one field
  361. // with HasOptionalKeyword specified.
  362. IsSynthetic() bool
  363. // Fields is a list of fields belonging to this oneof.
  364. Fields() FieldDescriptors
  365. isOneofDescriptor
  366. }
  367. type isOneofDescriptor interface{ ProtoType(OneofDescriptor) }
  368. // OneofDescriptors is a list of oneof declarations.
  369. type OneofDescriptors interface {
  370. // Len reports the number of oneof fields.
  371. Len() int
  372. // Get returns the ith OneofDescriptor. It panics if out of bounds.
  373. Get(i int) OneofDescriptor
  374. // ByName returns the OneofDescriptor for a oneof named s.
  375. // It returns nil if not found.
  376. ByName(s Name) OneofDescriptor
  377. doNotImplement
  378. }
  379. // ExtensionDescriptor is an alias of FieldDescriptor for documentation.
  380. type ExtensionDescriptor = FieldDescriptor
  381. // ExtensionTypeDescriptor is an ExtensionDescriptor with an associated ExtensionType.
  382. type ExtensionTypeDescriptor interface {
  383. ExtensionDescriptor
  384. // Type returns the associated ExtensionType.
  385. Type() ExtensionType
  386. // Descriptor returns the plain ExtensionDescriptor without the
  387. // associated ExtensionType.
  388. Descriptor() ExtensionDescriptor
  389. }
  390. // ExtensionDescriptors is a list of field declarations.
  391. type ExtensionDescriptors interface {
  392. // Len reports the number of fields.
  393. Len() int
  394. // Get returns the ith ExtensionDescriptor. It panics if out of bounds.
  395. Get(i int) ExtensionDescriptor
  396. // ByName returns the ExtensionDescriptor for a field named s.
  397. // It returns nil if not found.
  398. ByName(s Name) ExtensionDescriptor
  399. doNotImplement
  400. }
  401. // ExtensionType encapsulates an ExtensionDescriptor with a concrete
  402. // Go implementation. The nested field descriptor must be for a extension field.
  403. //
  404. // While a normal field is a member of the parent message that it is declared
  405. // within (see Descriptor.Parent), an extension field is a member of some other
  406. // target message (see ExtensionDescriptor.Extendee) and may have no
  407. // relationship with the parent. However, the full name of an extension field is
  408. // relative to the parent that it is declared within.
  409. //
  410. // For example:
  411. //
  412. // syntax = "proto2";
  413. // package example;
  414. // message FooMessage {
  415. // extensions 100 to max;
  416. // }
  417. // message BarMessage {
  418. // extends FooMessage { optional BarMessage bar_field = 100; }
  419. // }
  420. //
  421. // Field "bar_field" is an extension of FooMessage, but its full name is
  422. // "example.BarMessage.bar_field" instead of "example.FooMessage.bar_field".
  423. type ExtensionType interface {
  424. // New returns a new value for the field.
  425. // For scalars, this returns the default value in native Go form.
  426. New() Value
  427. // Zero returns a new value for the field.
  428. // For scalars, this returns the default value in native Go form.
  429. // For composite types, this returns an empty, read-only message, list, or map.
  430. Zero() Value
  431. // TypeDescriptor returns the extension type descriptor.
  432. TypeDescriptor() ExtensionTypeDescriptor
  433. // ValueOf wraps the input and returns it as a Value.
  434. // ValueOf panics if the input value is invalid or not the appropriate type.
  435. //
  436. // ValueOf is more extensive than protoreflect.ValueOf for a given field's
  437. // value as it has more type information available.
  438. ValueOf(interface{}) Value
  439. // InterfaceOf completely unwraps the Value to the underlying Go type.
  440. // InterfaceOf panics if the input is nil or does not represent the
  441. // appropriate underlying Go type. For composite types, it panics if the
  442. // value is not mutable.
  443. //
  444. // InterfaceOf is able to unwrap the Value further than Value.Interface
  445. // as it has more type information available.
  446. InterfaceOf(Value) interface{}
  447. // IsValidValue reports whether the Value is valid to assign to the field.
  448. IsValidValue(Value) bool
  449. // IsValidInterface reports whether the input is valid to assign to the field.
  450. IsValidInterface(interface{}) bool
  451. }
  452. // EnumDescriptor describes an enum and
  453. // corresponds with the google.protobuf.EnumDescriptorProto message.
  454. //
  455. // Nested declarations:
  456. // EnumValueDescriptor.
  457. type EnumDescriptor interface {
  458. Descriptor
  459. // Values is a list of nested enum value declarations.
  460. Values() EnumValueDescriptors
  461. // ReservedNames is a list of reserved enum names.
  462. ReservedNames() Names
  463. // ReservedRanges is a list of reserved ranges of enum numbers.
  464. ReservedRanges() EnumRanges
  465. isEnumDescriptor
  466. }
  467. type isEnumDescriptor interface{ ProtoType(EnumDescriptor) }
  468. // EnumType encapsulates an EnumDescriptor with a concrete Go implementation.
  469. type EnumType interface {
  470. // New returns an instance of this enum type with its value set to n.
  471. New(n EnumNumber) Enum
  472. // Descriptor returns the enum descriptor.
  473. //
  474. // Invariant: t.Descriptor() == t.New(0).Descriptor()
  475. Descriptor() EnumDescriptor
  476. }
  477. // EnumDescriptors is a list of enum declarations.
  478. type EnumDescriptors interface {
  479. // Len reports the number of enum types.
  480. Len() int
  481. // Get returns the ith EnumDescriptor. It panics if out of bounds.
  482. Get(i int) EnumDescriptor
  483. // ByName returns the EnumDescriptor for an enum named s.
  484. // It returns nil if not found.
  485. ByName(s Name) EnumDescriptor
  486. doNotImplement
  487. }
  488. // EnumValueDescriptor describes an enum value and
  489. // corresponds with the google.protobuf.EnumValueDescriptorProto message.
  490. //
  491. // All other proto declarations are in the namespace of the parent.
  492. // However, enum values do not follow this rule and are within the namespace
  493. // of the parent's parent (i.e., they are a sibling of the containing enum).
  494. // Thus, a value named "FOO_VALUE" declared within an enum uniquely identified
  495. // as "proto.package.MyEnum" has a full name of "proto.package.FOO_VALUE".
  496. type EnumValueDescriptor interface {
  497. Descriptor
  498. // Number returns the enum value as an integer.
  499. Number() EnumNumber
  500. isEnumValueDescriptor
  501. }
  502. type isEnumValueDescriptor interface{ ProtoType(EnumValueDescriptor) }
  503. // EnumValueDescriptors is a list of enum value declarations.
  504. type EnumValueDescriptors interface {
  505. // Len reports the number of enum values.
  506. Len() int
  507. // Get returns the ith EnumValueDescriptor. It panics if out of bounds.
  508. Get(i int) EnumValueDescriptor
  509. // ByName returns the EnumValueDescriptor for the enum value named s.
  510. // It returns nil if not found.
  511. ByName(s Name) EnumValueDescriptor
  512. // ByNumber returns the EnumValueDescriptor for the enum value numbered n.
  513. // If multiple have the same number, the first one defined is returned
  514. // It returns nil if not found.
  515. ByNumber(n EnumNumber) EnumValueDescriptor
  516. doNotImplement
  517. }
  518. // ServiceDescriptor describes a service and
  519. // corresponds with the google.protobuf.ServiceDescriptorProto message.
  520. //
  521. // Nested declarations: MethodDescriptor.
  522. type ServiceDescriptor interface {
  523. Descriptor
  524. // Methods is a list of nested message declarations.
  525. Methods() MethodDescriptors
  526. isServiceDescriptor
  527. }
  528. type isServiceDescriptor interface{ ProtoType(ServiceDescriptor) }
  529. // ServiceDescriptors is a list of service declarations.
  530. type ServiceDescriptors interface {
  531. // Len reports the number of services.
  532. Len() int
  533. // Get returns the ith ServiceDescriptor. It panics if out of bounds.
  534. Get(i int) ServiceDescriptor
  535. // ByName returns the ServiceDescriptor for a service named s.
  536. // It returns nil if not found.
  537. ByName(s Name) ServiceDescriptor
  538. doNotImplement
  539. }
  540. // MethodDescriptor describes a method and
  541. // corresponds with the google.protobuf.MethodDescriptorProto message.
  542. type MethodDescriptor interface {
  543. Descriptor
  544. // Input is the input message descriptor.
  545. Input() MessageDescriptor
  546. // Output is the output message descriptor.
  547. Output() MessageDescriptor
  548. // IsStreamingClient reports whether the client streams multiple messages.
  549. IsStreamingClient() bool
  550. // IsStreamingServer reports whether the server streams multiple messages.
  551. IsStreamingServer() bool
  552. isMethodDescriptor
  553. }
  554. type isMethodDescriptor interface{ ProtoType(MethodDescriptor) }
  555. // MethodDescriptors is a list of method declarations.
  556. type MethodDescriptors interface {
  557. // Len reports the number of methods.
  558. Len() int
  559. // Get returns the ith MethodDescriptor. It panics if out of bounds.
  560. Get(i int) MethodDescriptor
  561. // ByName returns the MethodDescriptor for a service method named s.
  562. // It returns nil if not found.
  563. ByName(s Name) MethodDescriptor
  564. doNotImplement
  565. }