main.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2016 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. import SwiftProtobuf
  16. import PluginLibrary
  17. func main() throws {
  18. var response = Google_Protobuf_Compiler_CodeGeneratorResponse()
  19. var log = ""
  20. let rawRequest = try Stdin.readall()
  21. let request = try Google_Protobuf_Compiler_CodeGeneratorRequest(protobuf: rawRequest)
  22. for protoFile in request.protoFile {
  23. log += "File \(protoFile.name!)\n"
  24. for service in protoFile.service {
  25. log += "Service \(service.name!)\n"
  26. for method in service.method {
  27. log += " Method \(method.name!)\n"
  28. log += " input \(method.inputType!)\n"
  29. log += " output \(method.outputType!)\n"
  30. log += " client_streaming \(method.clientStreaming!)\n"
  31. log += " server_streaming \(method.serverStreaming!)\n"
  32. }
  33. log += " Options \(service.options)\n"
  34. }
  35. }
  36. var logfile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
  37. logfile.name = "swiftgrpc.log"
  38. logfile.content = log
  39. response.file.append(logfile)
  40. let serializedResponse = try response.serializeProtobuf()
  41. Stdout.write(bytes: serializedResponse)
  42. }
  43. try main()