/src/grpc-swift/Sources/GRPC/GRPCServiceDescription.swift
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2021, gRPC Authors All rights reserved. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | public struct GRPCServiceDescriptor: Hashable, Sendable { |
18 | | /// The name of the service excluding the package, e.g. 'Echo'. |
19 | | public var name: String |
20 | | |
21 | | /// The full name of the service including the package, e.g. 'echo.Echo' |
22 | | public var fullName: String |
23 | | |
24 | | /// Methods defined on the service. |
25 | | public var methods: [GRPCMethodDescriptor] |
26 | | |
27 | 5 | public init(name: String, fullName: String, methods: [GRPCMethodDescriptor]) { |
28 | 5 | self.name = name |
29 | 5 | self.fullName = fullName |
30 | 5 | self.methods = methods |
31 | 5 | } |
32 | | } |
33 | | |
34 | | public struct GRPCMethodDescriptor: Hashable, Sendable { |
35 | | /// The name of the method, e.g. 'Get'. |
36 | | public var name: String |
37 | | |
38 | | /// The full name of the method include the fully qualified name of the service in the |
39 | | /// format 'package.Service/Method', for example 'echo.Echo/Get'. |
40 | | /// |
41 | | /// This differs from the ``path`` only in that the leading '/' is removed. |
42 | 0 | public var fullName: String { |
43 | 0 | assert(self.path.utf8.first == UInt8(ascii: "/")) |
44 | 0 | return String(self.path.dropFirst()) |
45 | 0 | } |
46 | | |
47 | | /// The path of the method in the format '/package.Service/method', for example '/echo.Echo/Get'. |
48 | | public var path: String |
49 | | |
50 | | /// The type of call. |
51 | | public var type: GRPCCallType |
52 | | |
53 | 20 | public init(name: String, path: String, type: GRPCCallType) { |
54 | 20 | self.name = name |
55 | 20 | self.path = path |
56 | 20 | self.type = type |
57 | 20 | } |
58 | | } |