From f2846164c5b4ddbd24f218980354ac13746772bf Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Sat, 12 Jan 2019 22:36:35 -0800 Subject: [PATCH 1/8] Allow client to specify metadata per call --- .../Generator-Client.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift index ca8d78ffc..58dab58e7 100644 --- a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift +++ b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift @@ -204,6 +204,14 @@ extension Generator { outdent() outdent() println("}") + println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName) {") + indent() + println("return try \(callName)Base(channel)") + indent() + println(".run(request: request, metadata: customMetadata ?? self.metadata)") + outdent() + outdent() + println("}") } if asynchronousCode { println("/// Asynchronous. Unary.") @@ -215,6 +223,14 @@ extension Generator { outdent() outdent() println("}") + println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") + indent() + println("return try \(callName)Base(channel)") + indent() + println(".start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)") + outdent() + outdent() + println("}") } case .serverStreaming: println("/// Asynchronous. Server-streaming.") @@ -228,6 +244,14 @@ extension Generator { outdent() outdent() println("}") + println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + indent() + println("return try \(callName)Base(channel)") + indent() + println(".start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)") + outdent() + outdent() + println("}") case .clientStreaming: println("/// Asynchronous. Client-streaming.") println("/// Use methods on the returned object to stream messages and") @@ -240,6 +264,14 @@ extension Generator { outdent() outdent() println("}") + println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + indent() + println("return try \(callName)Base(channel)") + indent() + println(".start(metadata: customMetadata ?? self.metadata, completion: completion)") + outdent() + outdent() + println("}") case .bidirectionalStreaming: println("/// Asynchronous. Bidirectional-streaming.") println("/// Use methods on the returned object to stream messages,") @@ -252,6 +284,14 @@ extension Generator { outdent() outdent() println("}") + println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + indent() + println("return try \(callName)Base(channel)") + indent() + println(".start(metadata: customMetadata ?? self.metadata, completion: completion)") + outdent() + outdent() + println("}") } println() } From 21af3746d60cba500afcc057ce57b156d38fdb97 Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Sat, 12 Jan 2019 23:09:44 -0800 Subject: [PATCH 2/8] Regenerate echo.grpc.swift --- .../Examples/Echo/Generated/echo.grpc.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sources/Examples/Echo/Generated/echo.grpc.swift b/Sources/Examples/Echo/Generated/echo.grpc.swift index 1f6c30530..107709b72 100644 --- a/Sources/Examples/Echo/Generated/echo.grpc.swift +++ b/Sources/Examples/Echo/Generated/echo.grpc.swift @@ -144,11 +144,19 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService return try Echo_EchoGetCallBase(channel) .run(request: request, metadata: metadata) } + internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?) throws -> Echo_EchoResponse { + return try Echo_EchoGetCallBase(channel) + .run(request: request, metadata: customMetadata ?? self.metadata) + } /// Asynchronous. Unary. internal func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { return try Echo_EchoGetCallBase(channel) .start(request: request, metadata: metadata, completion: completion) } + internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { + return try Echo_EchoGetCallBase(channel) + .start(request: request, metadata: customMetadata ?? self.metadata, completion: completion) + } /// Asynchronous. Server-streaming. /// Send the initial message. @@ -157,6 +165,10 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService return try Echo_EchoExpandCallBase(channel) .start(request: request, metadata: metadata, completion: completion) } + internal func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { + return try Echo_EchoExpandCallBase(channel) + .start(request: request, metadata: customMetadata ?? self.metadata, completion: completion) + } /// Asynchronous. Client-streaming. /// Use methods on the returned object to stream messages and @@ -165,6 +177,10 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService return try Echo_EchoCollectCallBase(channel) .start(metadata: metadata, completion: completion) } + internal func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { + return try Echo_EchoCollectCallBase(channel) + .start(metadata: customMetadata ?? self.metadata, completion: completion) + } /// Asynchronous. Bidirectional-streaming. /// Use methods on the returned object to stream messages, @@ -173,6 +189,10 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService return try Echo_EchoUpdateCallBase(channel) .start(metadata: metadata, completion: completion) } + internal func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { + return try Echo_EchoUpdateCallBase(channel) + .start(metadata: customMetadata ?? self.metadata, completion: completion) + } } From 305d434a28c743f28cb83384a08070c3e72a732f Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Sun, 13 Jan 2019 11:06:09 -0800 Subject: [PATCH 3/8] fix --- .../Generator-Client.swift | 102 ++++++++++-------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift index 58dab58e7..bd59abc1a 100644 --- a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift +++ b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift @@ -36,6 +36,8 @@ extension Generator { println() printServiceClientProtocol(asynchronousCode: asynchronousCode, synchronousCode: synchronousCode) + printServiceClientProtocolExtension(asynchronousCode: asynchronousCode, + synchronousCode: synchronousCode) println() printServiceClientImplementation(asynchronousCode: asynchronousCode, synchronousCode: synchronousCode) @@ -158,27 +160,27 @@ extension Generator { case .unary: if synchronousCode { println("/// Synchronous. Unary.") - println("func \(methodFunctionName)(_ request: \(methodInputName)) throws -> \(methodOutputName)") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName)") } if asynchronousCode { println("/// Asynchronous. Unary.") - println("func \(methodFunctionName)(_ request: \(methodInputName), completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName)") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName)") } case .serverStreaming: println("/// Asynchronous. Server-streaming.") println("/// Send the initial message.") println("/// Use methods on the returned object to get streamed responses.") - println("func \(methodFunctionName)(_ request: \(methodInputName), completion: ((CallResult) -> Void)?) throws -> \(callName)") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName)") case .clientStreaming: println("/// Asynchronous. Client-streaming.") println("/// Use methods on the returned object to stream messages and") println("/// to close the connection and wait for a final response.") - println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName)") + println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName)") case .bidirectionalStreaming: println("/// Asynchronous. Bidirectional-streaming.") println("/// Use methods on the returned object to stream messages,") println("/// to wait for replies, and to close the connection.") - println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName)") + println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName)") } println() } @@ -186,9 +188,9 @@ extension Generator { println("}") } - private func printServiceClientImplementation(asynchronousCode: Bool, - synchronousCode: Bool) { - println("\(access) final class \(serviceClassName)Client: ServiceClientBase, \(serviceClassName) {") + private func printServiceClientProtocolExtension(asynchronousCode: Bool, + synchronousCode: Bool) { + println("\(options.visibility.sourceSnippet) extension \(serviceClassName) {") indent() for method in service.methods { self.method = method @@ -196,14 +198,58 @@ extension Generator { case .unary: if synchronousCode { println("/// Synchronous. Unary.") - println("\(access) func \(methodFunctionName)(_ request: \(methodInputName)) throws -> \(methodOutputName) {") + println("func \(methodFunctionName)(_ request: \(methodInputName)) throws -> \(methodOutputName) {") indent() - println("return try \(callName)Base(channel)") - indent() - println(".run(request: request, metadata: metadata)") + println("return try self.\(methodFunctionName)(request, metadata: self.metadata)") outdent() + println("}") + } + if asynchronousCode { + println("/// Asynchronous. Unary.") + println("func \(methodFunctionName)(_ request: \(methodInputName), completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") + indent() + println("return try self.\(methodFunctionName)(request, metadata: self.metadata, completion: completion)") outdent() println("}") + } + case .serverStreaming: + println("/// Asynchronous. Server-streaming.") + println("func \(methodFunctionName)(_ request: \(methodInputName), completion: ((CallResult) -> Void)?) throws -> \(callName) {") + indent() + println("return try self.\(methodFunctionName)(request, metadata: self.metadata, completion: completion)") + outdent() + println("}") + case .clientStreaming: + println("/// Asynchronous. Client-streaming.") + println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {") + indent() + println("return try self.\(methodFunctionName)(metadata: self.metadata, completion: completion)") + outdent() + println("}") + case .bidirectionalStreaming: + println("/// Asynchronous. Bidirectional-streaming.") + println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {") + indent() + println("return try self.\(methodFunctionName)(metadata: self.metadata, completion: completion)") + outdent() + println("}") + } + println() + } + outdent() + println("}") + } + + private func printServiceClientImplementation(asynchronousCode: Bool, + synchronousCode: Bool) { + println("\(access) final class \(serviceClassName)Client: ServiceClientBase, \(serviceClassName) {") + indent() + for method in service.methods { + self.method = method + switch streamingType(method) { + case .unary: + if synchronousCode { + println("/// Synchronous. Unary.") println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName) {") indent() println("return try \(callName)Base(channel)") @@ -215,14 +261,6 @@ extension Generator { } if asynchronousCode { println("/// Asynchronous. Unary.") - println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") - indent() - println("return try \(callName)Base(channel)") - indent() - println(".start(request: request, metadata: metadata, completion: completion)") - outdent() - outdent() - println("}") println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") @@ -236,14 +274,6 @@ extension Generator { println("/// Asynchronous. Server-streaming.") println("/// Send the initial message.") println("/// Use methods on the returned object to get streamed responses.") - println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), completion: ((CallResult) -> Void)?) throws -> \(callName) {") - indent() - println("return try \(callName)Base(channel)") - indent() - println(".start(request: request, metadata: metadata, completion: completion)") - outdent() - outdent() - println("}") println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") @@ -256,14 +286,6 @@ extension Generator { println("/// Asynchronous. Client-streaming.") println("/// Use methods on the returned object to stream messages and") println("/// to close the connection and wait for a final response.") - println("\(access) func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {") - indent() - println("return try \(callName)Base(channel)") - indent() - println(".start(metadata: metadata, completion: completion)") - outdent() - outdent() - println("}") println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") @@ -276,14 +298,6 @@ extension Generator { println("/// Asynchronous. Bidirectional-streaming.") println("/// Use methods on the returned object to stream messages,") println("/// to wait for replies, and to close the connection.") - println("\(access) func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {") - indent() - println("return try \(callName)Base(channel)") - indent() - println(".start(metadata: metadata, completion: completion)") - outdent() - outdent() - println("}") println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") From ebff71a09c5c8ba128c30e59a6cf8b9892e38f58 Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Sun, 13 Jan 2019 11:11:41 -0800 Subject: [PATCH 4/8] regenerate --- .../Examples/Echo/Generated/echo.grpc.swift | 56 ++++++----- Sources/Examples/Echo/Generated/echo.pb.swift | 92 +++++++++---------- 2 files changed, 72 insertions(+), 76 deletions(-) diff --git a/Sources/Examples/Echo/Generated/echo.grpc.swift b/Sources/Examples/Echo/Generated/echo.grpc.swift index 107709b72..83ee9326f 100644 --- a/Sources/Examples/Echo/Generated/echo.grpc.swift +++ b/Sources/Examples/Echo/Generated/echo.grpc.swift @@ -117,42 +117,60 @@ class Echo_EchoUpdateCallTestStub: ClientCallBidirectionalStreamingTestStub Echo_EchoResponse + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?) throws -> Echo_EchoResponse /// Asynchronous. Unary. - func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall /// Asynchronous. Server-streaming. /// Send the initial message. /// Use methods on the returned object to get streamed responses. - func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall + func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall /// Asynchronous. Client-streaming. /// Use methods on the returned object to stream messages and /// to close the connection and wait for a final response. - func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall + func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall /// Asynchronous. Bidirectional-streaming. /// Use methods on the returned object to stream messages, /// to wait for replies, and to close the connection. - func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall + func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall + +} +internal extension Echo_EchoService { + /// Synchronous. Unary. + func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse { + return try self.get(request, metadata: self.metadata) + } + /// Asynchronous. Unary. + func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { + return try self.get(request, metadata: self.metadata, completion: completion) + } + + /// Asynchronous. Server-streaming. + func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { + return try self.expand(request, metadata: self.metadata, completion: completion) + } + + /// Asynchronous. Client-streaming. + func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { + return try self.collect(metadata: self.metadata, completion: completion) + } + + /// Asynchronous. Bidirectional-streaming. + func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { + return try self.update(metadata: self.metadata, completion: completion) + } } internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService { /// Synchronous. Unary. - internal func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse { - return try Echo_EchoGetCallBase(channel) - .run(request: request, metadata: metadata) - } internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?) throws -> Echo_EchoResponse { return try Echo_EchoGetCallBase(channel) .run(request: request, metadata: customMetadata ?? self.metadata) } /// Asynchronous. Unary. - internal func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { - return try Echo_EchoGetCallBase(channel) - .start(request: request, metadata: metadata, completion: completion) - } internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { return try Echo_EchoGetCallBase(channel) .start(request: request, metadata: customMetadata ?? self.metadata, completion: completion) @@ -161,10 +179,6 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService /// Asynchronous. Server-streaming. /// Send the initial message. /// Use methods on the returned object to get streamed responses. - internal func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { - return try Echo_EchoExpandCallBase(channel) - .start(request: request, metadata: metadata, completion: completion) - } internal func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { return try Echo_EchoExpandCallBase(channel) .start(request: request, metadata: customMetadata ?? self.metadata, completion: completion) @@ -173,10 +187,6 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService /// Asynchronous. Client-streaming. /// Use methods on the returned object to stream messages and /// to close the connection and wait for a final response. - internal func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { - return try Echo_EchoCollectCallBase(channel) - .start(metadata: metadata, completion: completion) - } internal func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { return try Echo_EchoCollectCallBase(channel) .start(metadata: customMetadata ?? self.metadata, completion: completion) @@ -185,10 +195,6 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService /// Asynchronous. Bidirectional-streaming. /// Use methods on the returned object to stream messages, /// to wait for replies, and to close the connection. - internal func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { - return try Echo_EchoUpdateCallBase(channel) - .start(metadata: metadata, completion: completion) - } internal func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { return try Echo_EchoUpdateCallBase(channel) .start(metadata: customMetadata ?? self.metadata, completion: completion) diff --git a/Sources/Examples/Echo/Generated/echo.pb.swift b/Sources/Examples/Echo/Generated/echo.pb.swift index aa7466d35..54afebc3a 100644 --- a/Sources/Examples/Echo/Generated/echo.pb.swift +++ b/Sources/Examples/Echo/Generated/echo.pb.swift @@ -33,8 +33,10 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP typealias Version = _2 } -struct Echo_EchoRequest: SwiftProtobuf.Message { - static let protoMessageName: String = _protobuf_package + ".EchoRequest" +struct Echo_EchoRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. /// The text of a message to be echoed. var text: String = String() @@ -42,11 +44,31 @@ struct Echo_EchoRequest: SwiftProtobuf.Message { var unknownFields = SwiftProtobuf.UnknownStorage() init() {} +} + +struct Echo_EchoResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The text of an echo response. + var text: String = String() + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "echo" + +extension Echo_EchoRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".EchoRequest" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "text"), + ] - /// Used by the decoding initializers in the SwiftProtobuf library, not generally - /// used directly. `init(serializedData:)`, `init(jsonUTF8Data:)`, and other decoding - /// initializers are defined in the SwiftProtobuf library. See the Message and - /// Message+*Additions` files. mutating func decodeMessage(decoder: inout D) throws { while let fieldNumber = try decoder.nextFieldNumber() { switch fieldNumber { @@ -56,32 +78,26 @@ struct Echo_EchoRequest: SwiftProtobuf.Message { } } - /// Used by the encoding methods of the SwiftProtobuf library, not generally - /// used directly. `Message.serializedData()`, `Message.jsonUTF8Data()`, and - /// other serializer methods are defined in the SwiftProtobuf library. See the - /// `Message` and `Message+*Additions` files. func traverse(visitor: inout V) throws { if !self.text.isEmpty { try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) } try unknownFields.traverse(visitor: &visitor) } + + static func ==(lhs: Echo_EchoRequest, rhs: Echo_EchoRequest) -> Bool { + if lhs.text != rhs.text {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } } -struct Echo_EchoResponse: SwiftProtobuf.Message { +extension Echo_EchoResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = _protobuf_package + ".EchoResponse" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "text"), + ] - /// The text of an echo response. - var text: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - - /// Used by the decoding initializers in the SwiftProtobuf library, not generally - /// used directly. `init(serializedData:)`, `init(jsonUTF8Data:)`, and other decoding - /// initializers are defined in the SwiftProtobuf library. See the Message and - /// Message+*Additions` files. mutating func decodeMessage(decoder: inout D) throws { while let fieldNumber = try decoder.nextFieldNumber() { switch fieldNumber { @@ -91,42 +107,16 @@ struct Echo_EchoResponse: SwiftProtobuf.Message { } } - /// Used by the encoding methods of the SwiftProtobuf library, not generally - /// used directly. `Message.serializedData()`, `Message.jsonUTF8Data()`, and - /// other serializer methods are defined in the SwiftProtobuf library. See the - /// `Message` and `Message+*Additions` files. func traverse(visitor: inout V) throws { if !self.text.isEmpty { try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) } try unknownFields.traverse(visitor: &visitor) } -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "echo" - -extension Echo_EchoRequest: SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] - - func _protobuf_generated_isEqualTo(other: Echo_EchoRequest) -> Bool { - if self.text != other.text {return false} - if unknownFields != other.unknownFields {return false} - return true - } -} - -extension Echo_EchoResponse: SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] - func _protobuf_generated_isEqualTo(other: Echo_EchoResponse) -> Bool { - if self.text != other.text {return false} - if unknownFields != other.unknownFields {return false} + static func ==(lhs: Echo_EchoResponse, rhs: Echo_EchoResponse) -> Bool { + if lhs.text != rhs.text {return false} + if lhs.unknownFields != rhs.unknownFields {return false} return true } } From 79762742d7539503e35f43718bd7585aba983862 Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Sun, 13 Jan 2019 11:34:39 -0800 Subject: [PATCH 5/8] fix teststub --- Sources/Examples/Echo/Generated/echo.grpc.swift | 10 +++++----- Sources/protoc-gen-swiftgrpc/Generator-Client.swift | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Examples/Echo/Generated/echo.grpc.swift b/Sources/Examples/Echo/Generated/echo.grpc.swift index 83ee9326f..b6be73450 100644 --- a/Sources/Examples/Echo/Generated/echo.grpc.swift +++ b/Sources/Examples/Echo/Generated/echo.grpc.swift @@ -205,31 +205,31 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService { var getRequests: [Echo_EchoRequest] = [] var getResponses: [Echo_EchoResponse] = [] - func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse { + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?) throws -> Echo_EchoResponse { getRequests.append(request) defer { getResponses.removeFirst() } return getResponses.first! } - func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { fatalError("not implemented") } var expandRequests: [Echo_EchoRequest] = [] var expandCalls: [Echo_EchoExpandCall] = [] - func expand(_ request: Echo_EchoRequest, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { + func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { expandRequests.append(request) defer { expandCalls.removeFirst() } return expandCalls.first! } var collectCalls: [Echo_EchoCollectCall] = [] - func collect(completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { + func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { defer { collectCalls.removeFirst() } return collectCalls.first! } var updateCalls: [Echo_EchoUpdateCall] = [] - func update(completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { + func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { defer { updateCalls.removeFirst() } return updateCalls.first! } diff --git a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift index bd59abc1a..fd1217604 100644 --- a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift +++ b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift @@ -322,14 +322,14 @@ extension Generator { case .unary: println("var \(methodFunctionName)Requests: [\(methodInputName)] = []") println("var \(methodFunctionName)Responses: [\(methodOutputName)] = []") - println("func \(methodFunctionName)(_ request: \(methodInputName)) throws -> \(methodOutputName) {") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName) {") indent() println("\(methodFunctionName)Requests.append(request)") println("defer { \(methodFunctionName)Responses.removeFirst() }") println("return \(methodFunctionName)Responses.first!") outdent() println("}") - println("func \(methodFunctionName)(_ request: \(methodInputName), completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") indent() println("fatalError(\"not implemented\")") outdent() @@ -337,7 +337,7 @@ extension Generator { case .serverStreaming: println("var \(methodFunctionName)Requests: [\(methodInputName)] = []") println("var \(methodFunctionName)Calls: [\(callName)] = []") - println("func \(methodFunctionName)(_ request: \(methodInputName), completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("\(methodFunctionName)Requests.append(request)") println("defer { \(methodFunctionName)Calls.removeFirst() }") @@ -346,7 +346,7 @@ extension Generator { println("}") case .clientStreaming: println("var \(methodFunctionName)Calls: [\(callName)] = []") - println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("defer { \(methodFunctionName)Calls.removeFirst() }") println("return \(methodFunctionName)Calls.first!") @@ -354,7 +354,7 @@ extension Generator { println("}") case .bidirectionalStreaming: println("var \(methodFunctionName)Calls: [\(callName)] = []") - println("func \(methodFunctionName)(completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("defer { \(methodFunctionName)Calls.removeFirst() }") println("return \(methodFunctionName)Calls.first!") From c757c6b665c4f042ad85827266a45bcf4ac412a8 Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Sun, 13 Jan 2019 11:49:52 -0800 Subject: [PATCH 6/8] add a newline --- Sources/Examples/Echo/Generated/echo.grpc.swift | 1 + Sources/protoc-gen-swiftgrpc/Generator-Client.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/Examples/Echo/Generated/echo.grpc.swift b/Sources/Examples/Echo/Generated/echo.grpc.swift index b6be73450..e01923732 100644 --- a/Sources/Examples/Echo/Generated/echo.grpc.swift +++ b/Sources/Examples/Echo/Generated/echo.grpc.swift @@ -137,6 +137,7 @@ internal protocol Echo_EchoService: ServiceClient { func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall } + internal extension Echo_EchoService { /// Synchronous. Unary. func get(_ request: Echo_EchoRequest) throws -> Echo_EchoResponse { diff --git a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift index fd1217604..2ebb604f8 100644 --- a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift +++ b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift @@ -36,6 +36,7 @@ extension Generator { println() printServiceClientProtocol(asynchronousCode: asynchronousCode, synchronousCode: synchronousCode) + println() printServiceClientProtocolExtension(asynchronousCode: asynchronousCode, synchronousCode: synchronousCode) println() From 31fae707449b11bf7265a90cfd5303271a709dbd Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Wed, 30 Jan 2019 18:25:10 -0800 Subject: [PATCH 7/8] Replace Metadata? with Metadata --- .../Examples/Echo/Generated/echo.grpc.swift | 40 ++++---- Sources/Examples/Echo/Generated/echo.pb.swift | 92 ++++++++++--------- .../Generator-Client.swift | 42 ++++----- 3 files changed, 92 insertions(+), 82 deletions(-) diff --git a/Sources/Examples/Echo/Generated/echo.grpc.swift b/Sources/Examples/Echo/Generated/echo.grpc.swift index e01923732..87ee13fc3 100644 --- a/Sources/Examples/Echo/Generated/echo.grpc.swift +++ b/Sources/Examples/Echo/Generated/echo.grpc.swift @@ -117,24 +117,24 @@ class Echo_EchoUpdateCallTestStub: ClientCallBidirectionalStreamingTestStub Echo_EchoResponse + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse /// Asynchronous. Unary. - func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall /// Asynchronous. Server-streaming. /// Send the initial message. /// Use methods on the returned object to get streamed responses. - func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall + func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall /// Asynchronous. Client-streaming. /// Use methods on the returned object to stream messages and /// to close the connection and wait for a final response. - func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall + func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall /// Asynchronous. Bidirectional-streaming. /// Use methods on the returned object to stream messages, /// to wait for replies, and to close the connection. - func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall + func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall } @@ -167,38 +167,38 @@ internal extension Echo_EchoService { internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService { /// Synchronous. Unary. - internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?) throws -> Echo_EchoResponse { + internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse { return try Echo_EchoGetCallBase(channel) - .run(request: request, metadata: customMetadata ?? self.metadata) + .run(request: request, metadata: customMetadata) } /// Asynchronous. Unary. - internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { + internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { return try Echo_EchoGetCallBase(channel) - .start(request: request, metadata: customMetadata ?? self.metadata, completion: completion) + .start(request: request, metadata: customMetadata, completion: completion) } /// Asynchronous. Server-streaming. /// Send the initial message. /// Use methods on the returned object to get streamed responses. - internal func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { + internal func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { return try Echo_EchoExpandCallBase(channel) - .start(request: request, metadata: customMetadata ?? self.metadata, completion: completion) + .start(request: request, metadata: customMetadata, completion: completion) } /// Asynchronous. Client-streaming. /// Use methods on the returned object to stream messages and /// to close the connection and wait for a final response. - internal func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { + internal func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { return try Echo_EchoCollectCallBase(channel) - .start(metadata: customMetadata ?? self.metadata, completion: completion) + .start(metadata: customMetadata, completion: completion) } /// Asynchronous. Bidirectional-streaming. /// Use methods on the returned object to stream messages, /// to wait for replies, and to close the connection. - internal func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { + internal func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { return try Echo_EchoUpdateCallBase(channel) - .start(metadata: customMetadata ?? self.metadata, completion: completion) + .start(metadata: customMetadata, completion: completion) } } @@ -206,31 +206,31 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService { var getRequests: [Echo_EchoRequest] = [] var getResponses: [Echo_EchoResponse] = [] - func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?) throws -> Echo_EchoResponse { + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse { getRequests.append(request) defer { getResponses.removeFirst() } return getResponses.first! } - func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { + func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall { fatalError("not implemented") } var expandRequests: [Echo_EchoRequest] = [] var expandCalls: [Echo_EchoExpandCall] = [] - func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { + func expand(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoExpandCall { expandRequests.append(request) defer { expandCalls.removeFirst() } return expandCalls.first! } var collectCalls: [Echo_EchoCollectCall] = [] - func collect(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { + func collect(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoCollectCall { defer { collectCalls.removeFirst() } return collectCalls.first! } var updateCalls: [Echo_EchoUpdateCall] = [] - func update(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { + func update(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> Echo_EchoUpdateCall { defer { updateCalls.removeFirst() } return updateCalls.first! } diff --git a/Sources/Examples/Echo/Generated/echo.pb.swift b/Sources/Examples/Echo/Generated/echo.pb.swift index 54afebc3a..82b69394e 100644 --- a/Sources/Examples/Echo/Generated/echo.pb.swift +++ b/Sources/Examples/Echo/Generated/echo.pb.swift @@ -33,10 +33,8 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP typealias Version = _2 } -struct Echo_EchoRequest { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. +struct Echo_EchoRequest: SwiftProtobuf.Message { + static let protoMessageName: String = _protobuf_package + ".EchoRequest" /// The text of a message to be echoed. var text: String = String() @@ -44,31 +42,11 @@ struct Echo_EchoRequest { var unknownFields = SwiftProtobuf.UnknownStorage() init() {} -} - -struct Echo_EchoResponse { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The text of an echo response. - var text: String = String() - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "echo" - -extension Echo_EchoRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = _protobuf_package + ".EchoRequest" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] + /// Used by the decoding initializers in the SwiftProtobuf library, not generally + /// used directly. `init(serializedData:)`, `init(jsonUTF8Data:)`, and other decoding + /// initializers are defined in the SwiftProtobuf library. See the Message and + /// Message+*Additions` files. mutating func decodeMessage(decoder: inout D) throws { while let fieldNumber = try decoder.nextFieldNumber() { switch fieldNumber { @@ -78,26 +56,32 @@ extension Echo_EchoRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImpleme } } + /// Used by the encoding methods of the SwiftProtobuf library, not generally + /// used directly. `Message.serializedData()`, `Message.jsonUTF8Data()`, and + /// other serializer methods are defined in the SwiftProtobuf library. See the + /// `Message` and `Message+*Additions` files. func traverse(visitor: inout V) throws { if !self.text.isEmpty { try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) } try unknownFields.traverse(visitor: &visitor) } - - static func ==(lhs: Echo_EchoRequest, rhs: Echo_EchoRequest) -> Bool { - if lhs.text != rhs.text {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } } -extension Echo_EchoResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { +struct Echo_EchoResponse: SwiftProtobuf.Message { static let protoMessageName: String = _protobuf_package + ".EchoResponse" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "text"), - ] + /// The text of an echo response. + var text: String = String() + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} + + /// Used by the decoding initializers in the SwiftProtobuf library, not generally + /// used directly. `init(serializedData:)`, `init(jsonUTF8Data:)`, and other decoding + /// initializers are defined in the SwiftProtobuf library. See the Message and + /// Message+*Additions` files. mutating func decodeMessage(decoder: inout D) throws { while let fieldNumber = try decoder.nextFieldNumber() { switch fieldNumber { @@ -107,16 +91,42 @@ extension Echo_EchoResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplem } } + /// Used by the encoding methods of the SwiftProtobuf library, not generally + /// used directly. `Message.serializedData()`, `Message.jsonUTF8Data()`, and + /// other serializer methods are defined in the SwiftProtobuf library. See the + /// `Message` and `Message+*Additions` files. func traverse(visitor: inout V) throws { if !self.text.isEmpty { try visitor.visitSingularStringField(value: self.text, fieldNumber: 1) } try unknownFields.traverse(visitor: &visitor) } +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "echo" + +extension Echo_EchoRequest: SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "text"), + ] - static func ==(lhs: Echo_EchoResponse, rhs: Echo_EchoResponse) -> Bool { - if lhs.text != rhs.text {return false} - if lhs.unknownFields != rhs.unknownFields {return false} + func _protobuf_generated_isEqualTo(other: Echo_EchoRequest) -> Bool { + if self.text != other.text {return false} + if unknownFields != other.unknownFields {return false} return true } } + +extension Echo_EchoResponse: SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "text"), + ] + + func _protobuf_generated_isEqualTo(other: Echo_EchoResponse) -> Bool { + if self.text != other.text {return false} + if unknownFields != other.unknownFields {return false} + return true + } +} \ No newline at end of file diff --git a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift index 2ebb604f8..66b6d383a 100644 --- a/Sources/protoc-gen-swiftgrpc/Generator-Client.swift +++ b/Sources/protoc-gen-swiftgrpc/Generator-Client.swift @@ -161,27 +161,27 @@ extension Generator { case .unary: if synchronousCode { println("/// Synchronous. Unary.") - println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName)") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata) throws -> \(methodOutputName)") } if asynchronousCode { println("/// Asynchronous. Unary.") - println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName)") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName)") } case .serverStreaming: println("/// Asynchronous. Server-streaming.") println("/// Send the initial message.") println("/// Use methods on the returned object to get streamed responses.") - println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName)") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName)") case .clientStreaming: println("/// Asynchronous. Client-streaming.") println("/// Use methods on the returned object to stream messages and") println("/// to close the connection and wait for a final response.") - println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName)") + println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName)") case .bidirectionalStreaming: println("/// Asynchronous. Bidirectional-streaming.") println("/// Use methods on the returned object to stream messages,") println("/// to wait for replies, and to close the connection.") - println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName)") + println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName)") } println() } @@ -190,7 +190,7 @@ extension Generator { } private func printServiceClientProtocolExtension(asynchronousCode: Bool, - synchronousCode: Bool) { + synchronousCode: Bool) { println("\(options.visibility.sourceSnippet) extension \(serviceClassName) {") indent() for method in service.methods { @@ -251,22 +251,22 @@ extension Generator { case .unary: if synchronousCode { println("/// Synchronous. Unary.") - println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName) {") + println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata) throws -> \(methodOutputName) {") indent() println("return try \(callName)Base(channel)") indent() - println(".run(request: request, metadata: customMetadata ?? self.metadata)") + println(".run(request: request, metadata: customMetadata)") outdent() outdent() println("}") } if asynchronousCode { println("/// Asynchronous. Unary.") - println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") + println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") indent() - println(".start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)") + println(".start(request: request, metadata: customMetadata, completion: completion)") outdent() outdent() println("}") @@ -275,11 +275,11 @@ extension Generator { println("/// Asynchronous. Server-streaming.") println("/// Send the initial message.") println("/// Use methods on the returned object to get streamed responses.") - println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") indent() - println(".start(request: request, metadata: customMetadata ?? self.metadata, completion: completion)") + println(".start(request: request, metadata: customMetadata, completion: completion)") outdent() outdent() println("}") @@ -287,11 +287,11 @@ extension Generator { println("/// Asynchronous. Client-streaming.") println("/// Use methods on the returned object to stream messages and") println("/// to close the connection and wait for a final response.") - println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") indent() - println(".start(metadata: customMetadata ?? self.metadata, completion: completion)") + println(".start(metadata: customMetadata, completion: completion)") outdent() outdent() println("}") @@ -299,11 +299,11 @@ extension Generator { println("/// Asynchronous. Bidirectional-streaming.") println("/// Use methods on the returned object to stream messages,") println("/// to wait for replies, and to close the connection.") - println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("\(access) func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("return try \(callName)Base(channel)") indent() - println(".start(metadata: customMetadata ?? self.metadata, completion: completion)") + println(".start(metadata: customMetadata, completion: completion)") outdent() outdent() println("}") @@ -323,14 +323,14 @@ extension Generator { case .unary: println("var \(methodFunctionName)Requests: [\(methodInputName)] = []") println("var \(methodFunctionName)Responses: [\(methodOutputName)] = []") - println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?) throws -> \(methodOutputName) {") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata) throws -> \(methodOutputName) {") indent() println("\(methodFunctionName)Requests.append(request)") println("defer { \(methodFunctionName)Responses.removeFirst() }") println("return \(methodFunctionName)Responses.first!") outdent() println("}") - println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {") indent() println("fatalError(\"not implemented\")") outdent() @@ -338,7 +338,7 @@ extension Generator { case .serverStreaming: println("var \(methodFunctionName)Requests: [\(methodInputName)] = []") println("var \(methodFunctionName)Calls: [\(callName)] = []") - println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("\(methodFunctionName)Requests.append(request)") println("defer { \(methodFunctionName)Calls.removeFirst() }") @@ -347,7 +347,7 @@ extension Generator { println("}") case .clientStreaming: println("var \(methodFunctionName)Calls: [\(callName)] = []") - println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("defer { \(methodFunctionName)Calls.removeFirst() }") println("return \(methodFunctionName)Calls.first!") @@ -355,7 +355,7 @@ extension Generator { println("}") case .bidirectionalStreaming: println("var \(methodFunctionName)Calls: [\(callName)] = []") - println("func \(methodFunctionName)(metadata customMetadata: Metadata?, completion: ((CallResult) -> Void)?) throws -> \(callName) {") + println("func \(methodFunctionName)(metadata customMetadata: Metadata, completion: ((CallResult) -> Void)?) throws -> \(callName) {") indent() println("defer { \(methodFunctionName)Calls.removeFirst() }") println("return \(methodFunctionName)Calls.first!") From 4a27b25f3063ac16b291dab19d4d6f6a3aa8b2e7 Mon Sep 17 00:00:00 2001 From: Taeho Kim Date: Wed, 30 Jan 2019 18:30:11 -0800 Subject: [PATCH 8/8] Add newline --- Sources/Examples/Echo/Generated/echo.pb.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Examples/Echo/Generated/echo.pb.swift b/Sources/Examples/Echo/Generated/echo.pb.swift index 82b69394e..aa7466d35 100644 --- a/Sources/Examples/Echo/Generated/echo.pb.swift +++ b/Sources/Examples/Echo/Generated/echo.pb.swift @@ -129,4 +129,4 @@ extension Echo_EchoResponse: SwiftProtobuf._MessageImplementationBase, SwiftProt if unknownFields != other.unknownFields {return false} return true } -} \ No newline at end of file +}