瀏覽代碼

Update generated code to use service descriptors (#2004)

Motivation:

The generated code refers to services literally using strings. With the
addition of service descriptors, the generated code can now utilize them
to refer to services.

Modifications:

- Update the generated code to use service descriptors.
- For each service in the generated code, extend `ServiceDescriptor` to
include a `static` property that holds the service descriptor for that
service. (I.e. for a service `Foo` in the `bar` package, the service
descriptor for `Foo` can be accessed using `ServiceDescriptor.bar_Foo`.)

Result:

The generated code will utilize and provide easy access to service
descriptors.
Clinton Nkwocha 1 年之前
父節點
當前提交
2b7f95140c
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      Tests/GRPCHTTP2TransportTests/Generated/control.grpc.swift

+ 12 - 4
Tests/GRPCHTTP2TransportTests/Generated/control.grpc.swift

@@ -26,12 +26,13 @@ import GRPCCore
 import GRPCProtobuf
 
 internal enum Control {
+    internal static let descriptor = ServiceDescriptor.Control
     internal enum Method {
         internal enum Unary {
             internal typealias Input = ControlInput
             internal typealias Output = ControlOutput
             internal static let descriptor = MethodDescriptor(
-                service: "Control",
+                service: Control.descriptor.fullyQualifiedService,
                 method: "Unary"
             )
         }
@@ -39,7 +40,7 @@ internal enum Control {
             internal typealias Input = ControlInput
             internal typealias Output = ControlOutput
             internal static let descriptor = MethodDescriptor(
-                service: "Control",
+                service: Control.descriptor.fullyQualifiedService,
                 method: "ServerStream"
             )
         }
@@ -47,7 +48,7 @@ internal enum Control {
             internal typealias Input = ControlInput
             internal typealias Output = ControlOutput
             internal static let descriptor = MethodDescriptor(
-                service: "Control",
+                service: Control.descriptor.fullyQualifiedService,
                 method: "ClientStream"
             )
         }
@@ -55,7 +56,7 @@ internal enum Control {
             internal typealias Input = ControlInput
             internal typealias Output = ControlOutput
             internal static let descriptor = MethodDescriptor(
-                service: "Control",
+                service: Control.descriptor.fullyQualifiedService,
                 method: "BidiStream"
             )
         }
@@ -76,6 +77,13 @@ internal enum Control {
     internal typealias Client = ControlClient
 }
 
+extension ServiceDescriptor {
+    internal static let Control = Self(
+        package: "",
+        service: "Control"
+    )
+}
+
 /// A controllable service for testing.
 ///
 /// The control service has one RPC of each kind, the input to each RPC controls